@silkweave/mcp 1.7.1 → 1.9.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/.turbo/turbo-build.log +8 -11
- package/.turbo/turbo-check.log +4 -13
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-prepack.log +10 -10
- package/build/index.d.mts +28 -3
- package/build/index.d.mts.map +1 -1
- package/build/index.mjs +67 -46
- package/build/index.mjs.map +1 -1
- package/package.json +5 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
> @silkweave/mcp@1.6.0 build /Users/atomic/projects/ai/silkweave/packages/mcp
|
|
3
|
-
> tsdown
|
|
4
|
-
|
|
1
|
+
$ tsdown
|
|
5
2
|
[34mℹ[39m [34mtsdown v0.21.8[39m powered by [38;2;255;126;23mrolldown v1.0.0-rc.15[39m
|
|
6
|
-
[34mℹ[39m config file: [4m/Users/atomic/projects/
|
|
3
|
+
[34mℹ[39m config file: [4m/Users/atomic/projects/silkweave/silkweave/packages/mcp/tsdown.config.ts[24m
|
|
7
4
|
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
8
5
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
9
6
|
[34mℹ[39m Build start
|
|
10
7
|
[34mℹ[39m Cleaning 4 files
|
|
11
|
-
[34mℹ[39m [2mbuild/[22m[1mindex.mjs[22m [
|
|
12
|
-
[34mℹ[39m [2mbuild/[22mindex.mjs.map [
|
|
13
|
-
[34mℹ[39m [2mbuild/[22mindex.d.mts.map [2m
|
|
14
|
-
[34mℹ[39m [2mbuild/[22m[32m[1mindex.d.mts[22m[39m [2m
|
|
15
|
-
[34mℹ[39m 4 files, total:
|
|
16
|
-
[32m✔[39m Build complete in [
|
|
8
|
+
[34mℹ[39m [2mbuild/[22m[1mindex.mjs[22m [2m17.31 kB[22m [2m│ gzip: 5.04 kB[22m
|
|
9
|
+
[34mℹ[39m [2mbuild/[22mindex.mjs.map [2m32.92 kB[22m [2m│ gzip: 9.07 kB[22m
|
|
10
|
+
[34mℹ[39m [2mbuild/[22mindex.d.mts.map [2m 1.22 kB[22m [2m│ gzip: 0.55 kB[22m
|
|
11
|
+
[34mℹ[39m [2mbuild/[22m[32m[1mindex.d.mts[22m[39m [2m 3.71 kB[22m [2m│ gzip: 1.36 kB[22m
|
|
12
|
+
[34mℹ[39m 4 files, total: 55.16 kB
|
|
13
|
+
[32m✔[39m Build complete in [32m673ms[39m
|
package/.turbo/turbo-check.log
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
> @silkweave/mcp@1.7.0 lint /Users/atomic/projects/silkweave/silkweave/packages/mcp
|
|
8
|
-
> eslint
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
> @silkweave/mcp@1.7.0 typecheck /Users/atomic/projects/silkweave/silkweave/packages/mcp
|
|
12
|
-
> tsc --noEmit
|
|
13
|
-
|
|
1
|
+
$ pnpm lint && pnpm typecheck
|
|
2
|
+
$ eslint
|
|
3
|
+
[ELIFECYCLE] Command failed.
|
|
4
|
+
[ELIFECYCLE] Command failed.
|
package/.turbo/turbo-lint.log
CHANGED
package/.turbo/turbo-prepack.log
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @silkweave/mcp@1.
|
|
3
|
+
> @silkweave/mcp@1.8.0 prepack /Users/atomic/projects/silkweave/silkweave/packages/mcp
|
|
4
4
|
> pnpm clean && pnpm build
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @silkweave/mcp@1.
|
|
7
|
+
> @silkweave/mcp@1.8.0 clean /Users/atomic/projects/silkweave/silkweave/packages/mcp
|
|
8
8
|
> rimraf build
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
> @silkweave/mcp@1.
|
|
11
|
+
> @silkweave/mcp@1.8.0 build /Users/atomic/projects/silkweave/silkweave/packages/mcp
|
|
12
12
|
> tsdown
|
|
13
13
|
|
|
14
14
|
[34mℹ[39m [34mtsdown v0.21.8[39m powered by [38;2;255;126;23mrolldown v1.0.0-rc.15[39m
|
|
15
|
-
[34mℹ[39m config file: [4m/Users/atomic/projects/
|
|
15
|
+
[34mℹ[39m config file: [4m/Users/atomic/projects/silkweave/silkweave/packages/mcp/tsdown.config.ts[24m
|
|
16
16
|
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
17
17
|
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
18
18
|
[34mℹ[39m Build start
|
|
19
|
-
[34mℹ[39m [2mbuild/[22m[1mindex.mjs[22m [
|
|
20
|
-
[34mℹ[39m [2mbuild/[22mindex.mjs.map [
|
|
21
|
-
[34mℹ[39m [2mbuild/[22mindex.d.mts.map [2m 0.
|
|
22
|
-
[34mℹ[39m [2mbuild/[22m[32m[1mindex.d.mts[22m[39m [2m
|
|
23
|
-
[34mℹ[39m 4 files, total:
|
|
24
|
-
[32m✔[39m Build complete in [
|
|
19
|
+
[34mℹ[39m [2mbuild/[22m[1mindex.mjs[22m [2m16.50 kB[22m [2m│ gzip: 4.74 kB[22m
|
|
20
|
+
[34mℹ[39m [2mbuild/[22mindex.mjs.map [2m30.99 kB[22m [2m│ gzip: 8.52 kB[22m
|
|
21
|
+
[34mℹ[39m [2mbuild/[22mindex.d.mts.map [2m 0.93 kB[22m [2m│ gzip: 0.43 kB[22m
|
|
22
|
+
[34mℹ[39m [2mbuild/[22m[32m[1mindex.d.mts[22m[39m [2m 2.15 kB[22m [2m│ gzip: 0.80 kB[22m
|
|
23
|
+
[34mℹ[39m 4 files, total: 50.57 kB
|
|
24
|
+
[32m✔[39m Build complete in [32m755ms[39m
|
package/build/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CallToolResult, ContentBlock, EmbeddedResource } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
import { AdapterFactory, SilkweaveError } from "@silkweave/core";
|
|
2
|
+
import { Action, AdapterFactory, SilkweaveContext, SilkweaveError, SilkweaveOptions } from "@silkweave/core";
|
|
3
3
|
import { CreateMcpExpressAppOptions } from "@modelcontextprotocol/sdk/server/express.js";
|
|
4
4
|
import { AuthConfig } from "@silkweave/auth";
|
|
5
5
|
import { CorsOptions, CorsOptions as CorsOptions$1 } from "cors";
|
|
6
|
+
import { Express } from "express";
|
|
6
7
|
|
|
7
8
|
//#region src/adapter/cliProxy.d.ts
|
|
8
9
|
type CLIFormatterFn = (message: ContentBlock, index: number, messages: ContentBlock[]) => string | undefined;
|
|
@@ -12,8 +13,32 @@ interface CliProxyOptions {
|
|
|
12
13
|
}
|
|
13
14
|
declare const cliProxy: AdapterFactory<CliProxyOptions>;
|
|
14
15
|
//#endregion
|
|
16
|
+
//#region src/lib/handler.d.ts
|
|
17
|
+
/** Headers required by the MCP protocol that must always be exposed when CORS is in use. */
|
|
18
|
+
declare const MCP_REQUIRED_HEADERS: string[];
|
|
19
|
+
interface CreateMcpExpressHandlerOptions extends CreateMcpExpressAppOptions {
|
|
20
|
+
/** Bearer-token / OAuth auth configuration. Omit to disable auth entirely. */
|
|
21
|
+
auth?: AuthConfig;
|
|
22
|
+
/** CORS configuration. `false` to disable, `true`/`undefined` for permissive defaults, or a CorsOptions object. */
|
|
23
|
+
cors?: CorsOptions$1 | boolean;
|
|
24
|
+
/** Hostname for the underlying express app (used by some MCP SDK checks). Default `'0.0.0.0'`. */
|
|
25
|
+
host?: string;
|
|
26
|
+
/** Mount the `/resource/:id` sideload route on the returned app. Default `true`. */
|
|
27
|
+
sideloadResources?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build an Express sub-app exposing the MCP Streamable HTTP transport, OAuth
|
|
31
|
+
* routes (if configured), and bearer-token auth middleware. The returned app
|
|
32
|
+
* can be listened on directly OR mounted onto an existing server via
|
|
33
|
+
* `parentApp.use(basePath, app)` / Nest's `httpAdapter.use(basePath, app)`.
|
|
34
|
+
*
|
|
35
|
+
* Used by `@silkweave/mcp`'s `http()` adapter (server-owning) and
|
|
36
|
+
* `@silkweave/nestjs`'s `mcp()` adapter (mounts on Nest's HTTP server).
|
|
37
|
+
*/
|
|
38
|
+
declare function createMcpExpressHandler(silkweaveOptions: SilkweaveOptions, context: SilkweaveContext, actions: Action[], options?: CreateMcpExpressHandlerOptions): Express;
|
|
39
|
+
//#endregion
|
|
15
40
|
//#region src/adapter/http.d.ts
|
|
16
|
-
interface HttpAdapterOptions extends
|
|
41
|
+
interface HttpAdapterOptions extends Omit<CreateMcpExpressHandlerOptions, 'auth' | 'cors'> {
|
|
17
42
|
host: string;
|
|
18
43
|
port: number;
|
|
19
44
|
auth?: AuthConfig;
|
|
@@ -50,5 +75,5 @@ declare function createSideloadResource(buffer: Buffer, {
|
|
|
50
75
|
contentType
|
|
51
76
|
}: Pick<SideloadResource, 'name' | 'contentType'>): Promise<SideloadResource>;
|
|
52
77
|
//#endregion
|
|
53
|
-
export { CLIFormatterFn, CliProxyOptions, type CorsOptions, HttpAdapterOptions, SideloadResource, cliProxy, createSideloadResource, errorToolResult, handleToolError, http, jsonToolResult, parseResourceMessage, smartToolResult, stdio };
|
|
78
|
+
export { CLIFormatterFn, CliProxyOptions, type CorsOptions, CreateMcpExpressHandlerOptions, HttpAdapterOptions, MCP_REQUIRED_HEADERS, SideloadResource, cliProxy, createMcpExpressHandler, createSideloadResource, errorToolResult, handleToolError, http, jsonToolResult, parseResourceMessage, smartToolResult, stdio };
|
|
54
79
|
//# sourceMappingURL=index.d.mts.map
|
package/build/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/adapter/cliProxy.ts","../src/adapter/http.ts","../src/adapter/stdio.ts","../src/util/result.ts","../src/util/sideload.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/adapter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AAK,gBAAA,4BAAyC,OAAA,CAAA,gBAAA"}
|
package/build/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { createCLILogger, createLogger } from "@silkweave/logger";
|
|
|
7
7
|
import { capitalCase, kebabCase, pascalCase } from "change-case";
|
|
8
8
|
import { Command } from "commander";
|
|
9
9
|
import { randomUUID } from "crypto";
|
|
10
|
-
import { z } from "zod";
|
|
10
|
+
import { z } from "zod/v4";
|
|
11
11
|
import { randomUUID as randomUUID$1 } from "node:crypto";
|
|
12
12
|
import { InMemoryEventStore } from "@modelcontextprotocol/sdk/examples/shared/inMemoryEventStore.js";
|
|
13
13
|
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
|
|
@@ -171,29 +171,31 @@ const cliProxy = ({ url, formatter = defaultFormatter }) => {
|
|
|
171
171
|
};
|
|
172
172
|
};
|
|
173
173
|
//#endregion
|
|
174
|
-
//#region src/
|
|
174
|
+
//#region src/lib/handler.ts
|
|
175
175
|
const authStorage = new AsyncLocalStorage();
|
|
176
|
-
/** Headers required by the MCP protocol that must always be exposed */
|
|
176
|
+
/** Headers required by the MCP protocol that must always be exposed when CORS is in use. */
|
|
177
177
|
const MCP_REQUIRED_HEADERS = [
|
|
178
178
|
"WWW-Authenticate",
|
|
179
179
|
"Mcp-Session-Id",
|
|
180
180
|
"Last-Event-Id",
|
|
181
181
|
"Mcp-Protocol-Version"
|
|
182
182
|
];
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
const callbackPath = auth.callbackPath ?? "/auth/callback";
|
|
186
|
-
const toOAuthReq = (req) => ({
|
|
183
|
+
function toOAuthReq(req) {
|
|
184
|
+
return {
|
|
187
185
|
method: req.method,
|
|
188
186
|
url: new URL(req.url, `${req.protocol}://${req.get("host")}`),
|
|
189
187
|
headers: Object.fromEntries(Object.entries(req.headers).map(([k, v]) => [k, Array.isArray(v) ? v[0] : v])),
|
|
190
188
|
body: req.body
|
|
191
|
-
});
|
|
192
|
-
const sendOAuth = (res, oauthRes) => {
|
|
193
|
-
for (const [key, value] of Object.entries(oauthRes.headers)) res.header(key, value);
|
|
194
|
-
if (oauthRes.body) res.status(oauthRes.status).send(typeof oauthRes.body === "string" ? oauthRes.body : JSON.stringify(oauthRes.body));
|
|
195
|
-
else res.status(oauthRes.status).end();
|
|
196
189
|
};
|
|
190
|
+
}
|
|
191
|
+
function sendOAuth(res, oauthRes) {
|
|
192
|
+
for (const [key, value] of Object.entries(oauthRes.headers)) res.header(key, value);
|
|
193
|
+
if (oauthRes.body) res.status(oauthRes.status).send(typeof oauthRes.body === "string" ? oauthRes.body : JSON.stringify(oauthRes.body));
|
|
194
|
+
else res.status(oauthRes.status).end();
|
|
195
|
+
}
|
|
196
|
+
function mountOAuthRoutes(app, auth) {
|
|
197
|
+
const provider = auth.provider;
|
|
198
|
+
const callbackPath = auth.callbackPath ?? "/auth/callback";
|
|
197
199
|
app.get("/.well-known/oauth-authorization-server", (_req, res) => {
|
|
198
200
|
sendOAuth(res, provider.metadata());
|
|
199
201
|
});
|
|
@@ -359,46 +361,65 @@ function mountMcpTransport(app, transports, createServer) {
|
|
|
359
361
|
app.delete("/mcp", handleSessionStream);
|
|
360
362
|
app.get("/mcp/resource/:id", handleSessionStream);
|
|
361
363
|
}
|
|
364
|
+
/**
|
|
365
|
+
* Build an Express sub-app exposing the MCP Streamable HTTP transport, OAuth
|
|
366
|
+
* routes (if configured), and bearer-token auth middleware. The returned app
|
|
367
|
+
* can be listened on directly OR mounted onto an existing server via
|
|
368
|
+
* `parentApp.use(basePath, app)` / Nest's `httpAdapter.use(basePath, app)`.
|
|
369
|
+
*
|
|
370
|
+
* Used by `@silkweave/mcp`'s `http()` adapter (server-owning) and
|
|
371
|
+
* `@silkweave/nestjs`'s `mcp()` adapter (mounts on Nest's HTTP server).
|
|
372
|
+
*/
|
|
373
|
+
function createMcpExpressHandler(silkweaveOptions, context, actions, options = {}) {
|
|
374
|
+
const { auth, cors: corsConfig, host = "0.0.0.0", sideloadResources = true, ...mcpOptions } = options;
|
|
375
|
+
const app = createMcpExpressApp({
|
|
376
|
+
...mcpOptions,
|
|
377
|
+
host
|
|
378
|
+
});
|
|
379
|
+
if (corsConfig !== false) {
|
|
380
|
+
const userConfig = corsConfig === true || corsConfig === void 0 ? {} : corsConfig;
|
|
381
|
+
const userExposed = userConfig.exposedHeaders;
|
|
382
|
+
const exposedHeaders = [...MCP_REQUIRED_HEADERS, ...Array.isArray(userExposed) ? userExposed : userExposed ? [userExposed] : []];
|
|
383
|
+
app.use(cors({
|
|
384
|
+
origin: "*",
|
|
385
|
+
...userConfig,
|
|
386
|
+
exposedHeaders
|
|
387
|
+
}));
|
|
388
|
+
}
|
|
389
|
+
if (auth?.authorizationServers?.length && auth.resourceUrl) app.get("/.well-known/oauth-protected-resource", (_req, res) => {
|
|
390
|
+
const metadata = generateProtectedResourceMetadata(auth.resourceUrl, auth.authorizationServers);
|
|
391
|
+
res.json(metadata);
|
|
392
|
+
});
|
|
393
|
+
const oauthPaths = auth?.provider ? mountOAuthRoutes(app, auth) : /* @__PURE__ */ new Set();
|
|
394
|
+
if (auth) mountAuthMiddleware(app, auth, oauthPaths, context);
|
|
395
|
+
if (sideloadResources) app.get("/resource/:id", async (req, res) => {
|
|
396
|
+
const id = req.params.id;
|
|
397
|
+
if (!id || typeof id !== "string") throw new Error("Invalid ID");
|
|
398
|
+
const resourceMeta = JSON.parse(await readFile(`resources/${id}.json`, "utf-8"));
|
|
399
|
+
const buffer = await readFile(`resources/${id}`);
|
|
400
|
+
res.status(200);
|
|
401
|
+
res.header("Content-Type", resourceMeta.contentType);
|
|
402
|
+
res.send(buffer);
|
|
403
|
+
});
|
|
404
|
+
mountMcpTransport(app, {}, () => createMcpServer(silkweaveOptions, actions, context));
|
|
405
|
+
return app;
|
|
406
|
+
}
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/adapter/http.ts
|
|
362
409
|
const http = ({ host, port, auth, cors: corsConfig, ...mcpOptions }) => {
|
|
363
410
|
return (options, baseContext) => {
|
|
364
411
|
const context = baseContext.fork({ adapter: "http" });
|
|
365
|
-
const app = createMcpExpressApp({
|
|
366
|
-
...mcpOptions,
|
|
367
|
-
host
|
|
368
|
-
});
|
|
369
|
-
if (corsConfig !== false) {
|
|
370
|
-
const userConfig = corsConfig === true || corsConfig === void 0 ? {} : corsConfig;
|
|
371
|
-
const userExposed = userConfig.exposedHeaders;
|
|
372
|
-
const exposedHeaders = [...MCP_REQUIRED_HEADERS, ...Array.isArray(userExposed) ? userExposed : userExposed ? [userExposed] : []];
|
|
373
|
-
app.use(cors({
|
|
374
|
-
origin: "*",
|
|
375
|
-
...userConfig,
|
|
376
|
-
exposedHeaders
|
|
377
|
-
}));
|
|
378
|
-
}
|
|
379
|
-
if (auth?.authorizationServers?.length && auth.resourceUrl) app.get("/.well-known/oauth-protected-resource", (_req, res) => {
|
|
380
|
-
const metadata = generateProtectedResourceMetadata(auth.resourceUrl, auth.authorizationServers);
|
|
381
|
-
res.json(metadata);
|
|
382
|
-
});
|
|
383
|
-
const oauthPaths = auth?.provider ? mountOAuthRoutes(app, auth) : /* @__PURE__ */ new Set();
|
|
384
|
-
if (auth) mountAuthMiddleware(app, auth, oauthPaths, context);
|
|
385
|
-
const transports = {};
|
|
386
|
-
let mountedActions = [];
|
|
387
|
-
app.get("/resource/:id", async (req, res) => {
|
|
388
|
-
const id = req.params.id;
|
|
389
|
-
if (!id || typeof id !== "string") throw new Error("Invalid ID");
|
|
390
|
-
const resourceMeta = JSON.parse(await readFile(`resources/${id}.json`, "utf-8"));
|
|
391
|
-
const buffer = await readFile(`resources/${id}`);
|
|
392
|
-
res.status(200);
|
|
393
|
-
res.header("Content-Type", resourceMeta.contentType);
|
|
394
|
-
res.send(buffer);
|
|
395
|
-
});
|
|
396
|
-
mountMcpTransport(app, transports, () => createMcpServer(options, mountedActions, context));
|
|
397
412
|
let httpServer;
|
|
413
|
+
let app;
|
|
398
414
|
return {
|
|
399
415
|
context,
|
|
400
416
|
start: async (actions) => {
|
|
401
|
-
|
|
417
|
+
app = createMcpExpressHandler(options, context, actions, {
|
|
418
|
+
...mcpOptions,
|
|
419
|
+
host,
|
|
420
|
+
auth,
|
|
421
|
+
cors: corsConfig
|
|
422
|
+
});
|
|
402
423
|
httpServer = app.listen(port, host, (error) => {
|
|
403
424
|
if (error) {
|
|
404
425
|
console.error("Failed to start server:", error);
|
|
@@ -496,6 +517,6 @@ async function createSideloadResource(buffer, { name, contentType }) {
|
|
|
496
517
|
return resource;
|
|
497
518
|
}
|
|
498
519
|
//#endregion
|
|
499
|
-
export { cliProxy, createSideloadResource, errorToolResult, handleToolError, http, jsonToolResult, parseResourceMessage, smartToolResult, stdio };
|
|
520
|
+
export { MCP_REQUIRED_HEADERS, cliProxy, createMcpExpressHandler, createSideloadResource, errorToolResult, handleToolError, http, jsonToolResult, parseResourceMessage, smartToolResult, stdio };
|
|
500
521
|
|
|
501
522
|
//# sourceMappingURL=index.mjs.map
|
package/build/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["randomUUID","registerTools"],"sources":["../src/util/result.ts","../src/adapter/cliProxy.ts","../src/adapter/http.ts","../src/adapter/stdio.ts","../src/util/sideload.ts"],"sourcesContent":["import { EmbeddedResource, type CallToolResult } from '@modelcontextprotocol/sdk/types.js'\nimport { SilkweaveError } from '@silkweave/core'\nimport { randomUUID } from 'node:crypto'\n\nexport function smartToolResult(data: string | object | object[]): CallToolResult {\n const text = typeof data === 'string' ? data : JSON.stringify(data)\n const mimeType = typeof data === 'string' ? 'text/plain' : 'application/json'\n const ext = typeof data === 'string' ? 'txt' : 'json'\n if (text.length > 4096) {\n const uri = `mcp://toolResult/${randomUUID()}.${ext}`\n const buffer = Buffer.from(text)\n const blob = buffer.toString('base64')\n return {\n content: [\n { type: 'text', text: `Received resource ${uri} with ${buffer.byteLength} bytes` },\n { type: 'resource', resource: { uri, mimeType, blob } }\n ]\n }\n } else {\n return {\n content: [{ type: 'text' as const, text }]\n }\n }\n}\n\nexport function jsonToolResult(data: object, isError = false): CallToolResult {\n const result: CallToolResult = { content: [{ type: 'text' as const, text: JSON.stringify(data) }] }\n if (isError) { result.isError = true }\n return result\n}\n\nexport function errorToolResult({ code, name, message }: SilkweaveError): CallToolResult {\n return {\n isError: true,\n content: [{\n type: 'text',\n text: JSON.stringify({ success: false, code, name, message })\n }]\n }\n}\n\nexport function handleToolError(error: unknown): CallToolResult {\n if (error instanceof SilkweaveError) {\n return jsonToolResult({ success: false, name: error.name, message: error.message, code: error.code }, true)\n } else if (error instanceof Error) {\n return jsonToolResult({ success: false, name: error.name, message: error.message, stack: error.stack }, true)\n } else {\n return jsonToolResult({ success: false, name: 'Unknown error', message: 'An unknown error occurred', error }, true)\n }\n}\n\nexport function parseResourceMessage({ resource }: EmbeddedResource) {\n const text = ('blob' in resource) ? Buffer.from(resource.blob, 'base64').toString('utf-8') : resource.text\n return text\n}\n","import { intro } from '@clack/prompts'\nimport { Client } from '@modelcontextprotocol/sdk/client'\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'\nimport { ContentBlock, LoggingMessageNotificationSchema, ProgressNotificationSchema, ToolResultContent } from '@modelcontextprotocol/sdk/types.js'\nimport { AdapterFactory, unwrap } from '@silkweave/core'\nimport { createCLILogger } from '@silkweave/logger'\nimport { kebabCase } from 'change-case'\nimport { Command } from 'commander'\nimport { randomUUID } from 'crypto'\nimport { z } from 'zod'\nimport { JSONSchema } from 'zod/v4/core'\nimport { parseResourceMessage } from '../util/result.js'\n\nexport type CLIFormatterFn = (message: ContentBlock, index: number, messages: ContentBlock[]) => string | undefined\n\nexport interface CliProxyOptions {\n url: URL\n formatter?: CLIFormatterFn\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nfunction addCliOption(command: Command, key: string, type: z.ZodType, defaultValue: any) {\n const description = type.description\n const flag = kebabCase(key)\n if (type instanceof z.ZodBoolean) {\n command.option(`--${flag}`, description, defaultValue)\n command.option(`--no-${flag}`)\n } else if (type instanceof z.ZodNumber) {\n command.option(`--${flag} <number>`, description, defaultValue)\n } else if (type instanceof z.ZodString || type instanceof z.ZodEnum) {\n command.option(`--${flag} <string>`, description, defaultValue)\n } else if (type instanceof z.ZodObject || type instanceof z.ZodRecord || type instanceof z.ZodArray) {\n command.option(`--${flag} <json>`, description ?? '', JSON.parse, defaultValue)\n } else {\n throw new Error(`Invalid zod type: ${type.def.type}`)\n }\n}\n\nconst defaultFormatter: CLIFormatterFn = (message) => {\n if (message.type === 'text' && !message.text.includes('mcp://toolResult/')) {\n return `${message.text}`\n } else if (message.type === 'resource') {\n return parseResourceMessage(message)\n } else {\n return JSON.stringify(message)\n }\n\n}\n\nexport const cliProxy: AdapterFactory<CliProxyOptions> = ({ url, formatter = defaultFormatter }) => {\n return (options, baseContext) => {\n const context = baseContext.fork({ adapter: 'cliProxy' })\n const program = new Command()\n .name(options.name)\n .description(options.description)\n .version(options.version)\n .option('-s, --silent', 'Silent mode, prevent log messages', false)\n\n return {\n context,\n start: async () => {\n const client = new Client({\n name: options.name,\n description: options.description,\n version: options.version\n })\n const transport = new StreamableHTTPClientTransport(url)\n await client.connect(transport)\n const { tools } = await client.listTools()\n for (const tool of tools) {\n const name = kebabCase(tool.name)\n const command = program.command(name)\n if (tool.description) { command.description(tool.description) }\n const schema = z.fromJSONSchema(tool.inputSchema as JSONSchema.JSONSchema)\n if (!(schema instanceof z.ZodObject)) { throw new Error('Invalid schema') }\n const shape = schema.shape\n for (const key of Object.keys(shape)) {\n const [type, { defaultValue }] = unwrap(shape[key])\n addCliOption(command, key, type, defaultValue)\n }\n command.action(async (args) => {\n const { silent } = program.opts<{ silent: boolean }>()\n const logger = createCLILogger()\n if (!silent) {\n intro(`${options.name} - ${tool.name}`)\n client.setNotificationHandler(LoggingMessageNotificationSchema, ({ params: { level, data } }) => {\n logger[level](data)\n })\n client.setNotificationHandler(ProgressNotificationSchema, ({ params: { progress, total, message } }) => {\n logger.info({ progress, total, message })\n })\n }\n const input = await schema.parseAsync(args)\n const response = await client.callTool({\n name: tool.name,\n arguments: input,\n _meta: { progressToken: randomUUID(), disposition: 'json' }\n }) as ToolResultContent\n response.content.forEach((message, index, messages) => {\n const text = formatter(message, index, messages)\n process.stdout.write(`${text}\\n`)\n })\n })\n }\n await program.parseAsync()\n await transport.close()\n },\n stop: async () => { }\n }\n }\n}\n","import { InMemoryEventStore } from '@modelcontextprotocol/sdk/examples/shared/inMemoryEventStore.js'\nimport { createMcpExpressApp, CreateMcpExpressAppOptions } from '@modelcontextprotocol/sdk/server/express.js'\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'\nimport { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js'\nimport { AuthConfig, AuthInfo, generateProtectedResourceMetadata, OAuthRequest, OAuthResponse, validateToken } from '@silkweave/auth'\nimport { Action, AdapterFactory, SilkweaveContext, SilkweaveOptions } from '@silkweave/core'\nimport { createLogger } from '@silkweave/logger'\nimport { capitalCase, pascalCase } from 'change-case'\nimport cors, { CorsOptions } from 'cors'\nimport { randomUUID } from 'crypto'\nimport express, { Express, Request, Response } from 'express'\nimport { readFile } from 'fs/promises'\nimport { Server } from 'http'\nimport { AsyncLocalStorage } from 'node:async_hooks'\nimport { handleToolError, jsonToolResult, smartToolResult } from '../util/result.js'\nimport { SideloadResource } from '../util/sideload.js'\n\nconst authStorage = new AsyncLocalStorage<AuthInfo>()\n\n/** Headers required by the MCP protocol that must always be exposed */\nconst MCP_REQUIRED_HEADERS = ['WWW-Authenticate', 'Mcp-Session-Id', 'Last-Event-Id', 'Mcp-Protocol-Version']\n\nexport interface HttpAdapterOptions extends CreateMcpExpressAppOptions {\n host: string\n port: number\n auth?: AuthConfig\n /** CORS configuration. `false` to disable, `true`/`undefined` for permissive defaults, or a CorsOptions object. */\n cors?: CorsOptions | boolean\n}\n\nfunction mountOAuthRoutes(app: Express, auth: AuthConfig): Set<string> {\n const provider = auth.provider!\n const callbackPath = auth.callbackPath ?? '/auth/callback'\n\n const toOAuthReq = (req: Request): OAuthRequest => ({\n method: req.method,\n url: new URL(req.url, `${req.protocol}://${req.get('host')}`),\n headers: Object.fromEntries(Object.entries(req.headers).map(([k, v]) => [k, Array.isArray(v) ? v[0] : v])),\n body: req.body as Record<string, string> | undefined\n })\n\n const sendOAuth = (res: Response, oauthRes: OAuthResponse) => {\n for (const [key, value] of Object.entries(oauthRes.headers)) { res.header(key, value) }\n if (oauthRes.body) {\n res.status(oauthRes.status).send(typeof oauthRes.body === 'string' ? oauthRes.body : JSON.stringify(oauthRes.body))\n } else {\n res.status(oauthRes.status).end()\n }\n }\n\n app.get('/.well-known/oauth-authorization-server', (_req: Request, res: Response) => {\n sendOAuth(res, provider.metadata())\n })\n app.get('/authorize', async (req: Request, res: Response) => {\n sendOAuth(res, await provider.authorize(toOAuthReq(req)))\n })\n app.get(callbackPath, async (req: Request, res: Response) => {\n sendOAuth(res, await provider.callback(toOAuthReq(req)))\n })\n app.post('/token', express.urlencoded({ extended: false }), async (req: Request, res: Response) => {\n sendOAuth(res, await provider.token(toOAuthReq(req)))\n })\n app.post('/register', express.json(), async (req: Request, res: Response) => {\n sendOAuth(res, await provider.register(toOAuthReq(req)))\n })\n\n return new Set(['/.well-known/oauth-authorization-server', '/authorize', callbackPath, '/token', '/register'])\n}\n\nfunction mountAuthMiddleware(app: Express, auth: AuthConfig, oauthPaths: Set<string>, context: SilkweaveContext) {\n app.use(async (req: Request, res: Response, next: (err?: unknown) => void) => {\n if (req.path.startsWith('/.well-known/') || oauthPaths.has(req.path)) { return next() }\n const result = await validateToken(req.headers.authorization, auth, context.fork({ request: req }))\n if (result.error) {\n for (const [key, value] of Object.entries(result.error.headers)) {\n res.header(key, value)\n }\n res.status(result.error.statusCode).json(result.error.body)\n return\n }\n if (result.auth) {\n authStorage.run(result.auth, () => { next() })\n } else {\n next()\n }\n })\n}\n\nfunction registerTools(server: McpServer, actions: Action[], context: SilkweaveContext) {\n for (const action of actions) {\n server.registerTool(pascalCase(action.name), {\n title: capitalCase(action.name),\n description: action.description,\n inputSchema: action.input\n }, async (input, extra) => {\n const logger = createLogger({\n stream: process.stderr,\n onLog: (level, data) => {\n extra.sendNotification({ method: 'notifications/message', params: { level, data } })\n },\n onProgress: ({ progress, total, message }) => {\n if (!extra._meta?.progressToken) { return }\n extra.sendNotification({\n method: 'notifications/progress',\n params: { progress, total, message, progressToken: extra._meta.progressToken }\n })\n }\n })\n const currentAuth = authStorage.getStore()\n const actionContext = context.fork({ logger, extra, ...(currentAuth ? { auth: currentAuth } : {}) })\n const disposition = extra._meta?.disposition\n return action.run(input, actionContext).then((result) => {\n if (action.toolResult) {\n const response = action.toolResult(result, actionContext)\n if (response) { return response }\n }\n if (disposition === 'json') {\n return jsonToolResult(result)\n } else {\n return smartToolResult(result)\n }\n }).catch(handleToolError)\n })\n }\n}\n\nfunction createMcpServer(options: SilkweaveOptions, actions: Action[], context: SilkweaveContext): McpServer {\n const server = new McpServer({\n name: options.name,\n description: options.description,\n version: options.version\n }, {\n capabilities: { tools: {}, logging: {} }\n })\n registerTools(server, actions, context)\n return server\n}\n\nfunction createSessionTransport(transports: Record<string, StreamableHTTPServerTransport>): StreamableHTTPServerTransport {\n const eventStore = new InMemoryEventStore()\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: () => randomUUID(),\n enableJsonResponse: false,\n eventStore,\n onsessioninitialized: (sId) => {\n console.log(`Session initialized with ID: ${sId}`)\n transports[sId] = transport\n }\n })\n transport.onerror = (error) => {\n console.error(error)\n }\n transport.onclose = () => {\n const sid = transport.sessionId\n if (sid && transports[sid]) {\n console.log(`Transport closed for session ${sid}, removing from transports map`)\n delete transports[sid]\n }\n }\n return transport\n}\n\nfunction mountMcpTransport(\n app: Express,\n transports: Record<string, StreamableHTTPServerTransport>,\n createServer: () => McpServer\n) {\n app.post('/mcp', async (req: Request, res: Response) => {\n const sessionId = req.headers['mcp-session-id'] as string | undefined\n try {\n if (sessionId && transports[sessionId]) {\n await transports[sessionId].handleRequest(req, res, req.body)\n return\n }\n\n if (!isInitializeRequest(req.body)) {\n res.status(404).json({\n jsonrpc: '2.0',\n error: { code: -32_000, message: 'Session not found' },\n id: null\n })\n return\n }\n\n const transport = createSessionTransport(transports)\n await createServer().connect(transport)\n await transport.handleRequest(req, res, req.body)\n } catch (error) {\n console.error('Error handling MCP request:', error)\n if (!res.headersSent) {\n res.status(500).json({\n jsonrpc: '2.0',\n error: { code: -32_603, message: 'Internal server error' },\n id: null\n })\n }\n }\n })\n\n const handleSessionStream = async (req: Request, res: Response) => {\n const sessionId = req.headers['mcp-session-id'] as string | undefined\n if (!sessionId || !transports[sessionId]) {\n res.status(400).send('Invalid or missing session ID')\n return\n }\n const transport = transports[sessionId]\n await transport.handleRequest(req, res)\n }\n\n app.get('/mcp', handleSessionStream)\n app.delete('/mcp', handleSessionStream)\n app.get('/mcp/resource/:id', handleSessionStream)\n}\n\nexport const http: AdapterFactory<HttpAdapterOptions> = ({ host, port, auth, cors: corsConfig, ...mcpOptions }) => {\n return (options, baseContext) => {\n const context = baseContext.fork({ adapter: 'http' })\n const app = createMcpExpressApp({ ...mcpOptions, host })\n\n if (corsConfig !== false) {\n const userConfig = corsConfig === true || corsConfig === undefined ? {} : corsConfig\n const userExposed = userConfig.exposedHeaders\n const exposedHeaders = [\n ...MCP_REQUIRED_HEADERS,\n ...(Array.isArray(userExposed) ? userExposed : userExposed ? [userExposed] : [])\n ]\n app.use(cors({ origin: '*', ...userConfig, exposedHeaders }))\n }\n\n if (auth?.authorizationServers?.length && auth.resourceUrl) {\n app.get('/.well-known/oauth-protected-resource', (_req: Request, res: Response) => {\n const metadata = generateProtectedResourceMetadata(auth.resourceUrl!, auth.authorizationServers!)\n res.json(metadata)\n })\n }\n\n const oauthPaths = auth?.provider ? mountOAuthRoutes(app, auth) : new Set<string>()\n\n if (auth) {\n mountAuthMiddleware(app, auth, oauthPaths, context)\n }\n\n const transports: Record<string, StreamableHTTPServerTransport> = {}\n let mountedActions: Action[] = []\n\n app.get('/resource/:id', async (req: Request, res: Response) => {\n const id = req.params.id\n if (!id || typeof id !== 'string') { throw new Error('Invalid ID') }\n const resourceMeta: SideloadResource = JSON.parse(await readFile(`resources/${id}.json`, 'utf-8'))\n const buffer = await readFile(`resources/${id}`)\n res.status(200)\n res.header('Content-Type', resourceMeta.contentType)\n res.send(buffer)\n })\n\n mountMcpTransport(app, transports, () => createMcpServer(options, mountedActions, context))\n\n let httpServer: Server | undefined\n return {\n context,\n start: async (actions) => {\n mountedActions = actions\n httpServer = app.listen(port, host, (error) => {\n if (error) {\n console.error('Failed to start server:', error)\n process.exit(1)\n }\n console.log(`MCP Streamable HTTP Server listening on http://${host}:${port}/mcp`)\n })\n },\n stop: async () => {\n if (httpServer) {\n await new Promise<void>((resolve, reject) => {\n return httpServer!.close((err) => {\n if (err) {\n reject(err)\n } else {\n resolve()\n }\n })\n })\n }\n httpServer = undefined\n }\n }\n }\n}\n","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { Action, AdapterFactory, SilkweaveContext } from '@silkweave/core'\nimport { createLogger } from '@silkweave/logger'\nimport { capitalCase, pascalCase } from 'change-case'\nimport { handleToolError, smartToolResult } from '../util/result.js'\n\nfunction registerTools(server: McpServer, actions: Action[], context: SilkweaveContext) {\n for (const action of actions) {\n server.registerTool(pascalCase(action.name), {\n title: capitalCase(action.name),\n description: action.description,\n inputSchema: action.input\n }, async (input, extra) => {\n const logger = createLogger({\n stream: false,\n onLog: (level, data) => {\n extra.sendNotification({ method: 'notifications/message', params: { level, data } })\n },\n onProgress: ({ progress, total, message }) => {\n if (!extra._meta?.progressToken) { return }\n extra.sendNotification({\n method: 'notifications/progress',\n params: { progress, total, message, progressToken: extra._meta.progressToken }\n })\n }\n })\n const actionContext = context.fork({ logger, extra })\n return action.run(input, actionContext)\n .then((result) => action.toolResult?.(result, actionContext) ?? smartToolResult(result))\n .catch(handleToolError)\n })\n }\n}\n\nexport const stdio: AdapterFactory = () => {\n return (options, baseContext) => {\n const context = baseContext.fork({ adapter: 'stdio' })\n const server = new McpServer({\n name: options.name,\n description: options.description,\n version: options.version\n }, {\n capabilities: { tools: {}, logging: {} }\n })\n return {\n context,\n start: async (actions) => {\n registerTools(server, actions, context)\n const transport = new StdioServerTransport()\n await server.connect(transport)\n },\n stop: async () => {\n await server?.close()\n }\n }\n }\n}\n","import { randomUUID } from 'crypto'\nimport { writeFile } from 'fs/promises'\n\nexport interface SideloadResource {\n id: string\n name: string\n contentType: string\n size: number\n}\n\nexport async function createSideloadResource(buffer: Buffer, { name, contentType }: Pick<SideloadResource, 'name' | 'contentType'>) {\n const id = randomUUID()\n const resource: SideloadResource = { id, name, contentType, size: buffer.length }\n await Promise.all([\n writeFile(`resources/${id}`, buffer),\n writeFile(`resources/${id}.json`, JSON.stringify(resource), 'utf-8')\n ])\n return resource\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAIA,SAAgB,gBAAgB,MAAkD;CAChF,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,KAAK;CACnE,MAAM,WAAW,OAAO,SAAS,WAAW,eAAe;CAC3D,MAAM,MAAM,OAAO,SAAS,WAAW,QAAQ;AAC/C,KAAI,KAAK,SAAS,MAAM;EACtB,MAAM,MAAM,oBAAoBA,cAAY,CAAC,GAAG;EAChD,MAAM,SAAS,OAAO,KAAK,KAAK;EAChC,MAAM,OAAO,OAAO,SAAS,SAAS;AACtC,SAAO,EACL,SAAS,CACP;GAAE,MAAM;GAAQ,MAAM,qBAAqB,IAAI,QAAQ,OAAO,WAAW;GAAS,EAClF;GAAE,MAAM;GAAY,UAAU;IAAE;IAAK;IAAU;IAAM;GAAE,CACxD,EACF;OAED,QAAO,EACL,SAAS,CAAC;EAAE,MAAM;EAAiB;EAAM,CAAC,EAC3C;;AAIL,SAAgB,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,QAAQ,CACrE,CAAC;AACF,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["randomUUID","registerTools"],"sources":["../src/util/result.ts","../src/adapter/cliProxy.ts","../src/lib/handler.ts","../src/adapter/http.ts","../src/adapter/stdio.ts","../src/util/sideload.ts"],"sourcesContent":["import { EmbeddedResource, type CallToolResult } from '@modelcontextprotocol/sdk/types.js'\nimport { SilkweaveError } from '@silkweave/core'\nimport { randomUUID } from 'node:crypto'\n\nexport function smartToolResult(data: string | object | object[]): CallToolResult {\n const text = typeof data === 'string' ? data : JSON.stringify(data)\n const mimeType = typeof data === 'string' ? 'text/plain' : 'application/json'\n const ext = typeof data === 'string' ? 'txt' : 'json'\n if (text.length > 4096) {\n const uri = `mcp://toolResult/${randomUUID()}.${ext}`\n const buffer = Buffer.from(text)\n const blob = buffer.toString('base64')\n return {\n content: [\n { type: 'text', text: `Received resource ${uri} with ${buffer.byteLength} bytes` },\n { type: 'resource', resource: { uri, mimeType, blob } }\n ]\n }\n } else {\n return {\n content: [{ type: 'text' as const, text }]\n }\n }\n}\n\nexport function jsonToolResult(data: object, isError = false): CallToolResult {\n const result: CallToolResult = { content: [{ type: 'text' as const, text: JSON.stringify(data) }] }\n if (isError) { result.isError = true }\n return result\n}\n\nexport function errorToolResult({ code, name, message }: SilkweaveError): CallToolResult {\n return {\n isError: true,\n content: [{\n type: 'text',\n text: JSON.stringify({ success: false, code, name, message })\n }]\n }\n}\n\nexport function handleToolError(error: unknown): CallToolResult {\n if (error instanceof SilkweaveError) {\n return jsonToolResult({ success: false, name: error.name, message: error.message, code: error.code }, true)\n } else if (error instanceof Error) {\n return jsonToolResult({ success: false, name: error.name, message: error.message, stack: error.stack }, true)\n } else {\n return jsonToolResult({ success: false, name: 'Unknown error', message: 'An unknown error occurred', error }, true)\n }\n}\n\nexport function parseResourceMessage({ resource }: EmbeddedResource) {\n const text = ('blob' in resource) ? Buffer.from(resource.blob, 'base64').toString('utf-8') : resource.text\n return text\n}\n","import { intro } from '@clack/prompts'\nimport { Client } from '@modelcontextprotocol/sdk/client'\nimport { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'\nimport { ContentBlock, LoggingMessageNotificationSchema, ProgressNotificationSchema, ToolResultContent } from '@modelcontextprotocol/sdk/types.js'\nimport { AdapterFactory, unwrap } from '@silkweave/core'\nimport { createCLILogger } from '@silkweave/logger'\nimport { kebabCase } from 'change-case'\nimport { Command } from 'commander'\nimport { randomUUID } from 'crypto'\nimport { z } from 'zod/v4'\nimport { JSONSchema } from 'zod/v4/core'\nimport { parseResourceMessage } from '../util/result.js'\n\nexport type CLIFormatterFn = (message: ContentBlock, index: number, messages: ContentBlock[]) => string | undefined\n\nexport interface CliProxyOptions {\n url: URL\n formatter?: CLIFormatterFn\n}\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nfunction addCliOption(command: Command, key: string, type: z.ZodType, defaultValue: any) {\n const description = type.description\n const flag = kebabCase(key)\n if (type instanceof z.ZodBoolean) {\n command.option(`--${flag}`, description, defaultValue)\n command.option(`--no-${flag}`)\n } else if (type instanceof z.ZodNumber) {\n command.option(`--${flag} <number>`, description, defaultValue)\n } else if (type instanceof z.ZodString || type instanceof z.ZodEnum) {\n command.option(`--${flag} <string>`, description, defaultValue)\n } else if (type instanceof z.ZodObject || type instanceof z.ZodRecord || type instanceof z.ZodArray) {\n command.option(`--${flag} <json>`, description ?? '', JSON.parse, defaultValue)\n } else {\n throw new Error(`Invalid zod type: ${type.def.type}`)\n }\n}\n\nconst defaultFormatter: CLIFormatterFn = (message) => {\n if (message.type === 'text' && !message.text.includes('mcp://toolResult/')) {\n return `${message.text}`\n } else if (message.type === 'resource') {\n return parseResourceMessage(message)\n } else {\n return JSON.stringify(message)\n }\n\n}\n\nexport const cliProxy: AdapterFactory<CliProxyOptions> = ({ url, formatter = defaultFormatter }) => {\n return (options, baseContext) => {\n const context = baseContext.fork({ adapter: 'cliProxy' })\n const program = new Command()\n .name(options.name)\n .description(options.description)\n .version(options.version)\n .option('-s, --silent', 'Silent mode, prevent log messages', false)\n\n return {\n context,\n start: async () => {\n const client = new Client({\n name: options.name,\n description: options.description,\n version: options.version\n })\n const transport = new StreamableHTTPClientTransport(url)\n await client.connect(transport)\n const { tools } = await client.listTools()\n for (const tool of tools) {\n const name = kebabCase(tool.name)\n const command = program.command(name)\n if (tool.description) { command.description(tool.description) }\n const schema = z.fromJSONSchema(tool.inputSchema as JSONSchema.JSONSchema)\n if (!(schema instanceof z.ZodObject)) { throw new Error('Invalid schema') }\n const shape = schema.shape\n for (const key of Object.keys(shape)) {\n const [type, { defaultValue }] = unwrap(shape[key])\n addCliOption(command, key, type, defaultValue)\n }\n command.action(async (args) => {\n const { silent } = program.opts<{ silent: boolean }>()\n const logger = createCLILogger()\n if (!silent) {\n intro(`${options.name} - ${tool.name}`)\n client.setNotificationHandler(LoggingMessageNotificationSchema, ({ params: { level, data } }) => {\n logger[level](data)\n })\n client.setNotificationHandler(ProgressNotificationSchema, ({ params: { progress, total, message } }) => {\n logger.info({ progress, total, message })\n })\n }\n const input = await schema.parseAsync(args)\n const response = await client.callTool({\n name: tool.name,\n arguments: input,\n _meta: { progressToken: randomUUID(), disposition: 'json' }\n }) as ToolResultContent\n response.content.forEach((message, index, messages) => {\n const text = formatter(message, index, messages)\n process.stdout.write(`${text}\\n`)\n })\n })\n }\n await program.parseAsync()\n await transport.close()\n },\n stop: async () => { }\n }\n }\n}\n","import { InMemoryEventStore } from '@modelcontextprotocol/sdk/examples/shared/inMemoryEventStore.js'\nimport { createMcpExpressApp, CreateMcpExpressAppOptions } from '@modelcontextprotocol/sdk/server/express.js'\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'\nimport { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js'\nimport { AuthConfig, AuthInfo, generateProtectedResourceMetadata, OAuthRequest, OAuthResponse, validateToken } from '@silkweave/auth'\nimport { Action, SilkweaveContext, SilkweaveOptions } from '@silkweave/core'\nimport { createLogger } from '@silkweave/logger'\nimport { capitalCase, pascalCase } from 'change-case'\nimport cors, { CorsOptions } from 'cors'\nimport { randomUUID } from 'crypto'\nimport express, { Express, Request, Response } from 'express'\nimport { readFile } from 'fs/promises'\nimport { AsyncLocalStorage } from 'node:async_hooks'\nimport { handleToolError, jsonToolResult, smartToolResult } from '../util/result.js'\nimport { SideloadResource } from '../util/sideload.js'\n\nconst authStorage = new AsyncLocalStorage<AuthInfo>()\n\n/** Headers required by the MCP protocol that must always be exposed when CORS is in use. */\nexport const MCP_REQUIRED_HEADERS = ['WWW-Authenticate', 'Mcp-Session-Id', 'Last-Event-Id', 'Mcp-Protocol-Version']\n\nexport interface CreateMcpExpressHandlerOptions extends CreateMcpExpressAppOptions {\n /** Bearer-token / OAuth auth configuration. Omit to disable auth entirely. */\n auth?: AuthConfig\n /** CORS configuration. `false` to disable, `true`/`undefined` for permissive defaults, or a CorsOptions object. */\n cors?: CorsOptions | boolean\n /** Hostname for the underlying express app (used by some MCP SDK checks). Default `'0.0.0.0'`. */\n host?: string\n /** Mount the `/resource/:id` sideload route on the returned app. Default `true`. */\n sideloadResources?: boolean\n}\n\nfunction toOAuthReq(req: Request): OAuthRequest {\n return {\n method: req.method,\n url: new URL(req.url, `${req.protocol}://${req.get('host')}`),\n headers: Object.fromEntries(Object.entries(req.headers).map(([k, v]) => [k, Array.isArray(v) ? v[0] : v])),\n body: req.body as Record<string, string> | undefined\n }\n}\n\nfunction sendOAuth(res: Response, oauthRes: OAuthResponse) {\n for (const [key, value] of Object.entries(oauthRes.headers)) { res.header(key, value) }\n if (oauthRes.body) {\n res.status(oauthRes.status).send(typeof oauthRes.body === 'string' ? oauthRes.body : JSON.stringify(oauthRes.body))\n } else {\n res.status(oauthRes.status).end()\n }\n}\n\nfunction mountOAuthRoutes(app: Express, auth: AuthConfig): Set<string> {\n const provider = auth.provider!\n const callbackPath = auth.callbackPath ?? '/auth/callback'\n\n app.get('/.well-known/oauth-authorization-server', (_req: Request, res: Response) => {\n sendOAuth(res, provider.metadata())\n })\n app.get('/authorize', async (req: Request, res: Response) => {\n sendOAuth(res, await provider.authorize(toOAuthReq(req)))\n })\n app.get(callbackPath, async (req: Request, res: Response) => {\n sendOAuth(res, await provider.callback(toOAuthReq(req)))\n })\n app.post('/token', express.urlencoded({ extended: false }), async (req: Request, res: Response) => {\n sendOAuth(res, await provider.token(toOAuthReq(req)))\n })\n app.post('/register', express.json(), async (req: Request, res: Response) => {\n sendOAuth(res, await provider.register(toOAuthReq(req)))\n })\n\n return new Set(['/.well-known/oauth-authorization-server', '/authorize', callbackPath, '/token', '/register'])\n}\n\nfunction mountAuthMiddleware(app: Express, auth: AuthConfig, oauthPaths: Set<string>, context: SilkweaveContext) {\n app.use(async (req: Request, res: Response, next: (err?: unknown) => void) => {\n if (req.path.startsWith('/.well-known/') || oauthPaths.has(req.path)) { return next() }\n const result = await validateToken(req.headers.authorization, auth, context.fork({ request: req }))\n if (result.error) {\n for (const [key, value] of Object.entries(result.error.headers)) {\n res.header(key, value)\n }\n res.status(result.error.statusCode).json(result.error.body)\n return\n }\n if (result.auth) {\n authStorage.run(result.auth, () => { next() })\n } else {\n next()\n }\n })\n}\n\nfunction registerTools(server: McpServer, actions: Action[], context: SilkweaveContext) {\n for (const action of actions) {\n server.registerTool(pascalCase(action.name), {\n title: capitalCase(action.name),\n description: action.description,\n inputSchema: action.input\n }, async (input, extra) => {\n const logger = createLogger({\n stream: process.stderr,\n onLog: (level, data) => {\n extra.sendNotification({ method: 'notifications/message', params: { level, data } })\n },\n onProgress: ({ progress, total, message }) => {\n if (!extra._meta?.progressToken) { return }\n extra.sendNotification({\n method: 'notifications/progress',\n params: { progress, total, message, progressToken: extra._meta.progressToken }\n })\n }\n })\n const currentAuth = authStorage.getStore()\n const actionContext = context.fork({ logger, extra, ...(currentAuth ? { auth: currentAuth } : {}) })\n const disposition = extra._meta?.disposition\n return action.run(input, actionContext).then((result) => {\n if (action.toolResult) {\n const response = action.toolResult(result, actionContext)\n if (response) { return response }\n }\n if (disposition === 'json') {\n return jsonToolResult(result)\n } else {\n return smartToolResult(result)\n }\n }).catch(handleToolError)\n })\n }\n}\n\nfunction createMcpServer(options: SilkweaveOptions, actions: Action[], context: SilkweaveContext): McpServer {\n const server = new McpServer({\n name: options.name,\n description: options.description,\n version: options.version\n }, {\n capabilities: { tools: {}, logging: {} }\n })\n registerTools(server, actions, context)\n return server\n}\n\nfunction createSessionTransport(transports: Record<string, StreamableHTTPServerTransport>): StreamableHTTPServerTransport {\n const eventStore = new InMemoryEventStore()\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: () => randomUUID(),\n enableJsonResponse: false,\n eventStore,\n onsessioninitialized: (sId) => {\n console.log(`Session initialized with ID: ${sId}`)\n transports[sId] = transport\n }\n })\n transport.onerror = (error) => {\n console.error(error)\n }\n transport.onclose = () => {\n const sid = transport.sessionId\n if (sid && transports[sid]) {\n console.log(`Transport closed for session ${sid}, removing from transports map`)\n delete transports[sid]\n }\n }\n return transport\n}\n\nfunction mountMcpTransport(\n app: Express,\n transports: Record<string, StreamableHTTPServerTransport>,\n createServer: () => McpServer\n) {\n app.post('/mcp', async (req: Request, res: Response) => {\n const sessionId = req.headers['mcp-session-id'] as string | undefined\n try {\n if (sessionId && transports[sessionId]) {\n await transports[sessionId].handleRequest(req, res, req.body)\n return\n }\n\n if (!isInitializeRequest(req.body)) {\n res.status(404).json({\n jsonrpc: '2.0',\n error: { code: -32_000, message: 'Session not found' },\n id: null\n })\n return\n }\n\n const transport = createSessionTransport(transports)\n await createServer().connect(transport)\n await transport.handleRequest(req, res, req.body)\n } catch (error) {\n console.error('Error handling MCP request:', error)\n if (!res.headersSent) {\n res.status(500).json({\n jsonrpc: '2.0',\n error: { code: -32_603, message: 'Internal server error' },\n id: null\n })\n }\n }\n })\n\n const handleSessionStream = async (req: Request, res: Response) => {\n const sessionId = req.headers['mcp-session-id'] as string | undefined\n if (!sessionId || !transports[sessionId]) {\n res.status(400).send('Invalid or missing session ID')\n return\n }\n const transport = transports[sessionId]\n await transport.handleRequest(req, res)\n }\n\n app.get('/mcp', handleSessionStream)\n app.delete('/mcp', handleSessionStream)\n app.get('/mcp/resource/:id', handleSessionStream)\n}\n\n/**\n * Build an Express sub-app exposing the MCP Streamable HTTP transport, OAuth\n * routes (if configured), and bearer-token auth middleware. The returned app\n * can be listened on directly OR mounted onto an existing server via\n * `parentApp.use(basePath, app)` / Nest's `httpAdapter.use(basePath, app)`.\n *\n * Used by `@silkweave/mcp`'s `http()` adapter (server-owning) and\n * `@silkweave/nestjs`'s `mcp()` adapter (mounts on Nest's HTTP server).\n */\nexport function createMcpExpressHandler(\n silkweaveOptions: SilkweaveOptions,\n context: SilkweaveContext,\n actions: Action[],\n options: CreateMcpExpressHandlerOptions = {}\n): Express {\n const { auth, cors: corsConfig, host = '0.0.0.0', sideloadResources = true, ...mcpOptions } = options\n const app = createMcpExpressApp({ ...mcpOptions, host })\n\n if (corsConfig !== false) {\n const userConfig = corsConfig === true || corsConfig === undefined ? {} : corsConfig\n const userExposed = userConfig.exposedHeaders\n const exposedHeaders = [\n ...MCP_REQUIRED_HEADERS,\n ...(Array.isArray(userExposed) ? userExposed : userExposed ? [userExposed] : [])\n ]\n app.use(cors({ origin: '*', ...userConfig, exposedHeaders }))\n }\n\n if (auth?.authorizationServers?.length && auth.resourceUrl) {\n app.get('/.well-known/oauth-protected-resource', (_req: Request, res: Response) => {\n const metadata = generateProtectedResourceMetadata(auth.resourceUrl!, auth.authorizationServers!)\n res.json(metadata)\n })\n }\n\n const oauthPaths = auth?.provider ? mountOAuthRoutes(app, auth) : new Set<string>()\n\n if (auth) {\n mountAuthMiddleware(app, auth, oauthPaths, context)\n }\n\n if (sideloadResources) {\n app.get('/resource/:id', async (req: Request, res: Response) => {\n const id = req.params.id\n if (!id || typeof id !== 'string') { throw new Error('Invalid ID') }\n const resourceMeta: SideloadResource = JSON.parse(await readFile(`resources/${id}.json`, 'utf-8'))\n const buffer = await readFile(`resources/${id}`)\n res.status(200)\n res.header('Content-Type', resourceMeta.contentType)\n res.send(buffer)\n })\n }\n\n const transports: Record<string, StreamableHTTPServerTransport> = {}\n mountMcpTransport(app, transports, () => createMcpServer(silkweaveOptions, actions, context))\n\n return app\n}\n","import { AuthConfig } from '@silkweave/auth'\nimport { AdapterFactory } from '@silkweave/core'\nimport { CorsOptions } from 'cors'\nimport { Express } from 'express'\nimport { Server } from 'http'\nimport { createMcpExpressHandler, CreateMcpExpressHandlerOptions } from '../lib/handler.js'\n\nexport interface HttpAdapterOptions extends Omit<CreateMcpExpressHandlerOptions, 'auth' | 'cors'> {\n host: string\n port: number\n auth?: AuthConfig\n /** CORS configuration. `false` to disable, `true`/`undefined` for permissive defaults, or a CorsOptions object. */\n cors?: CorsOptions | boolean\n}\n\nexport const http: AdapterFactory<HttpAdapterOptions> = ({ host, port, auth, cors: corsConfig, ...mcpOptions }) => {\n return (options, baseContext) => {\n const context = baseContext.fork({ adapter: 'http' })\n let httpServer: Server | undefined\n let app: Express | undefined\n return {\n context,\n start: async (actions) => {\n app = createMcpExpressHandler(options, context, actions, { ...mcpOptions, host, auth, cors: corsConfig })\n httpServer = app.listen(port, host, (error) => {\n if (error) {\n console.error('Failed to start server:', error)\n process.exit(1)\n }\n console.log(`MCP Streamable HTTP Server listening on http://${host}:${port}/mcp`)\n })\n },\n stop: async () => {\n if (httpServer) {\n await new Promise<void>((resolve, reject) => {\n return httpServer!.close((err) => {\n if (err) {\n reject(err)\n } else {\n resolve()\n }\n })\n })\n }\n httpServer = undefined\n }\n }\n }\n}\n","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { Action, AdapterFactory, SilkweaveContext } from '@silkweave/core'\nimport { createLogger } from '@silkweave/logger'\nimport { capitalCase, pascalCase } from 'change-case'\nimport { handleToolError, smartToolResult } from '../util/result.js'\n\nfunction registerTools(server: McpServer, actions: Action[], context: SilkweaveContext) {\n for (const action of actions) {\n server.registerTool(pascalCase(action.name), {\n title: capitalCase(action.name),\n description: action.description,\n inputSchema: action.input\n }, async (input, extra) => {\n const logger = createLogger({\n stream: false,\n onLog: (level, data) => {\n extra.sendNotification({ method: 'notifications/message', params: { level, data } })\n },\n onProgress: ({ progress, total, message }) => {\n if (!extra._meta?.progressToken) { return }\n extra.sendNotification({\n method: 'notifications/progress',\n params: { progress, total, message, progressToken: extra._meta.progressToken }\n })\n }\n })\n const actionContext = context.fork({ logger, extra })\n return action.run(input, actionContext)\n .then((result) => action.toolResult?.(result, actionContext) ?? smartToolResult(result))\n .catch(handleToolError)\n })\n }\n}\n\nexport const stdio: AdapterFactory = () => {\n return (options, baseContext) => {\n const context = baseContext.fork({ adapter: 'stdio' })\n const server = new McpServer({\n name: options.name,\n description: options.description,\n version: options.version\n }, {\n capabilities: { tools: {}, logging: {} }\n })\n return {\n context,\n start: async (actions) => {\n registerTools(server, actions, context)\n const transport = new StdioServerTransport()\n await server.connect(transport)\n },\n stop: async () => {\n await server?.close()\n }\n }\n }\n}\n","import { randomUUID } from 'crypto'\nimport { writeFile } from 'fs/promises'\n\nexport interface SideloadResource {\n id: string\n name: string\n contentType: string\n size: number\n}\n\nexport async function createSideloadResource(buffer: Buffer, { name, contentType }: Pick<SideloadResource, 'name' | 'contentType'>) {\n const id = randomUUID()\n const resource: SideloadResource = { id, name, contentType, size: buffer.length }\n await Promise.all([\n writeFile(`resources/${id}`, buffer),\n writeFile(`resources/${id}.json`, JSON.stringify(resource), 'utf-8')\n ])\n return resource\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAIA,SAAgB,gBAAgB,MAAkD;CAChF,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,KAAK;CACnE,MAAM,WAAW,OAAO,SAAS,WAAW,eAAe;CAC3D,MAAM,MAAM,OAAO,SAAS,WAAW,QAAQ;AAC/C,KAAI,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AAM,SAAS,IAAI,UAAU;GAC3B,MAAM,QAAQ;GACd,aAAa,QAAQ;GACrB,SAAS,QAAQ;GAClB,EAAE,EACD,cAAc;GAAE,OAAO,EAAE;GAAE,SAAS,EAAE;GAAE,EACzC,CAAC;AACF,SAAO;GACL;GACA,OAAO,OAAO,YAAY;AACxB,kBAAc,QAAQ,SAAS,QAAQ;IACvC,MAAM,YAAY,IAAI,sBAAsB;AAC5C,UAAM,OAAO,QAAQ,UAAU;;GAEjC,MAAM,YAAY;AAChB,UAAM,QAAQ,OAAO;;GAExB;;;;;AC7CL,eAAsB,uBAAuB,QAAgB,EAAE,MAAM,eAA+D;CAClI,MAAM,KAAK,YAAY;CACvB,MAAM,WAA6B;EAAE;EAAI;EAAM;EAAa,MAAM,OAAO;EAAQ;AACjF,OAAM,QAAQ,IAAI,CAChB,UAAU,aAAa,MAAM,OAAO,EACpC,UAAU,aAAa,GAAG,QAAQ,KAAK,UAAU,SAAS,EAAE,QAAQ,CACrE,CAAC;AACF,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silkweave/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Silkweave MCP Package",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"commander": "^13.1.0",
|
|
17
17
|
"cors": "^2.8.6",
|
|
18
18
|
"express": "^5.2.1",
|
|
19
|
-
"zod": "^
|
|
20
|
-
"@silkweave/auth": "1.
|
|
21
|
-
"@silkweave/
|
|
22
|
-
"@silkweave/
|
|
19
|
+
"zod": "^3.25.0",
|
|
20
|
+
"@silkweave/auth": "1.9.0",
|
|
21
|
+
"@silkweave/logger": "1.9.0",
|
|
22
|
+
"@silkweave/core": "1.9.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@eslint/js": "^10.0.1",
|