JZ

james-zou/mcp-springboot-server

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

10 stars 7 forks 质量 44 趋势 18Apache-2.0

这是一个使用 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 city
  • getWeather1(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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Author

James Zou

Acknowledgments

  • Spring Boot Team
  • Model Context Protocol Team
  • All contributors to this project

框架说明

在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →