@miragon/mcp-toolkit-core 2.5.0 → 2.6.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/README.md +1 -1
- package/dist/auth/caller.d.ts +55 -0
- package/dist/auth/caller.d.ts.map +1 -0
- package/dist/auth/caller.js +81 -0
- package/dist/auth/caller.js.map +1 -0
- package/dist/engine/pipeline-executor.d.ts +32 -4
- package/dist/engine/pipeline-executor.d.ts.map +1 -1
- package/dist/engine/pipeline-executor.js +22 -2
- package/dist/engine/pipeline-executor.js.map +1 -1
- package/dist/framework/catalogue.d.ts +2 -2
- package/dist/framework/render-view.d.ts +6 -4
- package/dist/framework/render-view.d.ts.map +1 -1
- package/dist/framework/render-view.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/org-gate.d.ts +31 -7
- package/dist/middleware/org-gate.d.ts.map +1 -1
- package/dist/middleware/org-gate.js +9 -6
- package/dist/middleware/org-gate.js.map +1 -1
- package/dist/middleware/role-filter.d.ts +39 -7
- package/dist/middleware/role-filter.d.ts.map +1 -1
- package/dist/middleware/role-filter.js +24 -28
- package/dist/middleware/role-filter.js.map +1 -1
- package/dist/tools/create-framework-app.d.ts +12 -1
- package/dist/tools/create-framework-app.d.ts.map +1 -1
- package/dist/tools/create-framework-app.js +10 -5
- package/dist/tools/create-framework-app.js.map +1 -1
- package/dist/tools/dashboard-store.d.ts +83 -13
- package/dist/tools/dashboard-store.d.ts.map +1 -1
- package/dist/tools/dashboard-store.js +174 -73
- package/dist/tools/dashboard-store.js.map +1 -1
- package/dist/tools/index.d.ts +5 -3
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/install-toolkit.d.ts +22 -1
- package/dist/tools/install-toolkit.d.ts.map +1 -1
- package/dist/tools/install-toolkit.js +15 -3
- package/dist/tools/install-toolkit.js.map +1 -1
- package/dist/tools/register-catalogue-tool.d.ts.map +1 -1
- package/dist/tools/register-catalogue-tool.js +2 -5
- package/dist/tools/register-catalogue-tool.js.map +1 -1
- package/dist/tools/register-dashboard-tools.d.ts +15 -3
- package/dist/tools/register-dashboard-tools.d.ts.map +1 -1
- package/dist/tools/register-dashboard-tools.js +120 -20
- package/dist/tools/register-dashboard-tools.js.map +1 -1
- package/dist/tools/register-framework-tools.d.ts.map +1 -1
- package/dist/tools/register-framework-tools.js +4 -6
- package/dist/tools/register-framework-tools.js.map +1 -1
- package/dist/tools/register-tool.d.ts +67 -9
- package/dist/tools/register-tool.d.ts.map +1 -1
- package/dist/tools/register-tool.js +17 -8
- package/dist/tools/register-tool.js.map +1 -1
- package/dist/tools/register-widget-tool.d.ts +46 -5
- package/dist/tools/register-widget-tool.d.ts.map +1 -1
- package/dist/tools/register-widget-tool.js +25 -27
- package/dist/tools/register-widget-tool.js.map +1 -1
- package/dist/tools/registrar-shared.d.ts +74 -0
- package/dist/tools/registrar-shared.d.ts.map +1 -0
- package/dist/tools/registrar-shared.js +32 -0
- package/dist/tools/registrar-shared.js.map +1 -0
- package/dist/tools/tool-name-guard.d.ts +37 -0
- package/dist/tools/tool-name-guard.d.ts.map +1 -0
- package/dist/tools/tool-name-guard.js +81 -0
- package/dist/tools/tool-name-guard.js.map +1 -0
- package/package.json +7 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MCPServer } from "mcp-use";
|
|
2
|
-
import type
|
|
2
|
+
import { type DashboardStore } from "./dashboard-store.js";
|
|
3
3
|
import type { WidgetRegistry } from "../registry/widget-registry.js";
|
|
4
4
|
export interface RegisterDashboardToolsOptions {
|
|
5
5
|
store: DashboardStore;
|
|
@@ -10,12 +10,24 @@ export interface RegisterDashboardToolsOptions {
|
|
|
10
10
|
* blocked on a cosmetic mistake. Omit to skip the check entirely.
|
|
11
11
|
*/
|
|
12
12
|
widgetRegistry?: WidgetRegistry;
|
|
13
|
+
/**
|
|
14
|
+
* Refuse every dashboard call that resolves no caller id — even one that
|
|
15
|
+
* carries no `ctx.auth` at all — instead of serving it in global scope.
|
|
16
|
+
* `createFrameworkApp` sets this whenever an `oauth` provider is configured.
|
|
17
|
+
* A call that DOES carry `ctx.auth` is held to it regardless: an
|
|
18
|
+
* authenticated caller without an id is never widened to global scope.
|
|
19
|
+
* Defaults to `false`.
|
|
20
|
+
*/
|
|
21
|
+
requireCallerIdentity?: boolean;
|
|
13
22
|
}
|
|
14
23
|
/**
|
|
15
24
|
* Registers `save-dashboard`, `list-dashboards`, `load-dashboard`, and
|
|
16
25
|
* `delete-dashboard`. The tools are thin CRUD wrappers around the injected
|
|
17
|
-
* `DashboardStore`;
|
|
18
|
-
*
|
|
26
|
+
* `DashboardStore`; the caller's scope is decided here via
|
|
27
|
+
* {@link resolveCaller} (both mcp-use 2 `ctx.auth` shapes; `user.id`, then
|
|
28
|
+
* `user.userId`, then the token's `sub`) and handed to the store as its
|
|
29
|
+
* `userId` filter. An authenticated call that resolves no id is refused —
|
|
30
|
+
* never served in global scope.
|
|
19
31
|
*
|
|
20
32
|
* `load-dashboard` returns the full record as JSON in `content[0].text`
|
|
21
33
|
* (mirrored into `structuredContent`) so the model itself receives the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-dashboard-tools.d.ts","sourceRoot":"","sources":["../../src/tools/register-dashboard-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"register-dashboard-tools.d.ts","sourceRoot":"","sources":["../../src/tools/register-dashboard-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,OAAO,EAML,KAAK,cAAc,EAEpB,MAAM,sBAAsB,CAAA;AAG7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAEpE,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,cAAc,CAAA;IACrB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,cAAc,CAAA;IAC/B;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC;AA0GD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,6BAA6B,GACrC,IAAI,CA8JN"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveCaller } from "../auth/caller.js";
|
|
3
|
+
import { errorResult, objectResult } from "./tool-results.js";
|
|
4
|
+
import { assertDashboardWritable, DashboardOwnershipError, DashboardUnreadableError, isDashboardOwnedBy, } from "./dashboard-store.js";
|
|
3
5
|
import { collectLayoutWidgets } from "../framework/view-builders.js";
|
|
4
6
|
import { layoutSchema } from "../framework/layout-schemas.js";
|
|
5
7
|
const stepRefSchema = z.object({
|
|
@@ -31,15 +33,70 @@ const saveSchema = z.object({
|
|
|
31
33
|
const idSchema = z.object({
|
|
32
34
|
id: z.string().describe("Dashboard id as returned by `save-dashboard` or `list-dashboards`."),
|
|
33
35
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Whose dashboards a call may touch: `{ userId: undefined }` is global scope
|
|
38
|
+
* (a server without OAuth), `{ userId }` is that caller's records only, and
|
|
39
|
+
* `undefined` means refuse — the call is authenticated (or OAuth is
|
|
40
|
+
* required) but no caller id resolves, and falling back to global scope would
|
|
41
|
+
* hand it every user's dashboards.
|
|
42
|
+
*/
|
|
43
|
+
function dashboardScope(ctx, requireCallerIdentity) {
|
|
44
|
+
const caller = resolveCaller(ctx);
|
|
45
|
+
if (caller?.userId)
|
|
46
|
+
return { userId: caller.userId };
|
|
47
|
+
if (caller === undefined && !requireCallerIdentity)
|
|
48
|
+
return { userId: undefined };
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const NO_IDENTITY_MESSAGE = "Access denied: this request carries no caller identity (the OAuth provider mapped no user id and the token has no `sub`). Dashboards are per-user, so they cannot be read or written without one.";
|
|
52
|
+
/**
|
|
53
|
+
* Defence in depth for custom stores with a laxer ownership rule (the 2.5
|
|
54
|
+
* contract handed owner-less records to every caller): the record `get`
|
|
55
|
+
* returns, but only if it is the caller's — {@link isDashboardOwnedBy}, so
|
|
56
|
+
* global scope passes everything through. A store that already follows the
|
|
57
|
+
* rule loses nothing but the extra read.
|
|
58
|
+
*/
|
|
59
|
+
async function ownRecord(store, id, scope) {
|
|
60
|
+
const record = await store.get(id, scope);
|
|
61
|
+
return record && isDashboardOwnedBy(record.userId, scope.userId) ? record : undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Keep only the identified caller's own summaries. A summary that names its
|
|
65
|
+
* owner is decided on the spot; one that doesn't (a store on the 2.5 summary
|
|
66
|
+
* shape) is verified through `get`, and an unreadable one that cannot be
|
|
67
|
+
* attributed that way is dropped rather than listed.
|
|
68
|
+
*/
|
|
69
|
+
async function ownSummaries(store, items, userId) {
|
|
70
|
+
const isOwn = async (item) => {
|
|
71
|
+
if (item.userId !== undefined)
|
|
72
|
+
return item.userId === userId;
|
|
73
|
+
try {
|
|
74
|
+
return (await ownRecord(store, item.id, { userId })) !== undefined;
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (err instanceof DashboardUnreadableError)
|
|
78
|
+
return false;
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const verdicts = await Promise.all(items.map(isOwn));
|
|
83
|
+
return items.filter((_item, index) => verdicts[index]);
|
|
84
|
+
}
|
|
85
|
+
/** Store refusals that reach the caller as a tool error rather than a crash. */
|
|
86
|
+
function refusalResult(err) {
|
|
87
|
+
if (err instanceof DashboardOwnershipError || err instanceof DashboardUnreadableError) {
|
|
88
|
+
return errorResult(err.message);
|
|
89
|
+
}
|
|
90
|
+
throw err;
|
|
37
91
|
}
|
|
38
92
|
/**
|
|
39
93
|
* Registers `save-dashboard`, `list-dashboards`, `load-dashboard`, and
|
|
40
94
|
* `delete-dashboard`. The tools are thin CRUD wrappers around the injected
|
|
41
|
-
* `DashboardStore`;
|
|
42
|
-
*
|
|
95
|
+
* `DashboardStore`; the caller's scope is decided here via
|
|
96
|
+
* {@link resolveCaller} (both mcp-use 2 `ctx.auth` shapes; `user.id`, then
|
|
97
|
+
* `user.userId`, then the token's `sub`) and handed to the store as its
|
|
98
|
+
* `userId` filter. An authenticated call that resolves no id is refused —
|
|
99
|
+
* never served in global scope.
|
|
43
100
|
*
|
|
44
101
|
* `load-dashboard` returns the full record as JSON in `content[0].text`
|
|
45
102
|
* (mirrored into `structuredContent`) so the model itself receives the
|
|
@@ -54,28 +111,45 @@ function extractUserId(ctx) {
|
|
|
54
111
|
*/
|
|
55
112
|
export function registerDashboardTools(server, options) {
|
|
56
113
|
const { store, widgetRegistry } = options;
|
|
114
|
+
const requireCallerIdentity = options.requireCallerIdentity ?? false;
|
|
57
115
|
server.tool({
|
|
58
116
|
name: "save-dashboard",
|
|
59
117
|
title: "Save Dashboard",
|
|
60
118
|
description: "Persists a dashboard (render-view input bundle + name). Pass an existing `id` to update, omit to create. The builder UI's Save button invokes this tool.",
|
|
61
119
|
inputSchema: saveSchema,
|
|
62
120
|
}, async (params, ctx) => {
|
|
121
|
+
const scope = dashboardScope(ctx, requireCallerIdentity);
|
|
122
|
+
if (!scope)
|
|
123
|
+
return errorResult(NO_IDENTITY_MESSAGE);
|
|
63
124
|
// Warn (never reject) on unknown widget ids — usually a typo. A save is
|
|
64
125
|
// deliberately never blocked on a cosmetic layout mistake; the unknown
|
|
65
126
|
// ids surface in the text summary so the user can spot and fix it.
|
|
66
127
|
const unknownWidgets = widgetRegistry
|
|
67
128
|
? [...new Set(collectLayoutWidgets(params.layout))].filter((id) => !widgetRegistry.get(id))
|
|
68
129
|
: [];
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
130
|
+
let record;
|
|
131
|
+
try {
|
|
132
|
+
if (scope.userId !== undefined && params.id !== undefined) {
|
|
133
|
+
// Defence in depth: a lax custom store's own save might let the
|
|
134
|
+
// caller overwrite (and so claim) a record it does not own.
|
|
135
|
+
const existing = await store.get(params.id, scope);
|
|
136
|
+
if (existing)
|
|
137
|
+
assertDashboardWritable(existing, scope.userId);
|
|
138
|
+
}
|
|
139
|
+
record = await store.save({
|
|
140
|
+
id: params.id,
|
|
141
|
+
name: params.name,
|
|
142
|
+
description: params.description,
|
|
143
|
+
userId: scope.userId,
|
|
144
|
+
keys: params.keys,
|
|
145
|
+
steps: params.steps,
|
|
146
|
+
layout: params.layout,
|
|
147
|
+
title: params.title,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
return refusalResult(err);
|
|
152
|
+
}
|
|
79
153
|
const summaryLines = [
|
|
80
154
|
`Saved dashboard "${record.name}" (${record.id}).`,
|
|
81
155
|
unknownWidgets.length > 0
|
|
@@ -99,8 +173,13 @@ export function registerDashboardTools(server, options) {
|
|
|
99
173
|
description: "Returns the dashboards visible to the caller (scoped by userId when auth is enabled). Metadata only — fetch a full record via `load-dashboard`.",
|
|
100
174
|
annotations: { readOnlyHint: true },
|
|
101
175
|
}, async (_params, ctx) => {
|
|
102
|
-
const
|
|
103
|
-
|
|
176
|
+
const scope = dashboardScope(ctx, requireCallerIdentity);
|
|
177
|
+
if (!scope)
|
|
178
|
+
return errorResult(NO_IDENTITY_MESSAGE);
|
|
179
|
+
const items = await store.list({ userId: scope.userId });
|
|
180
|
+
return objectResult({
|
|
181
|
+
items: scope.userId === undefined ? items : await ownSummaries(store, items, scope.userId),
|
|
182
|
+
});
|
|
104
183
|
});
|
|
105
184
|
server.tool({
|
|
106
185
|
name: "load-dashboard",
|
|
@@ -109,7 +188,16 @@ export function registerDashboardTools(server, options) {
|
|
|
109
188
|
inputSchema: idSchema,
|
|
110
189
|
annotations: { readOnlyHint: true },
|
|
111
190
|
}, async ({ id }, ctx) => {
|
|
112
|
-
const
|
|
191
|
+
const scope = dashboardScope(ctx, requireCallerIdentity);
|
|
192
|
+
if (!scope)
|
|
193
|
+
return errorResult(NO_IDENTITY_MESSAGE);
|
|
194
|
+
let record;
|
|
195
|
+
try {
|
|
196
|
+
record = await ownRecord(store, id, scope);
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
return refusalResult(err);
|
|
200
|
+
}
|
|
113
201
|
if (!record) {
|
|
114
202
|
return {
|
|
115
203
|
content: [{ type: "text", text: `Dashboard "${id}" not found.` }],
|
|
@@ -142,7 +230,19 @@ export function registerDashboardTools(server, options) {
|
|
|
142
230
|
description: "Permanently removes a dashboard by id.",
|
|
143
231
|
inputSchema: idSchema,
|
|
144
232
|
}, async ({ id }, ctx) => {
|
|
145
|
-
const
|
|
233
|
+
const scope = dashboardScope(ctx, requireCallerIdentity);
|
|
234
|
+
if (!scope)
|
|
235
|
+
return errorResult(NO_IDENTITY_MESSAGE);
|
|
236
|
+
let deleted;
|
|
237
|
+
try {
|
|
238
|
+
// Defence in depth: never let a lax custom store delete a record the
|
|
239
|
+
// identified caller does not own.
|
|
240
|
+
const deletable = scope.userId === undefined || (await ownRecord(store, id, scope));
|
|
241
|
+
deleted = deletable ? await store.delete(id, scope) : false;
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
return refusalResult(err);
|
|
245
|
+
}
|
|
146
246
|
return {
|
|
147
247
|
content: [
|
|
148
248
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-dashboard-tools.js","sourceRoot":"","sources":["../../src/tools/register-dashboard-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;A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AE,OAAO,CAAC,CAAC,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC,CAAC,cAAc,EAAE,cAAc;iBAC7E;aACF;YACD,iBAAiB,EAAE,EAAE,OAAO,EAAE;YAC9B,OAAO,EAAE,CAAC,OAAO;SAClB,CAAA;IACH,CAAC,CACF,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-framework-tools.d.ts","sourceRoot":"","sources":["../../src/tools/register-framework-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"register-framework-tools.d.ts","sourceRoot":"","sources":["../../src/tools/register-framework-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAA;AAQxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7D,OAAO,EAGL,KAAK,cAAc,EAEpB,MAAM,kBAAkB,CAAA;AAEzB,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD,qFAAqF;AACrF,eAAO,MAAM,gBAAgB,gBAAgB,CAAA;AAE7C,MAAM,WAAW,6BAA6B;IAC5C,YAAY,EAAE,YAAY,CAAA;IAC1B,cAAc,EAAE,cAAc,CAAA;IAC9B,MAAM,EAAE,SAAS,CAAA;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACnD,OAAO,EAAE,SAAS,EAAE,CAAA;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;;OAKG;IACH,GAAG,CAAC,EAAE,cAAc,CAAA;CACrB;AAyCD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,6BAA6B,GACrC,IAAI,CA0FN"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { resolvePipelineContext } from "../engine/pipeline-executor.js";
|
|
2
3
|
import { textResult } from "./tool-results.js";
|
|
3
4
|
import { getFrameworkManifest } from "../framework/manifest.js";
|
|
4
5
|
import { layoutInputSchema } from "../framework/layout-schemas.js";
|
|
5
6
|
import { renderView } from "../framework/render-view.js";
|
|
7
|
+
import { moduleToolOwner, withToolOwner } from "./tool-name-guard.js";
|
|
6
8
|
import { appsSdkMeta, viewResourceUri, } from "../types/meta.js";
|
|
7
9
|
/** View name (and thus `ui://views/render-view.html` URI) bound to `render-view`. */
|
|
8
10
|
export const RENDER_VIEW_NAME = "render-view";
|
|
@@ -29,10 +31,6 @@ const renderViewSchema = z.object({
|
|
|
29
31
|
layout: layoutInputSchema,
|
|
30
32
|
title: z.string().optional().describe("Optional view title."),
|
|
31
33
|
});
|
|
32
|
-
function extractUserId(ctx) {
|
|
33
|
-
const user = ctx?.auth?.user;
|
|
34
|
-
return typeof user?.userId === "string" ? user.userId : undefined;
|
|
35
|
-
}
|
|
36
34
|
/** Converts the camelCase resource CSP into the snake_cased `openai/widgetCSP` shape. */
|
|
37
35
|
function toWidgetCspMeta(csp) {
|
|
38
36
|
const meta = {};
|
|
@@ -81,7 +79,7 @@ export function registerFrameworkTools(server, options) {
|
|
|
81
79
|
},
|
|
82
80
|
stepRegistry,
|
|
83
81
|
appConfigs,
|
|
84
|
-
ctx:
|
|
82
|
+
ctx: resolvePipelineContext(ctx),
|
|
85
83
|
builderAvailable,
|
|
86
84
|
});
|
|
87
85
|
};
|
|
@@ -109,7 +107,7 @@ export function registerFrameworkTools(server, options) {
|
|
|
109
107
|
}),
|
|
110
108
|
}, renderHandler);
|
|
111
109
|
for (const plugin of plugins) {
|
|
112
|
-
plugin.registerWidgetTools?.(server, { widgetCSP, viewCsp: csp });
|
|
110
|
+
withToolOwner(server, moduleToolOwner(plugin.definition.name), () => plugin.registerWidgetTools?.(server, { widgetCSP, viewCsp: csp }));
|
|
113
111
|
}
|
|
114
112
|
server.tool({
|
|
115
113
|
name: refreshToolName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-framework-tools.js","sourceRoot":"","sources":["../../src/tools/register-framework-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;
|
|
1
|
+
{"version":3,"file":"register-framework-tools.js","sourceRoot":"","sources":["../../src/tools/register-framework-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAIrE,OAAO,EACL,WAAW,EACX,eAAe,GAGhB,MAAM,kBAAkB,CAAA;AAIzB,qFAAqF;AACrF,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAA;AAgC7C,MAAM,aA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BAAgB;QAC7B,IAAI,EAAE;YACJ,IAAI,EAAE,gBAAgB;YACtB,WAAW,EAAE,sDAAsD;YACnE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxB;QACD,uEAAuE;QACvE,sEAAsE;QACtE,0DAA0D;QAC1D,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE;QACxC,KAAK,EAAE,WAAW,CAAC;YACjB,WAAW,EAAE,eAAe,CAAC,gBAAgB,CAAC;YAC9C,KAAK,EAAE,aAAa;YACpB,QAAQ,EAAE,mBAAmB;YAC7B,OAAO,EAAE,eAAe;YACxB,iBAAiB,EAAE,sDAAsD;YACzE,SAAS;SACV,CAAC;KACH,EACD,aAAa,CACd,CAAA;IAED,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,aAAa,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAClE,MAAM,CAAC,mBAAmB,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAClE,CAAA;IACH,CAAC;IAED,MAAM,CAAC,IAAI,CACT;QACE,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,cAAc;QACrB,WAAW,EAAE,kDAAkD;QAC/D,WAAW,EAAE,gBAAgB;QAC7B,sEAAsE;QACtE,kEAAkE;QAClE,mDAAmD;QACnD,UAAU,EAAE,KAAK;KAClB,EACD,aAAa,CACd,CAAA;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type MCPServer } from "mcp-use";
|
|
1
|
+
import { type MCPServer, type ToolRef } from "mcp-use";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
type
|
|
3
|
+
import { type HandlerUser, type ToolDefinitionPassthrough, type ToolHandlerContext, type ToolRegistrarOptions, type TypedToolRefOptions, type ZodRawShape } from "./registrar-shared.js";
|
|
4
4
|
/**
|
|
5
5
|
* The validated args a handler receives. When an `inputSchema` shape is
|
|
6
6
|
* declared, this is inferred from it (`z.infer`), so handlers get precise types
|
|
@@ -8,7 +8,7 @@ type ZodRawShape = Record<string, z.ZodTypeAny>;
|
|
|
8
8
|
* falls back to a permissive record, matching the pre-generic behaviour.
|
|
9
9
|
*/
|
|
10
10
|
export type ToolArgs<TShape extends ZodRawShape = ZodRawShape> = z.infer<z.ZodObject<TShape>>;
|
|
11
|
-
export interface ToolConfig<TClient, TShape extends ZodRawShape = ZodRawShape> {
|
|
11
|
+
export interface ToolConfig<TClient, TShape extends ZodRawShape = ZodRawShape, TUser = unknown> {
|
|
12
12
|
name: string;
|
|
13
13
|
description: string;
|
|
14
14
|
category?: string;
|
|
@@ -30,16 +30,74 @@ export interface ToolConfig<TClient, TShape extends ZodRawShape = ZodRawShape> {
|
|
|
30
30
|
idempotentHint?: boolean;
|
|
31
31
|
openWorldHint?: boolean;
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Reject unknown input keys instead of silently stripping them: the input
|
|
35
|
+
* schema is advertised with `additionalProperties: false`, and a call with
|
|
36
|
+
* an unknown key fails with a tool error naming the valid keys. Overrides
|
|
37
|
+
* the registrar's `strictInput` option; off by default in 2.x.
|
|
38
|
+
*/
|
|
39
|
+
strictInput?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Every other mcp-use `ToolDefinition` field, forwarded verbatim to
|
|
42
|
+
* `server.tool` — `title`, `_meta`, `visibility`, `securitySchemes`,
|
|
43
|
+
* `view`, … The registrar-derived keys (name, description, schemas,
|
|
44
|
+
* annotations) always win.
|
|
45
|
+
*/
|
|
46
|
+
definition?: ToolDefinitionPassthrough;
|
|
47
|
+
/**
|
|
48
|
+
* The tool body. `ctx` is mcp-use's per-call context ({@link ToolHandlerContext}):
|
|
49
|
+
* `signal` for cancellation, `reportProgress`, `sendLog`, `client`, `auth`.
|
|
50
|
+
* The registrar always passes it; it is optional in the type so handlers
|
|
51
|
+
* stay directly callable as `(client, args)` — e.g. from unit tests.
|
|
52
|
+
*/
|
|
53
|
+
handler: (client: TClient, args: ToolArgs<TShape>, ctx?: ToolHandlerContext<TUser>) => Promise<unknown>;
|
|
34
54
|
formatResult?: (result: unknown, args: ToolArgs<TShape>) => string;
|
|
35
55
|
}
|
|
36
56
|
export interface RegisteredToolMeta {
|
|
37
57
|
name: string;
|
|
38
58
|
category?: string;
|
|
39
59
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
60
|
+
/**
|
|
61
|
+
* The structured output a registrar tool advertises for its `outputSchema`
|
|
62
|
+
* — the `ToolRef` output type. Arrays are wrapped into `{ data }` exactly
|
|
63
|
+
* like the advertised schema; no `outputSchema` means `never`, mirroring
|
|
64
|
+
* mcp-use's own `InferToolOutput`.
|
|
65
|
+
*/
|
|
66
|
+
export type RegistrarToolOutput<TOutput> = [TOutput] extends [z.ZodArray<z.ZodTypeAny>] ? {
|
|
67
|
+
data: z.output<TOutput>;
|
|
68
|
+
} : [TOutput] extends [z.ZodTypeAny] ? z.output<TOutput> : never;
|
|
69
|
+
/**
|
|
70
|
+
* The `register` function {@link createToolRegistrar} returns. Its static
|
|
71
|
+
* return type is `void` so hand-written wrappers typed as
|
|
72
|
+
* `ReturnType<typeof createToolRegistrar<C>>` (e.g. a toolset filter that
|
|
73
|
+
* skips registration) keep compiling; at runtime it returns the mcp-use
|
|
74
|
+
* `ToolRef`. Pass `toolRefs: true` for {@link TypedToolRegistrar}.
|
|
75
|
+
*/
|
|
76
|
+
export interface ToolRegistrar<TClient, TUser = unknown> {
|
|
77
|
+
<TShape extends ZodRawShape = ZodRawShape>(config: ToolConfig<TClient, TShape, TUser>): void;
|
|
78
|
+
getRegisteredTools: () => RegisteredToolMeta[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The `register` function `createToolRegistrar(server, client, { toolRefs: true })`
|
|
82
|
+
* returns: each call returns the tool's mcp-use `ToolRef`, typed with the
|
|
83
|
+
* literal tool name, the inferred input and the structured output — export
|
|
84
|
+
* it for `mcp-env.d.ts` / typed `useCallTool`, like a raw `server.tool` ref.
|
|
85
|
+
*/
|
|
86
|
+
export interface TypedToolRegistrar<TClient, TUser = unknown> {
|
|
87
|
+
<TShape extends ZodRawShape = ZodRawShape, const TName extends string = string, TOutput extends z.ZodTypeAny | undefined = undefined>(config: ToolConfig<TClient, TShape, TUser> & {
|
|
88
|
+
name: TName;
|
|
89
|
+
outputSchema?: TOutput;
|
|
90
|
+
}): ToolRef<TName, ToolArgs<TShape>, RegistrarToolOutput<TOutput>>;
|
|
91
|
+
getRegisteredTools: () => RegisteredToolMeta[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Registrar for a module's domain tools: builds the input/output schemas,
|
|
95
|
+
* wraps the handler in {@link withToolErrors}, and mirrors the result into
|
|
96
|
+
* `structuredContent`. Handlers receive `(client, args, ctx)` — `ctx` is
|
|
97
|
+
* mcp-use's per-call context. `options.strictInput` sets the default for
|
|
98
|
+
* every tool's `strictInput`; `options.toolRefs` types `register()`'s return
|
|
99
|
+
* value as the tool's `ToolRef`.
|
|
100
|
+
*/
|
|
101
|
+
export declare function createToolRegistrar<TClient, TUser = never>(server: MCPServer<TUser>, client: TClient, options: TypedToolRefOptions): TypedToolRegistrar<TClient, HandlerUser<TUser>>;
|
|
102
|
+
export declare function createToolRegistrar<TClient, TUser = never>(server: MCPServer<TUser>, client: TClient, options?: ToolRegistrarOptions): ToolRegistrar<TClient, HandlerUser<TUser>>;
|
|
45
103
|
//# sourceMappingURL=register-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-tool.d.ts","sourceRoot":"","sources":["../../src/tools/register-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,C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,OAAO,CAAA;KAAE,GACnF,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAA;IACjE,kBAAkB,EAAE,MAAM,kBAAkB,EAAE,CAAA;CAC/C;AA+BD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,KAAK,GAAG,KAAK,EACxD,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,EACxB,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,mBAAmB,GAC3B,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;AAClD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,KAAK,GAAG,KAAK,EACxD,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,EACxB,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,oBAAoB,GAC7B,aAAa,CAAC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { objectResult, textResult } from "./tool-results.js";
|
|
3
3
|
import { withToolErrors } from "./with-tool-errors.js";
|
|
4
|
+
import { registrarInputSchema, } from "./registrar-shared.js";
|
|
4
5
|
function wrapArraySchema(schema) {
|
|
5
6
|
if (!schema)
|
|
6
7
|
return undefined;
|
|
@@ -29,22 +30,30 @@ function toStructuredContent(result, toolName) {
|
|
|
29
30
|
throw new Error(`Tool "${toolName}" declares an outputSchema but its handler returned a ${kind} value; ` +
|
|
30
31
|
`structured output must be an object or array.`);
|
|
31
32
|
}
|
|
32
|
-
export function createToolRegistrar(server, client) {
|
|
33
|
+
export function createToolRegistrar(server, client, options = {}) {
|
|
33
34
|
const registeredTools = [];
|
|
35
|
+
// Registration is independent of the OAuth user type, which only shapes
|
|
36
|
+
// the callback ctx; the ctx is handed on typed by the registrar instead.
|
|
37
|
+
const target = server;
|
|
34
38
|
function register(config) {
|
|
35
39
|
registeredTools.push({ name: config.name, category: config.category });
|
|
36
|
-
|
|
40
|
+
return target.tool({
|
|
41
|
+
...config.definition,
|
|
42
|
+
// Every registrar-owned key is set explicitly — undefined included —
|
|
43
|
+
// so a cast or plain-JS `definition` cannot smuggle one in.
|
|
37
44
|
name: config.name,
|
|
38
45
|
description: config.description,
|
|
39
|
-
inputSchema: config.inputSchema
|
|
46
|
+
inputSchema: registrarInputSchema(config.inputSchema, config.strictInput ?? options.strictInput ?? false),
|
|
47
|
+
// mcp-use's alias: it reads `inputSchema ?? schema`.
|
|
48
|
+
schema: undefined,
|
|
40
49
|
outputSchema: wrapArraySchema(config.outputSchema),
|
|
41
50
|
annotations: config.annotations,
|
|
42
51
|
},
|
|
43
|
-
// The SDK validates args against the schema above
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const result = await config.handler(client, args);
|
|
52
|
+
// The SDK validates args against the schema above before the callback
|
|
53
|
+
// runs; the public `register` is generic over that shape, this
|
|
54
|
+
// implementation sees the erased `ToolArgs`.
|
|
55
|
+
withToolErrors(async (args, ctx) => {
|
|
56
|
+
const result = await config.handler(client, args, ctx);
|
|
48
57
|
if (config.formatResult) {
|
|
49
58
|
const formatted = textResult(config.formatResult(result, args));
|
|
50
59
|
// When an outputSchema is declared the tool promised structured
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-tool.js","sourceRoot":"","sources":["../../src/tools/register-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"register-tool.js","sourceRoot":"","sources":["../../src/tools/register-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;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AC,CAAC,CAAA;YAC/D,CAAC;YACD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;gBAClD,OAAO,YAAY,CAAC,MAAiC,CAAC,CAAA;YACxD,CAAC;YACD,oEAAoE;YACpE,sEAAsE;YACtE,oEAAoE;YACpE,oEAAoE;YACpE,6BAA6B;YAC7B,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;gBACxB,OAAO,YAAY,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;YAC/D,CAAC;YACD,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC5C,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;YACpD,CAAC;YACD,OAAO,UAAU,CAAC,+BAA+B,CAAC,CAAA;QACpD,CAAC,CAAC,CACH,CAAA;IACH,CAAC;IAED,QAAQ,CAAC,kBAAkB,GAAG,GAAG,EAAE,CAAC,eAAe,CAAA;IAEnD,OAAO,QAAsE,CAAA;AAC/E,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type MCPServer, type ToolAnnotations } from "mcp-use";
|
|
1
|
+
import { type MCPServer, type ToolAnnotations, type ToolRef } from "mcp-use";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { type WidgetToolMetaDefaults } from "../types/meta.js";
|
|
4
4
|
import type { ToolArgs } from "./register-tool.js";
|
|
5
|
-
type
|
|
5
|
+
import { type HandlerUser, type ToolHandlerContext, type ToolRegistrarOptions, type TypedToolRefOptions, type WidgetToolDefinitionPassthrough, type ZodRawShape } from "./registrar-shared.js";
|
|
6
6
|
interface WidgetToolResult {
|
|
7
7
|
text: string;
|
|
8
8
|
structuredContent: Record<string, unknown>;
|
|
@@ -14,7 +14,7 @@ interface WidgetToolResult {
|
|
|
14
14
|
* and binds a view so the host renders its result.
|
|
15
15
|
*/
|
|
16
16
|
export type WidgetToolVisibility = "app" | "model";
|
|
17
|
-
export interface WidgetToolConfig<TClient, TShape extends ZodRawShape = ZodRawShape> {
|
|
17
|
+
export interface WidgetToolConfig<TClient, TShape extends ZodRawShape = ZodRawShape, TUser = unknown> {
|
|
18
18
|
name: string;
|
|
19
19
|
title?: string;
|
|
20
20
|
description: string;
|
|
@@ -53,8 +53,43 @@ export interface WidgetToolConfig<TClient, TShape extends ZodRawShape = ZodRawSh
|
|
|
53
53
|
* Only emitted on model-visible widget tools.
|
|
54
54
|
*/
|
|
55
55
|
invoked?: string;
|
|
56
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Reject unknown input keys with a tool error naming the valid keys
|
|
58
|
+
* instead of silently stripping them (`additionalProperties: false` on the
|
|
59
|
+
* advertised schema). Overrides the registrar's `strictInput` option; off
|
|
60
|
+
* by default in 2.x.
|
|
61
|
+
*/
|
|
62
|
+
strictInput?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Every other mcp-use `ToolDefinition` field, forwarded verbatim to
|
|
65
|
+
* `server.tool` — e.g. `securitySchemes`. `title`, `visibility`, `view`
|
|
66
|
+
* and `_meta` stay registrar-derived (use `title` / `visibility` / `meta`).
|
|
67
|
+
*/
|
|
68
|
+
definition?: WidgetToolDefinitionPassthrough;
|
|
69
|
+
/**
|
|
70
|
+
* The tool body. `ctx` is mcp-use's per-call context ({@link ToolHandlerContext});
|
|
71
|
+
* always passed by the registrar, optional in the type so handlers stay
|
|
72
|
+
* directly callable as `(client, params)`.
|
|
73
|
+
*/
|
|
74
|
+
handler: (client: TClient, params: ToolArgs<TShape>, ctx?: ToolHandlerContext<TUser>) => Promise<WidgetToolResult>;
|
|
57
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The `ToolRef` output type of a widget tool: its declared `outputSchema`,
|
|
78
|
+
* else the `structuredContent` record every widget handler returns.
|
|
79
|
+
*/
|
|
80
|
+
export type WidgetToolOutput<TOutput> = [TOutput] extends [z.ZodTypeAny] ? z.output<TOutput> : WidgetToolResult["structuredContent"];
|
|
81
|
+
/**
|
|
82
|
+
* The `register` function {@link createWidgetToolRegistrar} returns. Its
|
|
83
|
+
* static return type is `void` (wrapper-compatible, like `ToolRegistrar`);
|
|
84
|
+
* at runtime it returns the mcp-use `ToolRef`. Pass `toolRefs: true` for
|
|
85
|
+
* {@link TypedWidgetToolRegistrar}.
|
|
86
|
+
*/
|
|
87
|
+
export type WidgetToolRegistrar<TClient, TUser = unknown> = <TShape extends ZodRawShape = ZodRawShape>(config: WidgetToolConfig<TClient, TShape, TUser>) => void;
|
|
88
|
+
/** The `ToolRef`-returning widget registrar (`toolRefs: true`). */
|
|
89
|
+
export type TypedWidgetToolRegistrar<TClient, TUser = unknown> = <TShape extends ZodRawShape = ZodRawShape, const TName extends string = string, TOutput extends z.ZodTypeAny | undefined = undefined>(config: WidgetToolConfig<TClient, TShape, TUser> & {
|
|
90
|
+
name: TName;
|
|
91
|
+
outputSchema?: TOutput;
|
|
92
|
+
}) => ToolRef<TName, ToolArgs<TShape>, WidgetToolOutput<TOutput>>;
|
|
58
93
|
/**
|
|
59
94
|
* Registrar for widget tools against mcp-use's native view binding.
|
|
60
95
|
*
|
|
@@ -69,7 +104,13 @@ export interface WidgetToolConfig<TClient, TShape extends ZodRawShape = ZodRawSh
|
|
|
69
104
|
* `createFrameworkApp` collects every `view` binding registered this way and
|
|
70
105
|
* primes the view registry with the shared app bundle, so each bound name
|
|
71
106
|
* resolves to the same compiled widget code.
|
|
107
|
+
*
|
|
108
|
+
* Handlers receive `(client, params, ctx)` — `ctx` is mcp-use's per-call
|
|
109
|
+
* context. `options.strictInput` sets the default for every tool's
|
|
110
|
+
* `strictInput`; `options.toolRefs` types `register()`'s return value as the
|
|
111
|
+
* tool's `ToolRef` (returned at runtime either way).
|
|
72
112
|
*/
|
|
73
|
-
export declare function createWidgetToolRegistrar<TClient>(server: MCPServer
|
|
113
|
+
export declare function createWidgetToolRegistrar<TClient, TUser = never>(server: MCPServer<TUser>, client: TClient, metaDefaults: WidgetToolMetaDefaults | undefined, options: TypedToolRefOptions): TypedWidgetToolRegistrar<TClient, HandlerUser<TUser>>;
|
|
114
|
+
export declare function createWidgetToolRegistrar<TClient, TUser = never>(server: MCPServer<TUser>, client: TClient, metaDefaults?: WidgetToolMetaDefaults, options?: ToolRegistrarOptions): WidgetToolRegistrar<TClient, HandlerUser<TUser>>;
|
|
74
115
|
export {};
|
|
75
116
|
//# sourceMappingURL=register-widget-tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-widget-tool.d.ts","sourceRoot":"","sources":["../../src/tools/register-widget-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"register-widget-tool.d.ts","sourceRoot":"","sources":["../../src/tools/register-widget-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;AAC5E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAgC,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAE5F,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,EACpC,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAA;AAE9B,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC3C;AAED;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,OAAO,CAAA;AAElD,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