简介
synapse
原始描述
Agent-to-agent P2P file sharing with semantic search using BitTorrent and vector embeddings
通过你的 Agent 添加
安装目录:synapse/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
Synapse 是一款融合 BitTorrent P2P 网络与语义搜索技术的 Agent 文件共享工具。用户通过命令行界面即可完成完整的文件共享生命周期:启动 seeder 守护进程作为网络节点,使用 share 命令将文件注入网络并自动生成磁力链接,系统同时为文件内容生成向量嵌入用于语义索引。其他用户可通过自然语言描述进行内容相似度搜索,search 命令将查询转换为向量并在分布式网络中匹配相关资源,最终通过磁力链接完成点对点下载。
该工具采用 Python 3.10+ 开发,依赖 uv 现代包管理器实现零配置环境部署,集成 sentence-transformers 进行文本向量化,使用 FAISS 或类似方案实现高效的相似度检索。默认接入 HiveBrain 社区的 Tracker 服务器协调节点发现,同时支持自定义 Tracker 配置。
显著优点
技术创新性:将传统 P2P 文件共享与向量语义搜索结合,突破基于文件名/关键词的检索限制,用户可用概念描述而非精确标题查找资源,大幅降低知识发现门槛。
去中心化架构:基于成熟的 BitTorrent DHT 网络,无单点故障风险,共享内容不依赖中心化服务器存储,抗审查能力较强,适合开放知识协作场景。
开发者体验优秀:uv 工具链实现依赖自动管理,免除传统 Python 虚拟环境的手动配置;CLI 设计遵循 Unix 哲学,命令语义清晰,支持守护进程模式便于长期运行。
隐私友好:无需注册账户即可参与网络,ML-DSA-87 后量子签名方案保障身份安全,无强制数据收集行为。
潜在缺点与局限性
网络传输未加密:Tracker API 当前使用 HTTP 明文传输,搜索查询与元数据存在中间人截获风险,需等待上游 HTTPS 升级。
生态依赖较新:uv 作为新兴工具仍在快速迭代,Windows 支持尚不完善;sentence-transformers 依赖 PyTorch,首次运行需下载数百 MB 模型文件。
搜索覆盖度有限:语义搜索依赖网络中节点主动共享并注册嵌入向量,冷启动阶段可用资源较少;向量匹配对非文本内容(图像、视频、二进制文件)效果受限。
运维复杂度:P2P 网络需要长期在线的 seeder 节点保障可用性,个人用户设备离线将导致共享内容不可发现,需权衡本地资源消耗与网络贡献。
适合的目标群体
- 研究团队与知识管理从业者:需要在内部分享大量文档、论文,并支持模糊概念检索的场景
- 开源社区与开发者:希望建立去中心化的技术文档、代码片段共享网络
- 隐私敏感用户:规避中心化云存储服务,偏好自主控制数据的主权主义者
- 边缘计算与离线优先场景:网络连接不稳定但需本地协作的环境
使用风险
供应链安全:安装流程包含 curl|bash 远程脚本执行,虽来源为 uv 官方域名,仍建议验证脚本哈希;59 个依赖项需持续关注 CVE 披露。
法律合规:P2P 文件共享技术本身中立,但用户需确保共享内容符合版权法规;Tracker 日志可能记录节点 IP 与查询模式。
数据持久性:无中心化备份机制,热门程度低的文件可能因所有 seeder 下线而永久丢失,重要数据需额外冗余策略。
性能消耗:向量嵌入计算需 CPU/GPU 资源,大规模文件库首次索引时间较长;守护进程持续占用内存与网络端口。
技能正文
name: synapse
description: Builds a Synapse UI for any MCP server — a React app built to one inlined HTML file, served as a ui:// resource for MCP Apps hosts (Claude, ChatGPT, NimbleBrain). Use to add a frontend to an MCP server. Triggers include "build a Synapse app", "make this interactive", "wire a ui:// resource".
license: MIT
compatibility: Node.js 22+, npm (for the React/Vite UI build). The MCP server itself can be Python (FastMCP) or TypeScript.
allowed-tools: Read Write Bash Glob Grep WebFetch
metadata:
area: synapse
version: "0.5.0"
author: NimbleBrain
Synapse — build a UI for an MCP Server
Give an MCP server an interactive UI. The UI is a React app built to one inlined HTML file with @nimblebrain/synapse + Vite, served by the server as the MCP resource ui://<name>/main, and mounted by an MCP Apps host (Claude, ChatGPT, NimbleBrain) in a sandboxed iframe wired to a postMessage bridge. The UI calls the server's existing tools over that bridge — it is data-layer-agnostic and needs no special server framework. Every host speaks the same bridge; they differ in which capabilities they declare, and the SDK behaves predictably when one is missing. Read Portability below before you write components.
Target @nimblebrain/synapse@^0.40.0 — the release these names ship in. Its peers are @modelcontextprotocol/ext-apps@^2.0.0, @modelcontextprotocol/client@^2.0.0 and @modelcontextprotocol/core@^2.0.0 (which need zod@^4.2 and Node 20+). A caret range on 0.x does not cross a minor, so an app stays on its pin until someone bumps it deliberately, and its CHANGELOG.md names what each minor breaks. The package is the documentation — read its exported types before writing code. Its guides live at synapse.nimblebrain.ai.
Pre-flight — read the SDK's types (the real docs)
From the installed package (node_modules/@nimblebrain/synapse/dist/*.d.ts) or the public repo (github.com/NimbleBrainInc/synapse):
- the
reactentry —AppProviderand its hooks (useApp,useCallTool,useCallToolAsTask,useDataSync,useTheme,useHostContext,useModelContext,useSendMessage,useOpen,useOpenConnectorSettings,useNotify,useTrail,useFileUpload,useToolResult,useToolInput,useResize,useToolAllowed). - the
uientry — the component library (AppFrame,ListDetailLayout,ListRow,Table,Badge,Prose,ConfirmDialog,tokens, …). Don't hand-roll styling. - the type exports —
ToolCallResult,Theme, theAppinterface (includinghostCapabilities),HostCapabilityError,hostSupports,NIMBLEBRAIN_EXTENSIONS.
Then read references/gotchas.md (non-obvious API facts that each save a debugging cycle) and references/host-contract.md (the catalog-entry _meta block + the bridge). Skim these first; they're short and they're the difference between working and "why is every tool call returning unauthenticated."
Portability — this is an MCP app, not a NimbleBrain app
Claude, ChatGPT and NimbleBrain all speak MCP Apps. Each declares what it offers in its
ui/initialize answer (hostCapabilities), and every gated Synapse call checks that declaration
before it sends, then does one documented thing when the capability is missing (resize is never
gated, and useDataSync only listens):
- a request with an answer rejects with
HostCapabilityError, without sending —useCallTool(serverTools),readServerResource(serverResources),downloadFile,useCallToolAsTask(tasks), the file picker anduploadFiles; - a request whose answer is only whether it happened resolves
false, without sending —useOpen,useOpenConnectorSettings,useNotify; each rejects with the host's reason when a host that serves it refuses; - a fire-and-forget call sends nothing —
useSendMessage(message),useModelContext(updateModelContext),useTrail(which returnsfalse),forwardKeys;openLinkopens the URL itself; - a hook that waits on the host keeps its initial value —
useToolResult/useToolInputstaynull;useDataSyncfires on a write only where the host relaysnotifications/resources/list_changedand your server announces it (step 5). Everywhere, it also re-reads when a tab hidden for a minute or more is shown again, and it runs calls at least 3 s apart ({ minIntervalMs }changes that).
The portable subset is the handshake, theme and host context, tool input/results, callTool,
sendMessage, updateModelContext and resize. An app built on that behaves the same everywhere.
The NimbleBrain extensions are ai.nimblebrain/open, open-connector-settings, notify,
location (with navigate back from the host), request-file, upload-files and keydown;
NIMBLEBRAIN_EXTENSIONS is the list in code. Each name is both the method and the identifier the
host declares in hostCapabilities.experimental to offer it, and an extension is used only where
it is declared.
A no-op is still invisible to the user, so read the declaration and hide what the host can't do:
hostSupports(app, "requestFile"), app.hostCapabilities.message, app.supportsTasks.
<AppProvider> renders nothing until the handshake completes, so all of these are settled before
any component reads them — and where the handshake never returns (the built HTML opened directly),
nothing under the provider renders at all.
Per-hook table, the extension list, serving one app to Claude and ChatGPT, and the two connection
entry points: references/portability.md.
Process
-
Analyze the server — language (Python/FastMCP or TS), the tool list + return shapes, where identity comes from (the MCP session, or HTTP headers a proxy in front of the server sets), and how it is deployed. NimbleBrain connects to a server over HTTP by URL, so the server runs as a service, often from a container image (which needs a Node build stage, step 7). A .mcpb bundle is only for desktop hosts. No server yet? Build it first with the mcp-server skill, then come back for the UI.
-
Scaffold ui/ — package.json (react/react-dom ^19, @nimblebrain/synapse@^0.40.0, @modelcontextprotocol/ext-apps@^2.0.0, @modelcontextprotocol/client@^2.0.0, @modelcontextprotocol/core@^2.0.0, zod@^4.2, vite, vite-plugin-singlefile, typescript; add marked + dompurify only if you render markdown), vite.config.ts (react(), viteSingleFile(), synapseVite(), build.assetsInlineLimit: Infinity), a strict tsconfig.json, index.html, and .gitignore (node_modules/, dist/, .vite/). Commit package-lock.json so the build can npm ci.
-
Build App.tsx — <AppProvider name="<server>" version="<version>">. One side-effect import goes in the Vite entry (main.tsx): import "@nimblebrain/synapse/ui/base" (the root-height chain AppFrame fills — applied before first paint; gotcha M). Don't import fonts — the SDK ships none, and typography arrives from the host like every other theme value (gotcha N). Use the package's AppFrame shell (with AppFrame.Body bleed hosting ListDetailLayout/SidebarLayout) — never a hand-rolled height:100vh (gotcha D). Drive data with useCallTool(name) or a thin useCall<T>() wrapper around useApp().callTool(name, args); re-read in useDataSync(() => …), which fires when your server announces a write (step 5) — the callback names no tool, so the answer is always to re-read; theme with tokens/useTheme; push agent context with useModelContext. Master lists use ListRow, not Table (gotcha D — a Table overflows a fixed-width rail and paints over the detail pane).
-
Sanitize any rendered HTML — do not skip (stored-XSS). If you render server- or agent-authored markdown (notes, descriptions, research output) via Prose / dangerouslySetInnerHTML, run it through DOMPurify first: DOMPurify.sanitize(marked.parse(md, { async: false }) as string). The iframe runs with allow-scripts and a script-src 'unsafe-inline' CSP, so sanitization — not the CSP — is the only thing stopping an injected <script>/onerror from running with full tool-bridge authority (read/exfiltrate/mutate everything the tools can reach). Plain <Text>{value}</Text> is safe (React escapes). Full chain: gotcha K.
-
Serve the UI as a resource, and announce writes. On FastMCP 4, @mcp.resource("ui://<name>/main", app=AppConfig(prefers_border=True, csp=ResourceCSP())) (from fastmcp.apps) returning the built ui/dist/index.html, served as the spec's MIME type text/html;profile=mcp-app (FastMCP's default for a ui:// URI; pass mime_type explicitly anywhere else). Full walkthrough, including a build-keyed bound URI so hosts don't render a cached build: synapse.nimblebrain.ai/docs/quickstart-python/. Resolve the path via an env var (<APP>_UI_DIR) with a __file__-relative fallback (gotcha E — an installed package lands in site-packages, so a __file__-relative ui/dist lookup misses). Make it a bare file read: no DB/auth session, identity-free HTML, all tenant data fetched at runtime through the bridge. Then make every tool that writes send notifications/resources/list_changed after the write commits — that is the only thing useDataSync fires on, and it covers every writer (the agent, another view, a webhook):
from fastmcp import Context
from mcp.types import ResourceListChangedNotification
@mcp.tool()
async def save_item(item: Item, ctx: Context) -> dict:
stored = store.save(item)
await ctx.session.send_notification(ResourceListChangedNotification(), related_request_id=ctx.request_id)
return stored
related_request_id makes it travel in the call's own response over HTTP. Announce once per write, not per row. Full guide: synapse.nimblebrain.ai/docs/guides/keep-ui-in-sync/.
-
Register the app with its host. The UI and resource from steps 2–5 are the same either way; only registration differs. Targeting the NimbleBrain host — NimbleBrain reads the _meta["ai.nimblebrain/host"] block from the server's connectors-catalog entry, which an operator adds: one placements[] entry (slot: "sidebar.apps", resourceUri: "ui://<name>/main", a route named after your server, label); the app's name and icon are the entry's title and icons. Write that block in the server's server.json for the operator, give the same placements to its Server Card (add_server_card(placements=[...])) so a NimbleBrain that has only the URL reads them, and keep the same _meta in an MCPB manifest.json if you also ship one (the mcp-server skill covers the card and server.json). Full contract + options: references/host-contract.md. Targeting Claude or ChatGPT — the host renders the resource your tool names: bind it with _meta.ui.resourceUri on the tool, serve that one resource under text/html;profile=mcp-app (never a second copy under another MIME), declare ui.visibility and ui.csp, and — if the server needs sign-in — securitySchemes plus a 401 challenge. On FastMCP 4, AppConfig(resource_uri=..., visibility=[...]) on the tool and AppConfig(csp=ResourceCSP(...)) on the resource write the ui.* keys; ChatGPT's own keys (openai/widgetAccessible, which defaults to false and leaves the UI read-only) go in plain meta=: synapse.nimblebrain.ai/docs/guides/chatgpt/. Then run npx @nimblebrain/synapse check --target nimblebrain,claude,chatgpt <server-url> for the hosts you target. Details: references/portability.md.
-
Container-deployed servers — multi-stage build. A container image must build the UI: a node:22 builder stage runs npm ci && npm run build, then the runtime COPY --from=builder …/ui/dist (so the runtime stays Node-free) and sets the UI-dir env var. Strip the ui/ source from the runtime layer — only dist ships. (A .mcpb bundle for desktop hosts gets ui/dist from its release CI.)
-
Local preview — cd ui && npm run dev → open /__preview. The preview starts your server over stdio from a manifest.json (gotcha F). For a server whose identity comes from HTTP headers and a DB, the real server can't be driven that way, so every call returns unauthenticated — point synapseVite({ serverCmd }) at a seeded stdio mock behind an env flag (gotcha F).
-
Verify — npx tsc --noEmit and npm run build (Vite/esbuild won't type-check on its own). Then run the server project's own lint/format/test gate (e.g. make verify, ruff format --check), not just the UI type-check — a format-only diff will redden CI even when types pass. Toggle the preview between light and dark and eyeball every surface — theme-blind color passes tsc/build and only breaks in one mode. Every tokens.* is backed in both; your own vars are not (gotcha L). Confirm the server serves ui://<name>/main as text/html;profile=mcp-app, and that a write through the preview refreshes the view (the preview relays your server's list_changed, gotcha F).
-
Run it in NimbleBrain. The nimblebrain skill sets up a local NimbleBrain (npx nimblebrain). Run your server over HTTP on loopback, then add it by URL: npx nimblebrain mcp add http://127.0.0.1:8000/mcp --json (CLI 0.3.0 or later, runtime v0.76.0 or later; npx nimblebrain update moves an older install). NimbleBrain reads the server's Server Card, and the card's placements give the app its sidebar entry. On Linux, bind the server to the Docker bridge address or 0.0.0.0 instead of 127.0.0.1 (Developing a server). Then open the app from the sidebar and check: the host's theme and fonts reach it, a write by the agent refreshes the view, and each NimbleBrain extension it uses works.
Out of scope
- Host-side rendering — the host already implements placement → iframe → bridge; you build and serve the UI and write the placement for the catalog entry, nothing more.
- Declarative host "commands"/toolbars — they don't exist. In-app buttons live inside the iframe and call tools via
useCallTool.
Analyze the server — language (Python/FastMCP or TS), the tool list + return shapes, where identity comes from (the MCP session, or HTTP headers a proxy in front of the server sets), and how it is deployed. NimbleBrain connects to a server over HTTP by URL, so the server runs as a service, often from a container image (which needs a Node build stage, step 7). A .mcpb bundle is only for desktop hosts. No server yet? Build it first with the mcp-server skill, then come back for the UI.
Scaffold ui/ — package.json (react/react-dom ^19, @nimblebrain/synapse@^0.40.0, @modelcontextprotocol/ext-apps@^2.0.0, @modelcontextprotocol/client@^2.0.0, @modelcontextprotocol/core@^2.0.0, zod@^4.2, vite, vite-plugin-singlefile, typescript; add marked + dompurify only if you render markdown), vite.config.ts (react(), viteSingleFile(), synapseVite(), build.assetsInlineLimit: Infinity), a strict tsconfig.json, index.html, and .gitignore (node_modules/, dist/, .vite/). Commit package-lock.json so the build can npm ci.
Build App.tsx — <AppProvider name="<server>" version="<version>">. One side-effect import goes in the Vite entry (main.tsx): import "@nimblebrain/synapse/ui/base" (the root-height chain AppFrame fills — applied before first paint; gotcha M). Don't import fonts — the SDK ships none, and typography arrives from the host like every other theme value (gotcha N). Use the package's AppFrame shell (with AppFrame.Body bleed hosting ListDetailLayout/SidebarLayout) — never a hand-rolled height:100vh (gotcha D). Drive data with useCallTool(name) or a thin useCall<T>() wrapper around useApp().callTool(name, args); re-read in useDataSync(() => …), which fires when your server announces a write (step 5) — the callback names no tool, so the answer is always to re-read; theme with tokens/useTheme; push agent context with useModelContext. Master lists use ListRow, not Table (gotcha D — a Table overflows a fixed-width rail and paints over the detail pane).
Sanitize any rendered HTML — do not skip (stored-XSS). If you render server- or agent-authored markdown (notes, descriptions, research output) via Prose / dangerouslySetInnerHTML, run it through DOMPurify first: DOMPurify.sanitize(marked.parse(md, { async: false }) as string). The iframe runs with allow-scripts and a script-src 'unsafe-inline' CSP, so sanitization — not the CSP — is the only thing stopping an injected <script>/onerror from running with full tool-bridge authority (read/exfiltrate/mutate everything the tools can reach). Plain <Text>{value}</Text> is safe (React escapes). Full chain: gotcha K.
Serve the UI as a resource, and announce writes. On FastMCP 4, @mcp.resource("ui://<name>/main", app=AppConfig(prefers_border=True, csp=ResourceCSP())) (from fastmcp.apps) returning the built ui/dist/index.html, served as the spec's MIME type text/html;profile=mcp-app (FastMCP's default for a ui:// URI; pass mime_type explicitly anywhere else). Full walkthrough, including a build-keyed bound URI so hosts don't render a cached build: synapse.nimblebrain.ai/docs/quickstart-python/. Resolve the path via an env var (<APP>_UI_DIR) with a __file__-relative fallback (gotcha E — an installed package lands in site-packages, so a __file__-relative ui/dist lookup misses). Make it a bare file read: no DB/auth session, identity-free HTML, all tenant data fetched at runtime through the bridge. Then make every tool that writes send notifications/resources/list_changed after the write commits — that is the only thing useDataSync fires on, and it covers every writer (the agent, another view, a webhook):
from fastmcp import Context
from mcp.types import ResourceListChangedNotification
@mcp.tool()
async def save_item(item: Item, ctx: Context) -> dict:
stored = store.save(item)
await ctx.session.send_notification(ResourceListChangedNotification(), related_request_id=ctx.request_id)
return stored
related_request_id makes it travel in the call's own response over HTTP. Announce once per write, not per row. Full guide: synapse.nimblebrain.ai/docs/guides/keep-ui-in-sync/.
Register the app with its host. The UI and resource from steps 2–5 are the same either way; only registration differs. Targeting the NimbleBrain host — NimbleBrain reads the _meta["ai.nimblebrain/host"] block from the server's connectors-catalog entry, which an operator adds: one placements[] entry (slot: "sidebar.apps", resourceUri: "ui://<name>/main", a route named after your server, label); the app's name and icon are the entry's title and icons. Write that block in the server's server.json for the operator, give the same placements to its Server Card (add_server_card(placements=[...])) so a NimbleBrain that has only the URL reads them, and keep the same _meta in an MCPB manifest.json if you also ship one (the mcp-server skill covers the card and server.json). Full contract + options: references/host-contract.md. Targeting Claude or ChatGPT — the host renders the resource your tool names: bind it with _meta.ui.resourceUri on the tool, serve that one resource under text/html;profile=mcp-app (never a second copy under another MIME), declare ui.visibility and ui.csp, and — if the server needs sign-in — securitySchemes plus a 401 challenge. On FastMCP 4, AppConfig(resource_uri=..., visibility=[...]) on the tool and AppConfig(csp=ResourceCSP(...)) on the resource write the ui.* keys; ChatGPT's own keys (openai/widgetAccessible, which defaults to false and leaves the UI read-only) go in plain meta=: synapse.nimblebrain.ai/docs/guides/chatgpt/. Then run npx @nimblebrain/synapse check --target nimblebrain,claude,chatgpt <server-url> for the hosts you target. Details: references/portability.md.
Container-deployed servers — multi-stage build. A container image must build the UI: a node:22 builder stage runs npm ci && npm run build, then the runtime COPY --from=builder …/ui/dist (so the runtime stays Node-free) and sets the UI-dir env var. Strip the ui/ source from the runtime layer — only dist ships. (A .mcpb bundle for desktop hosts gets ui/dist from its release CI.)
Local preview — cd ui && npm run dev → open /__preview. The preview starts your server over stdio from a manifest.json (gotcha F). For a server whose identity comes from HTTP headers and a DB, the real server can't be driven that way, so every call returns unauthenticated — point synapseVite({ serverCmd }) at a seeded stdio mock behind an env flag (gotcha F).
Verify — npx tsc --noEmit and npm run build (Vite/esbuild won't type-check on its own). Then run the server project's own lint/format/test gate (e.g. make verify, ruff format --check), not just the UI type-check — a format-only diff will redden CI even when types pass. Toggle the preview between light and dark and eyeball every surface — theme-blind color passes tsc/build and only breaks in one mode. Every tokens.* is backed in both; your own vars are not (gotcha L). Confirm the server serves ui://<name>/main as text/html;profile=mcp-app, and that a write through the preview refreshes the view (the preview relays your server's list_changed, gotcha F).
Run it in NimbleBrain. The nimblebrain skill sets up a local NimbleBrain (npx nimblebrain). Run your server over HTTP on loopback, then add it by URL: npx nimblebrain mcp add http://127.0.0.1:8000/mcp --json (CLI 0.3.0 or later, runtime v0.76.0 or later; npx nimblebrain update moves an older install). NimbleBrain reads the server's Server Card, and the card's placements give the app its sidebar entry. On Linux, bind the server to the Docker bridge address or 0.0.0.0 instead of 127.0.0.1 (Developing a server). Then open the app from the sidebar and check: the host's theme and fonts reach it, a write by the agent refreshes the view, and each NimbleBrain extension it uses works.
- Host-side rendering — the host already implements placement → iframe → bridge; you build and serve the UI and write the placement for the catalog entry, nothing more.
- Declarative host "commands"/toolbars — they don't exist. In-app buttons live inside the iframe and call tools via
useCallTool.