@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.
Files changed (76) hide show
  1. package/README.md +7 -7
  2. package/dist/framework/render-view.d.ts +1 -1
  3. package/dist/framework/render-view.d.ts.map +1 -1
  4. package/dist/framework/render-view.js +3 -0
  5. package/dist/framework/render-view.js.map +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/middleware/role-filter.d.ts +16 -32
  11. package/dist/middleware/role-filter.d.ts.map +1 -1
  12. package/dist/middleware/role-filter.js +10 -22
  13. package/dist/middleware/role-filter.js.map +1 -1
  14. package/dist/tools/backend-registry.d.ts +9 -3
  15. package/dist/tools/backend-registry.d.ts.map +1 -1
  16. package/dist/tools/backend-registry.js +13 -12
  17. package/dist/tools/backend-registry.js.map +1 -1
  18. package/dist/tools/create-framework-app.d.ts +51 -38
  19. package/dist/tools/create-framework-app.d.ts.map +1 -1
  20. package/dist/tools/create-framework-app.js +79 -78
  21. package/dist/tools/create-framework-app.js.map +1 -1
  22. package/dist/tools/index.d.ts +4 -5
  23. package/dist/tools/index.d.ts.map +1 -1
  24. package/dist/tools/index.js +3 -3
  25. package/dist/tools/index.js.map +1 -1
  26. package/dist/tools/install-toolkit.d.ts +77 -0
  27. package/dist/tools/install-toolkit.d.ts.map +1 -0
  28. package/dist/tools/install-toolkit.js +85 -0
  29. package/dist/tools/install-toolkit.js.map +1 -0
  30. package/dist/tools/register-catalogue-tool.d.ts +1 -1
  31. package/dist/tools/register-catalogue-tool.d.ts.map +1 -1
  32. package/dist/tools/register-catalogue-tool.js +2 -3
  33. package/dist/tools/register-catalogue-tool.js.map +1 -1
  34. package/dist/tools/register-dashboard-tools.d.ts +1 -1
  35. package/dist/tools/register-dashboard-tools.d.ts.map +1 -1
  36. package/dist/tools/register-dashboard-tools.js +6 -6
  37. package/dist/tools/register-dashboard-tools.js.map +1 -1
  38. package/dist/tools/register-framework-tools.d.ts +15 -47
  39. package/dist/tools/register-framework-tools.d.ts.map +1 -1
  40. package/dist/tools/register-framework-tools.js +31 -63
  41. package/dist/tools/register-framework-tools.js.map +1 -1
  42. package/dist/tools/register-tool.d.ts +1 -1
  43. package/dist/tools/register-tool.d.ts.map +1 -1
  44. package/dist/tools/register-tool.js +14 -8
  45. package/dist/tools/register-tool.js.map +1 -1
  46. package/dist/tools/register-widget-tool.d.ts +35 -11
  47. package/dist/tools/register-widget-tool.d.ts.map +1 -1
  48. package/dist/tools/register-widget-tool.js +57 -30
  49. package/dist/tools/register-widget-tool.js.map +1 -1
  50. package/dist/tools/tool-results.d.ts +46 -0
  51. package/dist/tools/tool-results.d.ts.map +1 -0
  52. package/dist/tools/tool-results.js +39 -0
  53. package/dist/tools/tool-results.js.map +1 -0
  54. package/dist/tools/with-tool-errors.d.ts +12 -6
  55. package/dist/tools/with-tool-errors.d.ts.map +1 -1
  56. package/dist/tools/with-tool-errors.js +12 -6
  57. package/dist/tools/with-tool-errors.js.map +1 -1
  58. package/dist/types/app.d.ts +10 -7
  59. package/dist/types/app.d.ts.map +1 -1
  60. package/dist/types/index.d.ts +2 -2
  61. package/dist/types/index.d.ts.map +1 -1
  62. package/dist/types/index.js +1 -1
  63. package/dist/types/index.js.map +1 -1
  64. package/dist/types/meta.d.ts +73 -56
  65. package/dist/types/meta.d.ts.map +1 -1
  66. package/dist/types/meta.js +49 -53
  67. package/dist/types/meta.js.map +1 -1
  68. package/package.json +14 -6
  69. package/dist/tools/app-resource-uri.d.ts +0 -28
  70. package/dist/tools/app-resource-uri.d.ts.map +0 -1
  71. package/dist/tools/app-resource-uri.js +0 -30
  72. package/dist/tools/app-resource-uri.js.map +0 -1
  73. package/dist/tools/tool-call-name.d.ts +0 -53
  74. package/dist/tools/tool-call-name.d.ts.map +0 -1
  75. package/dist/tools/tool-call-name.js +0 -92
  76. package/dist/tools/tool-call-name.js.map +0 -1
@@ -1,53 +0,0 @@
1
- import { type McpServerInstance } from "mcp-use/server";
2
- /**
3
- * Resolves the tool name of the in-flight `tools/call` request, or
4
- * `undefined` when called outside a tool-call request scope.
5
- *
6
- * Backs the role-filter's `tools/call` guard: mcp-use 1.28 passes only the
7
- * tool *arguments* to `mcp:tools/call` middleware as `ctx.params`, so the
8
- * `params.name` its typings declare is never populated at runtime. This
9
- * resolver recovers the real name from the JSON-RPC envelope captured at the
10
- * HTTP layer.
11
- */
12
- export type ToolNameResolver = () => string | undefined;
13
- /**
14
- * The resolver returned by {@link installToolCallNameCapture}: callable as a
15
- * plain {@link ToolNameResolver} (first `tools/call` name — the common case
16
- * and the logging-friendly one), with `.all()` exposing every name the
17
- * in-flight envelope carries. A JSON-RPC *batch* can contain several
18
- * `tools/call` requests, and a guard that only checks one of them can be
19
- * bypassed by the others — the role filter therefore consumes `.all()`.
20
- */
21
- export interface ToolNameCapture extends ToolNameResolver {
22
- /** Every `tools/call` name in the in-flight envelope, or `undefined` outside a capture scope. */
23
- all: () => string[] | undefined;
24
- }
25
- /**
26
- * Parse a JSON-RPC request body and return the `params.name` of every
27
- * `tools/call` request it carries: a single request yields zero or one entry,
28
- * a batch array yields one entry per `tools/call` it contains. Batches are a
29
- * real-world shape, not an edge case — Streamable-HTTP revision 2025-03-26
30
- * allows them, and claude.ai (via mcp-remote) frames single calls as
31
- * one-element batches.
32
- *
33
- * Pure and side-effect free so it can be unit-tested without an HTTP server.
34
- * Tolerates arbitrary `unknown` input: malformed bodies, malformed batch
35
- * entries, and non-`tools/call` methods contribute nothing rather than throw.
36
- */
37
- export declare function extractToolCallNames(body: unknown): string[];
38
- /**
39
- * First `tools/call` name of a JSON-RPC request body (single request or batch
40
- * array), or `undefined` when it carries none. Sufficient for logging; guards
41
- * must use {@link extractToolCallNames} — a batch can carry several calls.
42
- */
43
- export declare function extractToolCallName(body: unknown): string | undefined;
44
- /**
45
- * Whether `path` is one of the MCP transport endpoints mcp-use mounts the
46
- * Streamable-HTTP handler at. Both `/mcp` and `/sse` accept `tools/call`, so
47
- * the tool-name capture (and the role-filter guard that reads it) must cover
48
- * both — matching only `/mcp` leaves a `tools/call` over `/sse` unguarded.
49
- * Exported so the endpoint contract is pinned by a unit test.
50
- */
51
- export declare function isMcpTransportPath(path: string): boolean;
52
- export declare function installToolCallNameCapture(server: McpServerInstance<boolean>): ToolNameCapture;
53
- //# sourceMappingURL=tool-call-name.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-call-name.d.ts","sourceRoot":"","sources":["../../src/tools/tool-call-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAS1E;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,MAAM,GAAG,SAAS,CAAA;AAEvD;;;;;;;GAOG;AACH,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,iGAAiG;IACjG,GAAG,EAAE,MAAM,MAAM,EAAE,GAAG,SAAS,CAAA;CAChC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAU5D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAErE;AA0BD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,eAAe,CAuB9F"}
@@ -1,92 +0,0 @@
1
- import { getRequestContext } from "mcp-use/server";
2
- /**
3
- * Parse a JSON-RPC request body and return the `params.name` of every
4
- * `tools/call` request it carries: a single request yields zero or one entry,
5
- * a batch array yields one entry per `tools/call` it contains. Batches are a
6
- * real-world shape, not an edge case — Streamable-HTTP revision 2025-03-26
7
- * allows them, and claude.ai (via mcp-remote) frames single calls as
8
- * one-element batches.
9
- *
10
- * Pure and side-effect free so it can be unit-tested without an HTTP server.
11
- * Tolerates arbitrary `unknown` input: malformed bodies, malformed batch
12
- * entries, and non-`tools/call` methods contribute nothing rather than throw.
13
- */
14
- export function extractToolCallNames(body) {
15
- if (Array.isArray(body)) {
16
- return body.flatMap((entry) => extractToolCallNames(entry));
17
- }
18
- if (typeof body !== "object" || body === null)
19
- return [];
20
- const { method, params } = body;
21
- if (method !== "tools/call")
22
- return [];
23
- if (typeof params !== "object" || params === null)
24
- return [];
25
- const { name } = params;
26
- return typeof name === "string" ? [name] : [];
27
- }
28
- /**
29
- * First `tools/call` name of a JSON-RPC request body (single request or batch
30
- * array), or `undefined` when it carries none. Sufficient for logging; guards
31
- * must use {@link extractToolCallNames} — a batch can carry several calls.
32
- */
33
- export function extractToolCallName(body) {
34
- return extractToolCallNames(body)[0];
35
- }
36
- /**
37
- * Capture the `tools/call` tool name at the HTTP layer and expose it to the
38
- * MCP middleware chain.
39
- *
40
- * Registers a Hono middleware on the server that, for `POST` requests to an
41
- * MCP transport endpoint, clones the request body (so the MCP transport can
42
- * still read it), parses the JSON-RPC envelope, and — when it's a
43
- * `tools/call` — stashes the tool name in a `WeakMap` keyed by the
44
- * request-scoped Hono context. The returned resolver reads that map back via
45
- * `getRequestContext()`, which yields the same context inside the MCP
46
- * middleware chain.
47
- *
48
- * mcp-use mounts the *same* Streamable-HTTP handler at both `/mcp` and `/sse`
49
- * (`for (const endpoint of ["/mcp", "/sse"])`), so the capture must match both
50
- * — otherwise a `tools/call` sent to `/sse` executes but its name is never
51
- * captured, and the role-filter guard that depends on this resolver silently
52
- * falls open. Matching both endpoints closes that bypass.
53
- *
54
- * The `WeakMap` keying keeps the capture request-isolated: entries are
55
- * garbage-collected with their context and never leak across concurrent
56
- * requests.
57
- */
58
- const MCP_TRANSPORT_PATHS = new Set(["/mcp", "/sse"]);
59
- /**
60
- * Whether `path` is one of the MCP transport endpoints mcp-use mounts the
61
- * Streamable-HTTP handler at. Both `/mcp` and `/sse` accept `tools/call`, so
62
- * the tool-name capture (and the role-filter guard that reads it) must cover
63
- * both — matching only `/mcp` leaves a `tools/call` over `/sse` unguarded.
64
- * Exported so the endpoint contract is pinned by a unit test.
65
- */
66
- export function isMcpTransportPath(path) {
67
- return MCP_TRANSPORT_PATHS.has(path);
68
- }
69
- export function installToolCallNameCapture(server) {
70
- const toolNamesByRequest = new WeakMap();
71
- server.use(async (c, next) => {
72
- if (c.req.method === "POST" && isMcpTransportPath(c.req.path)) {
73
- const body = await c.req.raw
74
- .clone()
75
- .json()
76
- .catch(() => undefined);
77
- const toolNames = extractToolCallNames(body);
78
- if (toolNames.length > 0) {
79
- toolNamesByRequest.set(c, toolNames);
80
- }
81
- }
82
- await next();
83
- });
84
- const all = () => {
85
- const requestContext = getRequestContext();
86
- if (!requestContext)
87
- return undefined;
88
- return toolNamesByRequest.get(requestContext);
89
- };
90
- return Object.assign(() => all()?.[0], { all });
91
- }
92
- //# sourceMappingURL=tool-call-name.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tool-call-name.js","sourceRoot":"","sources":["../../src/tools/tool-call-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA0B,MAAM,gBAAgB,CAAA;AAkC1E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAa;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAA;IAC7D,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,CAAA;IACxD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAA8C,CAAA;IACzE,IAAI,MAAM,KAAK,YAAY;Q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