@silkweave/nestjs 1.11.0 → 2.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/.turbo/turbo-build.log +16 -17
- package/.turbo/turbo-prepack.log +7 -8
- package/README.md +98 -135
- package/build/index.d.mts +222 -197
- package/build/index.d.mts.map +1 -1
- package/build/index.mjs +698 -352
- package/build/index.mjs.map +1 -1
- package/package.json +16 -10
- package/src/decorator/mcp.ts +39 -0
- package/src/index.ts +5 -7
- package/src/lib/controllerDiscovery.ts +201 -0
- package/src/lib/metadata.ts +32 -46
- package/src/lib/rebind.ts +117 -0
- package/src/lib/reflect/classValidator.ts +56 -0
- package/src/lib/reflect/openapi.ts +87 -0
- package/src/lib/reflect/params.ts +63 -0
- package/src/lib/reflect/route.ts +58 -0
- package/src/lib/reflect/schema.ts +270 -0
- package/src/lib/reflect/swagger.ts +39 -0
- package/src/lib/silkweave.module.ts +17 -17
- package/src/lib/types.ts +14 -5
- package/tsconfig.tsbuildinfo +1 -1
- package/src/adapter/rest.ts +0 -161
- package/src/adapter/trpc.ts +0 -58
- package/src/adapter/typegen.ts +0 -55
- package/src/decorator/action.ts +0 -38
- package/src/decorator/actions.ts +0 -25
- package/src/lib/discovery.ts +0 -125
- package/src/lib/filter.ts +0 -26
package/build/index.d.mts
CHANGED
|
@@ -1,12 +1,89 @@
|
|
|
1
1
|
import { CanActivate, DynamicModule, MiddlewareConsumer, NestModule, Type } from "@nestjs/common";
|
|
2
|
-
import { AuthConfig } from "@silkweave/auth";
|
|
3
|
-
import { Action as Action$1, ActionKind, SilkweaveContext, SilkweaveOptions } from "@silkweave/core";
|
|
4
|
-
import z$1 from "zod/v4";
|
|
5
|
-
import { InferTrpcRouter } from "@silkweave/trpc";
|
|
6
|
-
import { TypegenFormat } from "@silkweave/typegen";
|
|
7
2
|
import { DiscoveryService, HttpAdapterHost, MetadataScanner, ModuleRef, Reflector } from "@nestjs/core";
|
|
3
|
+
import { Action, SilkweaveContext, SilkweaveOptions } from "@silkweave/core";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
import { AuthConfig } from "@silkweave/auth";
|
|
8
6
|
import { CorsOptions } from "cors";
|
|
9
7
|
|
|
8
|
+
//#region src/lib/reflect/schema.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* A transport-neutral description of a single input field. Every metadata
|
|
11
|
+
* source (swagger decorators, class-validator, an OpenAPI document, TypeScript
|
|
12
|
+
* `design:type`) is mapped to this shape, the shapes are merged by precedence,
|
|
13
|
+
* and the result is converted to Zod once. Keeping a single intermediate keeps
|
|
14
|
+
* the per-source mappers small and the Zod construction in one place.
|
|
15
|
+
*/
|
|
16
|
+
interface FieldDesc {
|
|
17
|
+
type?: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'unknown';
|
|
18
|
+
required?: boolean;
|
|
19
|
+
description?: string;
|
|
20
|
+
enum?: (string | number)[];
|
|
21
|
+
items?: FieldDesc;
|
|
22
|
+
min?: number;
|
|
23
|
+
max?: number;
|
|
24
|
+
minLength?: number;
|
|
25
|
+
maxLength?: number;
|
|
26
|
+
format?: string;
|
|
27
|
+
default?: unknown;
|
|
28
|
+
}
|
|
29
|
+
/** Merge `over` onto `base` - defined keys of `over` win. */
|
|
30
|
+
declare function mergeField(base: FieldDesc, over: FieldDesc): FieldDesc;
|
|
31
|
+
/** Convert a merged {@link FieldDesc} to a Zod schema. */
|
|
32
|
+
declare function fieldToZod(d: FieldDesc): z.ZodType;
|
|
33
|
+
/** Normalise a TS-enum object or an array literal to a flat value list. */
|
|
34
|
+
declare function normalizeEnum(value: unknown): (string | number)[] | undefined;
|
|
35
|
+
/** Map a swagger/`design:type` type token (constructor, `[Type]`, or string) to a base type. */
|
|
36
|
+
declare function typeTokenToBase(type: unknown): FieldDesc['type'] | undefined;
|
|
37
|
+
/** From the constructor TypeScript emits via `emitDecoratorMetadata`. */
|
|
38
|
+
declare function designTypeToField(ctor: unknown): FieldDesc;
|
|
39
|
+
/** From an `@ApiParam`/`@ApiQuery` entry stored under `swagger/apiParameters`. */
|
|
40
|
+
declare function swaggerParamToField(p: Record<string, any>): FieldDesc;
|
|
41
|
+
/** From an `@ApiProperty` options object stored under `swagger/apiModelProperties`. */
|
|
42
|
+
declare function apiPropertyToField(o: Record<string, any>): FieldDesc;
|
|
43
|
+
/** From an array of `class-validator` validation-metadata entries for one property. */
|
|
44
|
+
declare function classValidatorToField(metas: Array<{
|
|
45
|
+
type?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
constraints?: unknown[];
|
|
48
|
+
}>): FieldDesc;
|
|
49
|
+
/** From an OpenAPI Schema Object (used by both the doc and `@ApiParam({ schema })`). */
|
|
50
|
+
declare function openapiSchemaToField(schema: Record<string, any>): FieldDesc;
|
|
51
|
+
/**
|
|
52
|
+
* Reflect a whole-DTO class (`@Body() dto: CreateDto`) into per-property
|
|
53
|
+
* {@link FieldDesc}s. Property names are the union of `@ApiProperty` and
|
|
54
|
+
* `class-validator` decorated fields; each field merges `design:type` (base),
|
|
55
|
+
* then `class-validator` constraints, then `@ApiProperty` (highest). Properties
|
|
56
|
+
* default to required unless a source marks them optional.
|
|
57
|
+
*/
|
|
58
|
+
declare function reflectDtoFields(dtoType: any): Record<string, FieldDesc>;
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/lib/reflect/openapi.d.ts
|
|
61
|
+
/**
|
|
62
|
+
* A minimal view of an OpenAPI document - the subset we read. Matches the shape
|
|
63
|
+
* `SwaggerModule.createDocument()` returns, but typed loosely so callers can
|
|
64
|
+
* pass any compatible object without a hard `@nestjs/swagger` dependency.
|
|
65
|
+
*/
|
|
66
|
+
interface OpenApiDocument {
|
|
67
|
+
paths?: Record<string, Record<string, any>>;
|
|
68
|
+
components?: {
|
|
69
|
+
schemas?: Record<string, any>;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
interface OpenApiLookup {
|
|
73
|
+
doc: OpenApiDocument;
|
|
74
|
+
/** `${METHOD} ${path}` → operation object. */
|
|
75
|
+
operations: Map<string, any>;
|
|
76
|
+
}
|
|
77
|
+
/** Index a document's operations by `${METHOD} ${path}` for fast matching. */
|
|
78
|
+
declare function buildOpenApiLookup(doc: OpenApiDocument): OpenApiLookup;
|
|
79
|
+
/**
|
|
80
|
+
* Resolve the per-field descriptors for a route from an ingested OpenAPI
|
|
81
|
+
* document. Merges `parameters` (path/query/header) and the JSON request-body
|
|
82
|
+
* schema's properties into a single field map. Returns `{}` when the operation
|
|
83
|
+
* isn't found - callers fall back to decorator reflection.
|
|
84
|
+
*/
|
|
85
|
+
declare function openApiFields(lookup: OpenApiLookup, method: string, openapiPath: string): Record<string, FieldDesc>;
|
|
86
|
+
//#endregion
|
|
10
87
|
//#region src/lib/types.d.ts
|
|
11
88
|
/**
|
|
12
89
|
* Context passed to a Nest Silkweave adapter when `SilkweaveModule` wires it
|
|
@@ -23,7 +100,7 @@ interface NestAdapterRegisterContext {
|
|
|
23
100
|
/** Per-adapter context - already forked with `{ adapter: adapter.name, ...userContext }`. */
|
|
24
101
|
baseContext: SilkweaveContext;
|
|
25
102
|
/** Actions filtered to those enabled on this adapter. */
|
|
26
|
-
actions: Action
|
|
103
|
+
actions: Action[];
|
|
27
104
|
}
|
|
28
105
|
/**
|
|
29
106
|
* A Silkweave Nest adapter. Each transport (REST, tRPC, MCP) implements this
|
|
@@ -34,12 +111,13 @@ interface NestAdapterRegisterContext {
|
|
|
34
111
|
*/
|
|
35
112
|
interface NestSilkweaveAdapter {
|
|
36
113
|
/** Adapter discriminator - set on the silkweave context as `ctx.get('adapter')`. */
|
|
37
|
-
readonly name: '
|
|
114
|
+
readonly name: 'mcp';
|
|
115
|
+
/** URL prefix the adapter mounts on (e.g. `'/mcp'`). Surfaced for introspection. */
|
|
116
|
+
readonly basePath?: string;
|
|
38
117
|
/**
|
|
39
118
|
* When `true`, the adapter receives every discovered action regardless of
|
|
40
|
-
* each action's `
|
|
41
|
-
*
|
|
42
|
-
* action surface.
|
|
119
|
+
* each action's `isEnabled` gate. Reserved for non-runtime adapters that need
|
|
120
|
+
* the entire action surface.
|
|
43
121
|
*/
|
|
44
122
|
readonly allActions?: boolean;
|
|
45
123
|
/** Register this adapter's routes on Nest's HTTP server. */
|
|
@@ -48,10 +126,17 @@ interface NestSilkweaveAdapter {
|
|
|
48
126
|
interface SilkweaveModuleOptions {
|
|
49
127
|
/** Identity for the silkweave instance - surfaced to MCP clients, OpenAPI, etc. */
|
|
50
128
|
silkweave: SilkweaveOptions;
|
|
51
|
-
/** Adapters to mount.
|
|
129
|
+
/** Adapters to mount. Currently `mcp()`. */
|
|
52
130
|
adapters: NestSilkweaveAdapter[];
|
|
53
131
|
/** Initial context keys merged into every adapter's `baseContext`. */
|
|
54
132
|
context?: Record<string, unknown>;
|
|
133
|
+
/**
|
|
134
|
+
* Optional OpenAPI document (e.g. from `SwaggerModule.createDocument(app, cfg)`)
|
|
135
|
+
* used as an authoritative source when reflecting `@Mcp` tool input schemas.
|
|
136
|
+
* Matched to each method by HTTP verb + path; falls back to decorator
|
|
137
|
+
* reflection when an operation or field isn't present.
|
|
138
|
+
*/
|
|
139
|
+
openapi?: OpenApiDocument;
|
|
55
140
|
}
|
|
56
141
|
declare const SILKWEAVE_MODULE_OPTIONS = "__silkweave_module_options__";
|
|
57
142
|
//#endregion
|
|
@@ -84,208 +169,99 @@ interface McpAdapterOptions {
|
|
|
84
169
|
*/
|
|
85
170
|
declare function mcp(options?: McpAdapterOptions): NestSilkweaveAdapter;
|
|
86
171
|
//#endregion
|
|
87
|
-
//#region src/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
basePath?: string;
|
|
91
|
-
/** Optional bearer-token auth applied to every REST action. */
|
|
92
|
-
auth?: AuthConfig;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* REST adapter for `@silkweave/nestjs`. Registers each discovered `@Action`
|
|
96
|
-
* as an individual route on Nest's HTTP adapter:
|
|
97
|
-
*
|
|
98
|
-
* - `kind: 'query'` → `GET ${basePath}/${actionName-with-slashes}` (input from query string)
|
|
99
|
-
* - `kind: 'mutation'` → `POST ${basePath}/${actionName-with-slashes}` (input from JSON body)
|
|
100
|
-
*
|
|
101
|
-
* Routes show up in Nest's `RoutesResolver` logger and are eligible for
|
|
102
|
-
* `@nestjs/swagger` scanning. Works on `@nestjs/platform-express` out of the
|
|
103
|
-
* box. For `@nestjs/platform-fastify`, register `@fastify/express` first.
|
|
104
|
-
*/
|
|
105
|
-
declare function rest(options?: RestAdapterOptions): NestSilkweaveAdapter;
|
|
106
|
-
//#endregion
|
|
107
|
-
//#region src/adapter/trpc.d.ts
|
|
108
|
-
interface TrpcAdapterOptions {
|
|
109
|
-
/** URL prefix at which the tRPC handler is mounted. Default `'/trpc'`. */
|
|
110
|
-
basePath?: string;
|
|
111
|
-
/** Optional bearer-token auth applied to every tRPC procedure. */
|
|
112
|
-
auth?: AuthConfig;
|
|
113
|
-
}
|
|
172
|
+
//#region src/lib/metadata.d.ts
|
|
173
|
+
/** Reflect-metadata key carrying `@Mcp` options on a controller method. */
|
|
174
|
+
declare const MCP_METADATA = "__silkweave_mcp__";
|
|
114
175
|
/**
|
|
115
|
-
*
|
|
116
|
-
* `@
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* Works on `@nestjs/platform-express`. On `@nestjs/platform-fastify`, register
|
|
123
|
-
* `@fastify/express` first so Nest can serve Express-style middleware.
|
|
176
|
+
* Options for the `@Mcp()` method decorator. Every field is optional - an empty
|
|
177
|
+
* `@Mcp()` exposes the decorated controller route as an MCP tool with its name,
|
|
178
|
+
* description, and input schema fully reflected from the method's route
|
|
179
|
+
* (`@Get`/`@Post`/...), parameter decorators (`@Param`/`@Query`/`@Body`), and
|
|
180
|
+
* any `@nestjs/swagger` (`@ApiOperation`/`@ApiParam`/`@ApiProperty`) or
|
|
181
|
+
* `class-validator` metadata it carries.
|
|
124
182
|
*/
|
|
125
|
-
|
|
126
|
-
//#endregion
|
|
127
|
-
//#region src/adapter/typegen.d.ts
|
|
128
|
-
interface TypegenAdapterOptions {
|
|
129
|
-
/** Output file path for the generated `.d.ts` file. Resolved against `process.cwd()`. Parent directories are created automatically. */
|
|
130
|
-
path: string;
|
|
183
|
+
interface McpMetadata {
|
|
131
184
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* - `'trpc-router'` - `AppRouter` type alias for `createTRPCClient<AppRouter>()`
|
|
135
|
-
* - `'all'` - both
|
|
185
|
+
* MCP tool name override. When unset it is derived from the controller class
|
|
186
|
+
* and method name (e.g. `ChannelsController.findOne` → `ChannelsFindOne`).
|
|
136
187
|
*/
|
|
137
|
-
|
|
188
|
+
name?: string;
|
|
138
189
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* leave it on the default unless you know you want otherwise.
|
|
190
|
+
* Tool description override. When unset it falls back to the method's
|
|
191
|
+
* `@ApiOperation({ summary | description })`, then a generated default.
|
|
142
192
|
*/
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Typegen adapter for `@silkweave/nestjs`. Discovers every `@Action`-decorated
|
|
147
|
-
* method (regardless of `transports` filtering) and writes a single `.d.ts`
|
|
148
|
-
* file with REST input/output interfaces and/or a tRPC `AppRouter` type alias.
|
|
149
|
-
*
|
|
150
|
-
* Designed for the monorepo pattern where the server (this app) is the source
|
|
151
|
-
* of truth for types and consumer apps import from `path` - e.g.
|
|
152
|
-
* `path: '../app/src/types/silkweave.ts'`.
|
|
153
|
-
*/
|
|
154
|
-
declare function typegen(options: TypegenAdapterOptions): NestSilkweaveAdapter;
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region src/lib/metadata.d.ts
|
|
157
|
-
declare const ACTION_METADATA = "__silkweave_action__";
|
|
158
|
-
declare const ACTIONS_METADATA = "__silkweave_actions__";
|
|
159
|
-
type Transport = 'rest' | 'trpc' | 'mcp';
|
|
160
|
-
interface ActionMetadata<I extends object = object, O extends object = object, C = unknown> {
|
|
161
|
-
/** Action name. Defaults to the kebab-cased method name. */
|
|
162
|
-
name?: string;
|
|
163
|
-
/** Human-readable description. Becomes the MCP tool description and REST OpenAPI summary. */
|
|
164
|
-
description: string;
|
|
165
|
-
/** Zod object schema for the action's input. */
|
|
166
|
-
input: z$1.ZodType<I> & {
|
|
167
|
-
shape: Record<string, z$1.ZodTypeAny>;
|
|
168
|
-
};
|
|
169
|
-
/** Optional Zod object schema for the action's output (used by tRPC type inference). */
|
|
170
|
-
output?: z$1.ZodType<O> & {
|
|
171
|
-
shape: Record<string, z$1.ZodTypeAny>;
|
|
172
|
-
};
|
|
193
|
+
description?: string;
|
|
173
194
|
/**
|
|
174
|
-
* Zod
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* the action as a tRPC subscription.
|
|
195
|
+
* Zod raw-shape override merged over the reflected input fields (override
|
|
196
|
+
* wins per field). The escape hatch for shapes reflection can't express
|
|
197
|
+
* losslessly - discriminated unions, custom validators, `@Transform`, etc.
|
|
178
198
|
*/
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
toolResult?: Action$1<I, O>['toolResult'];
|
|
188
|
-
/** CLI positional-argument keys (unused for HTTP-only adapters, kept for parity with `createAction`). */
|
|
189
|
-
args?: (keyof I)[];
|
|
190
|
-
/** Custom MCP tool name override. If unset, derived from action name as PascalCase. */
|
|
191
|
-
mcpToolName?: string;
|
|
192
|
-
}
|
|
193
|
-
interface ActionsClassMetadata {
|
|
194
|
-
/** Prefix joined to the method-level action name with a dot. e.g. `Actions('users')` + method `list` → `users.list`. */
|
|
195
|
-
prefix?: string;
|
|
196
|
-
/** Class-level transports allowlist. Method-level `transports` overrides; otherwise inherits this. */
|
|
197
|
-
transports?: Transport[];
|
|
198
|
-
}
|
|
199
|
-
interface ResultToolResult<O extends object = object> {
|
|
200
|
-
toolResult?: Action$1<object, O>['toolResult'];
|
|
199
|
+
input?: Record<string, z.ZodType>;
|
|
200
|
+
/**
|
|
201
|
+
* Whether to apply the controller method's parameter-bound pipes
|
|
202
|
+
* (`@Param('id', ParseIntPipe)`) when re-binding the call. Default `'apply'`.
|
|
203
|
+
* Global/`ValidationPipe`, interceptors, and exception filters never run -
|
|
204
|
+
* the method is invoked directly, not through Nest's HTTP request pipeline.
|
|
205
|
+
*/
|
|
206
|
+
pipes?: 'apply' | 'skip';
|
|
201
207
|
}
|
|
202
|
-
type AnyActionMetadata = ActionMetadata<object, object> & ResultToolResult<object>;
|
|
203
|
-
declare const ACTION_RESPONSE_KEY = "__silkweave_response__";
|
|
204
208
|
//#endregion
|
|
205
|
-
//#region src/decorator/
|
|
209
|
+
//#region src/decorator/mcp.d.ts
|
|
206
210
|
/**
|
|
207
|
-
* Method decorator that
|
|
211
|
+
* Method decorator that exposes an existing NestJS controller route as an MCP
|
|
212
|
+
* tool. It is **additive** - the route keeps serving HTTP exactly as before;
|
|
213
|
+
* `@Mcp()` just opts the method into MCP discovery.
|
|
208
214
|
*
|
|
209
|
-
* The
|
|
210
|
-
*
|
|
211
|
-
*
|
|
215
|
+
* The tool's name, description, and input schema are reflected from the
|
|
216
|
+
* method's own metadata:
|
|
217
|
+
* - **fields** from the parameter decorators (`@Param`/`@Query`/`@Body`) - a
|
|
218
|
+
* `@Param('id')` becomes an `id` field; a whole-DTO `@Body() dto: CreateDto`
|
|
219
|
+
* is flattened to its properties,
|
|
220
|
+
* - **types/constraints/descriptions** from `@nestjs/swagger`
|
|
221
|
+
* (`@ApiParam`/`@ApiQuery`/`@ApiProperty`/`@ApiOperation`) and, when present,
|
|
222
|
+
* `class-validator` decorators on the DTOs,
|
|
223
|
+
* - optionally refined by an OpenAPI document passed to `SilkweaveModule`.
|
|
212
224
|
*
|
|
213
|
-
*
|
|
214
|
-
* and
|
|
215
|
-
* `auth`). The class instance is a normal Nest provider, so other services can
|
|
216
|
-
* be injected via the constructor.
|
|
225
|
+
* On a tool call the input is split back into the method's positional arguments
|
|
226
|
+
* and the method is invoked directly (with `@UseGuards` guards applied first).
|
|
217
227
|
*
|
|
218
228
|
* @example
|
|
219
229
|
* ```ts
|
|
220
|
-
* @
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* @
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* })
|
|
230
|
-
* list(input: { limit?: number }, ctx: SilkweaveContext) {
|
|
231
|
-
* return this.db.listUsers(input.limit)
|
|
230
|
+
* @Controller('sessions/:sessionId/channels')
|
|
231
|
+
* export class ChannelsController {
|
|
232
|
+
* @Get(':channelId')
|
|
233
|
+
* @ApiOperation({ summary: 'Get a specific channel by ID' })
|
|
234
|
+
* @ApiParam({ name: 'sessionId', description: 'Session ID' })
|
|
235
|
+
* @ApiParam({ name: 'channelId', description: 'Channel ID' })
|
|
236
|
+
* @Mcp()
|
|
237
|
+
* findOne(@Param('sessionId') sessionId: string, @Param('channelId') channelId: string) {
|
|
238
|
+
* return this.service.get(sessionId, channelId)
|
|
232
239
|
* }
|
|
233
240
|
* }
|
|
234
241
|
* ```
|
|
235
242
|
*/
|
|
236
|
-
declare function
|
|
243
|
+
declare function Mcp(options?: McpMetadata): MethodDecorator;
|
|
237
244
|
//#endregion
|
|
238
|
-
//#region src/
|
|
239
|
-
|
|
240
|
-
* Class decorator that groups a provider's `@Action` methods under a common
|
|
241
|
-
* prefix. The prefix is joined to each method's action name with a dot
|
|
242
|
-
* (e.g. `@Actions('users')` + method `list` → action name `users.list`).
|
|
243
|
-
*
|
|
244
|
-
* The class itself remains a normal Nest provider - add `@Injectable()`
|
|
245
|
-
* separately so it can be resolved by the DI container.
|
|
246
|
-
*
|
|
247
|
-
* Accepts either a prefix string (shorthand) or a full options object:
|
|
248
|
-
* ```ts
|
|
249
|
-
* @Actions('users')
|
|
250
|
-
* @Actions({ prefix: 'users', transports: ['rest', 'trpc'] })
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
declare function Actions(prefixOrOptions?: string | ActionsClassMetadata): ClassDecorator;
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region src/lib/discovery.d.ts
|
|
256
|
-
declare class ActionDiscovery {
|
|
245
|
+
//#region src/lib/controllerDiscovery.d.ts
|
|
246
|
+
declare class ControllerDiscovery {
|
|
257
247
|
private readonly discovery;
|
|
258
248
|
private readonly scanner;
|
|
259
249
|
private readonly reflector;
|
|
260
250
|
private readonly moduleRef;
|
|
261
251
|
constructor(discovery: DiscoveryService, scanner: MetadataScanner, reflector: Reflector, moduleRef: ModuleRef);
|
|
262
252
|
/**
|
|
263
|
-
* Walk every Nest provider, find methods annotated with `@
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* `ctx.get('request')`, populated by REST/tRPC and by MCP-over-HTTP from the
|
|
269
|
-
* SDK's `extra.requestInfo`) and (b) bind `this` to the resolved Nest provider
|
|
270
|
-
* so DI-injected dependencies remain available.
|
|
253
|
+
* Walk every Nest provider/controller, find methods annotated with `@Mcp`,
|
|
254
|
+
* and build a core `Action` per method whose input schema is reflected from
|
|
255
|
+
* the route + parameter decorators (+ optional OpenAPI document) and whose
|
|
256
|
+
* `run` re-binds the validated input back into the method's positional
|
|
257
|
+
* arguments (with `@UseGuards` guards applied first).
|
|
271
258
|
*/
|
|
272
|
-
discover(): Action
|
|
259
|
+
discover(openapi?: OpenApiDocument): Action[];
|
|
273
260
|
private toAction;
|
|
261
|
+
/** Build the merged Zod input shape and the per-argument re-bind plan. */
|
|
262
|
+
private buildInput;
|
|
274
263
|
}
|
|
275
264
|
//#endregion
|
|
276
|
-
//#region src/lib/filter.d.ts
|
|
277
|
-
/**
|
|
278
|
-
* Compile a `transports` allowlist + optional user `isEnabled` into a single
|
|
279
|
-
* `(ctx) => boolean` callback compatible with `Action.isEnabled`.
|
|
280
|
-
*
|
|
281
|
-
* - If `transports` is omitted, the action runs on every adapter.
|
|
282
|
-
* - If `transports` is set, the action is gated on `ctx.get<string>('adapter')`
|
|
283
|
-
* matching one of the listed transports. Each adapter in `@silkweave/nestjs`
|
|
284
|
-
* forks its context with `{ adapter: 'rest' | 'trpc' | 'mcp' }`.
|
|
285
|
-
* - If both `transports` and `userIsEnabled` are set, they are AND-combined.
|
|
286
|
-
*/
|
|
287
|
-
declare function buildIsEnabled(transports: Transport[] | undefined, userIsEnabled: ((ctx: SilkweaveContext) => boolean) | undefined): ((ctx: SilkweaveContext) => boolean) | undefined;
|
|
288
|
-
//#endregion
|
|
289
265
|
//#region src/lib/guards.d.ts
|
|
290
266
|
type GuardRef = Type<CanActivate> | CanActivate;
|
|
291
267
|
/**
|
|
@@ -309,17 +285,69 @@ declare function collectGuards(reflector: Reflector, classRef: Type<unknown>, ha
|
|
|
309
285
|
*/
|
|
310
286
|
declare function runGuards(guards: GuardRef[], moduleRef: ModuleRef, reflector: Reflector, classRef: Type<unknown>, handler: (...args: unknown[]) => unknown, request: unknown, response: unknown, contextType?: 'http' | 'rpc'): Promise<void>;
|
|
311
287
|
//#endregion
|
|
288
|
+
//#region src/lib/rebind.d.ts
|
|
289
|
+
/**
|
|
290
|
+
* Instruction for reconstructing one positional handler argument from the flat
|
|
291
|
+
* MCP tool input. Built at discovery time, consumed by {@link invokeRebound}.
|
|
292
|
+
*/
|
|
293
|
+
type Binding = {
|
|
294
|
+
kind: 'value';
|
|
295
|
+
field: string;
|
|
296
|
+
source: 'path' | 'query' | 'body';
|
|
297
|
+
metatype?: unknown;
|
|
298
|
+
pipes?: unknown[];
|
|
299
|
+
} | {
|
|
300
|
+
kind: 'object';
|
|
301
|
+
source: 'query' | 'body';
|
|
302
|
+
fields: string[];
|
|
303
|
+
metatype?: unknown;
|
|
304
|
+
pipes?: unknown[];
|
|
305
|
+
} | {
|
|
306
|
+
kind: 'params';
|
|
307
|
+
fields: string[];
|
|
308
|
+
} | {
|
|
309
|
+
kind: 'request';
|
|
310
|
+
} | {
|
|
311
|
+
kind: 'response';
|
|
312
|
+
} | {
|
|
313
|
+
kind: 'headers';
|
|
314
|
+
data?: string;
|
|
315
|
+
} | {
|
|
316
|
+
kind: 'ip';
|
|
317
|
+
} | {
|
|
318
|
+
kind: 'host';
|
|
319
|
+
data?: string;
|
|
320
|
+
} | {
|
|
321
|
+
kind: 'missing';
|
|
322
|
+
};
|
|
323
|
+
interface RequestLike {
|
|
324
|
+
headers?: Record<string, unknown>;
|
|
325
|
+
ip?: unknown;
|
|
326
|
+
hosts?: Record<string, unknown>;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Reconstruct the controller method's positional arguments from the validated
|
|
330
|
+
* tool `input` (and the request stand-in for `@Req`/`@Headers`/...), then call
|
|
331
|
+
* it. `applyParamPipes` controls whether parameter-bound pipes run.
|
|
332
|
+
*/
|
|
333
|
+
declare function invokeRebound(method: (...args: any[]) => any, instance: object, input: Record<string, unknown>, bindings: Binding[], request: RequestLike | undefined, applyParamPipes: boolean): Promise<unknown>;
|
|
334
|
+
/** Map a non-input parameter slot (`@Req`/`@Headers`/`@Ip`/...) to its runtime binding. */
|
|
335
|
+
declare function specialBinding(paramtype: number, data: string | undefined): Binding | null;
|
|
336
|
+
//#endregion
|
|
312
337
|
//#region src/lib/silkweave.module.d.ts
|
|
313
338
|
/**
|
|
314
339
|
* Root module for `@silkweave/nestjs`.
|
|
315
340
|
*
|
|
316
|
-
* Discovers every `@
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
341
|
+
* Discovers every `@Mcp`-decorated **controller method** via `DiscoveryService`,
|
|
342
|
+
* reflects each into a Silkweave action (input schema from the route + parameter
|
|
343
|
+
* decorators + optional OpenAPI document; invocation by re-binding the validated
|
|
344
|
+
* input back into the method), and registers the configured adapter(s) - `mcp()` -
|
|
345
|
+
* directly on Nest's HTTP adapter inside `configure()`.
|
|
346
|
+
*
|
|
347
|
+
* Because `configure()` runs during `registerModules` - before Nest's
|
|
348
|
+
* `registerRouter()` step - Silkweave's routes always sit ahead of every
|
|
349
|
+
* controller in the Express stack. The controllers keep serving HTTP exactly as
|
|
350
|
+
* before; `@Mcp` is purely additive.
|
|
323
351
|
*
|
|
324
352
|
* @example
|
|
325
353
|
* ```ts
|
|
@@ -327,13 +355,10 @@ declare function runGuards(guards: GuardRef[], moduleRef: ModuleRef, reflector:
|
|
|
327
355
|
* imports: [
|
|
328
356
|
* SilkweaveModule.forRoot({
|
|
329
357
|
* silkweave: { name: 'app', description: 'My App', version: '1.0.0' },
|
|
330
|
-
* adapters: [
|
|
331
|
-
* rest({ basePath: '/api' }),
|
|
332
|
-
* trpc({ basePath: '/trpc' }),
|
|
333
|
-
* mcp({ basePath: '/mcp' })
|
|
334
|
-
* ]
|
|
358
|
+
* adapters: [mcp({ basePath: '/mcp' })]
|
|
335
359
|
* })
|
|
336
|
-
* ]
|
|
360
|
+
* ],
|
|
361
|
+
* controllers: [ChannelsController]
|
|
337
362
|
* })
|
|
338
363
|
* export class AppModule {}
|
|
339
364
|
* ```
|
|
@@ -342,10 +367,10 @@ declare class SilkweaveModule implements NestModule {
|
|
|
342
367
|
private readonly options;
|
|
343
368
|
private readonly discovery;
|
|
344
369
|
private readonly httpAdapterHost;
|
|
345
|
-
constructor(options: SilkweaveModuleOptions, discovery:
|
|
370
|
+
constructor(options: SilkweaveModuleOptions, discovery: ControllerDiscovery, httpAdapterHost: HttpAdapterHost);
|
|
346
371
|
static forRoot(options: SilkweaveModuleOptions): DynamicModule;
|
|
347
372
|
configure(_consumer: MiddlewareConsumer): void;
|
|
348
373
|
}
|
|
349
374
|
//#endregion
|
|
350
|
-
export {
|
|
375
|
+
export { Binding, ControllerDiscovery, FieldDesc, MCP_METADATA, Mcp, McpAdapterOptions, McpMetadata, NestAdapterRegisterContext, NestSilkweaveAdapter, OpenApiDocument, OpenApiLookup, SILKWEAVE_MODULE_OPTIONS, SilkweaveModule, SilkweaveModuleOptions, apiPropertyToField, buildOpenApiLookup, classValidatorToField, collectGuards, designTypeToField, fieldToZod, invokeRebound, mcp, mergeField, normalizeEnum, openApiFields, openapiSchemaToField, reflectDtoFields, runGuards, specialBinding, swaggerParamToField, typeTokenToBase };
|
|
351
376
|
//# sourceMappingURL=index.d.mts.map
|
package/build/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/lib/reflect/schema.ts","../src/lib/reflect/openapi.ts","../src/lib/types.ts","../src/adapter/mcp.ts","../src/lib/metadata.ts","../src/decorator/mcp.ts","../src/lib/controllerDiscovery.ts","../src/lib/guards.ts","../src/lib/rebind.ts","../src/lib/silkweave.module.ts"],"mappings":";;;;;;;;;;;;;;;UAeiB,SAAA;EACf,IAAA;EACA,QAAA;EACA,WAAA;EACA,IAAA;EACA,KAAA,GAAQ,SAAA;EACR,GAAA;EACA,GAAA;EACA,SAAA;EACA,SAAA;EACA,MAAA;EACA,OAAA;AAAA;;iBAac,UAAA,CAAW,IAAA,EAAM,SAAA,EAAW,IAAA,EAAM,SAAA,GAAY,SAAA;;iBA2C9C,UAAA,CAAW,CAAA,EAAG,SAAA,GAAY,CAAA,CAAE,OAAA;;iBAc5B,aAAA,CAAc,KAAA;;iBAWd,eAAA,CAAgB,IAAA,YAAgB,SAAA;;iBAkBhC,iBAAA,CAAkB,IAAA,YAAgB,SAAA;;iBAQlC,mBAAA,CAAoB,CAAA,EAAG,MAAA,gBAAsB,SAAA;;iBAgB7C,kBAAA,CAAmB,CAAA,EAAG,MAAA,gBAAsB,SAAA;;iBA4D5C,qBAAA,CAAsB,KAAA,EAAO,KAAA;EAAQ,IAAA;EAAe,IAAA;EAAe,WAAA;AAAA,KAA6B,SAAA;AA/HhH;AAAA,iBAsIgB,oBAAA,CAAqB,MAAA,E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