Skip to main content
Glama

@brooswit/thatch

中央 HTTP MCP サーバーであり、Elysia のプラグインです。多数の Claude Code セッションが、1つのサーバーに URL 経由で接続します。サーバーはセッションを名前で特定し、ライブ中のセッションにメッセージをプッシュできます。

import { Elysia } from "elysia";
import { thatch, z } from "@brooswit/thatch";

const { plugin, mcp } = thatch({
  identify: (req) => req.headers.get("x-connection-name"),   // names the connection; null rejects it
  tools: {
    status: { description: "Fleet status", input: {}, handler: (_a, c) => `hello ${c.name}` },
  },
});

const app = new Elysia().use(plugin).listen(3000);

// push a message into a named session — from anywhere
const d = await mcp.send("epic-kan-39", { content: "PR #296 approved", meta: { key: "KAN-39" } });
//  d: { claim: "C2" }  — a connected session's stream took it
//     { claim: "refused", reason: "not-connected" | "no-channel-stream" | "bad-meta" | "closed-mid-send" }

Claude Code の接続方法は次のとおりです。

claude mcp add --transport http fleet http://localhost:3000/mcp --header "x-connection-name: epic-kan-39"

配信タイプが void でない理由

セッションへのプッシュは、MCP SD K が隠してしまうかたちで失敗することがあります。つまり、通知ストリームか接続されていながら接続が登録されている場合があり、その場合 SDK はフレームを黙って破棄してしまいます。thatch はそれを黙ってみず、明示的に拒否します(no-channel-stream)。また、C2 を主張するのは、実際にフレームを運ぶストリームが存在する場合だけです。C3(トランスクリプションに入ったこと)と C4(モデルが読んだこと)は観察できないため、そのAPI がそれらを観測済みとして認証することはありません。

Related MCP server: agent-network

API

  • thatch(options) → { plugin, mcp } — plugin はエンドポイント(デフォルトは /mcp)をマウントし、mcp はそのハンドルです。

  • options: identify(req)、onDuplicate("replace" がデフォルト | "reject")、history(デフォルト50)、tools、path、serverInfo。

  • mcp.connections: list()、get(name)、has(name)、count()、waitFor(name, { timeoutMs })。

  • mcp.send(name, frame)、mcp.sendMany(names, frame)、mcp.sendAll(frame, { where? })。

  • mcp.on("connect" | "disconnect" | "send", handler)。

  • Connection には、name、connectedAt、lastSeenAt、meta、channelReady、history が含まれます。

  • テストには import { FakeConnection } from "@brooswit/thatch/testing" を使用します。

支

protocol(フレーム、配信、メソッド — 純粋)・registry(名前付き接続 + 履歴)・channel(送信、正直な主張)・plugin(Elysia のマウンド、接続ごとに1つの MCP サーバー)・testing。

スクリプト

bun run check        # generate load tests + typecheck + unit + load + coverage ≥90%
bun test test/unit
MCP_LIVE=1 bun test test/live   # against a real Claude Code session (opt-in)

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers