@vendure/mcp-sdk 3.8.0-minor-bootstrap.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/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './src/mcp-tool.decorator';
2
+ export * from './src/standard-schema';
3
+ export * from './src/types';
package/lib/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./src/mcp-tool.decorator"), exports);
18
+ __exportStar(require("./src/standard-schema"), exports);
19
+ __exportStar(require("./src/types"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,wDAAsC;AACtC,8CAA4B"}
@@ -0,0 +1,222 @@
1
+ import type { Permission } from '@vendure/common/lib/generated-types';
2
+ import type { ID, RequestContext } from '@vendure/core';
3
+ import { McpStandardSchema } from './standard-schema';
4
+ import { McpToolBehavior, McpToolset } from './types';
5
+ /**
6
+ * @description
7
+ * A JSON Schema for a tool's input or output. Only object types are described here;
8
+ * any other JSON Schema keywords can be added via the index signature.
9
+ *
10
+ * @docsCategory core plugins/McpPlugin
11
+ * @since 3.8.0
12
+ */
13
+ export interface McpJsonSchema {
14
+ type: 'object';
15
+ properties?: Record<string, unknown>;
16
+ required?: string[];
17
+ /**
18
+ * @description
19
+ * Room for any other JSON Schema keyword, such as `additionalProperties`. Schemas are
20
+ * compiled as JSON Schema 2020-12, so leave out `$schema`.
21
+ */
22
+ [key: string]: unknown;
23
+ }
24
+ /**
25
+ * @description
26
+ * A tool input/output schema in either accepted form: a plain JSON Schema object
27
+ * ({@link McpJsonSchema}), or a Standard Schema object with JSON Schema conversion
28
+ * ({@link McpStandardSchema}, e.g. a Zod v4 schema).
29
+ *
30
+ * @docsCategory core plugins/McpPlugin
31
+ * @since 3.8.0
32
+ */
33
+ export type McpToolSchema = McpJsonSchema | McpStandardSchema;
34
+ /**
35
+ * @description
36
+ * Describes a single MCP tool. Attach this to a class with the {@link McpTool} decorator; the MCP
37
+ * server finds those classes on startup and exposes each one to agents.
38
+ *
39
+ * @docsCategory core plugins/McpPlugin
40
+ * @since 3.8.0
41
+ */
42
+ export interface McpToolMetadata {
43
+ /**
44
+ * @description
45
+ * The name of the tool, unique within its toolset, in snake_case, e.g. `search_products`.
46
+ * The names `search_tools` and `execute_tool` are reserved for the discovery meta-tools.
47
+ * The server refuses to start if a tool takes a reserved name, or a name already used in
48
+ * the same toolset.
49
+ */
50
+ name: string;
51
+ /**
52
+ * @description
53
+ * A short title for people to read, passed to the client and indexed for `search_tools`
54
+ * queries.
55
+ */
56
+ title?: string;
57
+ /**
58
+ * @description
59
+ * A plain description of what the tool does, written for an AI agent to read. It is sent to
60
+ * the client with the tool list, and indexed for `search_tools` queries. For a destructive
61
+ * tool it is repeated in the confirmation prompt.
62
+ */
63
+ description: string;
64
+ /**
65
+ * @description
66
+ * Extra search terms for the tool: synonyms and phrasings a user would actually say, e.g.
67
+ * `['money back', 'reimburse']` for a refund tool. They are indexed with the name, title and
68
+ * description to match `search_tools` queries in discovery mode. They are never shown to the
69
+ * agent or returned in a tool result.
70
+ */
71
+ keywords?: string[];
72
+ /**
73
+ * @description
74
+ * A `shop` tool appears on the MCP shop endpoint, an `admin` tool on the admin endpoint.
75
+ * Names only have to be unique within one toolset.
76
+ */
77
+ toolset: McpToolset;
78
+ /**
79
+ * @description
80
+ * The permissions needed to call the tool. The caller only needs one of them, the same OR
81
+ * logic as the `Allow` decorator.
82
+ *
83
+ * On a `shop` tool, omitting this or passing an empty array makes the tool public: every
84
+ * caller passes the permission check, including anonymous ones.
85
+ *
86
+ * On an `admin` tool it is required. The server refuses to start when it is omitted or empty.
87
+ * Use `[Permission.Authenticated]` if any signed-in administrator may call the tool.
88
+ */
89
+ permissions?: Permission[];
90
+ /**
91
+ * @description
92
+ * How the tool behaves, which decides how it is exposed to the agent:
93
+ *
94
+ * - `readonly`: the tool changes nothing. Its `readOnlyHint` and `idempotentHint`
95
+ * annotations are set to true.
96
+ * - `mutating`: the tool writes data and runs immediately.
97
+ * - `destructive`: the tool writes data and must be confirmed first. Its `destructiveHint`
98
+ * annotation is set to true. An optional `confirm` field is added to the input schema the
99
+ * caller sees. The registry refuses to run the tool unless the call passes `confirm: true`.
100
+ * A destructive tool must not declare a `confirm` property of its own.
101
+ *
102
+ * @default 'mutating'
103
+ */
104
+ behavior?: McpToolBehavior;
105
+ /**
106
+ * @description
107
+ * Set to `true` for Shop tools that use the shopper's active Order. This enables anonymous
108
+ * callers to continue the same cart using a `sessionToken`.
109
+ *
110
+ * Only valid for Shop tools. The `sessionToken` field is managed automatically.
111
+ *
112
+ * @default false
113
+ */
114
+ usesActiveOrder?: boolean;
115
+ /**
116
+ * @description
117
+ * The schema for the tool's arguments. Two forms are accepted: a plain JSON Schema object
118
+ * ({@link McpJsonSchema}), or a Standard Schema object that can emit JSON Schema
119
+ * ({@link McpStandardSchema}), such as a Zod v4 schema. The registry compiles the schema once
120
+ * at startup, and validates every call's arguments against it. A tool that omits it takes no
121
+ * arguments.
122
+ */
123
+ inputSchema?: McpToolSchema;
124
+ /**
125
+ * @description
126
+ * The schema for the tool's return value, in the same two forms as `inputSchema`. The registry
127
+ * validates each result against it and logs a warning on a mismatch. The call still succeeds,
128
+ * and the schema is not advertised to the client.
129
+ */
130
+ outputSchema?: McpToolSchema;
131
+ }
132
+ /**
133
+ * @description
134
+ * The MCP OAuth grant behind a tool call, when the call arrived over MCP OAuth.
135
+ *
136
+ * @docsCategory core plugins/McpPlugin
137
+ * @since 3.8.0
138
+ */
139
+ export interface McpCallerGrant {
140
+ id: ID;
141
+ /**
142
+ * @description
143
+ * Identifies the app that connected, rather than the person using it.
144
+ */
145
+ oauthClientId: ID;
146
+ }
147
+ /**
148
+ * @description
149
+ * Who is calling a tool and how. Passed as the optional third argument to
150
+ * {@link McpToolHandler.execute}.
151
+ *
152
+ * @docsCategory core plugins/McpPlugin
153
+ * @since 3.8.0
154
+ */
155
+ export interface McpCallerInfo {
156
+ /**
157
+ * @description
158
+ * The OAuth grant behind the call. It is set for every call that arrived via MCP OAuth, and
159
+ * undefined for anonymous shop calls and in-process calls.
160
+ */
161
+ grant?: McpCallerGrant;
162
+ /**
163
+ * @description
164
+ * The client IP resolved by the HTTP transport. It is set for every HTTP call, and undefined
165
+ * for in-process calls.
166
+ */
167
+ clientIp?: string;
168
+ }
169
+ /**
170
+ * @description
171
+ * The shape of an MCP tool class: an `execute` method that the server calls with the
172
+ * {@link RequestContext}, the input, and, when a tool needs to know who is calling,
173
+ * {@link McpCallerInfo}.
174
+ *
175
+ * @docsCategory core plugins/McpPlugin
176
+ * @since 3.8.0
177
+ */
178
+ export interface McpToolHandler<I = unknown, O = unknown> {
179
+ /**
180
+ * @description
181
+ * The tool's implementation. The server calls it with a {@link RequestContext} for the caller,
182
+ * the validated input, and {@link McpCallerInfo}. The caller info is always passed, though the
183
+ * parameter is optional so a tool that ignores it can leave it out. Whatever the method
184
+ * returns becomes the tool's result.
185
+ */
186
+ execute(ctx: RequestContext, input: I, caller?: McpCallerInfo): Promise<O> | O;
187
+ }
188
+ /**
189
+ * @description
190
+ * Marks a class as an MCP tool. The class must be a NestJS provider (can be injected via `@Injectable()`)
191
+ * so the MCP server can discover it and inject the services it depends on.
192
+ * It also needs an `execute` method (see {@link McpToolHandler}), which the server checks for when registering the
193
+ * tool. The {@link McpToolMetadata} you pass is read at runtime and used by the
194
+ * [MCP plugin](/reference/core-plugins/mcp-plugin/) to turn the class into a
195
+ * callable tool.
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * import { Injectable } from '\@nestjs/common';
200
+ * import { McpTool, McpToolHandler } from '\@vendure/mcp-sdk';
201
+ * import { Permission, RequestContext } from '\@vendure/core';
202
+ *
203
+ * \@Injectable()
204
+ * \@McpTool({
205
+ * name: 'search_products',
206
+ * description: 'Search the product catalog',
207
+ * toolset: 'shop',
208
+ * behavior: 'readonly',
209
+ * permissions: [Permission.Public],
210
+ * })
211
+ * export class SearchProductsTool implements McpToolHandler {
212
+ * execute(ctx: RequestContext, input: { term: string }) {
213
+ * // ...
214
+ * return { items: [] };
215
+ * }
216
+ * }
217
+ * ```
218
+ *
219
+ * @docsCategory core plugins/McpPlugin
220
+ * @since 3.8.0
221
+ */
222
+ export declare const McpTool: import("@nestjs/core", { with: { "resolution-mode": "import" } }).DiscoverableDecorator<McpToolMetadata>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.McpTool = void 0;
4
+ const core_1 = require("@nestjs/core");
5
+ /**
6
+ * @description
7
+ * Marks a class as an MCP tool. The class must be a NestJS provider (can be injected via `@Injectable()`)
8
+ * so the MCP server can discover it and inject the services it depends on.
9
+ * It also needs an `execute` method (see {@link McpToolHandler}), which the server checks for when registering the
10
+ * tool. The {@link McpToolMetadata} you pass is read at runtime and used by the
11
+ * [MCP plugin](/reference/core-plugins/mcp-plugin/) to turn the class into a
12
+ * callable tool.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import { Injectable } from '\@nestjs/common';
17
+ * import { McpTool, McpToolHandler } from '\@vendure/mcp-sdk';
18
+ * import { Permission, RequestContext } from '\@vendure/core';
19
+ *
20
+ * \@Injectable()
21
+ * \@McpTool({
22
+ * name: 'search_products',
23
+ * description: 'Search the product catalog',
24
+ * toolset: 'shop',
25
+ * behavior: 'readonly',
26
+ * permissions: [Permission.Public],
27
+ * })
28
+ * export class SearchProductsTool implements McpToolHandler {
29
+ * execute(ctx: RequestContext, input: { term: string }) {
30
+ * // ...
31
+ * return { items: [] };
32
+ * }
33
+ * }
34
+ * ```
35
+ *
36
+ * @docsCategory core plugins/McpPlugin
37
+ * @since 3.8.0
38
+ */
39
+ exports.McpTool = core_1.DiscoveryService.createDecorator();
40
+ //# sourceMappingURL=mcp-tool.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-tool.decorator.js","sourceRoot":"","sources":["../../src/mcp-tool.decorator.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAoMhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACU,QAAA,OAAO,GAAG,uBAAgB,CAAC,eAAe,EAAmB,CAAC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @description
3
+ * One validation failure reported by an {@link McpStandardSchema}.
4
+ *
5
+ * @docsCategory core plugins/McpPlugin
6
+ * @since 3.8.0
7
+ */
8
+ export interface McpStandardSchemaIssue {
9
+ /**
10
+ * @description
11
+ * A human readable message describing why the value was rejected.
12
+ */
13
+ readonly message: string;
14
+ /**
15
+ * @description
16
+ * Where the rejected value sits inside the validated input. Each segment is a property key,
17
+ * an array index, or an object carrying that key. It is absent when the issue applies to the
18
+ * value as a whole.
19
+ */
20
+ readonly path?: ReadonlyArray<PropertyKey | {
21
+ readonly key: PropertyKey;
22
+ }>;
23
+ }
24
+ /**
25
+ * @description
26
+ * The result of validating a value against an {@link McpStandardSchema}: the (possibly
27
+ * transformed) value on success, or a list of issues on failure.
28
+ *
29
+ * @docsCategory core plugins/McpPlugin
30
+ * @since 3.8.0
31
+ */
32
+ export type McpStandardSchemaResult<Output = unknown> = {
33
+ readonly value: Output;
34
+ readonly issues?: undefined;
35
+ } | {
36
+ readonly issues: readonly McpStandardSchemaIssue[];
37
+ };
38
+ /**
39
+ * @description
40
+ * A schema object implementing the [Standard Schema](https://standardschema.dev/) interface plus
41
+ * its JSON Schema conversion extension. Zod v4, ArkType, and Valibot schemas all implement this
42
+ * shape; it's declared structurally so `@vendure/mcp-sdk` doesn't depend on any schema library.
43
+ *
44
+ * The MCP server converts the schema to JSON Schema once at startup, to advertise the tool, and
45
+ * calls `validate` on every incoming call. The tool's `execute` method receives the validated
46
+ * value, so library features like defaults apply.
47
+ *
48
+ * @docsCategory core plugins/McpPlugin
49
+ * @since 3.8.0
50
+ */
51
+ export interface McpStandardSchema<Input = unknown, Output = Input> {
52
+ /**
53
+ * @description
54
+ * The Standard Schema properties that a schema library adds to each of its schemas. The MCP
55
+ * server reads `jsonSchema` once at startup, and calls `validate` on every tool call. The
56
+ * `version`, `vendor` and `types` properties belong to the Standard Schema contract, and are
57
+ * not read by the MCP server.
58
+ */
59
+ readonly '~standard': {
60
+ readonly version: 1;
61
+ readonly vendor: string;
62
+ readonly validate: (value: unknown) => McpStandardSchemaResult<Output> | Promise<McpStandardSchemaResult<Output>>;
63
+ readonly types?: {
64
+ readonly input: Input;
65
+ readonly output: Output;
66
+ };
67
+ readonly jsonSchema: {
68
+ input(options: {
69
+ readonly target: string;
70
+ readonly libraryOptions?: Record<string, unknown>;
71
+ }): Record<string, unknown>;
72
+ output(options: {
73
+ readonly target: string;
74
+ readonly libraryOptions?: Record<string, unknown>;
75
+ }): Record<string, unknown>;
76
+ };
77
+ };
78
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=standard-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standard-schema.js","sourceRoot":"","sources":["../../src/standard-schema.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @description
3
+ * Which API a tool uses: `shop` tools work over the Shop API, `admin` tools over
4
+ * the Admin API.
5
+ *
6
+ * @docsCategory core plugins/McpPlugin
7
+ * @since 3.8.0
8
+ */
9
+ export type McpToolset = 'shop' | 'admin';
10
+ /**
11
+ * @description
12
+ * How a tool behaves, which tells the MCP server how to expose it: `readonly` tools
13
+ * only read data, `mutating` tools change it, and `destructive` tools ask for
14
+ * confirmation before running.
15
+ *
16
+ * @docsCategory core plugins/McpPlugin
17
+ * @since 3.8.0
18
+ */
19
+ export type McpToolBehavior = 'readonly' | 'mutating' | 'destructive';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@vendure/mcp-sdk",
3
+ "version": "3.8.0-minor-bootstrap.0",
4
+ "license": "GPL-3.0-or-later",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "lib/**/*"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/vendurehq/vendure"
14
+ },
15
+ "scripts": {
16
+ "watch": "tsc -p ./tsconfig.build.json --watch",
17
+ "build": "rimraf lib && tsc -p ./tsconfig.build.json",
18
+ "ci": "npm run build",
19
+ "lint": "eslint --fix .",
20
+ "test": "vitest --config vitest.config.mts --run"
21
+ },
22
+ "homepage": "https://www.vendure.io/",
23
+ "funding": "https://github.com/sponsors/michaelbromley",
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "peerDependencies": {
28
+ "@nestjs/core": "^11.0.0 || ^12.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "@vendure/common": "^3.8.0-minor-bootstrap.0",
32
+ "@vendure/core": "^3.8.0-minor-bootstrap.0"
33
+ }
34
+ }