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
构造器和说明 |
---|
McpAsyncServer(McpServerTransportProvider mcpTransportProvider,
com.fasterxml.jackson.databind.ObjectMapper objectMapper,
McpServerFeatures.Async features,
java.time.Duration requestTimeout,
McpUriTemplateManagerFactory uriTemplateManagerFactory,
JsonSchemaValidator jsonSchemaValidator)
Create a new McpAsyncServer with the given transport provider and capabilities.
|
McpAsyncServer(McpStreamableServerTransportProvider mcpTransportProvider,
com.fasterxml.jackson.databind.ObjectMapper objectMapper,
McpServerFeatures.Async features,
java.time.Duration requestTimeout,
McpUriTemplateManagerFactory uriTemplateManagerFactory,
JsonSchemaValidator jsonSchemaValidator) |
限定符和类型 | 方法和说明 |
---|---|
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 resourceSpecification)
Add a new resource handler at runtime.
|
reactor.core.publisher.Mono<java.lang.Void> |
addTool(McpServerFeatures.AsyncToolSpecification toolSpecification)
Add a new tool call 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)
已过时。
Use
McpAsyncServerExchange#loggingNotification(LoggingMessageNotification)
instead. |
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> |
notifyResourcesUpdated(McpSchema.ResourcesUpdatedNotification resourcesUpdatedNotification)
Notifies clients that the resources have updated.
|
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> |
removeTool(java.lang.String toolName)
Remove a tool handler at runtime.
|
public McpAsyncServer(McpServerTransportProvider mcpTransportProvider, com.fasterxml.jackson.databind.ObjectMapper objectMapper, McpServerFeatures.Async features, java.time.Duration requestTimeout, McpUriTemplateManagerFactory uriTemplateManagerFactory, JsonSchemaValidator jsonSchemaValidator)
mcpTransportProvider
- The transport layer implementation for MCP
communication.features
- The MCP server supported features.objectMapper
- The ObjectMapper to use for JSON serialization/deserializationpublic McpAsyncServer(McpStreamableServerTransportProvider mcpTransportProvider, com.fasterxml.jackson.databind.ObjectMapper objectMapper, McpServerFeatures.Async features, java.time.Duration requestTimeout, McpUriTemplateManagerFactory uriTemplateManagerFactory, JsonSchemaValidator jsonSchemaValidator)
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 resourceSpecification)
resourceSpecification
- 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> notifyResourcesUpdated(McpSchema.ResourcesUpdatedNotification resourcesUpdatedNotification)
public 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()
@Deprecated public reactor.core.publisher.Mono<java.lang.Void> loggingNotification(McpSchema.LoggingMessageNotification loggingMessageNotification)
McpAsyncServerExchange#loggingNotification(LoggingMessageNotification)
instead.loggingMessageNotification
- The logging message to send