@silkweave/nestjs 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/build/index.d.mts +16 -1
- package/build/index.d.mts.map +1 -1
- package/build/index.mjs +5 -4
- package/build/index.mjs.map +1 -1
- package/package.json +9 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Silkweave
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -117,6 +117,21 @@ Exposes the decorated controller route as an MCP tool. Every option is optional.
|
|
|
117
117
|
| `description` | `string` | `@ApiOperation` summary/description, else generated | Tool description |
|
|
118
118
|
| `input` | `Record<string, z.ZodType>` | - | Zod raw-shape override merged over the reflected fields (per-field). The escape hatch for shapes reflection can't express - discriminated unions, custom validators, `@Transform` |
|
|
119
119
|
| `pipes` | `'apply' \| 'skip'` | `'apply'` | Whether to run parameter-bound pipes (`@Param('id', ParseIntPipe)`) when re-binding |
|
|
120
|
+
| `result` | `'json' \| 'smart'` | `'smart'` | Default MCP result format - `'json'` returns compact JSON text (`jsonToolResult`); `'smart'` inlines small payloads and offloads large ones to an embedded resource (`smartToolResult`). A client that sends `_meta.disposition` on the call overrides it |
|
|
121
|
+
|
|
122
|
+
### Result format
|
|
123
|
+
|
|
124
|
+
`@Mcp({ result })` sets the format for one tool. To set a default for **every** tool, pass `defaultResult` to the module:
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
SilkweaveModule.forRoot({
|
|
128
|
+
silkweave: { name: 'my-api', version: '1.0.0' },
|
|
129
|
+
adapters: [mcp()],
|
|
130
|
+
defaultResult: 'json' // module-wide default; a per-method @Mcp({ result }) still wins
|
|
131
|
+
})
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Precedence (highest first): a client's per-call `_meta.disposition` → `@Mcp({ result })` → module `defaultResult` → `'smart'`.
|
|
120
135
|
|
|
121
136
|
## How reflection works
|
|
122
137
|
|
package/build/index.d.mts
CHANGED
|
@@ -150,6 +150,13 @@ interface SilkweaveModuleOptions {
|
|
|
150
150
|
* authentication still works.
|
|
151
151
|
*/
|
|
152
152
|
globalGuards?: Type<CanActivate>[];
|
|
153
|
+
/**
|
|
154
|
+
* Default MCP result format for every `@Mcp` tool - `'json'` (compact JSON,
|
|
155
|
+
* `jsonToolResult`) or `'smart'` (inline small / embedded-resource large,
|
|
156
|
+
* `smartToolResult`). Defaults to `'smart'`. A per-method `@Mcp({ result })`
|
|
157
|
+
* overrides this, and a client's per-call `_meta.disposition` overrides both.
|
|
158
|
+
*/
|
|
159
|
+
defaultResult?: 'json' | 'smart';
|
|
153
160
|
}
|
|
154
161
|
declare const SILKWEAVE_MODULE_OPTIONS = "__silkweave_module_options__";
|
|
155
162
|
//#endregion
|
|
@@ -217,6 +224,14 @@ interface McpMetadata {
|
|
|
217
224
|
* the method is invoked directly, not through Nest's HTTP request pipeline.
|
|
218
225
|
*/
|
|
219
226
|
pipes?: 'apply' | 'skip';
|
|
227
|
+
/**
|
|
228
|
+
* Default MCP result format for this tool. `'json'` returns compact JSON text
|
|
229
|
+
* (`jsonToolResult`); `'smart'` (the default when unset) inlines small
|
|
230
|
+
* payloads and offloads large ones to an embedded resource (`smartToolResult`).
|
|
231
|
+
* This is only a default - a client that sends `_meta.disposition` on the tool
|
|
232
|
+
* call overrides it.
|
|
233
|
+
*/
|
|
234
|
+
result?: 'json' | 'smart';
|
|
220
235
|
}
|
|
221
236
|
//#endregion
|
|
222
237
|
//#region src/decorator/mcp.d.ts
|
|
@@ -271,7 +286,7 @@ declare class ControllerDiscovery {
|
|
|
271
286
|
* arguments (with `@UseGuards` guards - and any opted-in `globalGuards` -
|
|
272
287
|
* applied first).
|
|
273
288
|
*/
|
|
274
|
-
discover(openapi?: OpenApiDocument, globalGuards?: Type<CanActivate>[]): Action[];
|
|
289
|
+
discover(openapi?: OpenApiDocument, globalGuards?: Type<CanActivate>[], defaultResult?: 'json' | 'smart'): Action[];
|
|
275
290
|
private toAction;
|
|
276
291
|
/** Build the merged Zod input shape and the per-argument re-bind plan. */
|
|
277
292
|
private buildInput;
|
package/build/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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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AAA,EAAS,MAAA;AAAA;;;;;;AFmBX;;UETiB,oBAAA;EFSgB;EAAA,SEPtB,IAAA;EFOmD;EAAA,SELnD,QAAA;EFK4D;;;;;EAAA,SEC5D,UAAA;EFD4D;EEGrE,QAAA,CAAS,GAAA,EAAK,0BAAA;AAAA;AAAA,UAGC,sBAAA;;EAEf,SAAA,EAAW,gBAAA;EFmCiB;EEjC5B,QAAA,EAAU,oBAAA;EFiC8B;EE/BxC,OAAA,GAAU,MAAA;EF+BuC;;AAcnD;;;;EEtCE,OAAA,GAAU,eAAA;EFiDI;;;;;AAkBhB;;;;;AAQA;;EE9DE,YAAA,GAAe,IAAA,CAAK,WAAA;AAAA;AAAA,
|
|
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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AAU,IAAA,WACV,OAAA,MAAa,IAAA,yBACb,OAAA,WACA,QAAA,WACA,WAAA,oBACC,OAAA;;;;;;;KC7ES,OAAA;EACN,IAAA;EAAe,KAAA;EAAe,MAAA;EAAmC,QAAA;EAAoB,KAAA;AAAA;EACrF,IAAA;EAAgB,MAAA;EAA0B,MAAA;EAAkB,QAAA;EAAoB,KAAA;AAAA;EAChF,IAAA;EAAgB,MAAA;AAAA;EAChB,IAAA;AAAA;EACA,IAAA;AAAA;EACA,IAAA;EAAiB,IAAA;AAAA;EACjB,IAAA;AAAA;EACA,IAAA;EAAc,IAAA;AAAA;EACd,IAAA;AAAA;AAAA,UAEI,WAAA;EACR,OAAA,GAAU,MAAA;EACV,EAAA;EACA,KAAA,GAAQ,MAAA;AAAA;;;AR6DV;;;iBQIsB,aAAA,CACpB,MAAA,MAAY,IAAA,iBACZ,QAAA,UACA,KAAA,EAAO,MAAA,mBACP,QAAA,EAAU,OAAA,IACV,OAAA,EAAS,WAAA,cACT,eAAA,YACC,OAAA;;iBASa,cAAA,CAAe,SAAA,UAAmB,IAAA,uBAA2B,OAAA;;;;;;;ARvF7E;;;;;;;;;;;;;;;;;;AAwBA;;;;;;cSJa,eAAA,YAA2B,UAAA;EAAA,iBAEe,OAAA;EAAA,iBAClC,SAAA;EAAA,iBACA,eAAA;cAFkC,OAAA,EAAS,sBAAA,EAC3C,SAAA,EAAW,mBAAA,EACX,eAAA,EAAiB,eAAA;EAAA,OAG7B,OAAA,CAAQ,OAAA,EAAS,sBAAA,GAAyB,aAAA;EAajD,SAAA,CAAU,SAAA,EAAW,kBAAA;AAAA"}
|
package/build/index.mjs
CHANGED
|
@@ -9377,7 +9377,7 @@ let ControllerDiscovery = class ControllerDiscovery {
|
|
|
9377
9377
|
* arguments (with `@UseGuards` guards - and any opted-in `globalGuards` -
|
|
9378
9378
|
* applied first).
|
|
9379
9379
|
*/
|
|
9380
|
-
discover(openapi, globalGuards = []) {
|
|
9380
|
+
discover(openapi, globalGuards = [], defaultResult) {
|
|
9381
9381
|
const lookup = openapi ? buildOpenApiLookup(openapi) : void 0;
|
|
9382
9382
|
const discovered = [];
|
|
9383
9383
|
for (const wrapper of this.discovery.getProviders().concat(this.discovery.getControllers())) {
|
|
@@ -9400,9 +9400,9 @@ let ControllerDiscovery = class ControllerDiscovery {
|
|
|
9400
9400
|
});
|
|
9401
9401
|
}
|
|
9402
9402
|
}
|
|
9403
|
-
return discovered.map((d) => this.toAction(d, lookup, globalGuards));
|
|
9403
|
+
return discovered.map((d) => this.toAction(d, lookup, globalGuards, defaultResult));
|
|
9404
9404
|
}
|
|
9405
|
-
toAction(d, lookup, globalGuards) {
|
|
9405
|
+
toAction(d, lookup, globalGuards, defaultResult) {
|
|
9406
9406
|
const proto = Object.getPrototypeOf(d.instance);
|
|
9407
9407
|
const route = reflectRoute(d.classRef, d.method);
|
|
9408
9408
|
const slots = readParamSlots(d.classRef, d.methodName, proto);
|
|
@@ -9437,6 +9437,7 @@ let ControllerDiscovery = class ControllerDiscovery {
|
|
|
9437
9437
|
name,
|
|
9438
9438
|
description,
|
|
9439
9439
|
input: z.object(shape),
|
|
9440
|
+
...d.meta.result ?? defaultResult ? { disposition: d.meta.result ?? defaultResult } : {},
|
|
9440
9441
|
isEnabled: (ctx) => ctx.getOptional("adapter") === "mcp",
|
|
9441
9442
|
run: async (input, context) => {
|
|
9442
9443
|
await applyGuards(context, input);
|
|
@@ -9599,7 +9600,7 @@ let SilkweaveModule = _SilkweaveModule = class SilkweaveModule {
|
|
|
9599
9600
|
configure(_consumer) {
|
|
9600
9601
|
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
9601
9602
|
if (!httpAdapter) throw new Error("@silkweave/nestjs: HttpAdapterHost.httpAdapter is not available.");
|
|
9602
|
-
const allActions = this.discovery.discover(this.options.openapi, this.options.globalGuards);
|
|
9603
|
+
const allActions = this.discovery.discover(this.options.openapi, this.options.globalGuards, this.options.defaultResult);
|
|
9603
9604
|
for (const adapter of this.options.adapters) {
|
|
9604
9605
|
const baseContext = createContext({
|
|
9605
9606
|
...this.options.context ?? {},
|