public static class McpServer.SyncSpecification
extends java.lang.Object
限定符和类型 | 方法和说明 |
---|---|
McpSyncServer |
build()
Builds a synchronous MCP server that provides blocking operations.
|
McpServer.SyncSpecification |
capabilities(McpSchema.ServerCapabilities serverCapabilities)
Sets the server capabilities that will be advertised to clients during
connection initialization.
|
McpServer.SyncSpecification |
objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
Sets the object mapper to use for serializing and deserializing JSON messages.
|
McpServer.SyncSpecification |
prompts(java.util.List<McpServerFeatures.SyncPromptSpecification> prompts)
Registers multiple prompts with their handlers using a List.
|
McpServer.SyncSpecification |
prompts(java.util.Map<java.lang.String,McpServerFeatures.SyncPromptSpecification> prompts)
Registers multiple prompts with their handlers using a Map.
|
McpServer.SyncSpecification |
prompts(McpServerFeatures.SyncPromptSpecification... prompts)
Registers multiple prompts with their handlers using varargs.
|
McpServer.SyncSpecification |
resources(java.util.List<McpServerFeatures.SyncResourceSpecification> resourceSpecifications)
Registers multiple resources with their handlers using a List.
|
McpServer.SyncSpecification |
resources(java.util.Map<java.lang.String,McpServerFeatures.SyncResourceSpecification> resourceSpecifications)
Registers multiple resources with their handlers using a Map.
|
McpServer.SyncSpecification |
resources(McpServerFeatures.SyncResourceSpecification... resourceSpecifications)
Registers multiple resources with their handlers using varargs.
|
McpServer.SyncSpecification |
resourceTemplates(java.util.List<McpServerFeatures.SyncResourceTemplateSpecification> resourceTemplates)
Sets the resource templates that define patterns for dynamic resource access.
|
McpServer.SyncSpecification |
resourceTemplates(McpServerFeatures.SyncResourceTemplateSpecification... resourceTemplates)
Sets the resource templates using varargs for convenience.
|
McpServer.SyncSpecification |
rootsChangeHandler(java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>> handler)
Registers a consumer that will be notified when the list of roots changes.
|
McpServer.SyncSpecification |
rootsChangeHandlers(java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>>... handlers)
Registers multiple consumers that will be notified when the list of roots
changes using varargs.
|
McpServer.SyncSpecification |
rootsChangeHandlers(java.util.List<java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>>> handlers)
Registers multiple consumers that will be notified when the list of roots
changes.
|
McpServer.SyncSpecification |
serverInfo(McpSchema.Implementation serverInfo)
Sets the server implementation information that will be shared with clients
during connection initialization.
|
McpServer.SyncSpecification |
serverInfo(java.lang.String name,
java.lang.String version)
Sets the server implementation information using name and version strings.
|
McpServer.SyncSpecification |
tool(McpSchema.Tool tool,
java.util.function.BiFunction<McpSyncServerExchange,java.util.Map<java.lang.String,java.lang.Object>,McpSchema.CallToolResult> handler)
Adds a single tool with its implementation handler to the server.
|
McpServer.SyncSpecification |
tools(java.util.List<McpServerFeatures.SyncToolSpecification> toolSpecifications)
Adds multiple tools with their handlers to the server using a List.
|
McpServer.SyncSpecification |
tools(McpServerFeatures.SyncToolSpecification... toolSpecifications)
Adds multiple tools with their handlers to the server using varargs.
|
public McpServer.SyncSpecification serverInfo(McpSchema.Implementation serverInfo)
serverInfo
- The server implementation details including name and version.
Must not be null.java.lang.IllegalArgumentException
- if serverInfo is nullpublic McpServer.SyncSpecification serverInfo(java.lang.String name, java.lang.String version)
serverInfo(McpSchema.Implementation)
.name
- The server name. Must not be null or empty.version
- The server version. Must not be null or empty.java.lang.IllegalArgumentException
- if name or version is null or emptyserverInfo(McpSchema.Implementation)
public McpServer.SyncSpecification capabilities(McpSchema.ServerCapabilities serverCapabilities)
serverCapabilities
- The server capabilities configuration. Must not be
null.java.lang.IllegalArgumentException
- if serverCapabilities is nullpublic McpServer.SyncSpecification tool(McpSchema.Tool tool, java.util.function.BiFunction<McpSyncServerExchange,java.util.Map<java.lang.String,java.lang.Object>,McpSchema.CallToolResult> handler)
McpServerFeatures.SyncToolSpecification
explicitly.
Example usage:
.tool(
new Tool("calculator", "Performs calculations", schema),
(exchange, args) -> new CallToolResult("Result: " + calculate(args))
)
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.
The function's first argument is an McpSyncServerExchange
upon which
the server can interact with the connected client. The second argument is the
list of arguments passed to the tool.java.lang.IllegalArgumentException
- if tool or handler is nullpublic McpServer.SyncSpecification tools(java.util.List<McpServerFeatures.SyncToolSpecification> toolSpecifications)
toolSpecifications
- The list of tool specifications to add. Must not be
null.java.lang.IllegalArgumentException
- if toolSpecifications is nulltools(McpServerFeatures.SyncToolSpecification...)
public McpServer.SyncSpecification tools(McpServerFeatures.SyncToolSpecification... toolSpecifications)
Example usage:
.tools(
new ToolSpecification(calculatorTool, calculatorHandler),
new ToolSpecification(weatherTool, weatherHandler),
new ToolSpecification(fileManagerTool, fileManagerHandler)
)
toolSpecifications
- The tool specifications to add. Must not be null.java.lang.IllegalArgumentException
- if toolSpecifications is nulltools(List)
public McpServer.SyncSpecification resources(java.util.Map<java.lang.String,McpServerFeatures.SyncResourceSpecification> resourceSpecifications)
resourceSpecifications
- Map of resource name to specification. Must not
be null.java.lang.IllegalArgumentException
- if resourceSpecifications is nullresources(McpServerFeatures.SyncResourceSpecification...)
public McpServer.SyncSpecification resources(java.util.List<McpServerFeatures.SyncResourceSpecification> resourceSpecifications)
resourceSpecifications
- List of resource specifications. Must not be
null.java.lang.IllegalArgumentException
- if resourceSpecifications is nullresources(McpServerFeatures.SyncResourceSpecification...)
public McpServer.SyncSpecification resources(McpServerFeatures.SyncResourceSpecification... resourceSpecifications)
Example usage:
.resources(
new ResourceSpecification(fileResource, fileHandler),
new ResourceSpecification(dbResource, dbHandler),
new ResourceSpecification(apiResource, apiHandler)
)
resourceSpecifications
- The resource specifications to add. Must not be
null.java.lang.IllegalArgumentException
- if resourceSpecifications is nullpublic McpServer.SyncSpecification resourceTemplates(java.util.List<McpServerFeatures.SyncResourceTemplateSpecification> resourceTemplates)
Example usage:
.resourceTemplates(
new ResourceTemplate("file://{path}", "Access files by path"),
new ResourceTemplate("db://{table}/{id}", "Access database records")
)
resourceTemplates
- List of resource templates. If null, clears existing
templates.java.lang.IllegalArgumentException
- if resourceTemplates is null.#resourceTemplates(List...)
public McpServer.SyncSpecification resourceTemplates(McpServerFeatures.SyncResourceTemplateSpecification... resourceTemplates)
resourceTemplates(List)
.resourceTemplates
- The resource templates to set.java.lang.IllegalArgumentException
- if resourceTemplates is nullresourceTemplates(List)
public McpServer.SyncSpecification prompts(java.util.Map<java.lang.String,McpServerFeatures.SyncPromptSpecification> prompts)
Example usage:
Map<String, PromptSpecification> prompts = new HashMap<>();
prompts.put("analysis", new PromptSpecification(
new Prompt("analysis", "Code analysis template"),
(exchange, request) -> new GetPromptResult(generateAnalysisPrompt(request))
));
.prompts(prompts)
prompts
- Map of prompt name to specification. Must not be null.java.lang.IllegalArgumentException
- if prompts is nullpublic McpServer.SyncSpecification prompts(java.util.List<McpServerFeatures.SyncPromptSpecification> prompts)
prompts
- List of prompt specifications. Must not be null.java.lang.IllegalArgumentException
- if prompts is nullprompts(McpServerFeatures.SyncPromptSpecification...)
public McpServer.SyncSpecification prompts(McpServerFeatures.SyncPromptSpecification... prompts)
Example usage:
.prompts(
new PromptSpecification(analysisPrompt, analysisHandler),
new PromptSpecification(summaryPrompt, summaryHandler),
new PromptSpecification(reviewPrompt, reviewHandler)
)
prompts
- The prompt specifications to add. Must not be null.java.lang.IllegalArgumentException
- if prompts is nullpublic McpServer.SyncSpecification rootsChangeHandler(java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>> handler)
handler
- The handler to register. Must not be null. The function's first
argument is an McpSyncServerExchange
upon which the server can interact
with the connected client. The second argument is the list of roots.java.lang.IllegalArgumentException
- if consumer is nullpublic McpServer.SyncSpecification rootsChangeHandlers(java.util.List<java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>>> handlers)
handlers
- The list of handlers to register. Must not be null.java.lang.IllegalArgumentException
- if consumers is nullrootsChangeHandler(BiConsumer)
public McpServer.SyncSpecification rootsChangeHandlers(java.util.function.BiConsumer<McpSyncServerExchange,java.util.List<McpSchema.Root>>... handlers)
handlers
- The handlers to register. Must not be null.java.lang.IllegalArgumentException
- if consumers is nullrootsChangeHandlers(List)
public McpServer.SyncSpecification objectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
objectMapper
- the instance to use. Must not be null.java.lang.IllegalArgumentException
- if objectMapper is nullpublic McpSyncServer build()
McpSyncServer
configured with this builder's
settings.