@miragon/mcp-toolkit-core 2.5.0 → 2.7.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,51 +1,48 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { appsSdkMeta, viewResourceUri } from "../types/meta.js";
|
|
3
3
|
import { withToolErrors } from "./with-tool-errors.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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) {
|
|
20
|
-
return function register(config) {
|
|
4
|
+
import { registrarInputSchema, } from "./registrar-shared.js";
|
|
5
|
+
export function createWidgetToolRegistrar(server, client, metaDefaults, options = {}) {
|
|
6
|
+
// Registration is independent of the OAuth user type, which only shapes
|
|
7
|
+
// the callback ctx; the ctx is handed on typed by the registrar instead.
|
|
8
|
+
const target = server;
|
|
9
|
+
function register(config) {
|
|
21
10
|
const model = config.visibility === "model";
|
|
11
|
+
// Every registrar-owned key is set explicitly in both branches — undefined
|
|
12
|
+
// included — so a cast or plain-JS `definition` cannot smuggle one in.
|
|
22
13
|
const definition = {
|
|
14
|
+
...config.definition,
|
|
23
15
|
name: config.name,
|
|
24
16
|
title: config.title,
|
|
25
17
|
description: config.description,
|
|
26
|
-
inputSchema: config.inputSchema
|
|
18
|
+
inputSchema: registrarInputSchema(config.inputSchema, config.strictInput ?? options.strictInput ?? false),
|
|
19
|
+
// mcp-use's alias: it reads `inputSchema ?? schema`.
|
|
20
|
+
schema: undefined,
|
|
27
21
|
annotations: config.annotations,
|
|
28
22
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
// The SDK validates params against the schema above before the callback
|
|
24
|
+
// runs; the public `register` is generic over that shape, this
|
|
25
|
+
// implementation sees the erased `ToolArgs`.
|
|
26
|
+
const callback = withToolErrors(async (params, ctx) => {
|
|
27
|
+
const result = await config.handler(client, params, ctx);
|
|
33
28
|
return {
|
|
34
29
|
content: [{ type: "text", text: result.text }],
|
|
35
30
|
structuredContent: result.structuredContent,
|
|
36
31
|
};
|
|
37
32
|
});
|
|
38
33
|
if (!model) {
|
|
39
|
-
|
|
34
|
+
return target.tool({
|
|
40
35
|
...definition,
|
|
41
36
|
visibility: "app",
|
|
37
|
+
view: undefined,
|
|
42
38
|
outputSchema: config.outputSchema,
|
|
43
|
-
|
|
39
|
+
_meta: config.meta,
|
|
44
40
|
}, callback);
|
|
45
|
-
return;
|
|
46
41
|
}
|
|
47
|
-
|
|
42
|
+
return target.tool({
|
|
48
43
|
...definition,
|
|
44
|
+
// Host default: callable by the model (no `_meta.ui.visibility`).
|
|
45
|
+
visibility: undefined,
|
|
49
46
|
view: {
|
|
50
47
|
name: config.name,
|
|
51
48
|
description: config.description,
|
|
@@ -67,6 +64,7 @@ export function createWidgetToolRegistrar(server, client, metaDefaults) {
|
|
|
67
64
|
}),
|
|
68
65
|
},
|
|
69
66
|
}, callback);
|
|
70
|
-
}
|
|
67
|
+
}
|
|
68
|
+
return register;
|
|
71
69
|
}
|
|
72
70
|
//# 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,WAAW,EAAE,eAAe,EAA+B,MAAM,kBAAkB,CAAA;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;
|
|
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;AAEtD,OAAO,EACL,oBAAoB,GAOrB,MAAM,uBAAuB,CAAA;AAgJ9B,MAAM,UAAU,yBAAyB,CACvC,MAAwB,EACxB,MAAe,EACf,YAAqC,EACrC,UAAgC,EAAE;IAEl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C,IAAI,CAChB;YACE,GAAG,UAAU;YACb,kEAAkE;YAClE,UAAU,EAAE,SAAS;YACrB,IAAI,EAAE;gBACJ,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,GAAG,CAAC,YAAY,EAAE,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;IAED,OAAO,QAA4E,CAAA;AACrF,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { RequestContext, ToolDefinition } from "mcp-use";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** Input shape both registrars accept: a raw zod shape, wrapped into an object schema. */
|
|
4
|
+
export type ZodRawShape = Record<string, z.ZodTypeAny>;
|
|
5
|
+
/**
|
|
6
|
+
* mcp-use's per-call context, handed to registrar handlers as their third
|
|
7
|
+
* argument: `signal` (aborts when the client cancels or the connection
|
|
8
|
+
* drops), `reportProgress`, `sendLog`, `sendNotification`, `client`
|
|
9
|
+
* (capability queries), the originating `request`, and `auth`.
|
|
10
|
+
*
|
|
11
|
+
* `auth` is typed optional on purpose: plugins receive their server as a
|
|
12
|
+
* plain `MCPServer` even when the composition root installed OAuth
|
|
13
|
+
* (`createFrameworkApp` erases the user type), and a tool whose
|
|
14
|
+
* `securitySchemes` accept `noauth` runs signed out. `TUser` is the server's
|
|
15
|
+
* OAuth user type when the registrar was created from an `MCPServer<TUser>`,
|
|
16
|
+
* `unknown` otherwise.
|
|
17
|
+
*/
|
|
18
|
+
export type ToolHandlerContext<TUser = unknown> = RequestContext<TUser, "optional">;
|
|
19
|
+
/** The ctx user type a registrar created from an `MCPServer<TUser>` hands its handlers. */
|
|
20
|
+
export type HandlerUser<TUser> = [TUser] extends [never] ? unknown : TUser;
|
|
21
|
+
/** `ToolDefinition` keys every registrar derives itself from its config. */
|
|
22
|
+
type RegistrarOwnedKey = "name" | "description" | "inputSchema" | "schema" | "outputSchema" | "annotations";
|
|
23
|
+
/**
|
|
24
|
+
* The `ToolDefinition` fields `createToolRegistrar` forwards verbatim to
|
|
25
|
+
* `server.tool` (`definition`): `title`, `_meta`, `visibility`,
|
|
26
|
+
* `securitySchemes`, `view`, and any field a later mcp-use adds. The keys
|
|
27
|
+
* the registrar derives from its own config are excluded — they win.
|
|
28
|
+
*/
|
|
29
|
+
export type ToolDefinitionPassthrough = Omit<ToolDefinition, RegistrarOwnedKey>;
|
|
30
|
+
/**
|
|
31
|
+
* The `ToolDefinition` fields `createWidgetToolRegistrar` forwards verbatim
|
|
32
|
+
* (`definition`) — e.g. `securitySchemes`. On top of the shared owned keys
|
|
33
|
+
* the widget registrar derives `title`, `visibility`, `view` and `_meta`
|
|
34
|
+
* from its config (`title`, `visibility`, `meta`), so those stay excluded.
|
|
35
|
+
*/
|
|
36
|
+
export type WidgetToolDefinitionPassthrough = Omit<ToolDefinition, RegistrarOwnedKey | "title" | "visibility" | "view" | "_meta">;
|
|
37
|
+
/** Options shared by `createToolRegistrar` and `createWidgetToolRegistrar`. */
|
|
38
|
+
export interface ToolRegistrarOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Default for every tool's `strictInput` (a tool's own flag wins). Off by
|
|
41
|
+
* default in 2.x: a non-strict input silently strips unknown keys.
|
|
42
|
+
*/
|
|
43
|
+
strictInput?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Type `register()`'s return value as the tool's mcp-use `ToolRef` (name,
|
|
46
|
+
* input and output types — what `mcp-env.d.ts` / `useCallTool` infer from).
|
|
47
|
+
* The ref is returned at runtime either way; the static type is opt-in in
|
|
48
|
+
* 2.x because registrar wrappers typed as
|
|
49
|
+
* `ReturnType<typeof createToolRegistrar<C>>` may return `void` (a toolset
|
|
50
|
+
* filter registers nothing for a filtered tool).
|
|
51
|
+
*/
|
|
52
|
+
toolRefs?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** The registrar options that select the `ToolRef`-typed registrar. */
|
|
55
|
+
export type TypedToolRefOptions = ToolRegistrarOptions & {
|
|
56
|
+
toolRefs: true;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The message for unknown keys on a strict input: names every unknown key
|
|
60
|
+
* and every valid one, so a model can correct a typo in one retry instead of
|
|
61
|
+
* having the key silently dropped.
|
|
62
|
+
*/
|
|
63
|
+
export declare function unknownKeysMessage(unknown: readonly string[], valid: readonly string[]): string;
|
|
64
|
+
/**
|
|
65
|
+
* A strict object schema for a raw input shape: advertised with
|
|
66
|
+
* `additionalProperties: false`, and an unknown key fails validation with
|
|
67
|
+
* {@link unknownKeysMessage}. mcp-use's SDK runs input validation before the
|
|
68
|
+
* callback and returns the failure as an `isError` tool result.
|
|
69
|
+
*/
|
|
70
|
+
export declare function strictInputSchema(shape: ZodRawShape): z.ZodObject<ZodRawShape, z.core.$strict>;
|
|
71
|
+
/** The input schema a registrar advertises for a raw shape under its strictness setting. */
|
|
72
|
+
export declare function registrarInputSchema(shape: ZodRawShape | undefined, strict: boolean): z.ZodObject<ZodRawShape> | undefined;
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=registrar-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar-shared.d.ts","sourceRoot":"","sources":["../../src/tools/registrar-shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC7D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,0FAA0F;AAC1F,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,CAAA;AAEtD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,kBAAkB,CAAC,KAAK,GAAG,OAAO,IAAI,cAAc,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;AAEnF,2FAA2F;AAC3F,MAAM,MAAM,WAAW,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,OAAO,GAAG,KAAK,CAAA;AAE1E,4EAA4E;AAC5E,KAAK,iBAAiB,GACpB,MAAM,GAAG,aAAa,GAAG,aAAa,GAAG,QAAQ,GAAG,cAAc,GAAG,aAAa,CAAA;AAEpF;;;;;GAKG;AACH,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAA;AAE/E;;;;;GAKG;AACH,MAAM,MAAM,+BAA+B,GAAG,IAAI,CAChD,cAAc,EACd,iBAAiB,GAAG,OAAO,GAAG,YAAY,GAAG,MAAM,GAAG,OAAO,CAC9D,CAAA;AAED,+EAA+E;AAC/E,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED,uEAAuE;AACvE,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,CAAA;AAE3E;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAM/F;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAM9F;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,WAAW,GAAG,SAAS,EAC9B,MAAM,EAAE,OAAO,GACd,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,SAAS,CAGtC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The message for unknown keys on a strict input: names every unknown key
|
|
4
|
+
* and every valid one, so a model can correct a typo in one retry instead of
|
|
5
|
+
* having the key silently dropped.
|
|
6
|
+
*/
|
|
7
|
+
export function unknownKeysMessage(unknown, valid) {
|
|
8
|
+
const quote = (keys) => keys.map((key) => JSON.stringify(key)).join(", ");
|
|
9
|
+
const head = `Unknown key${unknown.length === 1 ? "" : "s"} ${quote(unknown)}.`;
|
|
10
|
+
return valid.length === 0
|
|
11
|
+
? `${head} This tool takes no arguments.`
|
|
12
|
+
: `${head} Valid keys: ${quote(valid)}.`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A strict object schema for a raw input shape: advertised with
|
|
16
|
+
* `additionalProperties: false`, and an unknown key fails validation with
|
|
17
|
+
* {@link unknownKeysMessage}. mcp-use's SDK runs input validation before the
|
|
18
|
+
* callback and returns the failure as an `isError` tool result.
|
|
19
|
+
*/
|
|
20
|
+
export function strictInputSchema(shape) {
|
|
21
|
+
const valid = Object.keys(shape);
|
|
22
|
+
return z.strictObject(shape, {
|
|
23
|
+
error: (issue) => issue.code === "unrecognized_keys" ? unknownKeysMessage(issue.keys, valid) : undefined,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** The input schema a registrar advertises for a raw shape under its strictness setting. */
|
|
27
|
+
export function registrarInputSchema(shape, strict) {
|
|
28
|
+
if (strict)
|
|
29
|
+
return strictInputSchema(shape ?? {});
|
|
30
|
+
return shape ? z.object(shape) : undefined;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=registrar-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar-shared.js","sourceRoot":"","sources":["../../src/tools/registrar-shared.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAmEvB;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAA0B,EAAE,KAAwB;IACrF,MAAM,KAAK,GAAG,CAAC,IAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC5F,MAAM,IAAI,GAAG,cAAc,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAA;IAC/E,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;QACvB,CAAC,CAAC,GAAG,IAAI,gCAAgC;QACzC,CAAC,CAAC,GAAG,IAAI,gBAAgB,KAAK,CAAC,KAAK,CAAC,GAAG,CAAA;AAC5C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAkB;IAClD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAChC,OAAO,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE;QAC3B,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CACf,KAAK,CAAC,IAAI,KAAK,mBAAmB,CAAC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;KACzF,CAAC,CAAA;AACJ,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,oBAAoB,CAClC,KAA8B,EAC9B,MAAe;IAEf,IAAI,MAAM;QAAE,OAAO,iBAAiB,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;IACjD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MCPServer } from "mcp-use";
|
|
2
|
+
/**
|
|
3
|
+
* What `installToolkit` does when a tool name is registered twice on its
|
|
4
|
+
* server. `"warn"` (the 2.x default) logs both owners and lets mcp-use keep
|
|
5
|
+
* the later registration, exactly as before; `"throw"` refuses the second
|
|
6
|
+
* registration, failing the boot.
|
|
7
|
+
*/
|
|
8
|
+
export type DuplicateToolNamePolicy = "warn" | "throw";
|
|
9
|
+
/** Owner label of the tools `installToolkit` itself registers. */
|
|
10
|
+
export declare const FRAMEWORK_TOOL_OWNER = "the toolkit framework";
|
|
11
|
+
/** Owner label of tools registered outside any toolkit-run hook. */
|
|
12
|
+
export declare const APPLICATION_TOOL_OWNER = "application code";
|
|
13
|
+
/** Owner label of the tools a module's `registerTools` / `registerWidgetTools` hook registers. */
|
|
14
|
+
export declare function moduleToolOwner(moduleName: string): string;
|
|
15
|
+
/** The diagnostic for a duplicate tool name, naming the tool and both owners. */
|
|
16
|
+
export declare function duplicateToolNameMessage(name: string, existingOwner: string, newOwner: string, policy: DuplicateToolNamePolicy): string;
|
|
17
|
+
/**
|
|
18
|
+
* Wrap `server.tool` so every registration is checked against the names
|
|
19
|
+
* already taken on this server. mcp-use's own `tool()` is a plain map set
|
|
20
|
+
* (last wins), so without this a module tool named like a framework tool —
|
|
21
|
+
* or like another module's — silently disappears.
|
|
22
|
+
*
|
|
23
|
+
* The wrapper stays installed, so registrations made by application code
|
|
24
|
+
* after `installToolkit` are guarded too. Tools registered on the server
|
|
25
|
+
* BEFORE the guard was installed are invisible to it (mcp-use has no public
|
|
26
|
+
* tool listing) — which is why the standard path registers its own tools
|
|
27
|
+
* after `installToolkit`. A registration mcp-use refuses claims no name.
|
|
28
|
+
* Installing twice keeps one wrapper; `"throw"` wins.
|
|
29
|
+
*/
|
|
30
|
+
export declare function installToolNameGuard(server: MCPServer, policy: DuplicateToolNamePolicy): void;
|
|
31
|
+
/**
|
|
32
|
+
* Run `register` with `owner` as the label for every tool it registers on
|
|
33
|
+
* `server`. A no-op wrapper when the server has no guard (e.g.
|
|
34
|
+
* `registerFrameworkTools` called on a server `installToolkit` never saw).
|
|
35
|
+
*/
|
|
36
|
+
export declare function withToolOwner<T>(server: object, owner: string, register: () => T): T;
|
|
37
|
+
//# sourceMappingURL=tool-name-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-name-guard.d.ts","sourceRoot":"","sources":["../../src/tools/tool-name-guard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,SAAS,CAAA;AAExD;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,OAAO,CAAA;AAEtD,kEAAkE;AAClE,eAAO,MAAM,oBAAoB,0BAA0B,CAAA;AAE3D,oEAAoE;AACpE,eAAO,MAAM,sBAAsB,qBAAqB,CAAA;AAExD,kGAAkG;AAClG,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,iFAAiF;AACjF,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,uBAAuB,GAC9B,MAAM,CASR;AAYD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,uBAAuB,GAAG,IAAI,CA8B7F;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CASpF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** Owner label of the tools `installToolkit` itself registers. */
|
|
2
|
+
export const FRAMEWORK_TOOL_OWNER = "the toolkit framework";
|
|
3
|
+
/** Owner label of tools registered outside any toolkit-run hook. */
|
|
4
|
+
export const APPLICATION_TOOL_OWNER = "application code";
|
|
5
|
+
/** Owner label of the tools a module's `registerTools` / `registerWidgetTools` hook registers. */
|
|
6
|
+
export function moduleToolOwner(moduleName) {
|
|
7
|
+
return `module "${moduleName}"`;
|
|
8
|
+
}
|
|
9
|
+
/** The diagnostic for a duplicate tool name, naming the tool and both owners. */
|
|
10
|
+
export function duplicateToolNameMessage(name, existingOwner, newOwner, policy) {
|
|
11
|
+
const head = `Duplicate tool name "${name}": already registered by ${existingOwner}, registered again by ${newOwner}.`;
|
|
12
|
+
if (policy === "throw")
|
|
13
|
+
return `${head} mcp-use keeps one tool per name — rename one of them.`;
|
|
14
|
+
return (`[mcp-toolkit] ${head} mcp-use keeps only the last registration, so the tool from ` +
|
|
15
|
+
`${newOwner} replaces the one from ${existingOwner} — rename one of them ` +
|
|
16
|
+
`(duplicateToolNames: "throw" in the installToolkit options, or in ` +
|
|
17
|
+
`createFrameworkApp's app options, makes this a boot error).`);
|
|
18
|
+
}
|
|
19
|
+
const guards = new WeakMap();
|
|
20
|
+
/**
|
|
21
|
+
* Wrap `server.tool` so every registration is checked against the names
|
|
22
|
+
* already taken on this server. mcp-use's own `tool()` is a plain map set
|
|
23
|
+
* (last wins), so without this a module tool named like a framework tool —
|
|
24
|
+
* or like another module's — silently disappears.
|
|
25
|
+
*
|
|
26
|
+
* The wrapper stays installed, so registrations made by application code
|
|
27
|
+
* after `installToolkit` are guarded too. Tools registered on the server
|
|
28
|
+
* BEFORE the guard was installed are invisible to it (mcp-use has no public
|
|
29
|
+
* tool listing) — which is why the standard path registers its own tools
|
|
30
|
+
* after `installToolkit`. A registration mcp-use refuses claims no name.
|
|
31
|
+
* Installing twice keeps one wrapper; `"throw"` wins.
|
|
32
|
+
*/
|
|
33
|
+
export function installToolNameGuard(server, policy) {
|
|
34
|
+
const existing = guards.get(server);
|
|
35
|
+
if (existing) {
|
|
36
|
+
if (policy === "throw")
|
|
37
|
+
existing.policy = "throw";
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const guard = { policy, owners: new Map(), scopes: [] };
|
|
41
|
+
guards.set(server, guard);
|
|
42
|
+
// `never` keeps the checked assignment sound under parameter
|
|
43
|
+
// contravariance — the wrapper only forwards the callback.
|
|
44
|
+
const original = server.tool.bind(server);
|
|
45
|
+
const guarded = (definition, callback) => {
|
|
46
|
+
const owner = guard.scopes.at(-1) ?? APPLICATION_TOOL_OWNER;
|
|
47
|
+
const previous = guard.owners.get(definition.name);
|
|
48
|
+
if (previous !== undefined && guard.policy === "throw") {
|
|
49
|
+
throw new Error(duplicateToolNameMessage(definition.name, previous, owner, "throw"));
|
|
50
|
+
}
|
|
51
|
+
// Only what mcp-use accepted counts: its `tool()` can still refuse the
|
|
52
|
+
// definition (e.g. a `noauth` scheme without mixedAuth, a view without an
|
|
53
|
+
// outputSchema). A refused registration claims no name — a fallback under
|
|
54
|
+
// the same name stays legal — and replaces nothing, so it is not warned.
|
|
55
|
+
const ref = original(definition, callback);
|
|
56
|
+
if (previous !== undefined) {
|
|
57
|
+
console.warn(duplicateToolNameMessage(definition.name, previous, owner, "warn"));
|
|
58
|
+
}
|
|
59
|
+
guard.owners.set(definition.name, owner);
|
|
60
|
+
return ref;
|
|
61
|
+
};
|
|
62
|
+
server.tool = guarded;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Run `register` with `owner` as the label for every tool it registers on
|
|
66
|
+
* `server`. A no-op wrapper when the server has no guard (e.g.
|
|
67
|
+
* `registerFrameworkTools` called on a server `installToolkit` never saw).
|
|
68
|
+
*/
|
|
69
|
+
export function withToolOwner(server, owner, register) {
|
|
70
|
+
const guard = guards.get(server);
|
|
71
|
+
if (!guard)
|
|
72
|
+
return register();
|
|
73
|
+
guard.scopes.push(owner);
|
|
74
|
+
try {
|
|
75
|
+
return register();
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
guard.scopes.pop();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=tool-name-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-name-guard.js","sourceRoot":"","sources":["../../src/tools/tool-name-guard.ts"],"names":[],"mappings":"AAUA,kEAAkE;AAClE,MAAM,CAAC,MAAM,oBAAoB,GAAG,uBAAuB,CAAA;AAE3D,oEAAoE;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAG,kBAAkB,CAAA;AAExD,kGAAkG;AAClG,MAAM,UAAU,eAAe,CAAC,UAAkB;IAChD,OAAO,WAAW,UAAU,GAAG,CAAA;AACjC,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,wBAAwB,CACtC,IAAY,EACZ,aAAqB,EACrB,QAAgB,EAChB,MAA+B;IAE/B,MAAM,IAAI,GAAG,wBAAwB,IAAI,4BAA4B,aAAa,yBAAyB,QAAQ,GAAG,CAAA;IACtH,IAAI,MAAM,KAAK,OAAO;QAAE,OAAO,GAAG,IAAI,wDAAwD,CAAA;IAC9F,OAAO,CACL,iBAAiB,IAAI,8DAA8D;QACnF,GAAG,QAAQ,0BAA0B,aAAa,wBAAwB;QAC1E,oEAAoE;QACpE,6DAA6D,CAC9D,CAAA;AACH,CAAC;AAUD,MAAM,MAAM,GAAG,IAAI,OAAO,EAAyB,CAAA;AAEnD;;;;;;;;;;;;GAYG;AACH,MAAM,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AE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;QAClF,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACxC,OAAO,GAAG,CAAA;IACZ,CAAC,CAAA;IACD,MAAM,CAAC,IAAI,GAAG,OAA6B,CAAA;AAC7C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAI,MAAc,EAAE,KAAa,EAAE,QAAiB;IAC/E,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAChC,IAAI,CAAC,KAAK;QAAE,OAAO,QAAQ,EAAE,CAAA;IAC7B,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACxB,IAAI,CAAC;QACH,OAAO,QAAQ,EAAE,CAAA;IACnB,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;IACpB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miragon/mcp-toolkit-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Framework runtime for MCP servers: plugin contract, step/widget registries, pipeline executor, render-view helpers.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,19 +33,19 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"mcp-use": "2.7.
|
|
36
|
+
"mcp-use": "2.7.3",
|
|
37
37
|
"zod": "^4.4.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@modelcontextprotocol/server": "2.
|
|
40
|
+
"@modelcontextprotocol/server": "2.2.0",
|
|
41
41
|
"@stryker-mutator/core": "10.0.0",
|
|
42
42
|
"@stryker-mutator/vitest-runner": "10.0.0",
|
|
43
|
-
"@types/node": "26.6.
|
|
44
|
-
"@vitest/coverage-v8": "
|
|
43
|
+
"@types/node": "26.6.4",
|
|
44
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
45
45
|
"fast-check": "4.10.2",
|
|
46
|
-
"mcp-use": "2.7.
|
|
46
|
+
"mcp-use": "2.7.3",
|
|
47
47
|
"typescript": "6.0.3",
|
|
48
|
-
"vitest": "
|
|
48
|
+
"vitest": "4.1.11",
|
|
49
49
|
"zod": "4.6.5"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|