跳到內容

MCP connector 和 remote MCP

pi-roundtable-mcp 是獨立的 npm 套件,裡面有兩個外掛。 兩個都透過 MCP 運作;MCP 是 agent 呼叫另一台 server 上工具的協定。

外掛 作用
mcpConnectors 你在 Discord 加入一台 MCP server,例如 Notion 或行事曆,你的 agent 就能用它的工具。
remoteMcp Discord 以外的 agent 能傳訊息給你的 agent,並讀取回答。它也能使用你選擇開放給它的 Discord 頻道。

兩個外掛合起來涵蓋兩個方向:你的 agent 能用別台 server 的工具,別處的 agent 也能找到你的 agent。

套件目前位於 pi-roundtable workspace 的 packages/mcp;完整選項和訊息文字見套件 README(英文)。

終端機視窗
bun add pi-roundtable-mcp pi-roundtable

需要 Bun 1.4.4 以上、>=0.50.0 <0.51.0 的 pi-roundtable,以及 bot 使用的 PostgreSQL。 mcpConnectors 還需要一個自行執行的 ContextForge gateway,見下方。 remoteMcp 需要能連到 host public listener 的 HTTPS 位址,例如 tunnel。

把外掛列在 roundtable.config.ts:

import type { RoundtableConfig } from "pi-roundtable";
import { mcpConnectors, remoteMcp } from "pi-roundtable-mcp";
const env = (name: string): string => process.env[name] ?? "";
export default {
// ... the rest of your config
plugins: [
mcpConnectors({
contextForge: {
url: env("CONTEXTFORGE_URL"),
jwtSecret: env("CONTEXTFORGE_JWT_SECRET"),
user: env("CONTEXTFORGE_USER"),
},
}),
remoteMcp({
dispatchToken: env("MCP_DISPATCH_TOKEN"),
publicUrl: env("PUBLIC_URL"),
}),
],
} satisfies RoundtableConfig;

兩個外掛可以只用其中一個。

mcpConnectors 必須設定 contextForge.url、contextForge.jwtSecret 和 contextForge.user;serverPrefix 預設為 roundtable-conn-,maxToolName 預設為 45,messages 可修改預設英文訊息。 remoteMcp 必須設定 dispatchToken 和 publicUrl;persona 可修改預設對話提示詞,host 自行管理對話時 answer 和 claim 必須一起提供,messages 可修改訊息,toolNames 預設為 agent_dispatch 和 agent_result。

/roundtable connector add 會開一個私人表單,讓你填 server 位址和 token。 list、describe、resync 和 remove 用來管理已加入的 connector;resync 會重新向 connector 的伺服器讀取工具(沒指定名稱就處理全部),伺服器改過名的工具不必重新加入 connector 就會接上。 只有 owner 能用這些指令。

ContextForge 保管每台上游 server 和它的 token。 它是 IBM 的開源 MCP gateway;這個套件不會替你執行它。 把 gateway 跑在 host 旁邊,並讓兩邊使用相同的 JWT secret。

外掛會把 connector 清單交給你的程式碼。 你的程式碼再依清單選擇 connector,替每個 agent 建立工具。 套件 README 有範例。

這個外掛在 host 的 public listener 上提供兩個 endpoint。

Endpoint 誰能呼叫 提供什麼
/mcp/personal 帶著 dispatch token 的 agent 兩個工具。一個開始或繼續與你的 agent 對話,並立即回傳;另一個在回答準備好時讀取結果。
/mcp/discord/<token> 持有 bundle 位址的 agent 使用已授權頻道的 Discord 工具,而且只限你允許的操作。

在想分享的頻道執行 /roundtable mcp authorize,即可授權頻道。 bot 會詢問你要開放哪些操作。 grants 列出授權,revoke 移除頻道,token 則更換 bundle 位址。

每個呼叫都會在執行時重新檢查,並寫入 audit table。 撤銷授權或更換位址會停止正在執行的呼叫。 授權範圍不會超過你和 bot 在該頻道都能執行的操作。

預設情況下,remoteMcp 會在 core 上把轉送訊息當成 owner conversation 執行。 host 若已有自己的 owner conversation,可以改傳 answer 和 claim,由 host 自己處理這些對話。 做法見 README。

兩個外掛的預設文字都是英文,也都能用 messages 選項修改。 Discord 訊息、錯誤訊息和工具說明都可以改成你使用的語言。