Zero-to-low code Spring Boot Starter that automatically converts existing REST Controllers into MCP Tools for seamless MCP ecosystem integration.
Overview#
api2mcp4j is a non-intrusive MCP Server generator for Spring Boot that automatically scans @RestController and @Service beans, registering their methods as MCP Tools, Resources, and Prompts. No business code changes are required to expose existing REST APIs to AI Agents.
Core Capabilities#
Auto-Discovery & Registration#
- Automatically scans
@RestController/@Servicebeans and registers methods as MCP Tools - Automatically skips
@Deprecatedmethods - Fine-grained scan control via
@ToolScan,@ResourceScan,@PromptScanannotations - Two scope modes:
interface(full registration) andcustom(annotation-only)
Multi-Parser Intelligent Fusion#
Extracts descriptions and parameter schemas via a configurable priority chain where later parsers override earlier ones:
- Swagger/OpenAPI: v2 & v3 support for interface descriptions and parameter info
- Javadoc: Parses
.javasource files via JavaParser (requires source copy to classpath) - Spring MVC metadata: Extracts paths, methods from
@RequestMappingetc. - Jackson serialization metadata: Derives parameter JSON Schemas
- Spring AI native descriptions: Compatible with Spring AI
@Toolannotation - Custom annotations: Supports proprietary
@McpToolannotation
Protocol Compatibility#
- Full MCP Java SDK compatibility: callbacks, resources, prompts
- Independent
McpToolannotation system, decoupled from Spring AI@Tool - Compatible with Cursor, Continue, and any standard MCP Client
Dual Stack Support#
server2mcp-starter-webmvc: For Spring MVCserver2mcp-starter-webflux: For reactive WebFlux
Typical Use Cases#
- Expose internal management system APIs to AI Agents without rewriting
- Build multi-Agent systems by converting microservices to MCP Tools
- Legacy Spring Boot projects adopting MCP at minimal cost
- Prototype AI features on production REST services without dual codebase maintenance
Not Suitable For#
- Non-Spring Boot Java projects
- Pure Stdio MCP Servers (currently exposes via Web endpoint only)
- Scenarios requiring hand-crafted prompts with extreme description precision
Architecture#
Maven multi-module structure:
| Module | Responsibility |
|---|---|
server2mcp-common | Common utilities and infrastructure |
server2mcp-core | Core logic: Bean scanning, multi-parser dispatch, MCP Tool/Resource/Prompt registration |
server2mcp-autoconfigure | Spring Boot auto-configuration entry point |
server2mcp-starter-webmvc | Spring MVC Starter |
server2mcp-starter-webflux | Spring WebFlux Starter |
server2mcp-test | Test module |
Core Flow: Auto-configuration trigger → Bean scanning → Multi-parser fusion → MCP Tool registration, exposed at default /mcp endpoint.
Design Philosophy: Analogous to MyBatis-Plus enhancing MyBatis — bridging REST to MCP via auto-configuration and annotation scanning without invading business code.
Key Configuration#
plugin:
mcp:
enabled: true
parser:
params: SWAGGER3, SWAGGER2, SpringMVC, JACKSON, TOOL
des: SWAGGER3, SWAGGER2, JAVADOC, TOOL, JACKSON
scope: interface
| Config Path | Description |
|---|---|
plugin.mcp.enabled | Master switch (true/false) |
plugin.mcp.scope | Scan scope mode |
plugin.mcp.parser.params | Parameter parser priority chain |
plugin.mcp.parser.des | Description parser priority chain |
spring.ai.mcp.* | MCP endpoint path and underlying config |
Installation#
⚠️ Not yet published to Maven Central; build from source required.
git clone https://github.com/TheEterna/api2mcp4j.git
cd api2mcp4j/server2mcp-starter-webmvc
mvn clean install
<dependency>
<groupId>com.ai.plug</groupId>
<artifactId>server2mcp-starter-webmvc</artifactId>
<version>1.1.4-SNAPSHOT</version>
</dependency>
WebFlux users should substitute server2mcp-starter-webflux.
Open Items#
- Maven Central release timeline: planned per README roadmap, but
1.1.4-SNAPSHOTnot yet available - MCP SDK version stability: depends on
io.modelcontextprotocol.sdk 0.14.0-SNAPSHOT(non-release) - Spring AI version compatibility: depends on
Spring AI 1.1.0-SNAPSHOT, untested against stable releases - Documentation site is SPA (JS-rendered), content cannot be fully verified
- No public production deployment cases or user feedback observed
- Currently only Web endpoint (SSE) exposure; Stdio transport support unclear