news 2026/7/5 15:53:34

springframework ai 初始化tool,代码链分析

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
springframework ai 初始化tool,代码链分析

以如下依赖为示例:

<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-mcp-server-webflux</artifactId><version>1.1.0</version></dependency>

yaml配置

spring: ai: mcp: server: protocol: STATELESS name: xxx-streamable-mcp-server version: 1.0.0 type: SYNC instructions: "xxx" resource-change-notification: true tool-change-notification: true prompt-change-notification: true

StatelessToolCallbackConverterAutoConfiguration

无状态工具执行服务自动装配类

初始化工具tool

org.springframework.ai.mcp.server.common.autoconfigure.StatelessToolCallbackConverterAutoConfiguration#syncTools

将tool作为参数,创建McpStatelessAsyncServer

org.springframework.ai.mcp.server.common.autoconfigure.McpServerStatelessAutoConfiguration#mcpStatelessSyncServer
io.modelcontextprotocol.server.McpServer.StatelessSyncSpecification#build
io.modelcontextprotocol.server.McpStatelessAsyncServer#McpStatelessAsyncServer(设置handler)

查询工具列表处理类

io.modelcontextprotocol.server.McpStatelessAsyncServer#toolsListRequestHandler

McpServerStatelessWebFluxAutoConfiguration

McpServerStatelessWebFluxAutoConfiguration 作用是将指定的endpoint暴露出去

@AutoConfiguration( before = {McpServerStatelessAutoConfiguration.class} ) @ConditionalOnClass({McpSchema.class}) @EnableConfigurationProperties({McpServerStreamableHttpProperties.class}) @Conditional({McpServerStdioDisabledCondition.class, McpServerStatelessAutoConfiguration.EnabledStatelessServerCondition.class}) public class McpServerStatelessWebFluxAutoConfiguration { @Bean @ConditionalOnMissingBean public WebFluxStatelessServerTransport webFluxStatelessServerTransport(@Qualifier("mcpServerObjectMapper") ObjectMapper objectMapper, McpServerStreamableHttpProperties serverProperties) { return WebFluxStatelessServerTransport.builder().jsonMapper(new JacksonMcpJsonMapper(objectMapper)).messageEndpoint(serverProperties.getMcpEndpoint()).build(); } @Bean @ConditionalOnMissingBean( name = {"webFluxStatelessServerRouterFunction"} ) public RouterFunction<?> webFluxStatelessServerRouterFunction(WebFluxStatelessServerTransport webFluxStatelessTransport) { return webFluxStatelessTransport.getRouterFunction(); } }

RouterFunction用的很巧妙

todo~~

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/5 15:52:09

Stout性能优化:压缩、缓存策略与CDN配置的详细教程

Stout性能优化&#xff1a;压缩、缓存策略与CDN配置的详细教程 【免费下载链接】Stout A reliable static website deploy tool 项目地址: https://gitcode.com/gh_mirrors/st/Stout Stout作为一款可靠的静态网站部署工具&#xff08;A reliable static website deploy …

作者头像 李华
网站建设 2026/7/5 15:51:58

SonarQube持续测试集成:TestNG与JUnit测试报告导入终极指南

1. 项目概述&#xff1a;为什么你的测试报告需要“体检中心”&#xff1f;在软件开发的日常里&#xff0c;我们写完代码&#xff0c;跑完单元测试&#xff0c;看到一片绿色&#xff08;通过&#xff09;就万事大吉了吗&#xff1f;作为一个踩过无数坑的老兵&#xff0c;我可以很…

作者头像 李华
网站建设 2026/7/5 15:50:52

为什么选择sw-test?探索Service Worker在前端开发中的革命性应用

为什么选择sw-test&#xff1f;探索Service Worker在前端开发中的革命性应用 【免费下载链接】sw-test Service Worker test repository. This is a very simple demo to show basic service worker features in action. 项目地址: https://gitcode.com/gh_mirrors/sw/sw-tes…

作者头像 李华
网站建设 2026/7/5 15:50:42

CronTick高级特性:分布式部署与集群管理最佳实践

CronTick高级特性&#xff1a;分布式部署与集群管理最佳实践 【免费下载链接】CronTick CronTick is a feature-rich open source task scheduling framework. 项目地址: https://gitcode.com/openeuler/CronTick 前往项目官网免费下载&#xff1a;https://ar.openeuler…

作者头像 李华
网站建设 2026/7/5 15:49:39

MetaCodable宏编程入门:快速掌握Swift Codable高级用法

MetaCodable宏编程入门&#xff1a;快速掌握Swift Codable高级用法 【免费下载链接】MetaCodable Supercharge Swifts Codable implementations with macros meta-programming. 项目地址: https://gitcode.com/gh_mirrors/me/MetaCodable 想要提升Swift开发效率&#xf…

作者头像 李华