@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.
Files changed (68) hide show
  1. package/README.md +1 -1
  2. package/dist/auth/caller.d.ts +55 -0
  3. package/dist/auth/caller.d.ts.map +1 -0
  4. package/dist/auth/caller.js +81 -0
  5. package/dist/auth/caller.js.map +1 -0
  6. package/dist/engine/pipeline-executor.d.ts +32 -4
  7. package/dist/engine/pipeline-executor.d.ts.map +1 -1
  8. package/dist/engine/pipeline-executor.js +22 -2
  9. package/dist/engine/pipeline-executor.js.map +1 -1
  10. package/dist/framework/catalogue.d.ts +2 -2
  11. package/dist/framework/render-view.d.ts +6 -4
  12. package/dist/framework/render-view.d.ts.map +1 -1
  13. package/dist/framework/render-view.js.map +1 -1
  14. package/dist/index.d.ts +5 -3
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +5 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/middleware/org-gate.d.ts +31 -7
  19. package/dist/middleware/org-gate.d.ts.map +1 -1
  20. package/dist/middleware/org-gate.js +9 -6
  21. package/dist/middleware/org-gate.js.map +1 -1
  22. package/dist/middleware/role-filter.d.ts +39 -7
  23. package/dist/middleware/role-filter.d.ts.map +1 -1
  24. package/dist/middleware/role-filter.js +24 -28
  25. package/dist/middleware/role-filter.js.map +1 -1
  26. package/dist/tools/create-framework-app.d.ts +12 -1
  27. package/dist/tools/create-framework-app.d.ts.map +1 -1
  28. package/dist/tools/create-framework-app.js +10 -5
  29. package/dist/tools/create-framework-app.js.map +1 -1
  30. package/dist/tools/dashboard-store.d.ts +83 -13
  31. package/dist/tools/dashboard-store.d.ts.map +1 -1
  32. package/dist/tools/dashboard-store.js +174 -73
  33. package/dist/tools/dashboard-store.js.map +1 -1
  34. package/dist/tools/index.d.ts +5 -3
  35. package/dist/tools/index.d.ts.map +1 -1
  36. package/dist/tools/index.js +1 -1
  37. package/dist/tools/index.js.map +1 -1
  38. package/dist/tools/install-toolkit.d.ts +22 -1
  39. package/dist/tools/install-toolkit.d.ts.map +1 -1
  40. package/dist/tools/install-toolkit.js +15 -3
  41. package/dist/tools/install-toolkit.js.map +1 -1
  42. package/dist/tools/register-catalogue-tool.d.ts.map +1 -1
  43. package/dist/tools/register-catalogue-tool.js +2 -5
  44. package/dist/tools/register-catalogue-tool.js.map +1 -1
  45. package/dist/tools/register-dashboard-tools.d.ts +15 -3
  46. package/dist/tools/register-dashboard-tools.d.ts.map +1 -1
  47. package/dist/tools/register-dashboard-tools.js +120 -20
  48. package/dist/tools/register-dashboard-tools.js.map +1 -1
  49. package/dist/tools/register-framework-tools.d.ts.map +1 -1
  50. package/dist/tools/register-framework-tools.js +4 -6
  51. package/dist/tools/register-framework-tools.js.map +1 -1
  52. package/dist/tools/register-tool.d.ts +67 -9
  53. package/dist/tools/register-tool.d.ts.map +1 -1
  54. package/dist/tools/register-tool.js +17 -8
  55. package/dist/tools/register-tool.js.map +1 -1
  56. package/dist/tools/register-widget-tool.d.ts +46 -5
  57. package/dist/tools/register-widget-tool.d.ts.map +1 -1
  58. package/dist/tools/register-widget-tool.js +25 -27
  59. package/dist/tools/register-widget-tool.js.map +1 -1
  60. package/dist/tools/registrar-shared.d.ts +74 -0
  61. package/dist/tools/registrar-shared.d.ts.map +1 -0
  62. package/dist/tools/registrar-shared.js +32 -0
  63. package/dist/tools/registrar-shared.js.map +1 -0
  64. package/dist/tools/tool-name-guard.d.ts +37 -0
  65. package/dist/tools/tool-name-guard.d.ts.map +1 -0
  66. package/dist/tools/tool-name-guard.js +81 -0
  67. package/dist/tools/tool-name-guard.js.map +1 -0
  68. package/package.json +7 -7
package/README.md CHANGED
@@ -9,7 +9,7 @@ Published to the public npm registry under the `@miragon` scope — no `.npmrc`
9
9
  or token needed.
10
10
 
11
11
  ```sh
12
- pnpm add @miragon/mcp-toolkit-core mcp-use@2.7.1 zod@4.5.4
12
+ pnpm add @miragon/mcp-toolkit-core mcp-use@2.7.3 zod@4.5.4
13
13
  ```
14
14
 
15
15
  Peer versions are pinned exactly — install the versions above.
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Caller identity — the ONE place the toolkit reads who is calling.
3
+ *
4
+ * mcp-use 2 hands out two `ctx.auth` shapes, and every auth consumer in the
5
+ * toolkit (role filter, org gate, dashboard scoping, the render-view /
6
+ * refresh-view pipeline context, the builder catalogue) has to read both:
7
+ *
8
+ * - **MCP middleware** (`server.use("mcp:…")`) receives the SDK `AuthInfo`.
9
+ * The provider-mapped `{ user, payload, permissions }` sit under
10
+ * `ctx.auth.extra` — there is no `ctx.auth.user`.
11
+ * - **Tool / resource / prompt callbacks** receive the flattened
12
+ * `ctx.auth = { user, payload, accessToken, scopes, … }`.
13
+ *
14
+ * The built-in providers (Keycloak, Auth0, WorkOS, Clerk, Supabase, Scalekit,
15
+ * …) map the user as `{ id, organizationId?, roles? }`; 1.x-era custom
16
+ * providers used `userId` / `organization_id`. Both spellings resolve here.
17
+ *
18
+ * Browser-safe on purpose (no mcp-use import): the shapes are read
19
+ * structurally, so the helper works on any `ctx` — including hosts that omit
20
+ * auth entirely.
21
+ */
22
+ /** The caller identity the toolkit's auth consumers act on. */
23
+ export interface Caller {
24
+ /**
25
+ * Stable subject id: `user.id`, else `user.userId`, else the verified
26
+ * token's `payload.sub`. `undefined` when the provider maps none — an
27
+ * authenticated caller WITHOUT an id is not anonymous; consumers that
28
+ * scope data per user must refuse it rather than fall back to global scope.
29
+ */
30
+ userId?: string;
31
+ /** `user.organizationId`, else `user.organization_id`. */
32
+ organizationId?: string;
33
+ /** String entries of `user.roles`; empty when the provider maps none. */
34
+ roles: string[];
35
+ }
36
+ /**
37
+ * Resolve the caller from a middleware or tool/resource/prompt `ctx`.
38
+ *
39
+ * Returns `undefined` when the request carries no auth at all (a server
40
+ * without OAuth, or a signed-out call to a `noauth` tool) — that is the only
41
+ * case where global, owner-less scope is legitimate. Any `ctx.auth` yields a
42
+ * {@link Caller}, even when no id can be resolved from it.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * server.tool({ name: "whoami", description: "…" }, (_args, ctx) => {
47
+ * const caller = resolveCaller(ctx)
48
+ * return textResult(caller?.userId ?? "anonymous")
49
+ * })
50
+ * ```
51
+ */
52
+ export declare function resolveCaller(ctx: unknown): Caller | undefined;
53
+ /** Convenience for `resolveCaller(ctx)?.userId`. */
54
+ export declare function resolveCallerId(ctx: unknown): string | undefined;
55
+ //# sourceMappingURL=caller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caller.d.ts","sourceRoot":"","sources":["../../src/auth/caller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,+DAA+D;AAC/D,MAAM,WAAW,MAAM;IACrB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,yEAAyE;IACzE,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB;AA8BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAa9D;AAED,oDAAoD;AACpD,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAEhE"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Caller identity — the ONE place the toolkit reads who is calling.
3
+ *
4
+ * mcp-use 2 hands out two `ctx.auth` shapes, and every auth consumer in the
5
+ * toolkit (role filter, org gate, dashboard scoping, the render-view /
6
+ * refresh-view pipeline context, the builder catalogue) has to read both:
7
+ *
8
+ * - **MCP middleware** (`server.use("mcp:…")`) receives the SDK `AuthInfo`.
9
+ * The provider-mapped `{ user, payload, permissions }` sit under
10
+ * `ctx.auth.extra` — there is no `ctx.auth.user`.
11
+ * - **Tool / resource / prompt callbacks** receive the flattened
12
+ * `ctx.auth = { user, payload, accessToken, scopes, … }`.
13
+ *
14
+ * The built-in providers (Keycloak, Auth0, WorkOS, Clerk, Supabase, Scalekit,
15
+ * …) map the user as `{ id, organizationId?, roles? }`; 1.x-era custom
16
+ * providers used `userId` / `organization_id`. Both spellings resolve here.
17
+ *
18
+ * Browser-safe on purpose (no mcp-use import): the shapes are read
19
+ * structurally, so the helper works on any `ctx` — including hosts that omit
20
+ * auth entirely.
21
+ */
22
+ function isRecord(value) {
23
+ return typeof value === "object" && value !== null;
24
+ }
25
+ function firstString(...candidates) {
26
+ for (const candidate of candidates) {
27
+ if (typeof candidate === "string" && candidate.length > 0)
28
+ return candidate;
29
+ }
30
+ return undefined;
31
+ }
32
+ /**
33
+ * Locate the provider-mapped `{ user, payload }` pair in either mcp-use 2
34
+ * shape. The flattened callback shape wins when both are present.
35
+ */
36
+ function identitySource(auth) {
37
+ const extra = isRecord(auth.extra) ? auth.extra : undefined;
38
+ const user = isRecord(auth.user) ? auth.user : isRecord(extra?.user) ? extra.user : undefined;
39
+ const payload = isRecord(auth.payload)
40
+ ? auth.payload
41
+ : isRecord(extra?.payload)
42
+ ? extra.payload
43
+ : undefined;
44
+ return { user, payload };
45
+ }
46
+ /**
47
+ * Resolve the caller from a middleware or tool/resource/prompt `ctx`.
48
+ *
49
+ * Returns `undefined` when the request carries no auth at all (a server
50
+ * without OAuth, or a signed-out call to a `noauth` tool) — that is the only
51
+ * case where global, owner-less scope is legitimate. Any `ctx.auth` yields a
52
+ * {@link Caller}, even when no id can be resolved from it.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * server.tool({ name: "whoami", description: "…" }, (_args, ctx) => {
57
+ * const caller = resolveCaller(ctx)
58
+ * return textResult(caller?.userId ?? "anonymous")
59
+ * })
60
+ * ```
61
+ */
62
+ export function resolveCaller(ctx) {
63
+ if (!isRecord(ctx) || !isRecord(ctx.auth))
64
+ return undefined;
65
+ const { user, payload } = identitySource(ctx.auth);
66
+ const userId = firstString(user?.id, user?.userId, payload?.sub);
67
+ const organizationId = firstString(user?.organizationId, user?.organization_id);
68
+ const roles = Array.isArray(user?.roles)
69
+ ? user.roles.filter((role) => typeof role === "string")
70
+ : [];
71
+ return {
72
+ ...(userId === undefined ? {} : { userId }),
73
+ ...(organizationId === undefined ? {} : { organizationId }),
74
+ roles,
75
+ };
76
+ }
77
+ /** Convenience for `resolveCaller(ctx)?.userId`. */
78
+ export function resolveCallerId(ctx) {
79
+ return resolveCaller(ctx)?.userId;
80
+ }
81
+ //# sourceMappingURL=caller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caller.js","sourceRoot":"","sources":["../../src/auth/caller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAmBH,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAA;AACpD,CAAC;AAED,SAAS,WAAW,CAAC,GAAG,UAAqB;IAC3C,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,SAAS,CAAA;IAC7E,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,IAAmB;IACzC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;IAC3D,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;IAC7F,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;QACpC,CAAC,CAAC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AAE,MAAM,CAAA;AACnC,CAAC"}
@@ -2,14 +2,42 @@ import type { PipelineContext } from "../types/context.js";
2
2
  import type { PipelineConfig } from "../types/pipeline.js";
3
3
  import type { StepRegistry } from "../registry/step-registry.js";
4
4
  /**
5
- * Per-request context threaded into steps. Currently only carries the
6
- * calling user's id, which the executor uses to pre-bind a user-scoped
7
- * `callTool` closure on the step's `appConfig` so step code stays
8
- * synchronous and userId-free.
5
+ * Per-request context threaded into steps: who is calling. The executor hands
6
+ * it to a user-scoped `callTool` closure on the step's `appConfig` (as its
7
+ * hidden third argument) so step code stays synchronous and userId-free.
8
+ * Build it from a tool handler's `ctx` with {@link resolvePipelineContext}.
9
9
  */
10
10
  export interface PipelineExecutionContext {
11
+ /**
12
+ * The caller's id ({@link resolveCaller}). `undefined` for a request without
13
+ * auth — and for an authenticated caller whose provider maps no id; tell the
14
+ * two apart with {@link PipelineExecutionContext.authenticated}.
15
+ */
11
16
  userId?: string;
17
+ /**
18
+ * `true` when the request carried auth, even if no `userId` resolved from
19
+ * it. An authenticated caller WITHOUT a `userId` is not anonymous: a closure
20
+ * that scopes data per user must refuse it rather than fall back to its
21
+ * global / anonymous scope. Absent for a request without auth (a server
22
+ * without OAuth).
23
+ */
24
+ authenticated?: boolean;
12
25
  }
26
+ /**
27
+ * The {@link PipelineExecutionContext} for a tool / resource / prompt `ctx`,
28
+ * read through {@link resolveCaller} (both mcp-use 2 `ctx.auth` shapes) — what
29
+ * render-view, refresh-view and the builder catalogue hand their pipeline.
30
+ * Use it too when calling `renderView` / `getBuilderCatalogue` from your own
31
+ * tool, instead of reading `ctx.auth` yourself.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * server.tool({ name: "my-view", … }, (args, ctx) =>
36
+ * renderView({ input: args, stepRegistry, ctx: resolvePipelineContext(ctx) }),
37
+ * )
38
+ * ```
39
+ */
40
+ export declare function resolvePipelineContext(ctx: unknown): PipelineExecutionContext;
13
41
  export interface ExecutePipelineOptions {
14
42
  config: PipelineConfig;
15
43
  initialKeys: Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"pipeline-executor.d.ts","sourceRoot":"","sources":["../../src/engine/pipeline-executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAEhE;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AA2BD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,cAAc,CAAA;IACtB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,QAAQ,EAAE,YAAY,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,GAAG,CAAC,EAAE,wBAAwB,CAAA;CAC/B;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,eAAe,CAAC,CAwD/F"}
1
+ {"version":3,"file":"pipeline-executor.d.ts","sourceRoot":"","sources":["../../src/engine/pipeline-executor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAEhE;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,wBAAwB,CAG7E;AA4BD,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,cAAc,CAAA;IACtB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,QAAQ,EAAE,YAAY,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,GAAG,CAAC,EAAE,wBAAwB,CAAA;CAC/B;AAED,wBAAsB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,eAAe,CAAC,CAwD/F"}
@@ -1,10 +1,30 @@
1
+ import { resolveCaller } from "../auth/caller.js";
2
+ /**
3
+ * The {@link PipelineExecutionContext} for a tool / resource / prompt `ctx`,
4
+ * read through {@link resolveCaller} (both mcp-use 2 `ctx.auth` shapes) — what
5
+ * render-view, refresh-view and the builder catalogue hand their pipeline.
6
+ * Use it too when calling `renderView` / `getBuilderCatalogue` from your own
7
+ * tool, instead of reading `ctx.auth` yourself.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * server.tool({ name: "my-view", … }, (args, ctx) =>
12
+ * renderView({ input: args, stepRegistry, ctx: resolvePipelineContext(ctx) }),
13
+ * )
14
+ * ```
15
+ */
16
+ export function resolvePipelineContext(ctx) {
17
+ const caller = resolveCaller(ctx);
18
+ return caller === undefined ? {} : { userId: caller.userId, authenticated: true };
19
+ }
1
20
  /**
2
21
  * If the step's appConfig contains a `callTool` function (a closure the
3
22
  * plugin injects via `AppPlugin.appConfig`, e.g. a typed `callTool` bound to
4
23
  * the module's own store or client), rewrap it so the step-facing call
5
24
  * signature is `(name, args)` while the underlying closure receives the
6
- * current `{ userId }` via a hidden 3rd argument — steps stay synchronous
7
- * and userId-free while the closure can still scope data per user.
25
+ * current {@link PipelineExecutionContext} (`{ userId, authenticated }`) via a
26
+ * hidden 3rd argument — steps stay synchronous and userId-free while the
27
+ * closure can still scope data per user.
8
28
  * All other keys pass through untouched.
9
29
  */
10
30
  function bindAppConfig(appConfig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,CAAC,IAAI,CAAC;gBAClB,MAAM,EAAE,GAAG,CAAC,EAAE;gBACd,MAAM,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aACzD,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -94,8 +94,8 @@ export interface CatalogueOptions {
94
94
  widgetRegistry: WidgetRegistry;
95
95
  appConfigs?: Record<string, unknown>;
96
96
  /**
97
- * Per-request context (currently: the calling userId). Mirrors
98
- * {@link RenderViewOptions.ctx}.
97
+ * Per-request context — who is calling; build it with
98
+ * `resolvePipelineContext(ctx)`. Mirrors {@link RenderViewOptions.ctx}.
99
99
  */
100
100
  ctx?: PipelineExecutionContext;
101
101
  }
@@ -14,10 +14,12 @@ export interface RenderViewOptions {
14
14
  stepRegistry: StepRegistry;
15
15
  appConfigs?: Record<string, Record<string, unknown>>;
16
16
  /**
17
- * Per-request context (currently: the calling userId) that the pipeline
18
- * executor uses to pre-bind user-scoped `callTool` closures on step
19
- * `appConfig`s. Pass it through from the tool handler's
20
- * `ctx.auth?.user?.userId`.
17
+ * Per-request context — who is calling — that the pipeline executor hands
18
+ * to user-scoped `callTool` closures on step `appConfig`s. Build it from the
19
+ * tool handler's `ctx` with `resolvePipelineContext(ctx)` (both mcp-use 2
20
+ * `ctx.auth` shapes; the caller id is `user.id`, then `user.userId`, then
21
+ * the token's `sub`). Never read `ctx.auth.user.userId` directly: no
22
+ * built-in mcp-use 2 provider sets it.
21
23
  */
22
24
  ctx?: PipelineExecutionContext;
23
25
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"render-view.d.ts","sourceRoot":"","sources":["../../src/framework/render-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,wBAAwB,EAAE,MAAM,gCAAgC,CAAA;AAE/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8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AE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,KAAK,EAAE,KAAK,CAAC,KAAK;SACnB;QACD,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,OAAO,EAAE;YACP,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;YACnC,QAAQ,EAAE,MAAM,CAAC,WAAW,CAC1B,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;gBAClD,EAAE;gBACF;oBACE,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,SAAS,EAAE,MAAM,CAAC,SAAS;iBAC5B;aACF,CAAC,CACH;YACD,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB;QACD,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,gBAAgB,EAAE,gBAAgB,IAAI,KAAK;KAC5C,CAAA;IAED,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;QACvD,iBAAiB;KAClB,CAAA;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { appsSdkMeta, viewResourceUri, VIEW_RESOURCE_URI_PREFIX } from "./types/
3
3
  export type { AppsSdkMetaOptions, AppResourceCsp } from "./types/index.js";
4
4
  export { createTranslator } from "./i18n/index.js";
5
5
  export type { Message, MessageCatalog, Catalogs, Translate, CreateTranslatorOptions, } from "./i18n/index.js";
6
- export { executePipeline } from "./engine/pipeline-executor.js";
6
+ export { executePipeline, resolvePipelineContext } from "./engine/pipeline-executor.js";
7
7
  export type { PipelineExecutionContext, ExecutePipelineOptions, } from "./engine/pipeline-executor.js";
8
8
  export { validatePipeline } from "./engine/context-builder.js";
9
9
  export { StepRegistry } from "./registry/step-registry.js";
@@ -24,8 +24,10 @@ export type { LayoutConfig, RowDef } from "./framework/layout-types.js";
24
24
  export { layoutInputSchema, layoutSchema, rowSchema } from "./framework/layout-schemas.js";
25
25
  export { resolveActiveModules, parseActiveModules } from "./framework/active-modules.js";
26
26
  export type { ActiveModuleSelection } from "./framework/active-modules.js";
27
+ export { resolveCaller, resolveCallerId } from "./auth/caller.js";
28
+ export type { Caller } from "./auth/caller.js";
27
29
  export { createOrgGateMiddleware } from "./middleware/org-gate.js";
28
- export type { OrgGateMiddleware } from "./middleware/org-gate.js";
30
+ export type { OrgGateMiddleware, OrgGateMiddlewareFn } from "./middleware/org-gate.js";
29
31
  export { createRoleFilterMiddleware } from "./middleware/role-filter.js";
30
- export type { RoleFilterMiddleware, RoleFilterMiddlewares, RoleFilterOptions, RoleFilterContext, } from "./middleware/role-filter.js";
32
+ export type { RoleFilterMiddleware, RoleFilterMiddlewareFn, RoleFilterMiddlewares, RoleFilterOptions, RoleFilterContext, } from "./middleware/role-filter.js";
31
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,sBAAsB,EACtB,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,SAAS,EACT,cAAc,EACd,eAAe,EACf,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,aAAa,GACd,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AACzF,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAA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,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAE1F,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AACxF,YAAY,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAA;AAK1E,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACjE,YAAY,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAClE,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AACtF,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAA;AACxE,YAAY,EACV,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,6BAA6B,CAAA"}
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ export { appsSdkMeta, viewResourceUri, VIEW_RESOURCE_URI_PREFIX } from "./types/
5
5
  // `LocaleProvider`/`useLocale` (in `@miragon/mcp-toolkit-ui`) consume a
6
6
  // `Translate` from here.
7
7
  export { createTranslator } from "./i18n/index.js";
8
- export { executePipeline } from "./engine/pipeline-executor.js";
8
+ export { executePipeline, resolvePipelineContext } from "./engine/pipeline-executor.js";
9
9
  export { validatePipeline } from "./engine/context-builder.js";
10
10
  export { StepRegistry } from "./registry/step-registry.js";
11
11
  export { WidgetRegistry } from "./registry/widget-registry.js";
@@ -17,6 +17,10 @@ export { getFrameworkManifest } from "./framework/manifest.js";
17
17
  export { normalizeLayout } from "./framework/layout-types.js";
18
18
  export { layoutInputSchema, layoutSchema, rowSchema } from "./framework/layout-schemas.js";
19
19
  export { resolveActiveModules, parseActiveModules } from "./framework/active-modules.js";
20
+ // Caller identity — the one reader of both mcp-use 2 `ctx.auth` shapes
21
+ // (middleware: SDK AuthInfo, user under `extra.user`; callbacks: flattened
22
+ // `auth.user`). Browser-safe; every toolkit auth consumer goes through it.
23
+ export { resolveCaller, resolveCallerId } from "./auth/caller.js";
20
24
  export { createOrgGateMiddleware } from "./middleware/org-gate.js";
21
25
  export { createRoleFilterMiddleware } from "./middleware/role-filter.js";
22
26
  // NOTE: Tool registrars (`createToolRegistrar`, `createWidgetToolRegistrar`)
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAGzF,gFAAgF;AAChF,6EAA6E;AAC7E,8EAA8E;AAC9E,wEAAwE;AACxE,yBAAyB;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AASlD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAK/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEnD,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAEvD,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,oBAAoB,GACrB,MAAM,8BAA8B,CAAA;AAOrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAwB9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAE7D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAE1F,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAA;AAGxF,O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C3E,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAGjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAElE,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAA;AASxE,6EAA6E;AAC7E,gEAAgE;AAChE,qEAAqE;AACrE,4EAA4E;AAC5E,4EAA4E"}
@@ -1,22 +1,46 @@
1
1
  /**
2
2
  * Organisation-scope gate for mcp-use middleware.
3
3
  *
4
- * Built for WorkOS-style tokens that carry an `organization_id` claim on the
5
- * user object. If `orgId` is given, every inbound MCP RPC must come from a
6
- * user whose token matches — other orgs (or tokens without any org context)
7
- * get rejected with a thrown error.
4
+ * If `orgId` is given, every inbound MCP RPC must come from a user whose
5
+ * token carries that organization — other orgs (or tokens without any org
6
+ * context) get rejected with a thrown error. The organization comes from
7
+ * {@link resolveCaller}: the provider-mapped `user.organizationId` (WorkOS,
8
+ * Clerk, Scalekit, …), or the 1.x-era `user.organization_id`, read from
9
+ * either mcp-use 2 shape — middleware receives the SDK `AuthInfo` with the
10
+ * mapped user under `ctx.auth.extra.user`.
8
11
  *
9
12
  * Register on an mcp-use server with `server.use("mcp:*", createOrgGateMiddleware(ORG_ID))`.
10
13
  * Pass `undefined` to disable (returns a pass-through middleware) — handy so
11
14
  * the caller can unconditionally wire it up and let env config decide.
12
15
  */
16
+ /**
17
+ * The slice of an mcp-use middleware context the gate reads. Structural (no
18
+ * mcp-use import), shaped so mcp-use 2's own `MiddlewareContext` is
19
+ * assignable to it.
20
+ */
13
21
  interface OrgGateContext {
14
22
  auth?: {
23
+ /** Callback-shaped (and 1.x-era) contexts: the provider-mapped user. */
15
24
  user?: Record<string, unknown>;
25
+ /** mcp-use 2 middleware: SDK `AuthInfo.extra`, holding the mapped `user`. */
26
+ extra?: Record<string, unknown>;
16
27
  };
17
28
  }
18
- type Next = () => Promise<unknown>;
19
- export type OrgGateMiddleware = (ctx: OrgGateContext, next: Next) => Promise<unknown>;
20
- export declare function createOrgGateMiddleware(orgId: string | undefined): OrgGateMiddleware;
29
+ /**
30
+ * An org-gate middleware as consumers type their own wrappers and test
31
+ * doubles: the chain result is `unknown`. Kept non-generic on purpose — it is
32
+ * the published 2.x shape, and a generic alias would no longer accept a
33
+ * consumer function that returns a concrete type. The factory's middleware
34
+ * ({@link OrgGateMiddlewareFn}) is assignable to it.
35
+ */
36
+ export type OrgGateMiddleware = (ctx: OrgGateContext, next: () => Promise<unknown>) => Promise<unknown>;
37
+ /**
38
+ * The middleware {@link createOrgGateMiddleware} returns. Generic over the
39
+ * chain's result so it registers directly on `server.use("mcp:*", …)` (and on
40
+ * any exact `mcp:` method) without a cast. Assignable to
41
+ * {@link OrgGateMiddleware}.
42
+ */
43
+ export type OrgGateMiddlewareFn = <TResult>(ctx: OrgGateContext, next: () => Promise<TResult>) => Promise<TResult>;
44
+ export declare function createOrgGateMiddleware(orgId: string | undefined): OrgGateMiddlewareFn;
21
45
  export {};
22
46
  //# sourceMappingURL=org-gate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"org-gate.d.ts","sourceRoot":"","sources":["../../src/middleware/org-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAA;CAC1C;AACD,KAAK,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;AAClC,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAErF,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,iBAAiB,CAgBpF"}
1
+ {"version":3,"file":"org-gate.d.ts","sourceRoot":"","sources":["../../src/middleware/org-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH;;;;GAIG;AACH,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE;QACL,wEAAwE;QACxE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC9B,6EAA6E;QAC7E,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAChC,CAAA;CACF;AAED;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,KACzB,OAAO,CAAC,OAAO,CAAC,CAAA;AAErB;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,EACxC,GAAG,EAAE,cAAc,EACnB,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,KACzB,OAAO,CAAC,OAAO,CAAC,CAAA;AAErB,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,mBAAmB,CAetF"}
@@ -1,21 +1,24 @@
1
1
  /**
2
2
  * Organisation-scope gate for mcp-use middleware.
3
3
  *
4
- * Built for WorkOS-style tokens that carry an `organization_id` claim on the
5
- * user object. If `orgId` is given, every inbound MCP RPC must come from a
6
- * user whose token matches — other orgs (or tokens without any org context)
7
- * get rejected with a thrown error.
4
+ * If `orgId` is given, every inbound MCP RPC must come from a user whose
5
+ * token carries that organization — other orgs (or tokens without any org
6
+ * context) get rejected with a thrown error. The organization comes from
7
+ * {@link resolveCaller}: the provider-mapped `user.organizationId` (WorkOS,
8
+ * Clerk, Scalekit, …), or the 1.x-era `user.organization_id`, read from
9
+ * either mcp-use 2 shape — middleware receives the SDK `AuthInfo` with the
10
+ * mapped user under `ctx.auth.extra.user`.
8
11
  *
9
12
  * Register on an mcp-use server with `server.use("mcp:*", createOrgGateMiddleware(ORG_ID))`.
10
13
  * Pass `undefined` to disable (returns a pass-through middleware) — handy so
11
14
  * the caller can unconditionally wire it up and let env config decide.
12
15
  */
16
+ import { resolveCaller } from "../auth/caller.js";
13
17
  export function createOrgGateMiddleware(orgId) {
14
18
  if (!orgId)
15
19
  return (_ctx, next) => next();
16
20
  return async (ctx, next) => {
17
- const user = ctx.auth?.user;
18
- const tokenOrgId = user?.organization_id;
21
+ const tokenOrgId = resolveCaller(ctx)?.organizationId;
19
22
  if (!tokenOrgId) {
20
23
  throw new Error("Access denied: no organization context in the token. Authenticate with the correct organization.");
21
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"org-gate.js","sourceRoot":"","sources":["../../src/middleware/org-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH,MAAM,UAAU,uBAAuB,CAAC,KAAyB;IAC/D,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAA;IAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,IAAI,CAAA;QAC3B,MAAM,UAAU,GAAG,IAAI,EAAE,eAAe,CAAA;QACxC,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,kGAAkG,CACnG,CAAA;QACH,CAAC;QACD,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;QAC9E,CAAC;QACD,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"org-gate.js","sourceRoot":"","sources":["../../src/middleware/org-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAuCjD,MAAM,UAAU,uBAAuB,CAAC,KAAyB;IAC/D,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAA;IAEzC,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QACzB,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,EAAE,cAAc,CAAA;QACrD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,kGAAkG,CACnG,CAAA;QACH,CAAC;QACD,IAAI,UAAU,KAAK,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;QAC9E,CAAC;QACD,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC"}
@@ -11,6 +11,10 @@
11
11
  * `ctx.params.name`. When no name is present it fails *open* by default
12
12
  * (allow) — pass `failClosed: true` to deny instead.
13
13
  *
14
+ * The caller's roles come from {@link resolveCaller}, which reads both mcp-use 2
15
+ * shapes — middleware receives the SDK `AuthInfo` with the provider-mapped user
16
+ * under `ctx.auth.extra.user`, never `ctx.auth.user`.
17
+ *
14
18
  * Batches need no special handling: mcp-use invokes `mcp:tools/call`
15
19
  * middleware once per call, so each entry of a JSON-RPC batch is guarded
16
20
  * individually (verified against 2.0.4 — a two-entry batch fires the guard
@@ -26,24 +30,53 @@
26
30
  * *unrestricted* access — this is deliberately opt-in so that adding a new
27
31
  * role doesn't silently revoke anyone's tools.
28
32
  */
33
+ /**
34
+ * The slice of an mcp-use middleware context the role filter reads. Kept
35
+ * structural (no mcp-use import) so the root barrel stays host-agnostic; it is
36
+ * shaped so mcp-use 2's own `MiddlewareContext` is assignable to it.
37
+ */
29
38
  export interface RoleFilterContext {
30
39
  auth?: {
40
+ /** Callback-shaped (and 1.x-era) contexts: the provider-mapped user. */
31
41
  user?: {
32
42
  roles?: unknown;
33
43
  };
44
+ /** mcp-use 2 middleware: SDK `AuthInfo.extra`, holding the mapped `user`. */
45
+ extra?: Record<string, unknown>;
34
46
  };
35
47
  method?: string;
36
48
  params?: {
37
49
  name?: unknown;
50
+ [key: string]: unknown;
38
51
  };
39
52
  }
40
- type Next = () => Promise<unknown>;
41
- export type RoleFilterMiddleware = (ctx: RoleFilterContext, next: Next) => Promise<unknown>;
42
- export interface RoleFilterMiddlewares {
53
+ /**
54
+ * A role-filter middleware as consumers type their own wrappers and test
55
+ * doubles: the chain result is `unknown`. Kept non-generic on purpose — it is
56
+ * the published 2.x shape, and a generic alias would no longer accept a
57
+ * consumer function that returns a concrete type. The factory's middlewares
58
+ * ({@link RoleFilterMiddlewareFn}) are assignable to it.
59
+ */
60
+ export type RoleFilterMiddleware = (ctx: RoleFilterContext, next: () => Promise<unknown>) => Promise<unknown>;
61
+ /**
62
+ * The middleware {@link createRoleFilterMiddleware} returns. Generic over the
63
+ * chain's result so it registers directly on
64
+ * `server.use("mcp:tools/list" | "mcp:tools/call", …)` without a cast — the
65
+ * result of `next()` flows back out with its type intact. Assignable to
66
+ * {@link RoleFilterMiddleware}.
67
+ */
68
+ export type RoleFilterMiddlewareFn = <TResult>(ctx: RoleFilterContext, next: () => Promise<TResult>) => Promise<TResult>;
69
+ /**
70
+ * The `tools/list` + `tools/call` pair. Without a type argument the fields are
71
+ * the non-generic {@link RoleFilterMiddleware} (the shape consumers build by
72
+ * hand); the factory returns `RoleFilterMiddlewares<RoleFilterMiddlewareFn>`,
73
+ * which is assignable to it.
74
+ */
75
+ export interface RoleFilterMiddlewares<TMiddleware = RoleFilterMiddleware> {
43
76
  /** Register with `server.use("mcp:tools/list", ...)`. */
44
- toolsList: RoleFilterMiddleware;
77
+ toolsList: TMiddleware;
45
78
  /** Register with `server.use("mcp:tools/call", ...)`. */
46
- toolsCall: RoleFilterMiddleware;
79
+ toolsCall: TMiddleware;
47
80
  }
48
81
  export interface RoleFilterOptions {
49
82
  /**
@@ -58,6 +91,5 @@ export interface RoleFilterOptions {
58
91
  */
59
92
  failClosed?: boolean;
60
93
  }
61
- export declare function createRoleFilterMiddleware(roleToModules: Record<string, string[]>, opts?: RoleFilterOptions): RoleFilterMiddlewares;
62
- export {};
94
+ export declare function createRoleFilterMiddleware(roleToModules: Record<string, string[]>, opts?: RoleFilterOptions): RoleFilterMiddlewares<RoleFilterMiddlewareFn>;
63
95
  //# sourceMappingURL=role-filter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"role-filter.d.ts","sourceRoot":"","sources":["../../src/middleware/role-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAA;IACrC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAC5B;AACD,KAAK,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;AAClC,MAAM,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAE3F,MAAM,WAAW,qBAAqB;IACpC,yDAAyD;IACzD,SAAS,EAAE,oBAAoB,CAAA;IAC/B,yDAAyD;IACzD,SAAS,EAAE,oBAAoB,CAAA;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EACvC,IAAI,GAAE,iBAAsB,GAC3B,qBAAqB,CAyDvB"}
1
+ {"version":3,"file":"role-filter.d.ts","sourceRoot":"","sources":["../../src/middleware/role-filter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAIH;;;;GAIG;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