Package io.modelcontextprotocol.server
Class McpServer.AsyncSpec
java.lang.Object
io.modelcontextprotocol.server.McpServer.AsyncSpec
- Enclosing interface:
- McpServer
Deprecated.
Asynchronous server specification.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Deprecated.Builds an asynchronous MCP server that provides non-blocking operations.capabilities(McpSchema.ServerCapabilities serverCapabilities) Deprecated.Sets the server capabilities that will be advertised to clients during connection initialization.prompts(McpServerFeatures.AsyncPromptRegistration... prompts) Deprecated.Registers multiple prompts with their handlers using varargs.Deprecated.Registers multiple prompts with their handlers using a List.Deprecated.Registers multiple prompts with their handlers using a Map.resources(McpServerFeatures.AsyncResourceRegistration... resourceRegistrations) Deprecated.Registers multiple resources with their handlers using varargs.resources(List<McpServerFeatures.AsyncResourceRegistration> resourceRegsitrations) Deprecated.Registers multiple resources with their handlers using a List.resources(Map<String, McpServerFeatures.AsyncResourceRegistration> resourceRegsitrations) Deprecated.Registers multiple resources with their handlers using a Map.resourceTemplates(McpSchema.ResourceTemplate... resourceTemplates) Deprecated.Sets the resource templates using varargs for convenience.resourceTemplates(List<McpSchema.ResourceTemplate> resourceTemplates) Deprecated.Sets the resource templates that define patterns for dynamic resource access.rootsChangeConsumer(Function<List<McpSchema.Root>, reactor.core.publisher.Mono<Void>> consumer) Deprecated.Registers a consumer that will be notified when the list of roots changes.rootsChangeConsumers(Function<List<McpSchema.Root>, reactor.core.publisher.Mono<Void>>... consumers) Deprecated.Registers multiple consumers that will be notified when the list of roots changes using varargs.rootsChangeConsumers(List<Function<List<McpSchema.Root>, reactor.core.publisher.Mono<Void>>> consumers) Deprecated.Registers multiple consumers that will be notified when the list of roots changes.serverInfo(McpSchema.Implementation serverInfo) Deprecated.Sets the server implementation information that will be shared with clients during connection initialization.serverInfo(String name, String version) Deprecated.Sets the server implementation information using name and version strings.tool(McpSchema.Tool tool, Function<Map<String, Object>, reactor.core.publisher.Mono<McpSchema.CallToolResult>> handler) Deprecated.Adds a single tool with its implementation handler to the server.tools(McpServerFeatures.AsyncToolRegistration... toolRegistrations) Deprecated.Adds multiple tools with their handlers to the server using varargs.tools(List<McpServerFeatures.AsyncToolRegistration> toolRegistrations) Deprecated.Adds multiple tools with their handlers to the server using a List.
-
Method Details
-
serverInfo
Deprecated.Sets the server implementation information that will be shared with clients during connection initialization. This helps with version compatibility, debugging, and server identification.- Parameters:
serverInfo- The server implementation details including name and version. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if serverInfo is null
-
serverInfo
Deprecated.Sets the server implementation information using name and version strings. This is a convenience method alternative toserverInfo(McpSchema.Implementation).- Parameters:
name- The server name. Must not be null or empty.version- The server version. Must not be null or empty.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if name or version is null or empty- See Also:
-
capabilities
Deprecated.Sets the server capabilities that will be advertised to clients during connection initialization. Capabilities define what features the server supports, such as:- Tool execution
- Resource access
- Prompt handling
- Streaming responses
- Batch operations
- Parameters:
serverCapabilities- The server capabilities configuration. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if serverCapabilities is null
-
tool
public McpServer.AsyncSpec tool(McpSchema.Tool tool, Function<Map<String, Object>, reactor.core.publisher.Mono<McpSchema.CallToolResult>> handler) Deprecated.Adds a single tool with its implementation handler to the server. This is a convenience method for registering individual tools without creating aMcpServerFeatures.AsyncToolRegistrationexplicitly.Example usage:
.tool( new Tool("calculator", "Performs calculations", schema), args -> Mono.just(new CallToolResult("Result: " + calculate(args))) )- Parameters:
tool- The tool definition including name, description, and schema. Must not be null.handler- The function that implements the tool's logic. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if tool or handler is null
-
tools
Deprecated.Adds multiple tools with their handlers to the server using a List. This method is useful when tools are dynamically generated or loaded from a configuration source.- Parameters:
toolRegistrations- The list of tool registrations to add. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if toolRegistrations is null- See Also:
-
tools
Deprecated.Adds multiple tools with their handlers to the server using varargs. This method provides a convenient way to register multiple tools inline.Example usage:
.tools( new McpServerFeatures.AsyncToolRegistration(calculatorTool, calculatorHandler), new McpServerFeatures.AsyncToolRegistration(weatherTool, weatherHandler), new McpServerFeatures.AsyncToolRegistration(fileManagerTool, fileManagerHandler) )- Parameters:
toolRegistrations- The tool registrations to add. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if toolRegistrations is null- See Also:
-
resources
public McpServer.AsyncSpec resources(Map<String, McpServerFeatures.AsyncResourceRegistration> resourceRegsitrations) Deprecated.Registers multiple resources with their handlers using a Map. This method is useful when resources are dynamically generated or loaded from a configuration source.- Parameters:
resourceRegsitrations- Map of resource name to registration. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if resourceRegsitrations is null- See Also:
-
resources
public McpServer.AsyncSpec resources(List<McpServerFeatures.AsyncResourceRegistration> resourceRegsitrations) Deprecated.Registers multiple resources with their handlers using a List. This method is useful when resources need to be added in bulk from a collection.- Parameters:
resourceRegsitrations- List of resource registrations. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if resourceRegsitrations is null- See Also:
-
resources
public McpServer.AsyncSpec resources(McpServerFeatures.AsyncResourceRegistration... resourceRegistrations) Deprecated.Registers multiple resources with their handlers using varargs. This method provides a convenient way to register multiple resources inline.Example usage:
.resources( new McpServerFeatures.AsyncResourceRegistration(fileResource, fileHandler), new McpServerFeatures.AsyncResourceRegistration(dbResource, dbHandler), new McpServerFeatures.AsyncResourceRegistration(apiResource, apiHandler) )- Parameters:
resourceRegistrations- The resource registrations to add. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if resourceRegistrations is null
-
resourceTemplates
Deprecated.Sets the resource templates that define patterns for dynamic resource access. Templates use URI patterns with placeholders that can be filled at runtime.Example usage:
.resourceTemplates( new ResourceTemplate("file://{path}", "Access files by path"), new ResourceTemplate("db://{table}/{id}", "Access database records") )- Parameters:
resourceTemplates- List of resource templates. If null, clears existing templates.- Returns:
- This builder instance for method chaining
- See Also:
-
resourceTemplates
Deprecated.Sets the resource templates using varargs for convenience. This is an alternative toresourceTemplates(List).- Parameters:
resourceTemplates- The resource templates to set.- Returns:
- This builder instance for method chaining
- See Also:
-
prompts
Deprecated.Registers multiple prompts with their handlers using a Map. This method is useful when prompts are dynamically generated or loaded from a configuration source.Example usage:
.prompts(Map.of("analysis", new McpServerFeatures.AsyncPromptRegistration( new Prompt("analysis", "Code analysis template"), request -> Mono.just(new GetPromptResult(generateAnalysisPrompt(request))) )));- Parameters:
prompts- Map of prompt name to registration. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if prompts is null
-
prompts
Deprecated.Registers multiple prompts with their handlers using a List. This method is useful when prompts need to be added in bulk from a collection.- Parameters:
prompts- List of prompt registrations. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if prompts is null- See Also:
-
prompts
Deprecated.Registers multiple prompts with their handlers using varargs. This method provides a convenient way to register multiple prompts inline.Example usage:
.prompts( new McpServerFeatures.AsyncPromptRegistration(analysisPrompt, analysisHandler), new McpServerFeatures.AsyncPromptRegistration(summaryPrompt, summaryHandler), new McpServerFeatures.AsyncPromptRegistration(reviewPrompt, reviewHandler) )- Parameters:
prompts- The prompt registrations to add. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if prompts is null
-
rootsChangeConsumer
public McpServer.AsyncSpec rootsChangeConsumer(Function<List<McpSchema.Root>, reactor.core.publisher.Mono<Void>> consumer) Deprecated.Registers a consumer that will be notified when the list of roots changes. This is useful for updating resource availability dynamically, such as when new files are added or removed.- Parameters:
consumer- The consumer to register. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if consumer is null
-
rootsChangeConsumers
public McpServer.AsyncSpec rootsChangeConsumers(List<Function<List<McpSchema.Root>, reactor.core.publisher.Mono<Void>>> consumers) Deprecated.Registers multiple consumers that will be notified when the list of roots changes. This method is useful when multiple consumers need to be registered at once.- Parameters:
consumers- The list of consumers to register. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if consumers is null
-
rootsChangeConsumers
public McpServer.AsyncSpec rootsChangeConsumers(Function<List<McpSchema.Root>, reactor.core.publisher.Mono<Void>>... consumers) Deprecated.Registers multiple consumers that will be notified when the list of roots changes using varargs. This method provides a convenient way to register multiple consumers inline.- Parameters:
consumers- The consumers to register. Must not be null.- Returns:
- This builder instance for method chaining
- Throws:
IllegalArgumentException- if consumers is null
-
build
Deprecated.Builds an asynchronous MCP server that provides non-blocking operations.- Returns:
- A new instance of
McpAsyncServerconfigured with this builder's settings
-