mcp-local-gateway

mcp-local-gateway

Minimal MCP server exposing a single tool, run_date, to execute the local date command via a Streamable HTTP endpoint.

Category
访问服务器

README

mcp-local-gateway

P0 goal: run a minimal local MCP server that exposes exactly one tool, run_date, through a Streamable HTTP /mcp endpoint.

This project is intentionally small. It does not expose arbitrary Bash. It does not use an OpenAI API key. It is designed for this validation chain:

ChatGPT Web
  -> HTTPS /mcp
  -> Cloudflare Tunnel or another HTTPS tunnel
  -> 127.0.0.1:8787
  -> Hono
  -> MCP Server
  -> policy layer
  -> fixed date command

Terms

  • MCP: Model Context Protocol, 模型上下文协议,用来让 AI Host 通过标准协议发现并调用外部工具。
  • Streamable HTTP: 可流式 HTTP 传输,适合远程 MCP server。
  • Hono: 轻量 HTTP framework,HTTP 框架。
  • OAuth: Open Authorization,开放授权。P0 只预留结构,不实现完整授权码流程。
  • Policy layer: 策略层,本项目中用于拒绝任意命令,只允许 run_date -> date。

Requirements

  • Node.js >= 20.11
  • npm
  • Linux / WSL recommended

Install

cd ~/project/mcp-local-gateway
npm install
cp .env.example .env

Start

npm run dev

Expected startup lines:

mcp-local-gateway listening on http://127.0.0.1:8787
health: http://127.0.0.1:8787/healthz
mcp:    http://127.0.0.1:8787/mcp
auth:   off

Local validation

In another terminal:

cd ~/project/mcp-local-gateway
npm run typecheck
npm run build
npm test
npm run test:local

The tools/list response should include run_date. The tools/call response should include JSON text containing stdout from the local date command.

Persistent user service / 用户级常驻服务

Use the user-level systemd service when you want the gateway to keep running after the terminal closes.

npm run service:install
npm run service:status
npm run service:logs
npm run service:uninstall

service:install runs npm run build and starts dist/index.js; it does not use npm run dev. The service keeps running after the terminal exits. Cloudflare Tunnel access to mcp.songlei.me depends on this service listening on 127.0.0.1:8787.

Persistent OpenAI Tunnel / OpenAI Tunnel 常驻运行

Use the user-level systemd service when you want tunnel-client to keep the OpenAI Tunnel process running after the terminal closes.

npm run tunnel:install
npm run tunnel:status
npm run tunnel:logs
npm run tunnel:uninstall

tunnel:install runs npm ci and npm run build, checks tunnel-client, ~/.config/homelab-mcp/openai-tunnel.env, and ~/.config/tunnel-client/homelab-stdio.yaml, then installs openai-tunnel-client.service. The service uses WorkingDirectory at the repository root, loads ~/.config/homelab-mcp/openai-tunnel.env, and runs:

tunnel-client run --profile homelab-stdio --health.listen-addr 127.0.0.1:18080 --health.url-file /tmp/homelab-openai-tunnel-stdio-health.url --log.file /tmp/homelab-openai-tunnel-stdio.log

After install, the script runs systemctl --user daemon-reload, enable, restart, and status for openai-tunnel-client.service, then waits for both /healthz and /readyz to succeed through the URL written to /tmp/homelab-openai-tunnel-stdio-health.url.

Static bearer mode

Use this before exposing through a tunnel if you are not using OAuth yet.

cat > .env <<'ENDENV'
HOST=127.0.0.1
PORT=8787
MCP_AUTH_MODE=static_bearer
MCP_STATIC_BEARER_TOKEN=replace-this-with-a-long-random-token
MCP_ALLOWED_ORIGINS=http://127.0.0.1:8787,http://localhost:8787,https://chatgpt.com
AUDIT_TO_STDOUT=true
AUDIT_LOG_FILE=logs/audit.jsonl
ENDENV

npm run dev

Validation with token:

MCP_STATIC_BEARER_TOKEN='replace-this-with-a-long-random-token' npm run test:local

Cloudflare Tunnel sketch

Do not bind this server to 0.0.0.0. Keep HOST=127.0.0.1 and publish it with a tunnel.

Example target mapping:

https://mcp.songlei.me/mcp -> http://127.0.0.1:8787/mcp

After that, create a ChatGPT connector and set Connector URL to:

https://mcp.songlei.me/mcp

P0 recommendation: use static bearer only for a private short-lived test. P1 should implement OAuth / OIDC token validation or put the MCP server behind a compatible identity-aware proxy.

Security constraints in P0

  • No arbitrary Bash.
  • run_date accepts no arguments.
  • Command execution uses spawn with shell: false.
  • Server refuses HOST=0.0.0.0.
  • /mcp checks Origin when Origin is present.
  • /mcp can enforce static Bearer token.
  • Each tool call writes JSONL audit records.

File map

src/index.ts              entry point
src/config.ts             environment config and startup safety checks
src/http/app.ts           Hono app, health endpoint, /mcp route
src/http/origin.ts        Origin allowlist guard
src/auth/auth.ts          off/static_bearer/oauth_placeholder auth middleware
src/mcp/server.ts         MCP server creation and tool registration
src/mcp/transport.ts      Streamable HTTP transport creation
src/tools/run-date.ts     run_date MCP tool
src/policy/policy.ts      P0 allow/deny logic
src/shell/exec-fixed.ts   fixed date command execution
src/audit/audit.ts        JSONL audit logger
scripts/local-validate.sh curl-based validation script
test/*.test.ts            minimal unit tests

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选