Provides a bridge that exposes an OpenAI-compatible /v1/chat/completions HTTP endpoint, allowing MCP tools to forward chat completion requests and responses with MCP-specific headers.
MCPTokenBridge
Overview (English)
MCPTokenBridge is a single-file Python bridge that simultaneously runs an OpenAI-compatible /v1/chat/completions HTTP endpoint (FastAPI + uvicorn) and a stdin-based MCP tool named hook. The hook worker thread never stops; it drains an internal queue so web requests are forwarded to MCP and returned with X-MCP-* headers. The process has only one entrypoint and starts both services together.
概览(中文)
MCPTokenBridge 是一个单文件的 Python 桥接程序,同时运行 OpenAI 风格的 /v1/chat/completions HTTP 接口(FastAPI + uvicorn)和基于 STDIN 的 MCP 工具 hook。hook 工作者线程常驻,持续从队列中取出请求并返回带有 X-MCP-* 头的结果;整个流程只有一个入口,启动即同时运行两种服务。
Getting Started / 快速开始
Run: single entry (HTTP + MCP) / 运行方式:单一入口(HTTP + MCP)
Network binding guidance / 网络绑定说明
English: Use
--host 0.0.0.0when you want every network adapter (e.g.,192.168.55.10:8888and192.168.1.11:8888) to be reachable on the same port. Use a specific host (e.g.,--host 192.168.55.10 --port 8888) to bind only that adapter; other adapters will not accept connections.中文:当需要让所有网卡(例如
192.168.55.10:8888与192.168.1.11:8888)都可访问时,使用--host 0.0.0.0。若只想绑定某个适配器,请指定具体地址(如--host 192.168.55.10 --port 8888);此时其他适配器将无法访问。
Flow (English)
HTTP
POST /v1/chat/completionsenqueues the request and waits for thehookworker reply.The
hooktool never terminates; it runs on a fixed background thread and returns MCP headers along with the chat response.
工作流(中文)
HTTP
POST /v1/chat/completions会将请求入队,等待hook工作者返回结果。hook工具常驻后台线程,不会结束,同时返回 MCP 相关的响应头与聊天内容。
Project Layout / 目录结构
mcptb.py— single runtime module for both HTTP and MCP modes / 兼作 HTTP 与 MCP 入口的单文件模块requirements.txt— dependencies / 依赖声明tests/— pytest suite / 单元测试logs/,bin/— outputs and helper scripts / 输出与辅助脚本
VS Code MCP configuration (English)
Place mcp.json under .vscode/ (or your global MCP directory) so Copilot Chat launches the combined entrypoint and keeps hook alive:
Ensure
pythonpoints to your virtual environment; the MCP stdin server and HTTP server start together on the specified host/port.Keep the process running; the
hooktool never terminates and forwards all chat completions through the queue.
VS Code MCP 配置(中文)
在 .vscode/(或全局 MCP 目录)下放置 mcp.json,让 Copilot Chat 启动组合入口并保持 hook 持续运行:
确认
python指向虚拟环境;MCP stdin 与 HTTP 服务器会在指定的主机和端口同时启动。进程需保持常驻;
hook工具不会结束,所有 Chat Completion 请求都会通过后台队列转发。