Spring Web to MCP Converter 🚀
@addozhang
Convert Spring REST API to MCP Server with OpenRewrite
Overview
What is Spring Web to MCP Converter?
Spring Web to MCP Converter is an OpenRewrite recipe collection that automatically converts traditional Spring Web REST APIs into Spring AI Model Context Protocol (MCP) server tools. It is designed for developers migrating Spring Boot REST controllers to expose their APIs through the MCP standard, making them accessible to AI agents.
How to use Spring Web to MCP Converter?
After building the project with mvn clean install, apply the recipes to your Spring Web project by running the Maven command twice: the first execution updates pom.xml with required repositories and dependencies, and the second performs the actual code conversion. The command is mvn org.openrewrite.maven:rewrite-maven-plugin:6.4.0:run -Drewrite.activeRecipes=RewriteWebToMCP -Drewrite.recipeArtifactCoordinates=com.atbug.rewrite:web-to-mcp:1.0-SNAPSHOT -Drewrite.exportDatatables=true.
Key features of Spring Web to MCP Converter
- Converts Spring Web annotations to
@Tooland@ToolParamannotations - Extracts JavaDoc comments as tool descriptions
- Adds Maven dependencies and repository configurations automatically
- Creates a
ToolCallbackProviderbean to register all tools - Configures MCP server properties in
application.propertiesorapplication.yml - Supports both YAML and Properties file formats
Use cases of Spring Web to MCP Converter
- Migrating an existing Spring Boot REST API to an MCP server without rewriting code
- Exposing traditional REST endpoints as AI‑accessible tools via the Model Context Protocol
- Adding MCP tool support to a Spring Boot 3.2+ application while preserving all existing REST endpoints
- Quickly prototyping MCP servers from well‑documented Spring Web controllers
FAQ from Spring Web to MCP Converter
What are the prerequisites for the target project?
The target project must use Spring Boot 3.2+ (3.2.0 or newer), Spring Web MVC, and Maven build tool. Java 17+ and Maven 3.6+ are required to run the converter.
How many times must the conversion command be run?
The command must be executed twice: the first run updates the POM with necessary repositories and dependencies, and the second run performs the actual code conversion of controllers to MCP tools.
Does the conversion break existing REST endpoints?
No. After conversion, the application continues to function as a traditional REST API while also acting as an MCP server. All existing endpoints remain unchanged.
Where does the converter add MCP configuration?
It adds MCP server configuration to application.properties or application.yml, setting server name, version, type, and SSE message endpoint.
How can I test the converted MCP server?
Run the converted application and use the official MCP Inspector (configured with SSE transport at http://localhost:8080/sse) to view and test all available tools.