MCP cover image
See in Github
2025-03-28

Springboot 、MCP,junit的模板想法项目。可用于STDIO和SSE模式。

1

Github Watches

2

Github Forks

7

Github Stars

Springboot + MCP + JUnit 模板项目


使用springboot快速构建一个mcp项目,项目支持 JUNIT单元测试。

模式支持: STDIOSSE

解说视频:

  • 全网首发:从零搭建 Springboot+MCP+JUnit 项目 【搭配CherryStudio】BV1qUXkYRE6C
  • 全网首发:Springboot+MCP(SSE)+JUnit 从搭建到上线 BV1rSXWYGEVz

开发环境

  • 开发IDE: IDEA
  • java版本: JAVA17 (Spring官方要求必须java17+)
  • maven版本: 3.8.1 (太高引入项目时可能报错,请选择适当版本)

参考文档资料

  1. MCP官网-协议 (必读文档)
  2. MCP官网-编码指南
  3. Spring官网

客户端测试方案

1. 对于STDIO客户端配置方式:

命令(Command):
    java
参数(Arguments):
    -jar
    -Dfile.encoding=UTF-8
    -Dspring.ai.mcp.server.stdio=true
    AbsolutePath/**/xxx.jar
环境(Environments):
    env1=xxx
    env2=yyy

指令是java(如果本地主环境不是17+,注意切换);

参数file.encoding指定System.in和System.out为UTF-8编码,避免编码问题;

参数spring.ai.mcp.server.stdio表示以stdio的方式启用该服务;

环境配置,是将配置写入当前系统环境,以供当前程序调取。


2. 对于SSE客户端配置方式:

SSE地址填写如下链接即可
http://主机地址:端口/sse

额外可选功能的探索

1. 修改消息端点

配置文件参见:McpServerProperties

spring.ai.mcp.server.sseMessageEndpoint=/mcp/message

2. 修改sse端点

原始的sse端点在/sse,而配置文件没有提供sse端点的配置方式,所以需要重新注入 ServerMcpTransport 来换掉原来的。

注意下面两个Bean配置都要加,因为自动注入文件 MpcWebMvcServerAutoConfiguration 中,对整个注册的注入条件是 @ConditionalOnMissingBean(ServerMcpTransport.class),导致下面两个bean都不会注入

private final String SSE_ENDPOINT = "/sse";

@Bean
@ConditionalOnMissingBean
public WebMvcSseServerTransport webMvcSseServerTransport(ObjectMapper objectMapper,
        McpServerProperties serverProperties) {
    return new WebMvcSseServerTransport(objectMapper, serverProperties.getSseMessageEndpoint(), SSE_ENDPOINT);
}

@Bean
public RouterFunction<ServerResponse> mvcMcpRouterFunction(WebMvcSseServerTransport transport) {
    return transport.getRouterFunction();
}

3. 一服务多端点?

需要重新注入多个 McpSyncServer ,详见类 MpcServerAutoConfiguration

因为多端点可能会涉及到的东西非常多,感兴趣的可以自己研究,我就只提供这样的指引啦!

4. SSE授权?

在2025.03.26 的MCP官方协议文档中,更新了鉴权方案, 期待Spring的更新。



Bye.ヾ(•ω•`)o

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • modelcontextprotocol
  • 模型上下文协议服务器

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

    Reviews

    4 (1)
    Avatar
    user_gdsppW4q
    2025-04-15

    I've been using Workflows MCP v0.1.0 by AgentDeskAI and it has significantly streamlined my workflow. The intuitive interface and robust functionalities are perfect for optimizing my tasks. Highly recommend for anyone looking to enhance productivity! Check it out at: https://mcp.so/server/workflows-mcp/AgentDeskAI.