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.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.
McpServer
,
McpSchema
,
McpClientSession
限定符和类型 | 方法和说明 |
---|---|
reactor.core.publisher.Mono<java.lang.Void> |
addPrompt(McpServerFeatures.AsyncPromptRegistration promptRegistration)
已过时。
This method will be removed in 0.9.0. Use
addPrompt(McpServerFeatures.AsyncPromptSpecification) . |
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.AsyncResourceRegistration resourceHandler)
已过时。
This method will be removed in 0.9.0. Use
addResource(McpServerFeatures.AsyncResourceSpecification) . |
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.AsyncToolRegistration toolRegistration)
已过时。
This method will be removed in 0.9.0. Use
addTool(McpServerFeatures.AsyncToolSpecification) . |
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.
|
reactor.core.publisher.Mono<McpSchema.CreateMessageResult> |
createMessage(McpSchema.CreateMessageRequest createMessageRequest)
已过时。
This will be removed in 0.9.0. Use
McpAsyncServerExchange.createMessage(McpSchema.CreateMessageRequest) . |
McpSchema.ClientCapabilities |
getClientCapabilities()
已过时。
This will be removed in 0.9.0. Use
McpAsyncServerExchange.getClientCapabilities() . |
McpSchema.Implementation |
getClientInfo()
已过时。
This will be removed in 0.9.0. Use
McpAsyncServerExchange.getClientInfo() . |
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<McpSchema.ListRootsResult> |
listRoots()
已过时。
This will be removed in 0.9.0. Use
McpAsyncServerExchange.listRoots() . |
reactor.core.publisher.Mono<McpSchema.ListRootsResult> |
listRoots(java.lang.String cursor)
已过时。
This will be removed in 0.9.0. Use
McpAsyncServerExchange.listRoots(String) . |
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()
@Deprecated public McpSchema.ClientCapabilities getClientCapabilities()
McpAsyncServerExchange.getClientCapabilities()
.@Deprecated public McpSchema.Implementation getClientInfo()
McpAsyncServerExchange.getClientInfo()
.public reactor.core.publisher.Mono<java.lang.Void> closeGracefully()
public void close()
@Deprecated public reactor.core.publisher.Mono<McpSchema.ListRootsResult> listRoots()
McpAsyncServerExchange.listRoots()
.@Deprecated public reactor.core.publisher.Mono<McpSchema.ListRootsResult> listRoots(java.lang.String cursor)
McpAsyncServerExchange.listRoots(String)
.cursor
- Optional pagination cursor from a previous list request@Deprecated public reactor.core.publisher.Mono<java.lang.Void> addTool(McpServerFeatures.AsyncToolRegistration toolRegistration)
addTool(McpServerFeatures.AsyncToolSpecification)
.toolRegistration
- The tool registration to addpublic 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()
@Deprecated public reactor.core.publisher.Mono<java.lang.Void> addResource(McpServerFeatures.AsyncResourceRegistration resourceHandler)
addResource(McpServerFeatures.AsyncResourceSpecification)
.resourceHandler
- The resource handler to addpublic 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 remove@Deprecated public reactor.core.publisher.Mono<java.lang.Void> addPrompt(McpServerFeatures.AsyncPromptRegistration promptRegistration)
addPrompt(McpServerFeatures.AsyncPromptSpecification)
.promptRegistration
- The prompt handler to addpublic 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@Deprecated public reactor.core.publisher.Mono<McpSchema.CreateMessageResult> createMessage(McpSchema.CreateMessageRequest createMessageRequest)
McpAsyncServerExchange.createMessage(McpSchema.CreateMessageRequest)
.createMessageRequest
- The request to create a new messageMcpError
- if the client has not been initialized or does not support
sampling capabilitiesMcpError
- if the client does not support the createMessage methodMcpSchema.CreateMessageRequest
,
McpSchema.CreateMessageResult
,
Sampling
Specification