Get the FREE Ultimate OpenClaw Setup Guide →

mcp-spring-ai

使用java 编写mcp server并说明接口的使用方式

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio chaozai0304-mcp-spring-ai-mcp-server java -jar path/to/mcp-spring-ai-app.jar \
  --env SPRING_OUTPUT_LOGGING="true" \
  --env SPRING_PROFILES_ACTIVE="default"

How to use

This MCP server is a Spring Boot-based MCP server that exposes a JSON-RPC over HTTP/SSE interface for interacting with AI tooling. Clients connect to the SSE endpoint to establish a session and then send JSON-RPC requests to the message endpoint to initialize and retrieve available tools, and to invoke specific tools. For example, you can connect to the SSE endpoint at /sse to establish a session, receive a data message containing the sessionId, and then POST to /mcp/message?sessionId={sessionId} with methods like notifications/initialized or tools/list to discover available tools. In the sample wiring, tools such as add (for arithmetic addition) and owner_getByUserName (fetching data by name) are exposed, each with its own input schema. The flow is: (1) open SSE connection to /sse, (2) request tool list via a tools/list or initialized notification, (3) use the sessionId shown in the data payload to POST tool invocations and receive results, all via JSON-RPC payloads.

How to install

Prerequisites:

  • Java 17 (or compatible JDK) installed
  • Maven installed (optional if using a pre-built jar)
  • Internet access for dependency resolution

Installation steps:

  1. Clone the repository or obtain the project sources.
  2. Build the project (if you have source): mvn -version # ensure Maven is installed mvn clean package

    after build, the jar is typically located under target/ (e.g., target/mcp-spring-ai-0.0.1-SNAPSHOT.jar)

  3. Run the MCP server: java -jar target/mcp-spring-ai-0.0.1-SNAPSHOT.jar
  4. Verify the server is running, then connect to the SSE endpoint at http://localhost:8090/sse and follow with tool discovery at http://localhost:8090/mcp/message?sessionId=YOUR_SESSION_ID.

Notes:

  • If you run via an IDE, ensure the proper Maven dependencies are resolved and the Spring Boot app starts with the embedded container.
  • If you want to run from a pre-built jar, adjust the path in mcp_config accordingly.

Additional notes

Tips and common issues:

  • Ensure Java 17 is used; the project targets Java 17.
  • The SSE and message endpoints are typically served under /sse and /mcp/message respectively unless customized via configuration (see yml parameters in the repository for spring.ai.mcp.server.* properties).
  • If the tools list is empty or tool invocations fail, verify that the server has initialized correctly (notifications/initialized) and that the sessionId used in subsequent requests matches the one provided in the SSE data payload.
  • Check environment variables and Spring profiles if environment-specific behavior is needed; you can enable verbose logging to troubleshoot transport or JSON parsing issues.
  • When using the Maven build, ensure network access to fetch Spring AI BOMs and related dependencies; corporate networks may require proxy configuration.

Related MCP Servers

Sponsor this space

Reach thousands of developers