独立的 Model Context Protocol 客户端Standalone Model Context Protocol client for pi and other applications
← → 翻页 · F 全屏 · O 目录 · T 明暗 · L 语言← → navigate · F fullscreen · O overview · T theme · L language
最大的文件是 client.ts;其次是 transports/streamable-http.ts——HTTP 传输要处理会话、SSE 解析、认证重试和断线续传。The largest file is client.ts, followed by transports/streamable-http.ts — the HTTP transport handles sessions, SSE parsing, auth retries and stream resumption.
支持的版本:2025-11-25、2025-06-18、2025-03-26、2024-11-05。服务器选了别的版本时连接直接失败,而不是“尽量兼容”。Supported versions: 2025-11-25, 2025-06-18, 2025-03-26, 2024-11-05. A server that picks another version fails the connection outright instead of a best-effort fallback.
传了 onProgress 时,请求的 _meta.progressToken 就是它的 id;每条 notifications/progress 都会重新计时——持续报进度的长任务不会超时。With onProgress, the request's _meta.progressToken is its id; every notifications/progress re-arms the timeout — long tasks that keep reporting never time out.
用进程组是为了 npx、uvx 这类包装命令:只杀包装进程会留下真正的服务器。Windows 上改用 taskkill /T /F。Process groups exist for wrapper commands such as npx and uvx: killing only the wrapper would leave the real server running. Windows uses taskkill /T /F instead.
Mcp-Session-Id,之后每个请求都带上;带着会话 id 收到 404 → McpSessionExpiredError。Sessions: the server returns Mcp-Session-Id in a response header and every later request carries it; a 404 with a session id → McpSessionExpiredError.error="insufficient_scope")先交给 authProvider.onUnauthorized() 一次,然后用新凭据重发;仍失败就抛 McpAuthRequiredError。A 401 (or a 403 with error="insufficient_scope") goes to authProvider.onUnauthorized() once, then the request is retried with the new credentials; if it still fails, McpAuthRequiredError is thrown.adaptOAuthProvider() 把它包装成传输用的 AuthProvider:并发的 401 共用一次授权;如果出错请求用的 token 已经被别人换掉了,就直接重试——轮换的 refresh token 不能用两次。adaptOAuthProvider() wraps it as the transport's AuthProvider: concurrent 401s share one authorization; if the failing request's token was already replaced, it simply retries — a rotating refresh token cannot be used twice.insufficient_scope 是 step-up:跳过刷新,请求“已授予 ∪ 挑战要求”的 scope。A 403 insufficient_scope is a step-up: refresh is skipped and the scope requested is “granted ∪ challenged”.LlmContent 的形状与 pi-ai 的 TextContent / ImageContent 一致,但 pi-mcp 并不依赖 pi-ai。LlmContent has the same shape as pi-ai's TextContent / ImageContent, yet pi-mcp does not depend on pi-ai.
四种 exposure:codemode(默认)、deferred(tool_search 加载后才声明)、direct(立即声明)、hidden;toolExposure 可以按工具覆盖。Four exposures: codemode (default), deferred (declared once tool_search loads them), direct (declared right away) and hidden; toolExposure overrides per tool.
实现 start / send / close 与三个监听即可接入新的传输。Implement start / send / close and three listeners to add a transport.
token() 加可选的 onUnauthorized():任何认证方案。token() plus an optional onUnauthorized(): any auth scheme.
自定义 OAuth 状态的存储与跳转方式。Customise how OAuth state is stored and how redirects happen.
响应服务器发来的请求(如 sampling、elicitation)。Answer requests from the server (e.g. sampling, elicitation).
监听 list_changed 等通知。Listen for notifications such as list_changed.