Skip to content
Meic6798Public

About

Spring Boot Starter: Auto-convert existing REST APIs (@RestController) to MCP Server with zero/low-code. Expose controllers as MCP Tools instantly.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

130 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

api2mcp4j

Turn your existing Spring Boot REST controllers into MCP (Model Context Protocol) tools β€” no rewrites, no @Tool everywhere.

<dependency>
  <groupId>com.ai.plug</groupId>
  <artifactId>server2mcp-starter-webmvc</artifactId>
  <version>1.1.4-SNAPSHOT</version>
</dependency>

Java Spring Boot Spring AI MCP SDK MCP Protocol Tests End-to-End License

English Β· δΈ­ζ–‡ Β· Docs Β· Integration Matrix


Why api2mcp4j?

Most MCP integrations force you to:

  • Add @Tool / @McpTool to every method
  • Duplicate business logic into a parallel "MCP" code path
  • Maintain separate tool descriptions

api2mcp4j scans your existing @RestController beans and exposes their methods as MCP tools β€” zero changes to business code. Like MyBatis-Plus enhances MyBatis, api2mcp4j enhances Spring AI MCP.

// Your existing controller β€” unchanged
@RestController
public class OrderController {
    @GetMapping("/orders/{id}")
    public Order getOrder(@PathVariable Long id) { ... }
}

// Becomes an MCP tool: orders_get_order
// With auto-generated description from Swagger / Javadoc / Spring MVC / Jackson / Spring AI

✨ Key Features

🎯 Non-intrusive interface scope auto-registers all controllers; no @Tool annotation needed
πŸ” 5-parser chain Swagger v3 / Swagger v2 / Javadoc / Spring MVC / Jackson / Spring AI β€” best description wins
πŸ› οΈ Full MCP coverage Tools / Resources / Prompts / Completions / Elicitation / Sampling / Roots
πŸ†• Protocol 2026-07-28 Wire schema + JSON-RPC routing + SSE long-poll + MRTR + OTel traceparent β€” 100%
πŸ”Œ Custom parsers Implement AbstractDesParser / AbstractParamParser, plug into the chain
πŸ§ͺ TDD discipline JUnit5, double commit [RED] then [GREEN], 600 tests all green
πŸš€ Quick start mvn spring-boot:run β†’ MCP endpoint ready

πŸš€ Quick Start (β‰ˆ 3 minutes)

1. Clone & build

git clone https://github.com/TheEterna/api2mcp4j.git
cd api2mcp4j
mvn clean install -DskipTests

2. Add to your Spring Boot project

<dependency>
  <groupId>com.ai.plug</groupId>
  <artifactId>server2mcp-starter-webmvc</artifactId>
  <version>1.1.4-SNAPSHOT</version>
</dependency>

3. Configure

plugin:
  mcp:
    enabled: true
    scope: interface   # 'interface' = auto-register all controllers; 'custom' = @ToolScan only
    parser:
      des:    SWAGGER3, JAVADOC, TOOL, JACKSON, SWAGGER2
      param:  MCPTOOL, JAVADOC, TOOL, SpringMVC, JACKSON, SWAGGER2, SWAGGER3

4. Start & test

mvn spring-boot:run

Your MCP server is live on http://localhost:8080/mcp/jsonrpc (and HTTP fallbacks on /mcp/discover, /mcp/tasks, /mcp/sse).


πŸ“‘ MCP Protocol 2026-07-28 β€” 100% Compatible

api2mcp4j is the first Java MCP framework to ship full 2026-07-28 support, even though Java MCP SDK 2.0 only implements the 2025-11-25 wire. We bypassed SDK limitations with a custom JSON-RPC router, SSE controller, and wire schema β€” all without breaking SDK upgrade compatibility (controllers stay as fallbacks when SDK β‰₯ 3.0.0 lands).

8 RPC routes, all real (not HTTP simulations)

RPC JSON-RPC endpoint SSE long-poll Source
server/discover βœ… POST /mcp/jsonrpc β€” DiscoverEndpoint
tasks/create βœ… β€” TaskStore
tasks/get / list / cancel βœ… β€” TasksEndpoint
tasks/augmented-prompt βœ… β€” AugmentedPromptEndpoint
subscriptions/listen βœ… (poll) βœ… GET /mcp/sse + Last-Event-ID + 15s heartbeat SseNotificationsController
input_required/respond (MRTR) βœ… envelope β€” MrtrToolCallbackWrapper

Wire JSON fields β€” 100% reachable

2026-07-28 field Status Where
tools.listChanged / resources.listChanged / prompts.listChanged βœ… SDK native WireSchemaExporter.syncAll()
tools.subscription / completions.listChanged (new in 2026-07-28) βœ… Custom wire WireServerCapabilities
experimental.io.modelcontextprotocol/tasks (new) βœ… Custom wire Same
_meta.resultType / ttlMs / cacheScope / cacheWrapperKey βœ… Auto-injected via meta map @McpTool(...) + McpCallToolResultConverter
_meta.taskHandle / inputRequests / requestState βœ… Auto-recognized InputRequiredResult / TaskHandle return values
_meta.traceparent / tracestate / baggage (W3C SEP-414) βœ… Auto-minted in JSON-RPC MetaUtils
MRTR state machine (cross-round merge + 8-round guard) βœ… MrtrDriver
outputSchema βœ… SDK field McpSchema.Tool.builder().outputSchema()
Capabilities health / diff / wire validation βœ… CapabilitiesHealth + SnapshotCompareTool + WireSchemaValidator

Full integration matrix β†’


βœ… One-line verification

The demo app boots with H2 in-memory DB (zero external dependencies) and validates every 2026-07-28 feature against a real HTTP/SSE wire:

cd server2mcp-test && mvn spring-boot:run    # starts on :8888 (H2 in-memory)

# In another shell:
bash scripts/verify-protocol-2026-07-28.sh http://localhost:8888
== 0. liveness ==                       βœ“ actuator reachable
== 1. server/discover (JSON-RPC) ==    βœ“Γ—7 (jsonrpc=2.0, preferredVersion=2026-07-28,
                                            tools.listChanged, tools.subscription,
                                            completions.listChanged, experimental.tasks,
                                            _meta.traceparent)
== 2. tasks/* (JSON-RPC) ==            βœ“Γ—5 (create, get, list, cancel full lifecycle)
== 3. tasks/augmented-prompt ==         βœ“Γ—1
== 4. subscriptions/listen ==           βœ“Γ—3 (HTTP poll + text/event-stream + connected)
== 5. input_required/respond ==         βœ“Γ—2 (accepted + state echo)
== 6. HTTP legacy endpoints ==          βœ“Γ—2 (/mcp/discover + /mcp/notifications)
== summary ==                           passed: 21 / failed: 0
ALL ASSERTIONS PASSED β€” protocol 2026-07-28 wire verified

Evidence log β†’


πŸ§ͺ Testing & Verification

Layer Count Status
Unit tests (server2mcp-core) 575 βœ… all green
Integration tests (server2mcp-starter-webmvc) 22 βœ… all green
Demo tests (server2mcp-test) 3 βœ… all green
End-to-end curl verification 21/21 βœ…
Total 600+ tests, 21/21 e2e βœ…

Test philosophy: TDD double-commit β€” [RED] test first, then [GREEN] implementation. See docs/specs/TEST_SPEC.md.


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Spring Boot Application                                     β”‚
β”‚                                                              β”‚
β”‚   β”Œβ”€β”€β”€ Your existing code (unchanged) ───┐                  β”‚
β”‚   β”‚ @RestController                       β”‚                  β”‚
β”‚   β”‚ @Service                              β”‚                  β”‚
β”‚   β”‚ @Component                            β”‚                  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                    β”‚                                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚   β”‚ api2mcp4j framework                   β”‚                  β”‚
β”‚   β”‚                                       β”‚                  β”‚
β”‚   β”‚  Scanner ──→ Parser chain ──→ Provider                 β”‚
β”‚   β”‚    β”‚            β”‚              β”‚                       β”‚
β”‚   β”‚  Spring MVC   5 parsers    SyncMcpToolMethodCallback   β”‚
β”‚   β”‚  discovery    (Swagger2/3,    (template method)        β”‚
β”‚   β”‚                Javadoc,                              β”‚
β”‚   β”‚                Jackson,                              β”‚
β”‚   β”‚                Spring AI)                             β”‚
β”‚   β”‚                                       β”‚                  β”‚
β”‚   β”‚  ── 2026-07-28 layer (new) ──                          β”‚
β”‚   β”‚  β€’ JsonRpcRouter + JsonRpcRoutes                       β”‚
β”‚   β”‚  β€’ WireServerCapabilities + JsonExporter               β”‚
β”‚   β”‚  β€’ SseNotificationsController                          β”‚
β”‚   β”‚  β€’ MrtrDriver + MrtrSessionStore                       β”‚
β”‚   β”‚  β€’ MrtrToolCallbackWrapper                             β”‚
β”‚   β”‚  β€’ MetaUtils (W3C traceparent mint)                    β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                    β”‚                                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚   β”‚ Spring AI MCP SDK 2.0                 β”‚                  β”‚
β”‚   β”‚   (McpSyncServer / McpAsyncServer)    β”‚                  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚  wire: JSON-RPC 2.0 + SSE
                     β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ MCP Clients        β”‚
            β”‚ β€’ Claude Desktop   β”‚
            β”‚ β€’ Cursor / Cline   β”‚
            β”‚ β€’ Your BFF / Agent β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Detailed architecture β†’


πŸ“¦ Modules

api2mcp4j/
β”œβ”€β”€ server2mcp-common                  # Constants & utilities
β”œβ”€β”€ server2mcp-core                    # Core engine: annotations, scanners, callbacks, providers
β”‚   β”œβ”€β”€ com.ai.plug.core.annotation.*  # @McpTool, @McpResource, @McpPrompt, @McpArg
β”‚   β”œβ”€β”€ com.ai.plug.core.parser.*      # 5-parser chain (des + param)
β”‚   β”œβ”€β”€ com.ai.plug.core.callback.*     # Sync + Async template methods
β”‚   β”œβ”€β”€ com.ai.plug.core.spec.*         # 2026-07-28 wire layer
β”‚   └── com.ai.plug.core.provider.*     # Spring AI bridge
β”œβ”€β”€ server2mcp-autoconfigure           # Spring Boot auto-configuration
β”œβ”€β”€ server2mcp-spring-boot-starters/
β”‚   β”œβ”€β”€ server2mcp-starter-webmvc      # βœ… Full endpoint wiring (JSON-RPC + SSE + HTTP)
β”‚   └── server2mcp-starter-webflux     # ⚠️ Framework core only (no endpoint wiring yet)
└── server2mcp-test                    # βœ… Demo app + 21/21 e2e verification

πŸ€” When to use api2mcp4j?

βœ… Use it for ❌ Don't use it for
Exposing internal REST APIs to AI agents quickly Greenfield MCP-first projects (use Spring AI MCP directly)
Wrapping legacy controllers as MCP tools Real-time streaming / SSE-only UIs
Multi-agent systems sharing tool definitions Apps that don't already use Spring Boot
Prototyping AI features on production services Tiny prototypes (overhead not worth it)

πŸ†š Comparison

Feature api2mcp4j Spring AI MCP Official Manual @Tool everywhere
Code changes required Minimal (config only) Medium–High High
Auto-discover from @RestController βœ… ❌ ❌
5-parser chain (Swagger + Javadoc + …) βœ… Limited Manual
Non-intrusive β˜…β˜…β˜…β˜…β˜… β˜…β˜…β˜… β˜…β˜†
Protocol 2026-07-28 (RPC + wire) βœ… 100% 🟑 partial βšͺ
MRTR multi-round βœ… with decorator βšͺ βšͺ
SSE long-poll + Last-Event-ID βœ… built-in 🟑 via SDK ❌
W3C traceparent (SEP-414) βœ… auto-minted ❌ ❌
Best for existing projects βœ… New apps Tiny demos

πŸ“š Documentation


🀝 Contributing

Issues, PRs, and ⭐ are very welcome.
This is a young project β€” your feedback shapes its future.

Before submitting a PR, please read:


πŸ“„ License

Apache License 2.0


πŸ—“οΈ Roadmap

  • Protocol 2026-07-28 wire & JSON-RPC routing (2026-08-03)
  • MRTR multi-round state machine + 8-round guard
  • SSE long-poll with Last-Event-ID resume
  • W3C traceparent auto-mint
  • WebFlux starter endpoint wiring (parity with WebMVC)
  • Publish to Maven Central
  • OTel SDK real instrumentation (currently wire-format only)
  • Multi-tenant isolation (@McpTool(tenant = "..."))
  • SDK β‰₯ 3.0.0 native router migration (tracked by scripts/trigger-phase3.sh)

Built with care by Han Β· Apache 2.0 Β· 100% protocol 2026-07-28 compatible

About

Spring Boot Starter: Auto-convert existing REST APIs (@RestController) to MCP Server with zero/low-code. Expose controllers as MCP Tools instantly.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages