
这是一个使用 Spring Boot 和 Spring AI MCP 的示例项目,展示了如何集成和使用 MCP 功能。A Spring Boot server implementation for Model Context Protocol (MCP), providing weather information services through MCP interfaces.
概览
A Spring Boot server implementation for Model Context Protocol (MCP), providing weather information services through MCP interfaces. - Weather information service via MCP - RESTful API endpoints - Server-Sent Events (SSE) support - Automatic tool registration - Spring Boot 3.x integration - JDK 17 or later - Maven 3.6.x or later - Spring Boot 3.2.0 or later The server will start on port 8080 by default. The main configuration properties are located in application.properties: For more configuration options, please check the application.properties file. The Weather Service provides the following MCP methods: - getWeather(String cityName): Get weather information for a specific city - getWeather1(String cityName): Alternative method to get weather information
README
以下为原文 README 节选,完整内容请查看原文。
MCP Spring Boot Server
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 file for details.
Author
James Zou
- Email: [email protected]
- GitHub: @jameszou
Acknowledgments
- Spring Boot Team
- Model Context Protocol Team
- All contributors to this project
框架说明
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →