This server implements the MCP specification, enabling AI models to expose tools, resources, and prompts through a standardized interface. Key features include:
- Asynchronous communication using reactive programming patterns
- Dynamic tool registration and management
- Resource handling with URI-based addressing
- Prompt template management
- Real-time client notifications for state changes
- Structured logging with configurable severity levels
- Support for client-side AI model sampling
The server follows a lifecycle:
- Initialization - Accepts client connections and negotiates capabilities
- Normal Operation - Handles client requests and sends notifications
- Graceful Shutdown - Ensures clean connection termination
This implementation uses Project Reactor for non-blocking operations, making it suitable for high-throughput scenarios and reactive applications. All operations return Mono or Flux types that can be composed into reactive pipelines.
The server supports runtime modification of its capabilities through methods like
addTool(io.modelcontextprotocol.server.McpServerFeatures.AsyncToolSpecification), addResource(io.modelcontextprotocol.server.McpServerFeatures.AsyncResourceSpecification), and addPrompt(io.modelcontextprotocol.server.McpServerFeatures.AsyncPromptSpecification), automatically notifying
connected clients of changes when configured to do so.
- Author:
- Christian Tzolov, Dariusz Jędrzejczyk
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Mono<Void>addPrompt(McpServerFeatures.AsyncPromptSpecification promptSpecification) Add a new prompt handler at runtime.reactor.core.publisher.Mono<Void>addResource(McpServerFeatures.AsyncResourceSpecification resourceHandler) Add a new resource handler at runtime.reactor.core.publisher.Mono<Void>addTool(McpServerFeatures.AsyncToolSpecification toolSpecification) Add a new tool specification at runtime.voidclose()Close the server immediately.reactor.core.publisher.Mono<Void>Gracefully closes the server, allowing any in-progress operations to complete.Get the server capabilities that define the supported features and functionality.Get the server implementation information.reactor.core.publisher.Mono<Void>loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification) Deprecated.reactor.core.publisher.Mono<Void>Notifies clients that the list of available prompts has changed.reactor.core.publisher.Mono<Void>Notifies clients that the list of available resources has changed.reactor.core.publisher.Mono<Void>Notifies clients that the list of available tools has changed.reactor.core.publisher.Mono<Void>removePrompt(String promptName) Remove a prompt handler at runtime.reactor.core.publisher.Mono<Void>removeResource(String resourceUri) Remove a resource handler at runtime.reactor.core.publisher.Mono<Void>removeTool(String toolName) Remove a tool handler at runtime.
-
Method Details
-
getServerCapabilities
Get the server capabilities that define the supported features and functionality.- Returns:
- The server capabilities
-
getServerInfo
Get the server implementation information.- Returns:
- The server implementation details
-
closeGracefully
Gracefully closes the server, allowing any in-progress operations to complete.- Returns:
- A Mono that completes when the server has been closed
-
close
public void close()Close the server immediately. -
addTool
public reactor.core.publisher.Mono<Void> addTool(McpServerFeatures.AsyncToolSpecification toolSpecification) Add a new tool specification at runtime.- Parameters:
toolSpecification- The tool specification to add- Returns:
- Mono that completes when clients have been notified of the change
-
removeTool
Remove a tool handler at runtime.- Parameters:
toolName- The name of the tool handler to remove- Returns:
- Mono that completes when clients have been notified of the change
-
notifyToolsListChanged
Notifies clients that the list of available tools has changed.- Returns:
- A Mono that completes when all clients have been notified
-
addResource
public reactor.core.publisher.Mono<Void> addResource(McpServerFeatures.AsyncResourceSpecification resourceHandler) Add a new resource handler at runtime.- Parameters:
resourceHandler- The resource handler to add- Returns:
- Mono that completes when clients have been notified of the change
-
removeResource
Remove a resource handler at runtime.- Parameters:
resourceUri- The URI of the resource handler to remove- Returns:
- Mono that completes when clients have been notified of the change
-
notifyResourcesListChanged
Notifies clients that the list of available resources has changed.- Returns:
- A Mono that completes when all clients have been notified
-
addPrompt
public reactor.core.publisher.Mono<Void> addPrompt(McpServerFeatures.AsyncPromptSpecification promptSpecification) Add a new prompt handler at runtime.- Parameters:
promptSpecification- The prompt handler to add- Returns:
- Mono that completes when clients have been notified of the change
-
removePrompt
Remove a prompt handler at runtime.- Parameters:
promptName- The name of the prompt handler to remove- Returns:
- Mono that completes when clients have been notified of the change
-
notifyPromptsListChanged
Notifies clients that the list of available prompts has changed.- Returns:
- A Mono that completes when all clients have been notified
-
loggingNotification
@Deprecated public reactor.core.publisher.Mono<Void> loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification) Deprecated.This implementation would, incorrectly, broadcast the logging message to all connected clients, using a single minLoggingLevel for all of them. Similar to the sampling and roots, the logging level should be set per client session and use the ServerExchange to send the logging message to the right client.- Parameters:
loggingMessageNotification- The logging message to send- Returns:
- A Mono that completes when the notification has been sent
-
McpAsyncServerExchange.loggingNotification(LoggingMessageNotification)instead.