public class McpAsyncServer
extends java.lang.Object
This server implements the MCP specification, enabling AI models to expose tools, resources, and prompts through a standardized interface. Key features include:
The server follows a lifecycle:
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.
McpServer
,
McpSchema
,
McpClientSession
限定符和类型 | 方法和说明 |
---|---|
reactor.core.publisher.Mono<java.lang.Void> |
addPrompt(McpServerFeatures.AsyncPromptSpecification promptSpecification)
Add a new prompt handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
addResource(McpServerFeatures.AsyncResourceSpecification resourceHandler)
Add a new resource handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
addResourceTemplate(McpServerFeatures.AsyncResourceTemplateSpecification resourceHandler)
Add a new resource template handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
addTool(McpServerFeatures.AsyncToolSpecification toolSpecification)
Add a new tool specification at runtime.
|
void |
close()
Close the server immediately.
|
reactor.core.publisher.Mono<java.lang.Void> |
closeGracefully()
Gracefully closes the server, allowing any in-progress operations to complete.
|
McpSchema.ServerCapabilities |
getServerCapabilities()
Get the server capabilities that define the supported features and functionality.
|
McpSchema.Implementation |
getServerInfo()
Get the server implementation information.
|
reactor.core.publisher.Mono<java.lang.Void> |
loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification)
Send a logging message notification to all connected clients.
|
reactor.core.publisher.Mono<java.lang.Void> |
notifyPromptsListChanged()
Notifies clients that the list of available prompts has changed.
|
reactor.core.publisher.Mono<java.lang.Void> |
notifyResourcesListChanged()
Notifies clients that the list of available resources has changed.
|
reactor.core.publisher.Mono<java.lang.Void> |
notifyToolsListChanged()
Notifies clients that the list of available tools has changed.
|
reactor.core.publisher.Mono<java.lang.Void> |
removePrompt(java.lang.String promptName)
Remove a prompt handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
removeResource(java.lang.String resourceUri)
Remove a resource handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
removeResourceTemplate(java.lang.String resourceUri)
Remove a resource template handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
removeTool(java.lang.String toolName)
Remove a tool handler at runtime.
|
public McpSchema.ServerCapabilities getServerCapabilities()
public McpSchema.Implementation getServerInfo()
public reactor.core.publisher.Mono<java.lang.Void> closeGracefully()
public void close()
public reactor.core.publisher.Mono<java.lang.Void> addTool(McpServerFeatures.AsyncToolSpecification toolSpecification)
toolSpecification
- The tool specification to addpublic reactor.core.publisher.Mono<java.lang.Void> removeTool(java.lang.String toolName)
toolName
- The name of the tool handler to removepublic reactor.core.publisher.Mono<java.lang.Void> notifyToolsListChanged()
public reactor.core.publisher.Mono<java.lang.Void> addResource(McpServerFeatures.AsyncResourceSpecification resourceHandler)
resourceHandler
- The resource handler to addpublic reactor.core.publisher.Mono<java.lang.Void> removeResource(java.lang.String resourceUri)
resourceUri
- The URI of the resource handler to removepublic reactor.core.publisher.Mono<java.lang.Void> notifyResourcesListChanged()
public reactor.core.publisher.Mono<java.lang.Void> addResourceTemplate(McpServerFeatures.AsyncResourceTemplateSpecification resourceHandler)
resourceHandler
- The resource template handler to addpublic reactor.core.publisher.Mono<java.lang.Void> removeResourceTemplate(java.lang.String resourceUri)
resourceUri
- The URI of the resource template handler to removepublic reactor.core.publisher.Mono<java.lang.Void> addPrompt(McpServerFeatures.AsyncPromptSpecification promptSpecification)
promptSpecification
- The prompt handler to addpublic reactor.core.publisher.Mono<java.lang.Void> removePrompt(java.lang.String promptName)
promptName
- The name of the prompt handler to removepublic reactor.core.publisher.Mono<java.lang.Void> notifyPromptsListChanged()
public reactor.core.publisher.Mono<java.lang.Void> loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification)
loggingMessageNotification
- The logging message to send