@miragon/mcp-toolkit-core 0.10.1 → 1.0.1
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 +7 -7
- package/dist/framework/render-view.d.ts +1 -1
- package/dist/framework/render-view.d.ts.map +1 -1
- package/dist/framework/render-view.js +3 -0
- package/dist/framework/render-view.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/middleware/role-filter.d.ts +16 -32
- package/dist/middleware/role-filter.d.ts.map +1 -1
- package/dist/middleware/role-filter.js +10 -22
- package/dist/middleware/role-filter.js.map +1 -1
- package/dist/tools/backend-registry.d.ts +9 -3
- package/dist/tools/backend-registry.d.ts.map +1 -1
- package/dist/tools/backend-registry.js +13 -12
- package/dist/tools/backend-registry.js.map +1 -1
- package/dist/tools/create-framework-app.d.ts +51 -38
- package/dist/tools/create-framework-app.d.ts.map +1 -1
- package/dist/tools/create-framework-app.js +79 -78
- package/dist/tools/create-framework-app.js.map +1 -1
- package/dist/tools/index.d.ts +4 -5
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -3
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/install-toolkit.d.ts +77 -0
- package/dist/tools/install-toolkit.d.ts.map +1 -0
- package/dist/tools/install-toolkit.js +85 -0
- package/dist/tools/install-toolkit.js.map +1 -0
- package/dist/tools/register-catalogue-tool.d.ts +1 -1
- package/dist/tools/register-catalogue-tool.d.ts.map +1 -1
- package/dist/tools/register-catalogue-tool.js +2 -3
- package/dist/tools/register-catalogue-tool.js.map +1 -1
- package/dist/tools/register-dashboard-tools.d.ts +1 -1
- package/dist/tools/register-dashboard-tools.d.ts.map +1 -1
- package/dist/tools/register-dashboard-tools.js +6 -6
- package/dist/tools/register-dashboard-tools.js.map +1 -1
- package/dist/tools/register-framework-tools.d.ts +15 -47
- package/dist/tools/register-framework-tools.d.ts.map +1 -1
- package/dist/tools/register-framework-tools.js +31 -63
- package/dist/tools/register-framework-tools.js.map +1 -1
- package/dist/tools/register-tool.d.ts +1 -1
- package/dist/tools/register-tool.d.ts.map +1 -1
- package/dist/tools/register-tool.js +14 -8
- package/dist/tools/register-tool.js.map +1 -1
- package/dist/tools/register-widget-tool.d.ts +35 -11
- package/dist/tools/register-widget-tool.d.ts.map +1 -1
- package/dist/tools/register-widget-tool.js +57 -30
- package/dist/tools/register-widget-tool.js.map +1 -1
- package/dist/tools/tool-results.d.ts +46 -0
- package/dist/tools/tool-results.d.ts.map +1 -0
- package/dist/tools/tool-results.js +39 -0
- package/dist/tools/tool-results.js.map +1 -0
- package/dist/tools/with-tool-errors.d.ts +12 -6
- package/dist/tools/with-tool-errors.d.ts.map +1 -1
- package/dist/tools/with-tool-errors.js +12 -6
- package/dist/tools/with-tool-errors.js.map +1 -1
- package/dist/types/app.d.ts +10 -7
- package/dist/types/app.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/meta.d.ts +73 -56
- package/dist/types/meta.d.ts.map +1 -1
- package/dist/types/meta.js +49 -53
- package/dist/types/meta.js.map +1 -1
- package/package.json +14 -6
- package/dist/tools/app-resource-uri.d.ts +0 -28
- package/dist/tools/app-resource-uri.d.ts.map +0 -1
- package/dist/tools/app-resource-uri.js +0 -30
- package/dist/tools/app-resource-uri.js.map +0 -1
- package/dist/tools/tool-call-name.d.ts +0 -53
- package/dist/tools/tool-call-name.d.ts.map +0 -1
- package/dist/tools/tool-call-name.js +0 -92
- package/dist/tools/tool-call-name.js.map +0 -1
|
@@ -1,37 +1,17 @@
|
|
|
1
|
-
import { type MCPServer } from "mcp-use
|
|
1
|
+
import { type MCPServer } from "mcp-use";
|
|
2
2
|
import type { StepRegistry } from "../registry/step-registry.js";
|
|
3
3
|
import type { WidgetRegistry } from "../registry/widget-registry.js";
|
|
4
4
|
import type { AppConfig, AppPlugin } from "../types/index.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* from the same value.
|
|
10
|
-
*/
|
|
11
|
-
export interface AppResourceCsp {
|
|
12
|
-
/** Origins allowed for fetch/XHR/WebSocket from inside the widget iframe. */
|
|
13
|
-
connectDomains?: string[];
|
|
14
|
-
/** Origins allowed for images, scripts, stylesheets, fonts. */
|
|
15
|
-
resourceDomains?: string[];
|
|
16
|
-
/** Allowed iframe origins. */
|
|
17
|
-
frameDomains?: string[];
|
|
18
|
-
/** Allowed `base-uri` origins. */
|
|
19
|
-
baseUriDomains?: string[];
|
|
20
|
-
}
|
|
5
|
+
import { type AppResourceCsp } from "../types/meta.js";
|
|
6
|
+
export type { AppResourceCsp } from "../types/meta.js";
|
|
7
|
+
/** View name (and thus `ui://views/render-view.html` URI) bound to `render-view`. */
|
|
8
|
+
export declare const RENDER_VIEW_NAME = "render-view";
|
|
21
9
|
export interface RegisterFrameworkToolsOptions {
|
|
22
10
|
stepRegistry: StepRegistry;
|
|
23
11
|
widgetRegistry: WidgetRegistry;
|
|
24
12
|
config: AppConfig;
|
|
25
13
|
appConfigs: Record<string, Record<string, unknown>>;
|
|
26
14
|
plugins: AppPlugin[];
|
|
27
|
-
/**
|
|
28
|
-
* The MCP UI resource URI that hosts the widget bundle (typically the
|
|
29
|
-
* compiled `mcp-app.html`). Referenced by `render-view` / `refresh-view`
|
|
30
|
-
* via the `_meta.ui.resourceUri` convention.
|
|
31
|
-
*/
|
|
32
|
-
resourceUri: string;
|
|
33
|
-
/** Absolute path to the bundled `mcp-app.html` served behind `resourceUri`. */
|
|
34
|
-
htmlPath: string;
|
|
35
15
|
/**
|
|
36
16
|
* Tool name for the refresh hook the UI calls to re-run the pipeline.
|
|
37
17
|
* The `@miragon/mcp-toolkit-ui` default matches this — change both in
|
|
@@ -48,36 +28,24 @@ export interface RegisterFrameworkToolsOptions {
|
|
|
48
28
|
*/
|
|
49
29
|
builderAvailable?: boolean;
|
|
50
30
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* resource advertises no CSP, which ext-apps hosts treat as the secure
|
|
56
|
-
* "no network" default; fine for a fully inlined bundle.
|
|
57
|
-
*/
|
|
58
|
-
baseUrl?: string;
|
|
59
|
-
/**
|
|
60
|
-
* Additional CSP origins advertised on the widget resource
|
|
61
|
-
* (`_meta.ui.csp`) and, snake_cased, on widget tools (`openai/widgetCSP`).
|
|
62
|
-
* Merged with the origin derived from {@link baseUrl}.
|
|
31
|
+
* Additional CSP origins advertised on the view resources (`_meta.ui.csp`,
|
|
32
|
+
* via each tool's `view.csp`) and, snake_cased, on widget tools
|
|
33
|
+
* (`openai/widgetCSP`). The server origin is appended by mcp-use itself at
|
|
34
|
+
* emission time, so this only needs third-party origins (e.g. a CDN).
|
|
63
35
|
*/
|
|
64
36
|
csp?: AppResourceCsp;
|
|
65
37
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Merges the configured CSP with the server origin derived from `baseUrl`
|
|
68
|
-
* (injected into connect/resource/baseUri domains, deduplicated) — the same
|
|
69
|
-
* enrichment native mcp-use applies to its widget definitions. Returns
|
|
70
|
-
* `undefined` when there is nothing to advertise.
|
|
71
|
-
*/
|
|
72
|
-
export declare function buildAppResourceCsp(baseUrl: string | undefined, csp: AppResourceCsp | undefined): AppResourceCsp | undefined;
|
|
73
38
|
/**
|
|
74
39
|
* Registers the framework-level MCP tools that make up a Miranum-style MCP
|
|
75
|
-
* app: the manifest tool, the `render-view` / `refresh-view` pair,
|
|
76
|
-
*
|
|
40
|
+
* app: the manifest tool, the `render-view` / `refresh-view` pair, plus any
|
|
41
|
+
* widget-action tools each plugin contributes. `render-view` is bound to its
|
|
42
|
+
* own view ({@link RENDER_VIEW_NAME}); the view resource itself is emitted by
|
|
43
|
+
* mcp-use from the registry `createFrameworkApp` primes with the app bundle.
|
|
77
44
|
*
|
|
78
45
|
* Intended to be called from `createFrameworkApp`, but exposed directly so
|
|
79
46
|
* consumers that build their own server can still opt into the framework
|
|
80
|
-
* tools without the rest of the boot helper
|
|
47
|
+
* tools without the rest of the boot helper — such consumers must prime the
|
|
48
|
+
* view registry themselves (see `createFrameworkApp`).
|
|
81
49
|
*/
|
|
82
50
|
export declare function registerFrameworkTools(server: MCPServer, options: RegisterFrameworkToolsOptions): void;
|
|
83
51
|
//# sourceMappingURL=register-framework-tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-framework-tools.d.ts","sourceRoot":"","sources":["../../src/tools/register-framework-tools.ts"],"names":[],"mappings":"
|
|
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;AAMxC,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;AAoDD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,6BAA6B,GACrC,IAAI,CAwFN"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import { createMcpAppsResource, RESOURCE_MIME_TYPE, text } from "mcp-use/server";
|
|
3
1
|
import { z } from "zod";
|
|
2
|
+
import { textResult } from "./tool-results.js";
|
|
4
3
|
import { getFrameworkManifest } from "../framework/manifest.js";
|
|
5
4
|
import { layoutInputSchema } from "../framework/layout-schemas.js";
|
|
6
5
|
import { renderView } from "../framework/render-view.js";
|
|
7
|
-
import {
|
|
6
|
+
import { appsSdkMeta, viewResourceUri, } from "../types/meta.js";
|
|
7
|
+
/** View name (and thus `ui://views/render-view.html` URI) bound to `render-view`. */
|
|
8
|
+
export const RENDER_VIEW_NAME = "render-view";
|
|
8
9
|
const stepRefSchema = z.object({
|
|
9
10
|
id: z.string().describe("Context key under which the step's result is stored, e.g. 'invoice'."),
|
|
10
11
|
step: z.string().describe("Registered step id, e.g. 'lexoffice:load-invoice'."),
|
|
@@ -29,36 +30,6 @@ function extractUserId(ctx) {
|
|
|
29
30
|
const user = ctx?.auth?.user;
|
|
30
31
|
return typeof user?.userId === "string" ? user.userId : undefined;
|
|
31
32
|
}
|
|
32
|
-
function withOrigin(list, origin) {
|
|
33
|
-
if (!list)
|
|
34
|
-
return [origin];
|
|
35
|
-
return list.includes(origin) ? list : [...list, origin];
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Merges the configured CSP with the server origin derived from `baseUrl`
|
|
39
|
-
* (injected into connect/resource/baseUri domains, deduplicated) — the same
|
|
40
|
-
* enrichment native mcp-use applies to its widget definitions. Returns
|
|
41
|
-
* `undefined` when there is nothing to advertise.
|
|
42
|
-
*/
|
|
43
|
-
export function buildAppResourceCsp(baseUrl, csp) {
|
|
44
|
-
let origin;
|
|
45
|
-
if (baseUrl) {
|
|
46
|
-
try {
|
|
47
|
-
origin = new URL(baseUrl).origin;
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
// Invalid baseUrl — skip origin injection rather than failing boot.
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (!origin)
|
|
54
|
-
return csp;
|
|
55
|
-
return {
|
|
56
|
-
...csp,
|
|
57
|
-
connectDomains: withOrigin(csp?.connectDomains, origin),
|
|
58
|
-
resourceDomains: withOrigin(csp?.resourceDomains, origin),
|
|
59
|
-
baseUriDomains: withOrigin(csp?.baseUriDomains, origin),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
33
|
/** Converts the camelCase resource CSP into the snake_cased `openai/widgetCSP` shape. */
|
|
63
34
|
function toWidgetCspMeta(csp) {
|
|
64
35
|
const meta = {};
|
|
@@ -74,17 +45,19 @@ function toWidgetCspMeta(csp) {
|
|
|
74
45
|
}
|
|
75
46
|
/**
|
|
76
47
|
* Registers the framework-level MCP tools that make up a Miranum-style MCP
|
|
77
|
-
* app: the manifest tool, the `render-view` / `refresh-view` pair,
|
|
78
|
-
*
|
|
48
|
+
* app: the manifest tool, the `render-view` / `refresh-view` pair, plus any
|
|
49
|
+
* widget-action tools each plugin contributes. `render-view` is bound to its
|
|
50
|
+
* own view ({@link RENDER_VIEW_NAME}); the view resource itself is emitted by
|
|
51
|
+
* mcp-use from the registry `createFrameworkApp` primes with the app bundle.
|
|
79
52
|
*
|
|
80
53
|
* Intended to be called from `createFrameworkApp`, but exposed directly so
|
|
81
54
|
* consumers that build their own server can still opt into the framework
|
|
82
|
-
* tools without the rest of the boot helper
|
|
55
|
+
* tools without the rest of the boot helper — such consumers must prime the
|
|
56
|
+
* view registry themselves (see `createFrameworkApp`).
|
|
83
57
|
*/
|
|
84
58
|
export function registerFrameworkTools(server, options) {
|
|
85
|
-
const { stepRegistry, widgetRegistry, config, appConfigs, plugins,
|
|
86
|
-
const
|
|
87
|
-
const widgetCSP = resourceCsp ? toWidgetCspMeta(resourceCsp) : undefined;
|
|
59
|
+
const { stepRegistry, widgetRegistry, config, appConfigs, plugins, refreshToolName = "refresh-view", builderAvailable = false, csp, } = options;
|
|
60
|
+
const widgetCSP = csp ? toWidgetCspMeta(csp) : undefined;
|
|
88
61
|
server.tool({
|
|
89
62
|
name: "get-framework-manifest",
|
|
90
63
|
description: "Returns all active apps, available pipeline steps, widgets, and their key contracts. Call this first to discover which step-ids and widget-ids exist — and which `props` each widget accepts (see each widget's `propsSchema`) — before building a view.",
|
|
@@ -93,7 +66,7 @@ export function registerFrameworkTools(server, options) {
|
|
|
93
66
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
94
67
|
async () => {
|
|
95
68
|
const manifest = getFrameworkManifest(stepRegistry, widgetRegistry, config);
|
|
96
|
-
return
|
|
69
|
+
return textResult(JSON.stringify(manifest, null, 2));
|
|
97
70
|
});
|
|
98
71
|
const renderHandler = async (params, ctx) => {
|
|
99
72
|
return renderView({
|
|
@@ -113,9 +86,18 @@ export function registerFrameworkTools(server, options) {
|
|
|
113
86
|
name: "render-view",
|
|
114
87
|
title: "Render View",
|
|
115
88
|
description: "Builds a UI from pipeline steps and widgets. IMPORTANT: call get-framework-manifest first to learn which step-ids and widget-ids are available — only use ids listed there. Each widget entry's optional `propsSchema` (JSON Schema) describes the per-instance `props` you can set on a layout cell to scope or configure that widget (e.g. one tab per `processDefinitionKey`).",
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
89
|
+
inputSchema: renderViewSchema,
|
|
90
|
+
view: {
|
|
91
|
+
name: RENDER_VIEW_NAME,
|
|
92
|
+
description: "Interactive view composed of pipeline-driven widgets",
|
|
93
|
+
...(csp ? { csp } : {}),
|
|
94
|
+
},
|
|
95
|
+
// The view envelope is dynamic (steps/layout are call-time arguments);
|
|
96
|
+
// `passthrough` satisfies the view binding's outputSchema requirement
|
|
97
|
+
// without stripping envelope keys on SDK-side validation.
|
|
98
|
+
outputSchema: z.object({}).passthrough(),
|
|
99
|
+
_meta: appsSdkMeta({
|
|
100
|
+
resourceUri: viewResourceUri(RENDER_VIEW_NAME),
|
|
119
101
|
title: "Render View",
|
|
120
102
|
invoking: "Rendering view...",
|
|
121
103
|
invoked: "View rendered",
|
|
@@ -124,31 +106,17 @@ export function registerFrameworkTools(server, options) {
|
|
|
124
106
|
}),
|
|
125
107
|
}, renderHandler);
|
|
126
108
|
for (const plugin of plugins) {
|
|
127
|
-
plugin.registerWidgetTools?.(server,
|
|
109
|
+
plugin.registerWidgetTools?.(server, { widgetCSP, viewCsp: csp });
|
|
128
110
|
}
|
|
129
111
|
server.tool({
|
|
130
112
|
name: refreshToolName,
|
|
131
113
|
title: "Refresh View",
|
|
132
114
|
description: "Re-runs the pipeline with the stored parameters.",
|
|
133
|
-
|
|
134
|
-
|
|
115
|
+
inputSchema: renderViewSchema,
|
|
116
|
+
// App-only: called by the already-rendered view, never by the model —
|
|
117
|
+
// and no view binding, since its result replaces state inside the
|
|
118
|
+
// existing iframe rather than rendering a new one.
|
|
119
|
+
visibility: "app",
|
|
135
120
|
}, renderHandler);
|
|
136
|
-
// The resource `_meta.ui.csp` must appear on the LISTING (resources/list)
|
|
137
|
-
// and on the READ contents — ext-apps hosts read it from the contents when
|
|
138
|
-
// sandboxing the iframe. `createMcpAppsResource` produces exactly the shape
|
|
139
|
-
// native mcp-use emits (mimeType `text/html;profile=mcp-app` + `_meta.ui`).
|
|
140
|
-
const resourceMeta = resourceCsp ? { ui: { csp: resourceCsp } } : undefined;
|
|
141
|
-
server.resource({
|
|
142
|
-
name: "mcp-app-html",
|
|
143
|
-
uri: resourceUri,
|
|
144
|
-
mimeType: RESOURCE_MIME_TYPE,
|
|
145
|
-
...(resourceMeta ? { _meta: resourceMeta } : {}),
|
|
146
|
-
}, async () => {
|
|
147
|
-
// Read lazily per request so dev servers pick up a rebuilt bundle
|
|
148
|
-
// without a restart (same behaviour as before).
|
|
149
|
-
const html = await fs.readFile(htmlPath, "utf-8");
|
|
150
|
-
const uiResource = createMcpAppsResource(resourceUri, html, resourceCsp ? { csp: resourceCsp } : undefined);
|
|
151
|
-
return { contents: [uiResource.resource] };
|
|
152
|
-
});
|
|
153
121
|
}
|
|
154
122
|
//# sourceMappingURL=register-framework-tools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-framework-tools.js","sourceRoot":"","sources":["../../src/tools/register-framework-tools.ts"],"names":[],"mappings":"
|
|
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;AAIxD,OAAO,EACL,WAAW,EACX,eAAe,GAGhB,MAAM,kBAAkB,CAAA;AAIzB,qFAAqF;AACrF,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAA;AAgC7C,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sEAAsE,CAAC;IAC/F,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oDAAoD,CAAC;IAC/E,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,IAAI,EAAE,CAAC;SACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EA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;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,MAAM,CAAC,mBAAmB,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAA;IACnE,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-tool.d.ts","sourceRoot":"","sources":["../../src/tools/register-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,
|
|
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,CAAA;AACxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,CAAA;AAK/C;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,CAAC,MAAM,SAAS,WAAW,GAAG,WAAW,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;AAE7F,MAAM,WAAW,UAAU,CAAC,OAAO,EAAE,MAAM,SAAS,WAAW,GAAG,WAAW;IAC3E,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,CAAC,CAAC,UAAU,CAAA;IAC3B,WAAW,CAAC,EAAE;QACZ,YAAY,CAAC,EAAE,OAAO,CAAA;QACtB,eAAe,CAAC,EAAE,OAAO,CAAA;QACzB,cAAc,CAAC,EAAE,OAAO,CAAA;QACxB,aAAa,CAAC,EAAE,OAAO,CAAA;KACxB,CAAA;IACD,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACtE,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,MAAM,CAAA;CACnE;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AA+BD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO;KAG3D,MAAM,SAAS,WAAW,wBAAwB,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC;;EAyDhG"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { array, object, text } from "mcp-use/server";
|
|
2
1
|
import { z } from "zod";
|
|
2
|
+
import { objectResult, textResult } from "./tool-results.js";
|
|
3
3
|
import { withToolErrors } from "./with-tool-errors.js";
|
|
4
4
|
function wrapArraySchema(schema) {
|
|
5
5
|
if (!schema)
|
|
@@ -36,7 +36,7 @@ export function createToolRegistrar(server, client) {
|
|
|
36
36
|
server.tool({
|
|
37
37
|
name: config.name,
|
|
38
38
|
description: config.description,
|
|
39
|
-
|
|
39
|
+
inputSchema: config.inputSchema ? z.object(config.inputSchema) : undefined,
|
|
40
40
|
outputSchema: wrapArraySchema(config.outputSchema),
|
|
41
41
|
annotations: config.annotations,
|
|
42
42
|
},
|
|
@@ -46,7 +46,7 @@ export function createToolRegistrar(server, client) {
|
|
|
46
46
|
const args = looseArgs;
|
|
47
47
|
const result = await config.handler(client, args);
|
|
48
48
|
if (config.formatResult) {
|
|
49
|
-
const formatted =
|
|
49
|
+
const formatted = textResult(config.formatResult(result, args));
|
|
50
50
|
// When an outputSchema is declared the tool promised structured
|
|
51
51
|
// output, so mirror the raw result into structuredContent alongside
|
|
52
52
|
// the human-readable text instead of dropping it. Without an
|
|
@@ -57,10 +57,16 @@ export function createToolRegistrar(server, client) {
|
|
|
57
57
|
return formatted;
|
|
58
58
|
}
|
|
59
59
|
if (Array.isArray(result)) {
|
|
60
|
-
|
|
60
|
+
// Wrap here rather than delegating to mcp-use's `array()` helper.
|
|
61
|
+
// Up to 1.34 that helper produced `structuredContent: { data: [...] }`;
|
|
62
|
+
// the 2.x shim emits the bare array instead, which contradicts the
|
|
63
|
+
// `z.object({ data: <array> })` outputSchema `wrapArraySchema`
|
|
64
|
+
// declares — and MCP requires an object there regardless. Owning the
|
|
65
|
+
// wrap keeps the declared schema and the emitted payload in step.
|
|
66
|
+
return objectResult(toStructuredContent(result, config.name));
|
|
61
67
|
}
|
|
62
68
|
if (result !== null && typeof result === "object") {
|
|
63
|
-
return
|
|
69
|
+
return objectResult(result);
|
|
64
70
|
}
|
|
65
71
|
// A declared outputSchema requires an object `structuredContent`; a
|
|
66
72
|
// scalar/null/undefined result would make the SDK reject the response
|
|
@@ -68,12 +74,12 @@ export function createToolRegistrar(server, client) {
|
|
|
68
74
|
// (see toStructuredContent). Without an outputSchema, the text-only
|
|
69
75
|
// fallbacks below are valid.
|
|
70
76
|
if (config.outputSchema) {
|
|
71
|
-
return
|
|
77
|
+
return objectResult(toStructuredContent(result, config.name));
|
|
72
78
|
}
|
|
73
79
|
if (result !== null && result !== undefined) {
|
|
74
|
-
return
|
|
80
|
+
return textResult(JSON.stringify(result, null, 2));
|
|
75
81
|
}
|
|
76
|
-
return
|
|
82
|
+
return textResult("Success (no content returned)");
|
|
77
83
|
}));
|
|
78
84
|
}
|
|
79
85
|
register.getRegisteredTools = () => registeredTools;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-tool.js","sourceRoot":"","sources":["../../src/tools/register-tool.ts"],"names":[],"mappings":"
|
|
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;AA8CtD,SAAS,eAAe,CAAC,MAAgC;IACvD,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAA;IAC7B,OAAO,MAAM,YAAY,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;AAC3E,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAS,mBAAmB,CAAC,MAAe,EAAE,QAAgB;IAC5D,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IAClD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAiC,CAAA;IAC3F,MAAM,IAAI,GAAG,MAAM,KAAK,IAAI,CA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BAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAA;gBACtF,CAAC;gBACD,OAAO,SAAS,CAAA;YAClB,CAAC;YACD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1B,kEAAkE;gBAClE,wEAAwE;gBACxE,mEAAmE;gBACnE,+DAA+D;gBAC/D,qEAAqE;gBACrE,kEAAkE;gBAClE,OAAO,YAAY,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,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,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type MCPServer, type ToolAnnotations } from "mcp-use
|
|
1
|
+
import { type MCPServer, type ToolAnnotations } 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";
|
|
@@ -8,11 +8,12 @@ interface WidgetToolResult {
|
|
|
8
8
|
structuredContent: Record<string, unknown>;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* Who may call or see the tool. `"app"` hides the tool from the LLM tool
|
|
12
|
+
* surface while keeping it callable from a widget (emitted natively by
|
|
13
|
+
* mcp-use as `_meta.ui.visibility: ["app"]`); `"model"` exposes it to the LLM
|
|
14
|
+
* and binds a view so the host renders its result.
|
|
14
15
|
*/
|
|
15
|
-
export type WidgetToolVisibility = "app" | "model"
|
|
16
|
+
export type WidgetToolVisibility = "app" | "model";
|
|
16
17
|
export interface WidgetToolConfig<TClient, TShape extends ZodRawShape = ZodRawShape> {
|
|
17
18
|
name: string;
|
|
18
19
|
title?: string;
|
|
@@ -21,15 +22,23 @@ export interface WidgetToolConfig<TClient, TShape extends ZodRawShape = ZodRawSh
|
|
|
21
22
|
/** MCP tool annotations (e.g. `readOnlyHint`) advertised to the host. */
|
|
22
23
|
annotations?: ToolAnnotations;
|
|
23
24
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* Defaults to `"app"` (the historical behaviour — widget tools are
|
|
26
|
+
* app-only). Use `"model"` for a widget-RENDERING tool: it is bound to its
|
|
27
|
+
* own view (named after the tool) and gets the Apps SDK `openai/*` keys.
|
|
27
28
|
*/
|
|
28
29
|
visibility?: WidgetToolVisibility;
|
|
30
|
+
/**
|
|
31
|
+
* Structured-output schema. Model-visible (view-bound) tools require one —
|
|
32
|
+
* mcp-use refuses a `view` binding without it — so the registrar defaults
|
|
33
|
+
* to a passthrough object matching `WidgetToolResult.structuredContent`.
|
|
34
|
+
* Declare a precise schema to give hosts and view hooks typed output.
|
|
35
|
+
*/
|
|
36
|
+
outputSchema?: z.ZodTypeAny;
|
|
29
37
|
/**
|
|
30
38
|
* Extra `_meta` entries merged flat into the emitted `_meta`, alongside the
|
|
31
|
-
* `
|
|
32
|
-
*
|
|
39
|
+
* `openai/*` block this registrar builds (collisions: the registrar wins).
|
|
40
|
+
* The `ui` namespace is owned by mcp-use (derived from `view`/`visibility`)
|
|
41
|
+
* and must not be stamped here.
|
|
33
42
|
*/
|
|
34
43
|
meta?: Record<string, unknown>;
|
|
35
44
|
/**
|
|
@@ -46,6 +55,21 @@ export interface WidgetToolConfig<TClient, TShape extends ZodRawShape = ZodRawSh
|
|
|
46
55
|
invoked?: string;
|
|
47
56
|
handler: (client: TClient, params: ToolArgs<TShape>) => Promise<WidgetToolResult>;
|
|
48
57
|
}
|
|
49
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Registrar for widget tools against mcp-use's native view binding.
|
|
60
|
+
*
|
|
61
|
+
* Model-visible tools are bound to a view named after the tool
|
|
62
|
+
* (`view: { name: <tool name> }`); mcp-use derives the MCP Apps wire keys
|
|
63
|
+
* (`_meta.ui.resourceUri`, flat `ui/resourceUri`) from that binding, and the
|
|
64
|
+
* registrar adds the Apps SDK `openai/*` keys pointing at the same resource
|
|
65
|
+
* (`viewResourceUri(<tool name>)`). App-only tools carry the native
|
|
66
|
+
* `visibility: "app"` and no view — their results feed an already-rendered
|
|
67
|
+
* widget via `callTool`.
|
|
68
|
+
*
|
|
69
|
+
* `createFrameworkApp` collects every `view` binding registered this way and
|
|
70
|
+
* primes the view registry with the shared app bundle, so each bound name
|
|
71
|
+
* resolves to the same compiled widget code.
|
|
72
|
+
*/
|
|
73
|
+
export declare function createWidgetToolRegistrar<TClient>(server: MCPServer, client: TClient, metaDefaults?: WidgetToolMetaDefaults): <TShape extends ZodRawShape = ZodRawShape>(config: WidgetToolConfig<TClient, TShape>) => void;
|
|
50
74
|
export {};
|
|
51
75
|
//# 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,
|
|
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;AAC9D,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;AAElD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,CAAA;AAK/C,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,MAAM,WAAW,gBAAgB,CAAC,OAAO,EAAE,MAAM,SAAS,WAAW,GAAG,WAAW;IACjF,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,yEAAyE;IACzE,WAAW,CAAC,EAAE,eAAe,CAAA;IAC7B;;;;OAIG;IACH,UAAU,CAAC,EAAE,oBAAoB,CAAA;IACjC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,CAAC,CAAC,UAAU,CAAA;IAC3B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAA;CAClF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAC/C,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,OAAO,EACf,YAAY,CAAC,EAAE,sBAAsB,IAEZ,MAAM,SAAS,WAAW,GAAG,WAAW,EAC/D,QAAQ,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,UA6D5C"}
|
|
@@ -1,45 +1,72 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { appsSdkMeta, viewResourceUri } from "../types/meta.js";
|
|
3
3
|
import { withToolErrors } from "./with-tool-errors.js";
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Registrar for widget tools against mcp-use's native view binding.
|
|
6
|
+
*
|
|
7
|
+
* Model-visible tools are bound to a view named after the tool
|
|
8
|
+
* (`view: { name: <tool name> }`); mcp-use derives the MCP Apps wire keys
|
|
9
|
+
* (`_meta.ui.resourceUri`, flat `ui/resourceUri`) from that binding, and the
|
|
10
|
+
* registrar adds the Apps SDK `openai/*` keys pointing at the same resource
|
|
11
|
+
* (`viewResourceUri(<tool name>)`). App-only tools carry the native
|
|
12
|
+
* `visibility: "app"` and no view — their results feed an already-rendered
|
|
13
|
+
* widget via `callTool`.
|
|
14
|
+
*
|
|
15
|
+
* `createFrameworkApp` collects every `view` binding registered this way and
|
|
16
|
+
* primes the view registry with the shared app bundle, so each bound name
|
|
17
|
+
* resolves to the same compiled widget code.
|
|
18
|
+
*/
|
|
19
|
+
export function createWidgetToolRegistrar(server, client, metaDefaults) {
|
|
10
20
|
return function register(config) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
// the LLM still sees them; otherwise mark app-only. The `resourceUri` is
|
|
14
|
-
// always present so the host knows which bundle renders the result.
|
|
15
|
-
// Model-visible tools additionally get the dual-protocol widget contract
|
|
16
|
-
// (flat `ui/resourceUri` + `openai/*` keys) ext-apps hosts key on.
|
|
17
|
-
const ui = uiMeta({
|
|
18
|
-
resourceUri,
|
|
19
|
-
appOnly: app && !model,
|
|
20
|
-
title: config.title ?? config.name,
|
|
21
|
-
invoking: config.invoking,
|
|
22
|
-
invoked: config.invoked,
|
|
23
|
-
widgetDescription: config.description,
|
|
24
|
-
widgetCSP: metaDefaults?.widgetCSP,
|
|
25
|
-
});
|
|
26
|
-
server.tool({
|
|
21
|
+
const model = config.visibility === "model";
|
|
22
|
+
const definition = {
|
|
27
23
|
name: config.name,
|
|
28
24
|
title: config.title,
|
|
29
25
|
description: config.description,
|
|
30
|
-
|
|
26
|
+
inputSchema: config.inputSchema ? z.object(config.inputSchema) : undefined,
|
|
31
27
|
annotations: config.annotations,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
withToolErrors(async (looseParams) => {
|
|
28
|
+
};
|
|
29
|
+
const callback = withToolErrors(async (looseParams) => {
|
|
30
|
+
// The SDK validates params against the schema above, so the loose
|
|
31
|
+
// callback param is safely the handler's precise `ToolArgs<TShape>`.
|
|
37
32
|
const result = await config.handler(client, looseParams);
|
|
38
33
|
return {
|
|
39
34
|
content: [{ type: "text", text: result.text }],
|
|
40
35
|
structuredContent: result.structuredContent,
|
|
41
36
|
};
|
|
42
|
-
})
|
|
37
|
+
});
|
|
38
|
+
if (!model) {
|
|
39
|
+
server.tool({
|
|
40
|
+
...definition,
|
|
41
|
+
visibility: "app",
|
|
42
|
+
outputSchema: config.outputSchema,
|
|
43
|
+
...(config.meta ? { _meta: config.meta } : {}),
|
|
44
|
+
}, callback);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
server.tool({
|
|
48
|
+
...definition,
|
|
49
|
+
view: {
|
|
50
|
+
name: config.name,
|
|
51
|
+
description: config.description,
|
|
52
|
+
...(metaDefaults?.viewCsp ? { csp: metaDefaults.viewCsp } : {}),
|
|
53
|
+
},
|
|
54
|
+
// A view binding requires an outputSchema; `passthrough` matches the
|
|
55
|
+
// free-form `WidgetToolResult.structuredContent` without stripping
|
|
56
|
+
// keys on SDK-side validation.
|
|
57
|
+
outputSchema: config.outputSchema ?? z.object({}).passthrough(),
|
|
58
|
+
_meta: {
|
|
59
|
+
...config.meta,
|
|
60
|
+
...appsSdkMeta({
|
|
61
|
+
resourceUri: viewResourceUri(config.name),
|
|
62
|
+
title: config.title ?? config.name,
|
|
63
|
+
invoking: config.invoking,
|
|
64
|
+
invoked: config.invoked,
|
|
65
|
+
widgetDescription: config.description,
|
|
66
|
+
widgetCSP: metaDefaults?.widgetCSP,
|
|
67
|
+
}),
|
|
68
|
+
},
|
|
69
|
+
}, callback);
|
|
43
70
|
};
|
|
44
71
|
}
|
|
45
72
|
//# sourceMappingURL=register-widget-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-widget-tool.js","sourceRoot":"","sources":["../../src/tools/register-widget-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"register-widget-tool.js","sourceRoot":"","sources":["../../src/tools/register-widget-tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,eAAe,EAA+B,MAAM,kBAAkB,CAAA;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AA+DtD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAiB,EACjB,MAAe,EACf,YAAqC;IAErC,OAAO,SAAS,QAAQ,CACtB,MAAyC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,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChE;YACD,qEAAqE;YACrE,mEAAmE;YACnE,+BAA+B;YAC/B,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE;YAC/D,KAAK,EAAE;gBACL,GAAG,MAAM,CAAC,IAAI;gBACd,GAAG,WAAW,CAAC;oBACb,WAAW,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC;oBACzC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI;oBAClC,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,iBAAiB,EAAE,MAAM,CAAC,WAAW;oBACrC,SAAS,EAAE,YAAY,EAAE,SAAS;iBACnC,CAAC;aACH;SACF,EACD,QAAQ,CACT,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toolkit-owned `CallToolResult` builders, byte-for-byte equivalent to the
|
|
3
|
+
* mcp-use v1 response helpers (`text` / `object` / `error`) the registrars
|
|
4
|
+
* used to import. The v2 migration guide deprecates those helpers in favour
|
|
5
|
+
* of raw result structures; owning the three shapes the toolkit actually
|
|
6
|
+
* emits keeps the wire output identical across the swap and survives their
|
|
7
|
+
* eventual upstream removal.
|
|
8
|
+
*/
|
|
9
|
+
/** A plain-text tool result (`text/plain` mime hint), as mcp-use's `text()` emitted. */
|
|
10
|
+
export declare function textResult(content: string): {
|
|
11
|
+
content: {
|
|
12
|
+
type: "text";
|
|
13
|
+
text: string;
|
|
14
|
+
}[];
|
|
15
|
+
_meta: {
|
|
16
|
+
mimeType: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* An object tool result: pretty-printed JSON text plus `structuredContent`,
|
|
21
|
+
* as mcp-use's `object()` emitted for non-array payloads (the registrars wrap
|
|
22
|
+
* arrays into `{ data }` before calling this — see `toStructuredContent`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function objectResult<T extends Record<string, unknown>>(data: T): {
|
|
25
|
+
content: {
|
|
26
|
+
type: "text";
|
|
27
|
+
text: string;
|
|
28
|
+
}[];
|
|
29
|
+
structuredContent: T;
|
|
30
|
+
_meta: {
|
|
31
|
+
mimeType: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* An error tool result. The literal `isError: true` matters: tools with an
|
|
36
|
+
* `outputSchema` (every view-bound tool) have a callback type demanding
|
|
37
|
+
* either matching `structuredContent` or an explicit `isError: true` result.
|
|
38
|
+
*/
|
|
39
|
+
export declare function errorResult(message: string): {
|
|
40
|
+
isError: true;
|
|
41
|
+
content: {
|
|
42
|
+
type: "text";
|
|
43
|
+
text: string;
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=tool-results.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-results.d.ts","sourceRoot":"","sources":["../../src/tools/tool-results.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,wFAAwF;AACxF,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM;;;;;;;;EAKzC;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC;;;;;;;;;EAMtE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM;;;;;;EAK1C"}
|