@b3os/mcp 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,77 @@
1
- # Temporary Holding Version
1
+ # @b3os/mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The B3OS MCP server over stdio. MCP clients start it with `npx -y @b3os/mcp`; `b3os mcp install --client
4
+ claude|cursor|codex` writes that entry for you. It reads `B3OS_API_KEY`, else the `b3os login` token, else the
5
+ node socket or sandbox URL (the SDK's routing rules).
6
+
7
+ ## Tools
8
+
9
+ Fifteen core tools, always listed in this order (deterministic `tools/list` keeps prompt caches warm):
10
+
11
+ | Tool | Calls |
12
+ |---|---|
13
+ | `vision_scrape` | `vision.scrape`: a URL as Markdown (or html, text, links, a screenshot image) |
14
+ | `vision_map` | `vision.map`: a site's URLs, optionally ranked for a phrase |
15
+ | `vision_crawl` | `vision.createCrawl` and `listCrawlPages`; waits up to `wait_s`, then returns the job id (call again with `job_id`) |
16
+ | `vision_act` | `vision.createSession`, `act`, `closeSession`: browser actions in one call; `keep_session` keeps the session |
17
+ | `render_screenshot` | `render.createScreenshot`: the image as MCP image content plus its signed URL |
18
+ | `render_video` | `render.createVideo` / `getVideo`: waits up to `wait_s`, returns artifact URLs or the job id |
19
+ | `sandbox_create` | `sandboxes.createSandbox` |
20
+ | `sandbox_exec` | `sandboxes.exec` (buffered): exit code, stdout, stderr |
21
+ | `sandbox_read_file` | `sandboxes.readFile`: UTF-8 text or base64, or a directory listing |
22
+ | `sandbox_write_file` | `sandboxes.writeFile` (UTF-8 or base64 content, parents created) |
23
+ | `sandbox_delete` | `sandboxes.deleteSandbox` |
24
+ | `routine_run` | `routines.createRun`: waits up to `wait_s` for the output; `job_id` continues |
25
+ | `actions_search` | `actions.search` |
26
+ | `actions_describe` | `actions.describe`: input and output schemas, effect class, connections |
27
+ | `actions_call` | `actions.call`; credentials come from vault connections, never from arguments |
28
+
29
+ Marketplace actions are reached through `actions_search` → `actions_describe` → `actions_call` (ARCHITECTURE §5.5).
30
+ `--packs github,slack` (or `B3OS_MCP_PACKS`) also lists every action of those packs as its own tool, under the
31
+ registry's MCP name (`github__create-issue`) with the pack's annotations.
32
+
33
+ API errors come back as tool results with `isError: true` and the error's code, detail, validation pointers and
34
+ request id, so a model can correct its call. Long jobs send `notifications/progress` when the request carries a
35
+ `progressToken`, and `notifications/cancelled` aborts the call. Text output is truncated at 100,000 characters by
36
+ default (`max_chars` on `vision_scrape`).
37
+
38
+ ## Protocol
39
+
40
+ Dual-era, per the MCP 2026-07-28 versioning rules:
41
+
42
+ - Legacy clients open with `initialize` (2024-11-05, 2025-03-26, 2025-06-18, 2025-11-25): the server answers with
43
+ the client's version when it supports it, else 2025-11-25, and serves that version for the process. Tool `title`
44
+ and `structuredContent` are sent from 2025-06-18 on.
45
+ - Modern clients (2026-07-28) send `_meta["io.modelcontextprotocol/protocolVersion"]` on each request and may call
46
+ `server/discover`. Results carry `resultType: "complete"` and `_meta["io.modelcontextprotocol/serverInfo"]`;
47
+ `tools/list` carries `ttlMs` (300000) and `cacheScope` (`private`); an unknown version gets error -32022 with the
48
+ supported list.
49
+
50
+ `ping`, `resources/list`, `resources/templates/list` and `prompts/list` (empty) answer too. Logs go to stderr only.
51
+
52
+ ## Reuse
53
+
54
+ The tool table and the protocol handler do not depend on Node and run in a Worker, so another transport can serve
55
+ exactly the same tools:
56
+
57
+ ```ts
58
+ import { McpServer } from "@b3os/mcp/server";
59
+ import { coreTools } from "@b3os/mcp/tools";
60
+ import { B3OS } from "@b3os/sdk";
61
+
62
+ const server = new McpServer({ client: new B3OS({ apiKey, fetch: forward }) });
63
+ await server.handle(jsonRpcMessage, (out) => respond(out));
64
+ ```
65
+
66
+ ## Development
67
+
68
+ ```sh
69
+ pnpm --filter @b3os/mcp typecheck
70
+ pnpm --filter @b3os/mcp test # protocol, tools against a local API, cancellation, the stdio process
71
+ pnpm --filter @b3os/mcp build && bash packages/mcp/test/interop/run.sh
72
+ # opt-in: the official MCP TypeScript client (@modelcontextprotocol/sdk 1.32.1)
73
+ # connects over stdio, lists and calls tools, and cancels a call
74
+ ```
75
+
76
+ The interop check covers the `initialize` handshake (that client negotiates 2025-11-25, its newest version; it does
77
+ not implement the stateless 2026-07-28 revision), so the 2026-07-28 path is covered by the unit tests only.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ // `b3os-mcp` launcher for the built server (MCP clients run `npx -y @b3os/mcp`).
3
+ import { main } from "../dist/main.js";
4
+
5
+ process.exitCode = await main(process.argv.slice(2));
@@ -0,0 +1,3 @@
1
+ export { INSTRUCTIONS, type JsonRpcRequest, type JsonRpcResponse, LEGACY_VERSIONS, McpServer, type McpServerOptions, MODERN_VERSIONS, type Outgoing, SERVER_INFO, } from "./server.ts";
2
+ export { defaultClient, type StdioOptions, serveStdio, storedLogin } from "./stdio.ts";
3
+ export { actionTool, type ContentBlock, coreTools, errorResult, type JsonSchemaObject, packTools, type ToolAnnotations, type ToolContext, type ToolDef, type ToolResult, } from "./tools.ts";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // @b3os/mcp: the B3OS MCP server. `npx -y @b3os/mcp` serves it over stdio; the tool table (`@b3os/mcp/tools`)
2
+ // and the protocol handler (`@b3os/mcp/server`) are runtime-agnostic so other transports can reuse them.
3
+ export { INSTRUCTIONS, LEGACY_VERSIONS, McpServer, MODERN_VERSIONS, SERVER_INFO, } from "./server.js";
4
+ export { defaultClient, serveStdio, storedLogin } from "./stdio.js";
5
+ export { actionTool, coreTools, errorResult, packTools, } from "./tools.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAC9G,yGAAyG;AAEzG,OAAO,EACL,YAAY,EAGZ,eAAe,EACf,SAAS,EAET,eAAe,EAEf,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACvF,OAAO,EACL,UAAU,EAEV,SAAS,EACT,WAAW,EAEX,SAAS,GAKV,MAAM,YAAY,CAAC"}
package/dist/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function main(argv: string[]): Promise<number>;
package/dist/main.js ADDED
@@ -0,0 +1,29 @@
1
+ // `b3os-mcp [--packs github,slack]`: the stdio entry point MCP clients start.
2
+ import { serveStdio } from "./stdio.js";
3
+ export async function main(argv) {
4
+ let packs;
5
+ for (let i = 0; i < argv.length; i++) {
6
+ const a = argv[i];
7
+ if (a === "--packs")
8
+ packs = (argv[++i] ?? "").split(",").filter(Boolean);
9
+ else if (a.startsWith("--packs="))
10
+ packs = a.slice(8).split(",").filter(Boolean);
11
+ else if (a === "--help" || a === "-h") {
12
+ process.stderr.write("usage: b3os-mcp [--packs github,slack]\n" +
13
+ "Serves the B3OS MCP tools over stdio. Credentials: B3OS_API_KEY, else the b3os login token.\n");
14
+ return 0;
15
+ }
16
+ else if (a === "--version") {
17
+ process.stdout.write("b3os-mcp 0.1.0\n");
18
+ return 0;
19
+ }
20
+ }
21
+ await serveStdio({ packs: packs ?? process.env.B3OS_MCP_PACKS?.split(",").filter(Boolean) });
22
+ return 0;
23
+ }
24
+ if (/[\\/]src[\\/]main\.ts$/.test(process.argv[1] ?? "")) {
25
+ main(process.argv.slice(2)).then((code) => {
26
+ process.exitCode = code;
27
+ });
28
+ }
29
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAE9E,OAAO,EAAE,UAAU,EAAE,MAAM,YAA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,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACxC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,61 @@
1
+ import { type B3OS, SDK_VERSION } from "@b3os/sdk";
2
+ import { type ToolDef } from "./tools.ts";
3
+ export declare const MODERN_VERSIONS: readonly ["2026-07-28"];
4
+ export declare const LEGACY_VERSIONS: readonly ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
5
+ export declare const SERVER_INFO: {
6
+ name: string;
7
+ title: string;
8
+ version: string;
9
+ };
10
+ export declare const INSTRUCTIONS: string;
11
+ type Id = string | number;
12
+ export interface JsonRpcRequest {
13
+ jsonrpc: "2.0";
14
+ id?: Id | null;
15
+ method: string;
16
+ params?: Record<string, unknown> & {
17
+ _meta?: Record<string, unknown>;
18
+ };
19
+ }
20
+ export interface JsonRpcResponse {
21
+ jsonrpc: "2.0";
22
+ id: Id | null;
23
+ result?: unknown;
24
+ error?: {
25
+ code: number;
26
+ message: string;
27
+ data?: unknown;
28
+ };
29
+ }
30
+ export type Outgoing = JsonRpcResponse | {
31
+ jsonrpc: "2.0";
32
+ method: string;
33
+ params?: unknown;
34
+ };
35
+ export interface McpServerOptions {
36
+ client: B3OS;
37
+ /** Packs whose actions become direct tools (`github`, `io.b3os/slack`). */
38
+ packs?: readonly string[];
39
+ /** Replace the tool set (tests, custom servers). */
40
+ tools?: readonly ToolDef[];
41
+ /** How long clients may cache tools/list (modern protocol). Default 5 minutes. */
42
+ ttlMs?: number;
43
+ }
44
+ export declare class McpServer {
45
+ private readonly client;
46
+ private readonly packs;
47
+ private tools;
48
+ private toolsLoading;
49
+ private readonly ttlMs;
50
+ /** The version a legacy `initialize` negotiated, for this process (stdio) or session. */
51
+ legacyVersion: string | undefined;
52
+ private readonly inflight;
53
+ constructor(opts: McpServerOptions);
54
+ private toolList;
55
+ /** Handles one message. `send` receives the response (requests only) and any notifications (progress). */
56
+ handle(msg: unknown, send: (m: Outgoing) => void): Promise<void>;
57
+ private notification;
58
+ private withMeta;
59
+ private request;
60
+ }
61
+ export { SDK_VERSION };
package/dist/server.js ADDED
@@ -0,0 +1,226 @@
1
+ // A dual-era MCP server over any message transport. Legacy clients (protocol 2024-11-05 through 2025-11-25) open
2
+ // with `initialize`; modern ones (2026-07-28, stateless) put the protocol version in each request's `_meta`, may
3
+ // call `server/discover`, and get `resultType` plus cache hints on list results. Tool calls run concurrently;
4
+ // `notifications/cancelled` aborts one.
5
+ import { SDK_VERSION } from "@b3os/sdk";
6
+ import { coreTools, errorResult, packTools } from "./tools.js";
7
+ export const MODERN_VERSIONS = ["2026-07-28"];
8
+ export const LEGACY_VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
9
+ const META_VERSION = "io.modelcontextprotocol/protocolVersion";
10
+ const META_SERVER_INFO = "io.modelcontextprotocol/serverInfo";
11
+ export const SERVER_INFO = { name: "b3os", title: "B3OS", version: "0.1.0" };
12
+ export const INSTRUCTIONS = "B3OS tools run on the B3OS node: vision_* reads and drives web pages, render_* takes screenshots and videos, " +
13
+ "sandbox_* runs code in microVMs (create one, then exec, read and write files, delete it when done), routine_run " +
14
+ "runs published workflows, and actions_search, actions_describe and actions_call reach marketplace actions. " +
15
+ "Long jobs return an id; call the same tool with job_id to keep waiting.";
16
+ const ERR = {
17
+ parse: -32700,
18
+ invalidRequest: -32600,
19
+ methodNotFound: -32601,
20
+ invalidParams: -32602,
21
+ internal: -32603,
22
+ unsupportedVersion: -32022,
23
+ };
24
+ export class McpServer {
25
+ client;
26
+ packs;
27
+ tools;
28
+ toolsLoading;
29
+ ttlMs;
30
+ /** The version a legacy `initialize` negotiated, for this process (stdio) or session. */
31
+ legacyVersion;
32
+ inflight = new Map();
33
+ constructor(opts) {
34
+ this.client = opts.client;
35
+ this.packs = opts.packs ?? [];
36
+ this.tools = opts.tools;
37
+ this.ttlMs = opts.ttlMs ?? 300_000;
38
+ }
39
+ async toolList() {
40
+ if (this.tools)
41
+ return this.tools;
42
+ this.toolsLoading ??= (async () => {
43
+ const extra = this.packs.length ? await packTools(this.client, this.packs).catch(() => []) : [];
44
+ const seen = new Set(coreTools.map((t) => t.name));
45
+ const tools = [...coreTools, ...extra.filter((t) => !seen.has(t.name) && seen.add(t.name))];
46
+ this.tools = tools;
47
+ return tools;
48
+ })();
49
+ return this.toolsLoading;
50
+ }
51
+ /** Handles one message. `send` receives the response (requests only) and any notifications (progress). */
52
+ async handle(msg, send) {
53
+ if (!msg || typeof msg !== "object" || Array.isArray(msg)) {
54
+ send(errorResponse(null, ERR.invalidRequest, "Invalid request"));
55
+ return;
56
+ }
57
+ const m = msg;
58
+ if (typeof m.method !== "string") {
59
+ // A response from the client (we send no requests), ignore it.
60
+ if ("result" in m || "error" in m)
61
+ return;
62
+ send(errorResponse(m.id ?? null, ERR.invalidRequest, "Invalid request: no method"));
63
+ return;
64
+ }
65
+ const isNotification = m.id === undefined || m.id === null;
66
+ if (isNotification) {
67
+ this.notification(m);
68
+ return;
69
+ }
70
+ const id = m.id;
71
+ const meta = (m.params?._meta ?? {});
72
+ const requested = typeof meta[META_VERSION] === "string" ? meta[META_VERSION] : undefined;
73
+ const modern = requested !== undefined;
74
+ if (modern &&
75
+ !MODERN_VERSIONS.includes(requested) &&
76
+ !LEGACY_VERSIONS.includes(requested)) {
77
+ send(errorResponse(id, ERR.unsupportedVersion, "Unsupported protocol version", {
78
+ supported: [...MODERN_VERSIONS, ...LEGACY_VERSIONS],
79
+ requested,
80
+ }));
81
+ return;
82
+ }
83
+ try {
84
+ const result = await this.request(m, id, modern && MODERN_VERSIONS.includes(requested), send);
85
+ send({ jsonrpc: "2.0", id, result });
86
+ }
87
+ catch (e) {
88
+ if (e instanceof RpcError)
89
+ send(errorResponse(id, e.code, e.message, e.data));
90
+ else
91
+ send(errorResponse(id, ERR.internal, e?.message ?? "Internal error"));
92
+ }
93
+ }
94
+ notification(m) {
95
+ if (m.method === "notifications/cancelled") {
96
+ const rid = m.params?.requestId;
97
+ if (rid !== undefined)
98
+ this.inflight.get(rid)?.abort();
99
+ }
100
+ // notifications/initialized and anything else: nothing to do.
101
+ }
102
+ withMeta(modern, result, cacheable = false) {
103
+ if (!modern)
104
+ return result;
105
+ const r = {
106
+ resultType: "complete",
107
+ ...result,
108
+ _meta: { ...(result._meta ?? {}), [META_SERVER_INFO]: SERVER_INFO },
109
+ };
110
+ if (cacheable) {
111
+ r.ttlMs = this.ttlMs;
112
+ r.cacheScope = "private";
113
+ }
114
+ return r;
115
+ }
116
+ async request(m, id, modern, send) {
117
+ const p = (m.params ?? {});
118
+ switch (m.method) {
119
+ case "initialize": {
120
+ const asked = typeof p.protocolVersion === "string" ? p.protocolVersion : undefined;
121
+ const version = asked && LEGACY_VERSIONS.includes(asked) ? asked : LEGACY_VERSIONS[0];
122
+ this.legacyVersion = version;
123
+ return {
124
+ protocolVersion: version,
125
+ capabilities: { tools: { listChanged: false } },
126
+ serverInfo: version >= "2025-06-18" ? SERVER_INFO : { name: SERVER_INFO.name, version: SERVER_INFO.version },
127
+ instructions: INSTRUCTIONS,
128
+ };
129
+ }
130
+ case "server/discover":
131
+ return {
132
+ resultType: "complete",
133
+ supportedVersions: [...MODERN_VERSIONS, ...LEGACY_VERSIONS],
134
+ capabilities: { tools: {} },
135
+ _meta: { [META_SERVER_INFO]: SERVER_INFO },
136
+ instructions: INSTRUCTIONS,
137
+ ttlMs: this.ttlMs,
138
+ cacheScope: "public",
139
+ };
140
+ case "ping":
141
+ return {};
142
+ case "tools/list": {
143
+ const tools = await this.toolList();
144
+ const newer = modern || (this.legacyVersion ?? LEGACY_VERSIONS[0]) >= "2025-06-18";
145
+ return this.withMeta(modern, {
146
+ tools: tools.map((t) => ({
147
+ name: t.name,
148
+ ...(newer ? { title: t.title } : {}),
149
+ description: t.description,
150
+ inputSchema: t.inputSchema,
151
+ annotations: t.annotations,
152
+ })),
153
+ }, true);
154
+ }
155
+ case "tools/call": {
156
+ const name = p.name;
157
+ if (typeof name !== "string")
158
+ throw new RpcError(ERR.invalidParams, "tools/call needs a tool name");
159
+ const tool = (await this.toolList()).find((t) => t.name === name);
160
+ if (!tool)
161
+ throw new RpcError(ERR.invalidParams, `Unknown tool: ${name}`);
162
+ const args = (p.arguments ?? {});
163
+ if (typeof args !== "object" || Array.isArray(args))
164
+ throw new RpcError(ERR.invalidParams, "arguments must be an object");
165
+ const ac = new AbortController();
166
+ this.inflight.set(id, ac);
167
+ const token = p._meta?.progressToken;
168
+ let result;
169
+ try {
170
+ result = await tool.call(this.client, args, {
171
+ signal: ac.signal,
172
+ progress: token === undefined
173
+ ? undefined
174
+ : (completed, total, message) => send({
175
+ jsonrpc: "2.0",
176
+ method: "notifications/progress",
177
+ params: {
178
+ progressToken: token,
179
+ progress: completed,
180
+ ...(total ? { total } : {}),
181
+ ...(message ? { message } : {}),
182
+ },
183
+ }),
184
+ });
185
+ }
186
+ catch (e) {
187
+ result = errorResult(e);
188
+ }
189
+ finally {
190
+ this.inflight.delete(id);
191
+ }
192
+ const newer = modern || (this.legacyVersion ?? LEGACY_VERSIONS[0]) >= "2025-06-18";
193
+ const out = { content: result.content };
194
+ if (result.isError)
195
+ out.isError = true;
196
+ if (newer && result.structuredContent)
197
+ out.structuredContent = result.structuredContent;
198
+ if (!newer)
199
+ out.content = result.content.filter((c) => c.type !== "resource_link");
200
+ return this.withMeta(modern, out);
201
+ }
202
+ case "resources/list":
203
+ return this.withMeta(modern, { resources: [] }, true);
204
+ case "resources/templates/list":
205
+ return this.withMeta(modern, { resourceTemplates: [] }, true);
206
+ case "prompts/list":
207
+ return this.withMeta(modern, { prompts: [] }, true);
208
+ default:
209
+ throw new RpcError(ERR.methodNotFound, `Method not found: ${m.method}`);
210
+ }
211
+ }
212
+ }
213
+ class RpcError extends Error {
214
+ code;
215
+ data;
216
+ constructor(code, message, data) {
217
+ super(message);
218
+ this.code = code;
219
+ this.data = data;
220
+ }
221
+ }
222
+ function errorResponse(id, code, message, data) {
223
+ return { jsonrpc: "2.0", id, error: data === undefined ? { code, message } : { code, message, data } };
224
+ }
225
+ export { SDK_VERSION };
226
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,iHAAiH;AACjH,8GAA8G;AAC9G,wCAAwC;AAExC,OAAO,EAAa,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAiC,MAAM,YAAY,CAAC;AAE9F,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,YAAY,CAAU,CAAC;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAU,CAAC;AACjG,MAAM,YAAY,GAAG,yCAAyC,CAAC;AAC/D,MAAM,gBAAgB,GAAG,oCAAoC,CAAC;AAE9D,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAE7E,MAAM,CAAC,MAAM,YAAY,GACvB,+GAA+G;IAC/G,kHAAkH;IAClH,6GAA6G;IAC7G,yEAAyE,CAAC;AA8B5E,MAAM,GAAG,GAAG;IACV,KAAK,EAAE,CAAC,KAAK;IACb,cAAc,EAAE,CAAC,KAAK;IACtB,cAAc,EAAE,CAAC,KAAK;IACtB,aAAa,EAAE,CAAC,KAAK;IACrB,QAAQ,EAAE,CAAC,KAAK;IAChB,kBAAkB,EAAE,CAAC,KAAK;CAClB,CAAC;AAEX,MAAM,OAAO,SAAS;IACH,MAAM,CAAO;IACb,KAAK,CAAoB;IAClC,KAAK,CAAiC;IACtC,YAAY,CAA0C;IAC7C,KAAK,CAAS;IAC/B,yFAAyF;IACzF,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