McpAsyncServer to provide blocking operations. This class delegates all
operations to an underlying async server instance while providing a simpler,
synchronous API for scenarios where reactive programming is not required.
The MCP server enables AI models to expose tools, resources, and prompts through a standardized interface. Key features available through this synchronous API include:
- Tool registration and management for extending AI model capabilities
- Resource handling with URI-based addressing for providing context
- Prompt template management for standardized interactions
- Real-time client notifications for state changes
- Structured logging with configurable severity levels
- Support for client-side AI model sampling
While McpAsyncServer uses Project Reactor's Mono and Flux types for
non-blocking operations, this class converts those into blocking calls, making it more
suitable for:
- Traditional synchronous applications
- Simple scripting scenarios
- Testing and debugging
- Cases where reactive programming adds unnecessary complexity
The server supports runtime modification of its capabilities through methods like
addTool(io.modelcontextprotocol.server.McpServerFeatures.SyncToolRegistration), addResource(io.modelcontextprotocol.server.McpServerFeatures.SyncResourceRegistration), and addPrompt(io.modelcontextprotocol.server.McpServerFeatures.SyncPromptRegistration), automatically notifying
connected clients of changes when configured to do so.
- Author:
- Christian Tzolov, Dariusz Jędrzejczyk
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMcpSyncServer(McpAsyncServer asyncServer) Creates a new synchronous server that wraps the provided async server. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPrompt(McpServerFeatures.SyncPromptRegistration promptRegistration) Deprecated.This method will be removed in 0.9.0.voidaddPrompt(McpServerFeatures.SyncPromptSpecification promptSpecification) Add a new prompt handler.voidaddResource(McpServerFeatures.SyncResourceRegistration resourceHandler) Deprecated.This method will be removed in 0.9.0.voidaddResource(McpServerFeatures.SyncResourceSpecification resourceHandler) Add a new resource handler.voidaddTool(McpServerFeatures.SyncToolRegistration toolHandler) Deprecated.This method will be removed in 0.9.0.voidaddTool(McpServerFeatures.SyncToolSpecification toolHandler) Add a new tool handler.voidclose()Close the server immediately.voidClose the server gracefully.createMessage(McpSchema.CreateMessageRequest createMessageRequest) Deprecated.This method will be removed in 0.9.0.Get the underlying async server instance.Deprecated.This method will be removed in 0.9.0.Deprecated.This method will be removed in 0.9.0.Get the server capabilities that define the supported features and functionality.Get the server implementation information.Deprecated.This method will be removed in 0.9.0.Deprecated.This method will be removed in 0.9.0.voidloggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification) Send a logging message notification to all clients.voidNotify clients that the list of available prompts has changed.voidNotify clients that the list of available resources has changed.voidNotify clients that the list of available tools has changed.voidremovePrompt(String promptName) Remove a prompt handler.voidremoveResource(String resourceUri) Remove a resource handler.voidremoveTool(String toolName) Remove a tool handler.
-
Constructor Details
-
McpSyncServer
Creates a new synchronous server that wraps the provided async server.- Parameters:
asyncServer- The async server to wrap
-
-
Method Details
-
listRoots
Deprecated.This method will be removed in 0.9.0. UseMcpSyncServerExchange.listRoots().Retrieves the list of all roots provided by the client.- Returns:
- The list of roots
-
listRoots
Deprecated.This method will be removed in 0.9.0. UseMcpSyncServerExchange.listRoots(String).Retrieves a paginated list of roots provided by the server.- Parameters:
cursor- Optional pagination cursor from a previous list request- Returns:
- The list of roots
-
addTool
Deprecated.This method will be removed in 0.9.0. UseaddTool(McpServerFeatures.SyncToolSpecification).Add a new tool handler.- Parameters:
toolHandler- The tool handler to add
-
addTool
Add a new tool handler.- Parameters:
toolHandler- The tool handler to add
-
removeTool
Remove a tool handler.- Parameters:
toolName- The name of the tool handler to remove
-
addResource
Deprecated.This method will be removed in 0.9.0. UseaddResource(McpServerFeatures.SyncResourceSpecification).Add a new resource handler.- Parameters:
resourceHandler- The resource handler to add
-
addResource
Add a new resource handler.- Parameters:
resourceHandler- The resource handler to add
-
removeResource
Remove a resource handler.- Parameters:
resourceUri- The URI of the resource handler to remove
-
addPrompt
Deprecated.This method will be removed in 0.9.0. UseaddPrompt(McpServerFeatures.SyncPromptSpecification).Add a new prompt handler.- Parameters:
promptRegistration- The prompt registration to add
-
addPrompt
Add a new prompt handler.- Parameters:
promptSpecification- The prompt specification to add
-
removePrompt
Remove a prompt handler.- Parameters:
promptName- The name of the prompt handler to remove
-
notifyToolsListChanged
public void notifyToolsListChanged()Notify clients that the list of available tools has changed. -
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 method will be removed in 0.9.0. UseMcpSyncServerExchange.getClientCapabilities().Get the client capabilities that define the supported features and functionality.- Returns:
- The client capabilities
-
getClientInfo
Deprecated.This method will be removed in 0.9.0. UseMcpSyncServerExchange.getClientInfo().Get the client implementation information.- Returns:
- The client implementation details
-
notifyResourcesListChanged
public void notifyResourcesListChanged()Notify clients that the list of available resources has changed. -
notifyPromptsListChanged
public void notifyPromptsListChanged()Notify clients that the list of available prompts has changed. -
loggingNotification
Send a logging message notification to all clients.- Parameters:
loggingMessageNotification- The logging message notification to send
-
closeGracefully
public void closeGracefully()Close the server gracefully. -
close
public void close()Close the server immediately. -
getAsyncServer
Get the underlying async server instance.- Returns:
- The wrapped async server
-
createMessage
@Deprecated public McpSchema.CreateMessageResult createMessage(McpSchema.CreateMessageRequest createMessageRequest) Deprecated.This method will be removed in 0.9.0. UseMcpSyncServerExchange.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.
Unlike its async counterpart, this method blocks until the message creation is complete, making it easier to use in synchronous code paths.
-