openapi
把使用openapi作为接口文档的用springboot构建的web应用转成mcp server
claude mcp add --transport stdio h2562961224-openapi-mcp-server docker run -i openapi-mcp-server:latest \ --env JAVA_OPTS="Default JVM options if needed" \ --env SPRING_PROFILES_ACTIVE="prod"
How to use
This MCP server enables using OpenAPI (Swagger) as the interface document for MCP operations. It is built on Java 17 with Spring Boot and Spring MVC, and supports multi-session usage with authentication. The server exposes MCP-compatible endpoints driven by an OpenAPI definition, allowing clients to discover available tools and execute them via a standard client (as demonstrated in the provided client example). The MCP SDK makes it easy to list tools and call a specific tool by name with arguments, enabling integration with various clients without writing custom frontends. Typical usage involves authenticating to obtain a token, connecting with an MCP client, listing available tools, and invoking a tool with the required parameters. For example, you can list tools like TenantController.pageUser and then call it with arguments such as current and pageSize to fetch paginated user data. The server also supports session management and user context maintenance via a UserContextSetter implementation.
How to install
Prerequisites:
- Java 17+ installed
- Maven or Gradle build tool
- (Optional) Docker if you prefer running via container
Steps:
- Create a new Spring Boot project or use your existing one that targets Java 17+.
- Add the MCP Spring WebMVC dependency:
- Implement required classes mentioned in the README, notably:
- InternalWebMvcSseServerTransport.java
- McpConfig.java
- RestApiToolProvider.java
- UserContextSetter.java
-
Implement a UserContextSetter to populate and clear user context from your auth mechanism, e.g. using a JWT token.
-
Ensure your application exposes the MCP endpoints (for example via SSE transport at /mcp/sse/...).
-
Run the application with your preferred method (IDE, Maven/Gradle, or Docker).
Docker (optional):
- Build and run a Docker image for your Spring app, or use a prebuilt image if available.
Example (Docker):
- docker build -t openapi-mcp-server:latest .
- docker run -p 8080:8080 openapi-mcp-server:latest
Notes:
- Ensure Java 17+ compatibility and proper Spring Boot configuration.
- Configure authentication and user context as described in the README.
Additional notes
Tips and notes:
- Authentication: Implement UserContextSetter to extract user context from your tokens (e.g., JWT). The MCP client will rely on this context for multi-session handling.
- OpenAPI integration: The server uses OpenAPI documents for exposing tools; ensure your OpenAPI spec is aligned with the MCP tool definitions.
- Endpoints: The Client example shows connecting via an SSE transport URL like /mcp/sse/{token}. Ensure your server is exposing the SSE endpoint and secure it properly.
- Environment variables: You may want to configure SPRING_PROFILES_ACTIVE, JAVA_OPTS, and any JWT-related settings (e.g., token validation keys) via environment variables.
- Debugging: If tools do not appear in listTools, verify that RestApiToolProvider is correctly wired and that the user context is properly set before invoking tools.
- Common issues: Java version mismatch, missing dependencies, or misconfigured security causing 401/403 errors.