harness_to_mcp
Exposes internal tools from agent harnesses (Claude Code, Codex, etc.) as a standard MCP server by intercepting LLM API calls.
README
harness_to_mcp: Expose harness internal tools as a standard MCP server
Contents: Features | Install | Demo | How it works | Notes
Turn any agent harness (Claude Code, Codex, OpenClaw, OpenCode, ...) into an MCP server.
How: harness_to_mcp sits between the harness and its LLM API, grabs the tool list from the hijacked request, and routes MCP tools/call back into the harness tool loop.
▮ Features
- ☑ One command to expose
claude/codex/openclaw/opencodeas an MCP server - ☑ Co-locates one MCP HTTP server and one hijack LLM API server on the same port
- ☑ Extracts the harness tool list automatically from intercepted LLM requests
- ☑ Mirrors captured harness system prompt into MCP
initialize.result.instructions - ☑ Forwards MCP
tools/callinto the harness tool loop and maps the tool result back - ☑ Compatible LLM API protocols:
- OpenAI Chat Completions (
openclaw,opencode) - OpenAI Responses (
codex) - Anthropic Messages (
claude)
- OpenAI Chat Completions (
- ☑ Isolated harness config — will not pollute the user's own config and logs
- ☑ One harness process per MCP session, the harness process is stopped automatically on session close
- ☑ Plain server mode for bringing your own harness
- ☑ Pure-Python, clean dependencies — easy to hack and vibe-code on
▮ Install
pip install harness_to_mcp
The target harness CLI (claude, codex, openclaw, ...) needs to be installed separately and available on PATH.
▮ Demo
1. One-liner to expose a harness as MCP
harness_to_mcp claude
# or: harness_to_mcp codex / openclaw / opencode
Each command starts a server and launches one corresponding harness instance. The harness is started with an isolated config, so it will not touch the user's own config or logs.
The MCP endpoint is then ready at:
http://127.0.0.1:<port>/mcp
Point any MCP client (Claude Desktop, Cursor, your own script, ...) at it and the harness's internal tools show up as standard MCP tools.
You can inspect the exposed tools with python examples/list_tools.py.
2. Only run the server (plug in any harness)
harness_to_mcp
This mode starts only the server. It listens on MCP plus all hijack LLM API routes, but does not launch any harness by itself. Configure your harness's LLM API as the hijack API, send one request, and its internal tools are exposed on MCP. This is also how you plug in claude / codex / openclaw / opencode with your own custom config.
Exposed endpoints:
| Purpose | Path |
|---|---|
| MCP | POST /mcp (alias: POST /harness_to_mcp/mcp) |
| OpenAI Chat Completions | POST /harness_to_mcp/v1/chat/completions |
| OpenAI Responses | POST / WebSocket /harness_to_mcp/v1/responses |
| Anthropic Messages | POST /harness_to_mcp/v1/messages |
3. Python API
We also provide a Python interface:
from harness_to_mcp import HarnessToMcp
with HarnessToMcp(port=9330) as server:
print(server.mcp_url) # e.g. http://127.0.0.1:9330/mcp
print(server.hijack_base_url) # e.g. http://127.0.0.1:9330/harness_to_mcp
▮ How it works
sequenceDiagram
participant C as MCP Client
participant M as harness_to_mcp<br/>MCP Server
participant H as harness_to_mcp<br/>Hijack API Server
participant R as Harness
C->>M: initialize
M->>R: launch harness session
R->>H: send hijacked LLM API request
H-->>M: extract tool list from request
M-->>C: tools/list
C->>M: tools/call
M-->>H: resolve waiting request as tool call
H-->>R: return tool call payload
R->>R: execute internal tool
R->>H: send next request with tool result
H-->>M: match tool_call_id and deliver tool result
M-->>C: MCP tool response
In short:
- MCP client calls
initialize→ we spawn a harness. - The harness fires off its first LLM request (with the tool schema in it) → we intercept the request, extract the tool list, and reply to the MCP client with
tools/list. - MCP client calls
tools/call→ we complete the pending LLM response as a tool call, the harness executes its internal tool, and sends the result back in the next LLM request. - We match the
tool_call_id, extract the tool result, and return it as the MCP tool response.
▮ Notes
- The LLM API layer is split into reusable adapters:
chat completions,responses,messages. - The harness launcher layer is split per-harness:
opencode,openclaw,codex,claude. - Plain server mode (
harness_to_mcpwith no subcommand) never auto-launches a harness. - Intercepted waiting requests are kept alive with periodic heartbeat bytes until MCP receives the next tool call.
▮ License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。