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.AsyncToolRegistration), addResource(io.modelcontextprotocol.server.McpServerFeatures.AsyncResourceRegistration), and addPrompt(io.modelcontextprotocol.server.McpServerFeatures.AsyncPromptRegistration), 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.AsyncPromptRegistration promptRegistration) Deprecated.This method will be removed in 0.9.0.reactor.core.publisher.Mono<Void>addPrompt(McpServerFeatures.AsyncPromptSpecification promptSpecification) Add a new prompt handler at runtime.reactor.core.publisher.Mono<Void>addResource(McpServerFeatures.AsyncResourceRegistration resourceHandler) Deprecated.This method will be removed in 0.9.0.reactor.core.publisher.Mono<Void>addResource(McpServerFeatures.AsyncResourceSpecification resourceHandler) Add a new resource handler at runtime.reactor.core.publisher.Mono<Void>addTool(McpServerFeatures.AsyncToolRegistration toolRegistration) Deprecated.This method will be removed in 0.9.0.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.reactor.core.publisher.Mono<McpSchema.CreateMessageResult>createMessage(McpSchema.CreateMessageRequest createMessageRequest) Deprecated.This will be removed in 0.9.0.Deprecated.This will be removed in 0.9.0.Deprecated.This will be removed in 0.9.0.Get the server capabilities that define the supported features and functionality.Get the server implementation information.reactor.core.publisher.Mono<McpSchema.ListRootsResult>Deprecated.This will be removed in 0.9.0.reactor.core.publisher.Mono<McpSchema.ListRootsResult>Deprecated.This will be removed in 0.9.0.reactor.core.publisher.Mono<Void>loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification) Send a logging message notification to all connected clients.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
-
getClientCapabilities
Deprecated.This will be removed in 0.9.0. UseMcpAsyncServerExchange.getClientCapabilities().Get the client capabilities that define the supported features and functionality.- Returns:
- The client capabilities
-
getClientInfo
Deprecated.This will be removed in 0.9.0. UseMcpAsyncServerExchange.getClientInfo().Get the client implementation information.- Returns:
- The client 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. -
listRoots
Deprecated.This will be removed in 0.9.0. UseMcpAsyncServerExchange.listRoots().Retrieves the list of all roots provided by the client.- Returns:
- A Mono that emits the list of roots result.
-
listRoots
Deprecated.This will be removed in 0.9.0. UseMcpAsyncServerExchange.listRoots(String).Retrieves a paginated list of roots provided by the server.- Parameters:
cursor- Optional pagination cursor from a previous list request- Returns:
- A Mono that emits the list of roots result containing
-
addTool
@Deprecated public reactor.core.publisher.Mono<Void> addTool(McpServerFeatures.AsyncToolRegistration toolRegistration) Deprecated.This method will be removed in 0.9.0. UseaddTool(McpServerFeatures.AsyncToolSpecification).Add a new tool registration at runtime.- Parameters:
toolRegistration- The tool registration to add- Returns:
- Mono that completes when clients have been notified of the change
-
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
@Deprecated public reactor.core.publisher.Mono<Void> addResource(McpServerFeatures.AsyncResourceRegistration resourceHandler) Deprecated.This method will be removed in 0.9.0. UseaddResource(McpServerFeatures.AsyncResourceSpecification).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
-
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
@Deprecated public reactor.core.publisher.Mono<Void> addPrompt(McpServerFeatures.AsyncPromptRegistration promptRegistration) Deprecated.This method will be removed in 0.9.0. UseaddPrompt(McpServerFeatures.AsyncPromptSpecification).Add a new prompt handler at runtime.- Parameters:
promptRegistration- The prompt handler to add- Returns:
- Mono that completes when clients have been notified of the change
-
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
public reactor.core.publisher.Mono<Void> loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification) Send a logging message notification to all connected clients. Messages below the current minimum logging level will be filtered out.- Parameters:
loggingMessageNotification- The logging message to send- Returns:
- A Mono that completes when the notification has been sent
-
createMessage
@Deprecated public reactor.core.publisher.Mono<McpSchema.CreateMessageResult> createMessage(McpSchema.CreateMessageRequest createMessageRequest) Deprecated.This will be removed in 0.9.0. UseMcpAsyncServerExchange.createMessage(McpSchema.CreateMessageRequest).Create a new message using the sampling capabilities of the client. The Model Context Protocol (MCP) provides a standardized way for servers to request LLM sampling (“completions” or “generations”) from language models via clients. This flow allows clients to maintain control over model access, selection, and permissions while enabling servers to leverage AI capabilities—with no server API keys necessary. Servers can request text or image-based interactions and optionally include context from MCP servers in their prompts.- Parameters:
createMessageRequest- The request to create a new message- Returns:
- A Mono that completes when the message has been created
- Throws:
McpError- if the client has not been initialized or does not support sampling capabilitiesMcpError- if the client does not support the createMessage method- See Also:
-