Install
$ agentstack add mcp-james-zou-mcp-springboot-server ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
MCP Spring Boot Server
[](https://opensource.org/licenses/Apache-2.0) [](https://www.oracle.com/java/technologies/downloads/#java17) [](https://spring.io/projects/spring-boot) [](mailto:18301545237@163.com)
A Spring Boot server implementation for Model Context Protocol (MCP), providing weather information services through MCP interfaces.
Features
- Weather information service via MCP
- RESTful API endpoints
- Server-Sent Events (SSE) support
- Automatic tool registration
- Spring Boot 3.x integration
Requirements
- JDK 17 or later
- Maven 3.6.x or later
- Spring Boot 3.2.0 or later
Getting Started
Clone the Repository
git clone https://github.com/yourusername/mcp-springboot-server.git
cd mcp-springboot-server
Build the Project
mvn clean install
Run the Application
mvn spring-boot:run
The server will start on port 8080 by default.
Configuration
The main configuration properties are located in application.properties:
server.port=8080
spring.application.name=mcp-demo
spring.ai.mcp.server.enabled=true
For more configuration options, please check the application.properties file.
API Documentation
Weather Service
The Weather Service provides the following MCP methods:
getWeather(String cityName): Get weather information for a specific citygetWeather1(String cityName): Alternative method to get weather information
Example usage in the test client:
var transport = new HttpClientSseClientTransport("http://localhost:8080");
var client = McpClient.sync(transport).build();
Project Structure
src/
├── main/
│ ├── java/
│ │ └── com/unionhole/mcpserver/
│ │ ├── config/
│ │ ├── service/
│ │ └── McpDemoApplication.java
│ └── resources/
│ └── application.properties
└── test/
└── java/
└── com/unionhole/mcpserver/
└── ClientSseTest.java
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
Author
James Zou
- Email: [18301545237@163.com](mailto:18301545237@163.com)
- GitHub: @jameszou
Acknowledgments
- Spring Boot Team
- Model Context Protocol Team
- All contributors to this project
框架说明
1. Maven 依赖配置
项目使用了以下主要依赖:
org.springframework.ai
spring-ai-core
${spring-ai.version}
org.springframework.ai
spring-ai-starter-mcp-server-webmvc
${spring-ai.version}
com.unionhole
mcp-facade-generator
${mcp-facade.version}
2. MCP 配置说明
在 application.properties 中配置 MCP 服务器:
# MCP 服务器配置
spring.ai.mcp.server.enabled=true
spring.ai.mcp.server.resource-change-notification=true
spring.ai.mcp.server.prompt-change-notification=true
spring.ai.mcp.server.tool-change-notification=true
spring.ai.mcp.server.name=mcp-demo-service
spring.ai.mcp.server.version=1.0.0
spring.ai.mcp.server.type=SYNC
spring.ai.mcp.server.sse-message-endpoint=/mcp/messages
3. MCP Tools 配置
通过 McpServerConfig 类配置 MCP Tools:
@Configuration
public class McpServerConfig {
@Bean
public ToolCallbackProvider autoRegisterTools(ApplicationContext applicationContext) {
// 获取所有带有 @Component 注解且类名以 Facade 结尾的 bean
String[] beanNames = applicationContext.getBeanNamesForAnnotation(Component.class);
List facadeBeans = new ArrayList<>();
for (String beanName : beanNames) {
if (beanName.endsWith("Facade")) {
facadeBeans.add(applicationContext.getBean(beanName));
}
}
return MethodToolCallbackProvider.builder()
.toolObjects(facadeBeans.toArray())
.build();
}
}
4. 业务服务开发
- 创建服务类并添加
@MCPService注解:
@MCPService
@Service
public class WeatherService {
public String getWeather(String cityName) {
// 实现业务逻辑
return "Weather info for " + cityName;
}
}
- 使用
@MCPMethod注解标记需要暴露的方法:
@MCPMethod(description = "获取天气信息")
public String getWeather(String cityName) {
// 方法实现
}
5. 客户端测试
使用提供的 ClientSseTest 类进行测试:
public class ClientSseTest {
public static void main(String[] args) {
var transport = new HttpClientSseClientTransport("http://localhost:8080");
var client = McpClient.sync(transport).build();
try {
client.initialize();
client.ping();
// 列出可用的工具
McpSchema.ListToolsResult toolsList = client.listTools();
System.out.println("Available Tools = " + toolsList);
client.closeGracefully();
} catch (Exception e) {
e.printStackTrace();
}
}
}
注意事项
- 确保正确配置了 Spring AI 和 MCP 的版本
- 所有 Facade 类都应该使用
@Component注解 - 建议使用
@MCPMethod注解来提供方法的描述信息 - 异常处理应该在服务层统一处理
常见问题解决
1. 编译时出现 IllegalArgumentException
如果在编译过程中遇到以下错误:
java: java.lang.IllegalArgumentException
解决方案:
在 IntelliJ IDEA 中添加 VM 选项:
- 打开 Settings (Ctrl + Alt + S)
- 导航到 Build, Execution, Deployment > Compiler
- 在 "Build process VM options" 字段中添加:
`` -Djps.track.ap.dependencies=false ``
- 点击 Apply 和 OK
- 重新构建项目
参考文档
Copyright © 2024 James Zou. All rights reserved.
Source & license
This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: James-Zou
- Source: James-Zou/mcp-springboot-server
- License: Apache-2.0
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.