Api2mcp4j logo

Api2mcp4j

Community
TheEterna

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

PublisherTheEterna
Repositoryapi2mcp4j
LanguageJava
Forks
17
Stars
109
Available tools
0
Transport typestdio
LicenseApache-2.0
Links
  • Connect tools to AI workflows

    Api2mcp4j exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    109 stars and 17 forks from the linked repository.

api2mcp4j

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

xml
<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.

java
// 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-intrusiveinterface scope auto-registers all controllers; no @Tool annotation needed
🔍 5-parser chainSwagger v3 / Swagger v2 / Javadoc / Spring MVC / Jackson / Spring AI — best description wins
🛠️ Full MCP coverageTools / Resources / Prompts / Completions / Elicitation / Sampling / Roots
🆕 Protocol 2026-07-28Wire schema + JSON-RPC routing + SSE long-poll + MRTR + OTel traceparent — 100%
🔌 Custom parsersImplement AbstractDesParser / AbstractParamParser, plug into the chain
🧪 TDD disciplineJUnit5, double commit [RED] then [GREEN], 600 tests all green
🚀 Quick startmvn spring-boot:run → MCP endpoint ready

🚀 Quick Start (≈ 3 minutes)

1. Clone & build

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

2. Add to your Spring Boot project

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

3. Configure

yaml
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

bash
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)

RPCJSON-RPC endpointSSE long-pollSource
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 heartbeatSseNotificationsController
input_required/respond (MRTR)✅ envelope—MrtrToolCallbackWrapper

Wire JSON fields — 100% reachable

2026-07-28 fieldStatusWhere
tools.listChanged / resources.listChanged / prompts.listChanged✅ SDK nativeWireSchemaExporter.syncAll()
tools.subscription / completions.listChanged (new in 2026-07-28)✅ Custom wireWireServerCapabilities
experimental.io.modelcontextprotocol/tasks (new)✅ Custom wireSame
_meta.resultType / ttlMs / cacheScope / cacheWrapperKey✅ Auto-injected via meta map@McpTool(...) + McpCallToolResultConverter
_meta.taskHandle / inputRequests / requestState✅ Auto-recognizedInputRequiredResult / TaskHandle return values
_meta.traceparent / tracestate / baggage (W3C SEP-414)✅ Auto-minted in JSON-RPCMetaUtils
MRTR state machine (cross-round merge + 8-round guard)✅MrtrDriver
outputSchema✅ SDK fieldMcpSchema.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:

bash
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

LayerCountStatus
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 verification21/21✅
Total600+ 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 quicklyGreenfield MCP-first projects (use Spring AI MCP directly)
Wrapping legacy controllers as MCP toolsReal-time streaming / SSE-only UIs
Multi-agent systems sharing tool definitionsApps that don't already use Spring Boot
Prototyping AI features on production servicesTiny prototypes (overhead not worth it)

🆚 Comparison

Featureapi2mcp4jSpring AI MCP OfficialManual @Tool everywhere
Code changes requiredMinimal (config only)Medium–HighHigh
Auto-discover from @RestController✅❌❌
5-parser chain (Swagger + Javadoc + …)✅LimitedManual
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 appsTiny 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)

Use Api2mcp4j MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once Api2mcp4j is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add Api2mcp4j as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the Api2mcp4j MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "api2mcp4j": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the Api2mcp4j MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the Api2mcp4j MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use Api2mcp4j to help me with this task?
Api2mcp4j
Sure. I read it.
Here is what I found using Api2mcp4j.

Frequently asked questions

What is the Api2mcp4j MCP server used for?

Api2mcp4j is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use Api2mcp4j MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use Api2mcp4j with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use Api2mcp4j MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With Api2mcp4j connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect Api2mcp4j MCP to TypingMind?

Api2mcp4j runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does Api2mcp4j MCP provide in TypingMind?

Api2mcp4j exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use Api2mcp4j MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If Api2mcp4j requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇