
Relay Mcp
io.github.zhowe-designs由 GitHub 帳號 zhowe-designs 發布v0.1.0更新於 Nov 3, 2026
Self-hosted session relay. Shared threads across Claude Code, Cowork, and Claude.ai.
概覽
自架的工作階段中繼,讓 Claude Code、Cowork 與 Claude.ai 共用訊息討論串,在工作階段之間傳遞狀態。
- 可以做什麼
- 列出與建立具名討論串,顯示最近活動時間與訊息數量
- 張貼訊息到討論串,討論串不存在時自動建立
- 由新到舊讀取最近訊息,可選擇更新讀取游標
- 只回傳該讀取端上次檢查之後的新訊息
- 軟封存討論串,使其從預設清單隱藏但保留歷史
- 適用情境
- 適合在多個 Claude 介面之間工作時使用,讓某個工作階段留下筆記或狀態,供另一個工作階段稍後取用,不必複製貼上。它是工作階段之間的輕量白板,不是日誌、決策紀錄或記憶儲存。
- 執行需求
- 需自行部署:Cloudflare 帳號(Workers)、一個 Supabase 專案並執行提供的遷移腳本,本機需 Node 20 以上。需設定 Worker 密鑰 RELAY_API_KEY、SUPABASE_URL、SUPABASE_SERVICE_KEY 與 RELAY_USER_ID。用戶端以 HTTP 連線到部署網址加 /mcp,使用 Authorization Bearer 標頭或 Claude.ai 連接器的 OAuth;Claude Desktop 需透過 mcp-remote 橋接。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Relay Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
relay-mcp
This repo is the open-source reference implementation. The author runs a private deployed instance at a different URL, but you should deploy your own instance for production use.
A self-hosted session relay for Claude. When you work across multiple Claude surfaces (Code, Cowork, Claude.ai connectors), each surface lives in its own context window. The relay gives them a shared message thread they can all post to and read from, so a Code session can hand state to a Chat session without copy-paste, and a scheduled Cowork task can leave a note your morning Chat picks up. It is a lightweight whiteboard, not a log or a memory store.
Tools
The server exposes six MCP tools.
Every message carries a surface field (chat, cowork, code, other) and an optional free-text session_tag so threads stay legible across many parallel sessions.
Architecture
-
Cloudflare Worker at
src/index.ts. Stateless. Speaks streamable HTTP MCP at/mcp. -
Supabase Postgres for thread, message, and read-cursor storage. Three tables, all prefixed
relay_. RLS enabled with zero policies; only the Worker's service-role key can read or write. -
Two auth paths on the same server:
- Static Bearer for Claude Code and Cowork:
Authorization: Bearer <RELAY_API_KEY>. Simplest possible. No browser flow. - OAuth 2.1 with Dynamic Client Registration for Claude.ai custom connectors. The Worker exposes
/.well-known/oauth-authorization-server,/register,/authorize, and/token. Access tokens are HS256 JWTs signed withRELAY_API_KEY. Stateless, no KV or Durable Objects required. Access tokens last 90 days, refresh tokens 365.
See Security for the consolidated auth, rotation, and threat-model writeup.
- Static Bearer for Claude Code and Cowork:
-
Single tenant in v1. The Worker reads a hardcoded user UUID from the
RELAY_USER_IDsecret. Multi-user support is a one-file change insrc/oauth.tsplus an RLS policy migration; the schema already carriesuser_idcolumns.
Deploy your own
Self-hosting takes about ten minutes. You will need a Cloudflare account (Workers free tier is fine), a Supabase project, and Node 20+ locally.
1. Clone and install
2. Create a Supabase project and run the migration
Create a new project at supabase.com. In the SQL editor, paste and run migrations/001_initial.sql. This creates relay_threads, relay_messages, relay_read_cursors, sets up indexes, enables RLS with zero policies, and revokes anon and authenticated grants.
From Project Settings → API, copy:
- The Project URL (looks like
https://abcdef.supabase.co). - The service_role key. Treat this like a database password.
3. Pick a tenant UUID
Generate one (uuidgen, crypto.randomUUID(), or any UUID v4 generator). This is the single user the v1 server is bound to. You can rotate it later, but everything posted under one UUID is invisible under another.
4. Set Worker secrets
5. Deploy
Wrangler prints the deployed URL, something like https://relay-mcp.<your-subdomain>.workers.dev. That URL plus /mcp is the MCP endpoint.
6. Optional: custom domain
Edit wrangler.toml and uncomment the routes block, swapping relay-mcp.example.com for a hostname on a Cloudflare zone you own. Re-run npx wrangler deploy. Wrangler creates the CNAME automatically.
7. Smoke test
Forty assertions, including the OAuth flow. All green means you are live.
Configure your clients
Replace <RELAY_URL> with your deployed URL and <RELAY_API_KEY> with the secret you set above.
Claude Code
Add to .mcp.json in the project root, or to ~/.claude.json for global access.
Restart Claude Code, run /mcp, and confirm relay appears with six tools.
Cursor
Add to .cursor/mcp.json in the project root, or to ~/.cursor/mcp.json for global access.
Restart Cursor, open the MCP settings, and confirm relay appears with six tools.
Gotcha: the relay block must sit inside the mcpServers object. Cursor silently ignores any server defined at the top level of the file. If the tools do not show up, this is the first thing to check.
Cowork scheduled tasks
Add an mcp_servers block to any task prompt that needs relay access.
Claude Desktop
Claude Desktop's MCP support expects stdio commands, not remote HTTP URLs. To connect to a remote relay, use the mcp-remote bridge, which adapts a stdio-launched process to a remote HTTP MCP server.
Open claude_desktop_config.json (on Windows: %APPDATA%\Claude\claude_desktop_config.json; on macOS: ~/Library/Application Support/Claude/claude_desktop_config.json) and add:
Fully quit Claude Desktop (not just close the window) and reopen. The relay should appear in the tools menu with six tools.
Gotcha: Claude Desktop rewrites claude_desktop_config.json on some session lifecycle events and can silently wipe manual mcpServers additions. If your relay disappears between sessions, re-add the block and keep a backup copy somewhere outside the Claude Desktop config directory so you can paste it back. The Claude.ai custom connector path below avoids this entirely and is preferable if you can use it.
Claude.ai custom connector
Claude.ai uses OAuth 2.1 with Dynamic Client Registration, which the relay supports.
- In Claude.ai, open Settings → Connectors → Add custom connector.
- Name: anything, e.g.
Relay. - Remote MCP server URL:
<RELAY_URL>/mcp. - Leave the Advanced OAuth fields blank. Claude.ai handles registration automatically.
- Click Add. A browser tab opens to your Worker's
/authorizepage. - Paste your
RELAY_API_KEYinto the single input and click Authorize. - The browser redirects back to Claude.ai. The connector lists six tools.
Access tokens last 90 days with automatic refresh, so you should rarely re-authorize. If auth ever fails, remove the connector and re-add.
Troubleshooting
Common failure modes from real deploys, with the first thing to check for each.
Smoke test fails with 401 Unauthorized. The RELAY_API_KEY in your local environment does not match the secret deployed to the Worker. Re-run npx wrangler secret put RELAY_API_KEY, then re-export the same value in the shell where you run the smoke test. Wrangler does not display secret values after they are set, so if in doubt, rotate to a fresh value on both sides.
Worker returns 5xx on any tool call. Almost always the Supabase service-role key was not set, or was set to the anon key by mistake. Re-run npx wrangler secret put SUPABASE_SERVICE_KEY with the value from Supabase Project Settings -> API -> service_role. Also confirm SUPABASE_URL is the project URL (no trailing /mcp, no path) and RELAY_USER_ID is a valid UUID v4.
Custom domain returns 530. Cloudflare 530 is a DNS resolution failure, usually the CNAME has not propagated yet. Wait a few minutes and retry. If it persists, confirm the hostname in wrangler.toml is on a Cloudflare zone you actually own and that npx wrangler deploy reported the route as attached.
Cursor does not see the relay tools. The relay block is sitting at the top level of .cursor/mcp.json instead of inside the mcpServers object. Cursor silently ignores top-level entries. Move the block inside mcpServers and restart Cursor.
Claude Desktop does not see the relay tools. Two likely causes. First, mcp-remote is missing or npx cannot fetch it on launch (Claude Desktop swallows stderr); run npx -y mcp-remote --help once in a terminal to prime the cache and surface any install errors. Second, Claude Desktop has overwritten claude_desktop_config.json and wiped your mcpServers entry; re-add it from your backup and fully quit and reopen the app.
OAuth flow on Claude.ai loops back to the authorize page. The browser blocked third-party cookies on the Worker domain, or your RELAY_API_KEY was pasted with surrounding whitespace. Try a fresh browser profile, paste the key carefully, and watch the Worker logs (npx wrangler tail) for the actual error.
Usage
Once connected, you describe intent. The model picks the right tool. Some examples of sentences that work:
- "Post the last error, the migration diff, and my theory to relay thread
migration-debug, surface code." - "Read
daily-standup, show me everything Cowork posted this morning." - "Pull the last ten messages from
migration-debug."
Thread naming
Short, dash-separated, topic-scoped. migration-debug, not april_migration_issues_2026. One thread per topic, not one per day. Threads accumulate; conversations continue across weeks. A thread auto-creates the first time anything posts to it, so there is no ceremony around starting one.
Good: migration-debug, daily-standup, pricing-notes, scratch.
Bad: april-18-bugs, thread-1, general.
Surface tagging is not optional
Always set surface to chat, cowork, code, or other. Six months from now when you scroll a thread, knowing a message came from a scheduled Cowork task versus a live Chat conversation changes how you weight it. Use session_tag for free-text grouping inside a surface (e.g. one tag per debugging session).
Archive dead threads
When a topic is done, call relay_archive_thread. Archived threads hide from the default list_threads output but stay queryable via include_archived. Think Slack channels, not Git branches. Archive preserves history; it does not delete.
The boundary rule: transient layer, not canonical state
The relay is a conversation layer between sessions. It is not a log, not a decision record, and not a memory store. Anything you will care about next week belongs in your real system of record (decision log, task tracker, docs, code comments, etc.). The relay is what was said in the moment, not what was decided. If a relay post captures a real decision, write it down somewhere durable before moving on.
Never relay secrets
Same rule as any chat. API keys, service-role tokens, OAuth secrets, database credentials. Those go in Wrangler secrets or your password manager. They never go in a relay message. The relay database is not a vault. See Security for the full list of what not to post.
Security
This section consolidates the relay's auth model, key rotation procedure, content rules, and threat model.
Auth model
Static Bearer. Claude Code and Cowork authenticate with Authorization: Bearer <RELAY_API_KEY>. The Worker compares the header to the RELAY_API_KEY secret on every request. There is no browser flow, no token exchange, no refresh. Whoever has the key has full access to every thread under the configured RELAY_USER_ID.
OAuth 2.1 with DCR. Claude.ai custom connectors use OAuth 2.1 with Dynamic Client Registration against /register, /authorize, and /token. The user pastes their RELAY_API_KEY once into the Worker's authorize page; the Worker verifies it and issues an HS256 JWT signed with that same RELAY_API_KEY. Access tokens last 90 days, refresh tokens 365. No server-side session store, no KV, no Durable Objects.
Key rotation runbook
Rotate RELAY_API_KEY with:
Consequences to plan for:
- All OAuth tokens are invalidated. Tokens are JWTs signed with
RELAY_API_KEY, so changing the secret breaks every existing signature. Every Claude.ai connector user must remove and re-add the connector and re-authorize with the new key. - Static Bearer clients break until reconfigured. Update
.mcp.json,.cursor/mcp.json,claude_desktop_config.json, and any Cowork taskmcp_serversblocks with the new key. Until each is updated, that client returns 401.
Rotate when a key is suspected exposed, when a teammate with access leaves, or on a routine schedule if your threat model calls for one.
What not to post
Threads are persisted in Supabase and are visible to anyone holding the RELAY_API_KEY. Treat the relay as a shared whiteboard, not a vault. Do not post:
- API keys, service-role tokens, OAuth client secrets, refresh tokens.
- Database passwords or connection strings with embedded credentials.
- Customer PII, regulated data, or anything covered by an NDA.
- Anything that would be a problem if the relay backend, the Supabase project, or any client config holding the API key were compromised.
Secrets belong in Wrangler secrets or a password manager. The relay database is not a vault.
Threat model
The relay is single-tenant in v1. It assumes the operator trusts every session that holds the RELAY_API_KEY, because any holder can read and write every thread under the configured RELAY_USER_ID. There is no per-session scoping, no audit trail beyond Worker logs, and no policy layer between the Worker and Supabase. Multi-user or multi-tenant deployments need additional auth layering (per-user keys, scoped tokens, RLS policies keyed off user_id) that is not provided here. The schema already carries user_id columns to make that extension straightforward, but you have to build it.
Development
Schema
Three tables, all prefixed relay_. Migration at migrations/001_initial.sql.
relay_threads. One row per named thread per user.relay_messages. One row per posted message. Indexed on(thread_id, created_at desc).relay_read_cursors. One row per(thread_id, reader_tag). Tracks "last time this reader checked."
Service-role access only. RLS is enabled with zero policies, and anon and authenticated are revoked. Only the Worker's service-role key can read or write.
Layout
Contributing
This is not an actively maintained community project. PRs are welcome for bugfixes, documentation improvements, and obvious quality-of-life additions. Larger features or refactors will likely be declined to keep the surface area small. Open an issue first if you want to discuss something nontrivial.
License
MIT. See LICENSE.
來源:README.md,提交 d29db24
工具
0版本歷史
1- v0.1.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分