Extensions & Privacy

MCP Compatibility & Tool Calling Gateway

Bridge Anthropic Tool Use and OpenAI Function Calling schemas for seamless MCP tool execution.

In modern autonomous developer workflows, the Model Context Protocol (MCP) forms the essential nervous system connecting AI models to your workstation. Via MCP, agents like Claude Code or Codex can inspect local files, run terminal commands, execute database queries, or query Git pull requests.

However, when developers attempt to switch backends to more cost-effective models like DeepSeek, Moonshot/Kimi, or self-hosted models, a major roadblock emerges: Claude Code strictly relies on Anthropic's proprietary Tool Use JSON schemas. Generic reverse proxies invariably fail to map tool schemas and streaming deltas correctly, triggering schema validation crashes, corrupted tool arguments, or infinite agent hangs.

Magpie AI's built-in Go gateway (127.0.0.1:3425) eliminates this friction, providing full-duplex protocol translation for MCP and seamless tool calling pass-through.


The Technical Divergence in Tool Calling

Understanding the architectural mismatch between Anthropic and OpenAI schemas highlights why standard proxies break:

Protocol DimensionAnthropic Messages API (Claude Code Native)OpenAI / DeepSeek Specification
Tool Declarationtools: [{ name, description, input_schema }]tools: [{ type: "function", function: { ... } }]
Model Invocationscontent: [{ type: "tool_use", id, name, input }]tool_calls: [{ id, type: "function", function }]
Streaming Eventscontent_block_start -> input_json_deltadelta.tool_calls[i].function.arguments
Tool Execution Responserole: "user", content: [{ type: "tool_result" }]role: "tool", tool_call_id, content

Standard proxies treat requests as basic chat completions. When streaming tool invocations occur, parameters get split across malformed packets, inevitably causing Claude Code to throw Malformed tool_use parameter.


Magpie AI's Full-Duplex MCP Translation Engine

Magpie AI's local gateway provides bidirectional protocol transformation transparently:

text
┌────────────────────────────────────────────────────────┐
│            Claude Code CLI (Triggers MCP Tool Call)    │
│  - Executes shell command                              │
│  - Reads local files                                   │
│  - Calls custom MCP server (Postgres / GitHub / etc.)  │
└──────────────────────────┬─────────────────────────────┘
                           │ (Anthropic Format Tool Use Request)
                           ▼
┌────────────────────────────────────────────────────────┐
│         Magpie AI Local Gateway (127.0.0.1:3425)       │
│  ┌──────────────────────────────────────────────────┐  │
│  │   Bidirectional Tool Schema Translation Engine   │  │
│  │  - Maps input_schema to OpenAI function params   │  │
│  │  - Reconstructs stream chunks into tool_use      │  │
│  │  - Maps tool_result responses back to role: tool │  │
│  │  - Validates JSON boundaries in memory           │  │
│  └──────────────────────────────────────────────────┘  │
└──────────────────────────┬─────────────────────────────┘
                           │ (OpenAI Compatible Function Call)
                           ▼
┌────────────────────────────────────────────────────────┐
│       Upstream LLM (DeepSeek V3 / R1, Kimi, OpenAI)    │
│  - Evaluates tool schemas and outputs function call    │
│  - Fills parameter payload arguments                   │
└────────────────────────────────────────────────────────┘

Key Engineering Capabilities:

  1. Streaming JSON Parameter Reassembly: Models like DeepSeek stream function call arguments as micro-tokens. Magpie buffers and validates these JSON chunks in RAM, emitting them strictly formatted as Anthropic input_json_delta events.
  2. Parallel Tool Invocation Support: When an agent issues simultaneous requests to inspect 3 different files, the gateway tracks individual tool IDs, ensuring zero correlation mismatches.
  3. Zero Configuration Changes: Your existing MCP servers registered in ~/.claude.json (whether running over stdio or SSE) require zero modifications.

Practical Example: Powering Claude Code's MCP via DeepSeek

Let's test this in action by connecting Claude Code to DeepSeek while running local filesystem and MCP tools.

1. Assign DeepSeek to Claude Code

bash
magpie claude deepseek/deepseek-v4-pro

2. Launch Claude Code

Start your normal coding assistant:

bash
claude

Give Claude Code a multi-step autonomous task:

text
> Scan package.json for outdated dependencies below v5.0 and output findings to outdated.md

3. Execution Walkthrough

  • Claude Code formats its file-reading tool call into Anthropic's tool schema;
  • Magpie AI translates the schema on the fly into OpenAI function calling format for DeepSeek;
  • DeepSeek decides to call ReadFile;
  • Magpie translates the response to an Anthropic tool_use chunk and streams it to Claude Code;
  • Claude Code executes the file read on disk and returns the content;
  • DeepSeek analyzes the content and triggers WriteFile;
  • outdated.md is generated.

The entire multi-turn autonomous cycle succeeds effortlessly, consuming DeepSeek's budget-friendly tokens for a 90% cost reduction over official pricing.


Troubleshooting

Q: What if a smaller model returns raw tool call JSON as plain text?

A: Lightweight models (such as 7B/8B local models) can struggle with complex tool schemas. We strongly recommend robust frontier reasoning models such as DeepSeek V3, DeepSeek R1, Kimi K2.5, or GPT-4o, which exhibit state-of-the-art tool-use proficiency.

Q: Does the gateway tamper with tool outputs?

A: No. Magpie adapts only envelope schemas and transmission protocol headers. Payload bytes returned by tools (file data, SQL tables, shell output) pass through untouched.

Q: Do I need to alter my stdio or SSE MCP servers in ~/.claude.json?

A: Not at all. Your existing MCP server registrations remain unchanged. Claude Code spawns and communicates with them as usual; Magpie only translates the tool definition schemas and invocations passing to and from the upstream model.