mcp-streamable-http-server-boot-starter-docs
Streamable-HTTP MCP Servers
Streamable HTTP transport 允许 MCP 服务器作为独立进程运行,可以使用 HTTP POST 和 GET 请求处理多个客户端连接,并可选地使用 Server-Sent Events (SSE) 流式传输多个服务器消息。它取代了 SSE 传输。
这些服务器随规范版本 2025-03-26 引入,非常适合需要通知客户端有关工具、资源或 prompts 动态更改的应用程序。
提示: 设置
spring.ai.mcp.server.protocol=STREAMABLE属性
提示: 使用 Streamable-HTTP clients 连接到 Streamable-HTTP 服务器。
Streamable-HTTP WebMVC Server
使用 spring-ai-starter-mcp-server-webmvc 依赖:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webmvc</artifactId>
</dependency>
并将 spring.ai.mcp.server.protocol 属性设置为 STREAMABLE。
- 具有 Spring MVC Streamable 传输的完整 MCP 服务器功能
- 支持工具、资源、prompts、completion、logging、progression、ping、root-changes 功能
- 持久连接管理
Streamable-HTTP WebFlux Server
使用 spring-ai-starter-mcp-server-webflux 依赖:
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-mcp-server-webflux</artifactId>
</dependency>
并将 spring.ai.mcp.server.protocol 属性设置为 STREAMABLE。
- 具有 WebFlux Streamable 传输的响应式 MCP 服务器
- 支持工具、资源、prompts、completion、logging、progression、ping、root-changes 功能
- 非阻塞、持久连接管理
Configuration Properties
Common Properties
所有通用属性以 spring.ai.mcp.server 为前缀:
| Property | Description | Default |
|---|---|---|
enabled | Enable/disable the streamable MCP server | true |
protocol | MCP server protocol | Must be set to STREAMABLE to enable the streamable server |
tool-callback-converter | Enable/disable the conversion of Spring AI ToolCallbacks into MCP Tool specs | true |
name | Server name for identification | mcp-server |
version | Server version | 1.0.0 |
instructions | Optional instructions for client interaction | null |
type | Server type (SYNC/ASYNC) | SYNC |
capabilities.resource | Enable/disable resource capabilities | true |
capabilities.tool | Enable/disable tool capabilities | true |
capabilities.prompt | Enable/disable prompt capabilities | true |
capabilities.completion | Enable/disable completion capabilities | true |
resource-change-notification | Enable resource change notifications | true |
prompt-change-notification | Enable prompt change notifications | true |
tool-change-notification | Enable tool change notifications | true |
tool-response-mime-type | Response MIME type per tool name | - |
request-timeout | Request timeout duration | 20 seconds |
MCP Annotations Properties
MCP Server Annotations 提供了一种使用 Java 注解实现 MCP 服务器处理器的声明式方法。
服务器 mcp-annotations 属性以 spring.ai.mcp.server.annotation-scanner 为前缀:
| Property | Description | Default Value |
|---|---|---|
enabled | Enable/disable the MCP server annotations auto-scanning | true |
Streamable-HTTP Properties
所有 streamable-HTTP 属性以 spring.ai.mcp.server.streamable-http 为前缀:
| Property | Description | Default |
|---|---|---|
mcp-endpoint | Custom MCP endpoint path | /mcp |
keep-alive-interval | Connection keep-alive interval | null (disabled) |
disallow-delete | Disallow delete operations | false |
Features and Capabilities
MCP 服务器支持四种主要功能类型,可以单独启用或禁用:
- Tools - 使用
spring.ai.mcp.server.capabilities.tool=true|false启用/禁用工具功能 - Resources - 使用
spring.ai.mcp.server.capabilities.resource=true|false启用/禁用资源功能 - Prompts - 使用
spring.ai.mcp.server.capabilities.prompt=true|false启用/禁用 prompt 功能 - Completions - 使用
spring.ai.mcp.server.capabilities.completion=true|false启用/禁用 completion 功能
默认情况下,所有功能都已启用。禁用功能将阻止服务器向客户端注册和暴露相应的功能。
MCP Server Boot Starter 允许服务器向客户端暴露工具、资源和 prompts。 它根据服务器类型自动将注册为 Spring beans 的自定义功能处理器转换为同步/异步规范:
Tools
允许服务器暴露可由语言模型调用的工具。MCP Server Boot Starter 提供:
- 变更通知支持
- Spring AI Tools 根据服务器类型自动转换为同步/异步规范
- 通过 Spring beans 自动工具规范:
@Bean
public ToolCallbackProvider myTools(...) {
List<ToolCallback> tools = ...
return ToolCallbackProvider.from(tools);
}
或使用低级 API:
@Bean
public List<McpServerFeatures.SyncToolSpecification> myTools(...) {
List<McpServerFeatures.SyncToolSpecification> tools = ...
return tools;
}
自动配置将自动检测并注册来自以下内容的所有工具回调:
- 单个
ToolCallbackbeans ToolCallbackbeans 列表ToolCallbackProviderbeans
工具按名称去重,使用每个工具名称的第一次出现。
提示: 您可以通过将
tool-callback-converter设置为false来禁用所有工具回调的自动检测和注册。
Tool Context Support
支持 ToolContext,允许将上下文信息传递给工具调用。它在 exchange 键下包含一个 McpSyncServerExchange 实例,可通过 McpToolUtils.getMcpExchange(toolContext) 访问。请参阅此