@silkweave/nestjs 3.2.1 → 4.0.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/build/mcp.d.mts +1 -1
- package/build/mcp.mjs +1 -1
- package/build/mcp.mjs.map +1 -1
- package/package.json +9 -9
package/build/mcp.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as NestSilkweaveAdapter } from "./types-6rbW7fLE.mjs";
|
|
2
2
|
import { t as AuthConfig } from "./index-ByAnTJu5.mjs";
|
|
3
|
-
import { FilterActions } from "@silkweave/mcp";
|
|
3
|
+
import { FilterActions } from "@silkweave/mcp/server";
|
|
4
4
|
import { CorsOptions } from "cors";
|
|
5
5
|
|
|
6
6
|
//#region src/adapter/mcp.d.ts
|
package/build/mcp.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { authMiddleware, mcpCors, mcpTransport, oauthRoutes, protectedResourceMetadata, sideloadResource } from "@silkweave/mcp";
|
|
1
|
+
import { authMiddleware, mcpCors, mcpTransport, oauthRoutes, protectedResourceMetadata, sideloadResource } from "@silkweave/mcp/server";
|
|
2
2
|
import express from "express";
|
|
3
3
|
//#region src/adapter/mcp.ts
|
|
4
4
|
function compose(...handlers) {
|
package/build/mcp.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.mjs","names":[],"sources":["../src/adapter/mcp.ts"],"sourcesContent":["import { AuthConfig } from '@silkweave/auth'\nimport {\n authMiddleware,\n mcpCors,\n mcpTransport,\n oauthRoutes,\n protectedResourceMetadata,\n sideloadResource,\n type FilterActions\n} from '@silkweave/mcp'\nimport { type CorsOptions } from 'cors'\nimport express, { type RequestHandler } from 'express'\nimport type { NestAdapterRegisterContext, NestSilkweaveAdapter } from '../lib/types.js'\n\nexport interface McpAdapterOptions {\n /** URL prefix the MCP namespace lives under - the transport itself is at this exact path. Default `'/mcp'`. */\n basePath?: string\n /** Optional bearer-token / OAuth 2.1 config. */\n auth?: AuthConfig\n /** CORS configuration. `false` to disable, `true`/omitted for permissive defaults, or a `CorsOptions` object. */\n cors?: CorsOptions | boolean\n /** Mount the sideload resource route at `${basePath}/resource/:id`. Default `true`. */\n sideloadResources?: boolean\n /** Directory the sideload route reads from. Default `'resources'`. */\n resourceDir?: string\n /**\n * Per-request tool filter, applied before tools are registered on every\n * `POST ${basePath}` (the stateless transport recomputes the tool list per\n * request, so e.g. API-key permission changes apply on the next\n * `tools/list`). Receives the synthesized actions (with their `tags`) and a\n * request stand-in (`headers`/`url`/`method`/`toolName`). A throw surfaces\n * as its `SilkweaveError.statusCode` (else 500) - never an empty tool list.\n */\n filterActions?: FilterActions\n}\n\nfunction compose(...handlers: RequestHandler[]): RequestHandler {\n return (req, res, next) => {\n let i = 0\n const dispatch: () => void = () => {\n const h = handlers[i++]\n if (!h) { return next() }\n h(req, res, (err) => err ? next(err) : dispatch())\n }\n dispatch()\n }\n}\n\n/**\n * MCP adapter for `@silkweave/nestjs`. Registers the MCP Streamable HTTP\n * transport, sideload, well-known and OAuth routes individually on Nest's\n * HTTP adapter at the configured `basePath` (default `/mcp`):\n *\n * - `POST/GET/DELETE ${basePath}` - Streamable HTTP transport\n * - `GET ${basePath}/resource/:id` - sideload (`sideloadResources` opt-out)\n * - `GET ${basePath}/.well-known/oauth-protected-resource` - RFC 9728 metadata (when `auth.resourceUrl`/`auth.authorizationServers` set)\n * - `GET ${basePath}/authorize`, `POST ${basePath}/token`, `POST ${basePath}/register`, `GET ${basePath}${callbackPath}` (when `auth.provider` set)\n *\n * Each route is a real Nest-level route - they show up in\n * `RoutesResolver`'s log and there is no sub-app or middleware-slot\n * indirection.\n */\nexport function mcp(options: McpAdapterOptions = {}): NestSilkweaveAdapter {\n return {\n name: 'mcp',\n register({ httpAdapter, silkweaveOptions, baseContext, actions, onToolCall }: NestAdapterRegisterContext): void {\n const basePath = (options.basePath ?? '/mcp').replace(/\\/$/, '')\n if (!basePath) { throw new Error('@silkweave/nestjs mcp(): basePath cannot be empty or \"/\" - pick a path like \"/mcp\".') }\n\n const adapter = httpAdapter as unknown as {\n get: (path: string, ...h: RequestHandler[]) => unknown\n post: (path: string, ...h: RequestHandler[]) => unknown\n delete: (path: string, ...h: RequestHandler[]) => unknown\n }\n\n const corsHandler = mcpCors(options.cors ?? true)\n const auth = options.auth\n const guard = auth ? authMiddleware(auth, baseContext) : null\n const prefix = (...handlers: (RequestHandler | null)[]): RequestHandler[] =>\n handlers.filter((h): h is RequestHandler => Boolean(h))\n\n // Public auth-discovery / OAuth routes - registered first so they're\n // never inadvertently guarded by the auth middleware.\n if (auth?.authorizationServers?.length && auth.resourceUrl) {\n adapter.get(\n `${basePath}/.well-known/oauth-protected-resource`,\n ...prefix(corsHandler, protectedResourceMetadata(auth))\n )\n }\n if (auth?.provider) {\n const oauth = oauthRoutes(auth)\n adapter.get(`${basePath}/.well-known/oauth-authorization-server`, ...prefix(corsHandler, oauth.wellKnownAuthServer))\n adapter.get(`${basePath}/authorize`, ...prefix(corsHandler, oauth.authorize))\n adapter.get(`${basePath}${oauth.callbackPath}`, ...prefix(corsHandler, oauth.callback))\n adapter.post(`${basePath}/token`, ...prefix(corsHandler, ...oauth.token))\n adapter.post(`${basePath}/register`, ...prefix(corsHandler, ...oauth.register))\n }\n\n // Protected routes - wrapped with auth middleware (when configured).\n const protect = guard ? (h: RequestHandler) => compose(guard, h) : (h: RequestHandler) => h\n\n if (options.sideloadResources !== false) {\n adapter.get(`${basePath}/resource/:id`, ...prefix(corsHandler, protect(sideloadResource({ resourceDir: options.resourceDir }))))\n }\n\n const transport = mcpTransport(silkweaveOptions, baseContext, actions, { filterActions: options.filterActions, onToolCall })\n adapter.post(basePath, ...prefix(corsHandler, express.json(), protect(transport.post)))\n }\n }\n}\n"],"mappings":";;;AAoCA,SAAS,QAAQ,GAAG,UAA4C;AAC9D,SAAQ,KAAK,KAAK,SAAS;EACzB,IAAI,IAAI;EACR,MAAM,iBAA6B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sB;AAE1F,OAAI,QAAQ,sBAAsB,MAChC,SAAQ,IAAI,GAAG,SAAS,gBAAgB,GAAG,OAAO,aAAa,QAAQ,iBAAiB,EAAE,aAAa,QAAQ,aAAa,CAAC,CAAC,CAAC,CAAC;GAGlI,MAAM,YAAY,aAAa,kBAAkB,aAAa,SAAS;IAAE,eAAe,QAAQ;IAAe;IAAY,CAAC;AAC5H,WAAQ,KAAK,UAAU,GAAG,OAAO,aAAa,QAAQ,MAAM,EAAE,QAAQ,UAAU,KAAK,CAAC,CAAC;;EAE1F"}
|
|
1
|
+
{"version":3,"file":"mcp.mjs","names":[],"sources":["../src/adapter/mcp.ts"],"sourcesContent":["import { AuthConfig } from '@silkweave/auth'\nimport {\n authMiddleware,\n mcpCors,\n mcpTransport,\n oauthRoutes,\n protectedResourceMetadata,\n sideloadResource,\n type FilterActions\n} from '@silkweave/mcp/server'\nimport { type CorsOptions } from 'cors'\nimport express, { type RequestHandler } from 'express'\nimport type { NestAdapterRegisterContext, NestSilkweaveAdapter } from '../lib/types.js'\n\nexport interface McpAdapterOptions {\n /** URL prefix the MCP namespace lives under - the transport itself is at this exact path. Default `'/mcp'`. */\n basePath?: string\n /** Optional bearer-token / OAuth 2.1 config. */\n auth?: AuthConfig\n /** CORS configuration. `false` to disable, `true`/omitted for permissive defaults, or a `CorsOptions` object. */\n cors?: CorsOptions | boolean\n /** Mount the sideload resource route at `${basePath}/resource/:id`. Default `true`. */\n sideloadResources?: boolean\n /** Directory the sideload route reads from. Default `'resources'`. */\n resourceDir?: string\n /**\n * Per-request tool filter, applied before tools are registered on every\n * `POST ${basePath}` (the stateless transport recomputes the tool list per\n * request, so e.g. API-key permission changes apply on the next\n * `tools/list`). Receives the synthesized actions (with their `tags`) and a\n * request stand-in (`headers`/`url`/`method`/`toolName`). A throw surfaces\n * as its `SilkweaveError.statusCode` (else 500) - never an empty tool list.\n */\n filterActions?: FilterActions\n}\n\nfunction compose(...handlers: RequestHandler[]): RequestHandler {\n return (req, res, next) => {\n let i = 0\n const dispatch: () => void = () => {\n const h = handlers[i++]\n if (!h) { return next() }\n h(req, res, (err) => err ? next(err) : dispatch())\n }\n dispatch()\n }\n}\n\n/**\n * MCP adapter for `@silkweave/nestjs`. Registers the MCP Streamable HTTP\n * transport, sideload, well-known and OAuth routes individually on Nest's\n * HTTP adapter at the configured `basePath` (default `/mcp`):\n *\n * - `POST/GET/DELETE ${basePath}` - Streamable HTTP transport\n * - `GET ${basePath}/resource/:id` - sideload (`sideloadResources` opt-out)\n * - `GET ${basePath}/.well-known/oauth-protected-resource` - RFC 9728 metadata (when `auth.resourceUrl`/`auth.authorizationServers` set)\n * - `GET ${basePath}/authorize`, `POST ${basePath}/token`, `POST ${basePath}/register`, `GET ${basePath}${callbackPath}` (when `auth.provider` set)\n *\n * Each route is a real Nest-level route - they show up in\n * `RoutesResolver`'s log and there is no sub-app or middleware-slot\n * indirection.\n */\nexport function mcp(options: McpAdapterOptions = {}): NestSilkweaveAdapter {\n return {\n name: 'mcp',\n register({ httpAdapter, silkweaveOptions, baseContext, actions, onToolCall }: NestAdapterRegisterContext): void {\n const basePath = (options.basePath ?? '/mcp').replace(/\\/$/, '')\n if (!basePath) { throw new Error('@silkweave/nestjs mcp(): basePath cannot be empty or \"/\" - pick a path like \"/mcp\".') }\n\n const adapter = httpAdapter as unknown as {\n get: (path: string, ...h: RequestHandler[]) => unknown\n post: (path: string, ...h: RequestHandler[]) => unknown\n delete: (path: string, ...h: RequestHandler[]) => unknown\n }\n\n const corsHandler = mcpCors(options.cors ?? true)\n const auth = options.auth\n const guard = auth ? authMiddleware(auth, baseContext) : null\n const prefix = (...handlers: (RequestHandler | null)[]): RequestHandler[] =>\n handlers.filter((h): h is RequestHandler => Boolean(h))\n\n // Public auth-discovery / OAuth routes - registered first so they're\n // never inadvertently guarded by the auth middleware.\n if (auth?.authorizationServers?.length && auth.resourceUrl) {\n adapter.get(\n `${basePath}/.well-known/oauth-protected-resource`,\n ...prefix(corsHandler, protectedResourceMetadata(auth))\n )\n }\n if (auth?.provider) {\n const oauth = oauthRoutes(auth)\n adapter.get(`${basePath}/.well-known/oauth-authorization-server`, ...prefix(corsHandler, oauth.wellKnownAuthServer))\n adapter.get(`${basePath}/authorize`, ...prefix(corsHandler, oauth.authorize))\n adapter.get(`${basePath}${oauth.callbackPath}`, ...prefix(corsHandler, oauth.callback))\n adapter.post(`${basePath}/token`, ...prefix(corsHandler, ...oauth.token))\n adapter.post(`${basePath}/register`, ...prefix(corsHandler, ...oauth.register))\n }\n\n // Protected routes - wrapped with auth middleware (when configured).\n const protect = guard ? (h: RequestHandler) => compose(guard, h) : (h: RequestHandler) => h\n\n if (options.sideloadResources !== false) {\n adapter.get(`${basePath}/resource/:id`, ...prefix(corsHandler, protect(sideloadResource({ resourceDir: options.resourceDir }))))\n }\n\n const transport = mcpTransport(silkweaveOptions, baseContext, actions, { filterActions: options.filterActions, onToolCall })\n adapter.post(basePath, ...prefix(corsHandler, express.json(), protect(transport.post)))\n }\n }\n}\n"],"mappings":";;;AAoCA,SAAS,QAAQ,GAAG,UAA4C;AAC9D,SAAQ,KAAK,KAAK,SAAS;EACzB,IAAI,IAAI;EACR,MAAM,iBAA6B;GACjC,MAAM,IAAI,SAAS;AACnB,OAAI,CAAC,EAAK,QAAO,MAAM;AACvB,KAAE,KAAK,MAAM,QAAQ,MAAM,KAAK,IAAI,GAAG,UAAU,CAAC;;AAEpD,YAAU;;;;;;;;;;;;;;;;;AAkBd,SAAgB,IAAI,UAA6B,EAAE,EAAwB;AACzE,QAAO;EACL,MAAM;EACN,SAAS,EAAE,aAAa,kBAAkB,aAAa,SAAS,cAAgD;GAC9G,MAAM,YAAY,QAAQ,YAAY,QAAQ,QAAQ,OAAO,GAAG;AAChE,OAAI,CAAC,SAAY,OAAM,IAAI,MAAM,0FAAsF;GAEvH,MAAM,UAAU;GAMhB,MAAM,cAAc,QAAQ,QAAQ,QAAQ,KAAK;GACjD,MAAM,OAAO,QAAQ;GACrB,MAAM,QAAQ,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NestJS Adapter",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://www.silkweave.dev",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"@trpc/server": "^11.7.1",
|
|
48
48
|
"class-validator": "^0.14.0 || ^0.15.0",
|
|
49
49
|
"rxjs": "^7.0.0",
|
|
50
|
-
"@silkweave/typegen": "^
|
|
51
|
-
"@silkweave/
|
|
52
|
-
"@silkweave/
|
|
50
|
+
"@silkweave/typegen": "^4.0.0",
|
|
51
|
+
"@silkweave/mcp": "^4.0.0",
|
|
52
|
+
"@silkweave/trpc": "^4.0.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependenciesMeta": {
|
|
55
55
|
"@nestjs/swagger": {
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"cors": "^2.8.6",
|
|
77
77
|
"express": "^5.2.1",
|
|
78
78
|
"zod": "^3.25.0",
|
|
79
|
-
"@silkweave/core": "
|
|
79
|
+
"@silkweave/core": "4.0.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@eslint/js": "^10.0.1",
|
|
@@ -97,10 +97,10 @@
|
|
|
97
97
|
"typescript": "^5.9.3",
|
|
98
98
|
"typescript-eslint": "^8.56.1",
|
|
99
99
|
"vitest": "^4.1.9",
|
|
100
|
-
"@silkweave/auth": "
|
|
101
|
-
"@silkweave/
|
|
102
|
-
"@silkweave/
|
|
103
|
-
"@silkweave/typegen": "
|
|
100
|
+
"@silkweave/auth": "4.0.0",
|
|
101
|
+
"@silkweave/trpc": "4.0.0",
|
|
102
|
+
"@silkweave/mcp": "4.0.0",
|
|
103
|
+
"@silkweave/typegen": "4.0.0"
|
|
104
104
|
},
|
|
105
105
|
"scripts": {
|
|
106
106
|
"clean": "rimraf build",
|