mcp -demo
一个基于Spring Boot 的MCP(Model Control Protocol)服务示例项目
claude mcp add --transport stdio liqingdong-mcp-server-demo docker run -i liqingdong/mcp-server-demo:latest \ --env JAVA_OPTS="-Xms256m -Xmx512m" \ --env SPRING_PROFILES_ACTIVE="default"
How to use
This MCP server is a Spring Boot-based sample that exposes two core MCP services: NumberService and WeatherService. Services are annotated with @Tool for exposure and @ToolParam for parameters, enabling standardized MCP tool interactions. The NumberService provides basic numeric utilities such as parity checks and prime detection, while WeatherService simulates weather data retrieval (with a note that integration with a real API like OpenWeatherMap is straightforward). You can test these tools with an MCP client (e.g., a UI or CLI client that supports MCP tools) by invoking the exposed tool endpoints and supplying parameters as defined by @ToolParam annotations. The server supports both STDIO-like and SSE communication modes as demonstrated in the README, making it adaptable to different client workflows.
How to install
Prerequisites:
- Java JDK 17 installed and available in PATH (or use Docker if you prefer containerized execution)
- Maven 3.8+ (if building from source)
- Git (to clone the repository)
Option A: Build from source
- Clone the repository git clone https://github.com/liqingdong/mcp-server-demo.git
- Navigate to project directory cd mcp-server-demo
- Build the project mvn clean install
- Run the application locally java -jar target/mcp-server-demo-0.0.1-SNAPSHOT.jar
Option B: Run via Docker
- Ensure Docker is installed and running
- Pull and run the image (example; replace with actual image name/tag if different) docker run -i liqingdong/mcp-server-demo:latest
Notes:
- If running locally, you may adjust application properties in src/main/resources/application.yml or via environment variables.
- The README indicates two modes: STDIO and SSE; use the provided startup commands to enable the desired mode.
Additional notes
Tips and common considerations:
- Ensure Java 17 compatibility for Spring Boot 3.4.4 as used by this demo.
- When running in Docker, expose ports if you need external clients to connect (adjust docker run with -p mappings as needed).
- You can enable different Spring profiles via SPRING_PROFILES_ACTIVE to tailor configuration for dev, test, or prod.
- The core tools rely on @Tool and @ToolParam; for extending capabilities, add new service classes annotated accordingly and add corresponding unit tests to maintain test coverage.
- If you plan to wire a real weather API, replace the random/placeholder weather data logic in WeatherService with a real API client and handle API keys securely (e.g., via environment variables).