mcp-use 2.0.0-beta.13 → 2.0.0-beta.15

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 (34) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-XKJP5S7C.js → chunk-E7M6OYZ5.js} +5 -2
  3. package/dist/{chunk-XKJP5S7C.js.map → chunk-E7M6OYZ5.js.map} +1 -1
  4. package/dist/{chunk-STCR3P5O.js → chunk-XUI7QE2D.js} +4 -1
  5. package/dist/chunk-XUI7QE2D.js.map +1 -0
  6. package/dist/{chunk-JEVBOMCE.js → chunk-ZJJD33SF.js} +2 -2
  7. package/dist/chunk-ZJJD33SF.js.map +1 -0
  8. package/dist/cli/dev.d.ts.map +1 -1
  9. package/dist/cli/views-plugin.d.ts.map +1 -1
  10. package/dist/commands/build.js +2 -2
  11. package/dist/commands/dev.js +2 -1
  12. package/dist/commands/dev.js.map +1 -1
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +212 -41
  16. package/dist/index.js.map +1 -1
  17. package/dist/inspector-shell.d.ts.map +1 -1
  18. package/dist/{landing-handler-Z7WDR4S2.js → landing-handler-WE66NIGB.js} +2 -2
  19. package/dist/landing.js +1 -1
  20. package/dist/middleware/mcp-middleware.d.ts +142 -102
  21. package/dist/middleware/mcp-middleware.d.ts.map +1 -1
  22. package/dist/react/components/theme-provider.d.ts +3 -0
  23. package/dist/react/components/theme-provider.d.ts.map +1 -1
  24. package/dist/react/hooks/use-host-context.d.ts +5 -0
  25. package/dist/react/hooks/use-host-context.d.ts.map +1 -1
  26. package/dist/react/index.js +58 -1
  27. package/dist/react/index.js.map +1 -1
  28. package/dist/server.d.ts +6 -4
  29. package/dist/server.d.ts.map +1 -1
  30. package/dist/views/document.d.ts.map +1 -1
  31. package/package.json +4 -4
  32. package/dist/chunk-JEVBOMCE.js.map +0 -1
  33. package/dist/chunk-STCR3P5O.js.map +0 -1
  34. /package/dist/{landing-handler-Z7WDR4S2.js.map → landing-handler-WE66NIGB.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"inspector-shell.d.ts","sourceRoot":"","sources":["../src/inspector-shell.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,aAAa,SAAS,CAAC;AAEpC;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,+EAA2F,CAAC;AAErI;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE5D;AAED,2EAA2E;AAC3E,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElE;AAED,oFAAoF;AACpF,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAIhE;AAED,8EAA8E;AAC9E,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAOT;AAED,+CAA+C;AAC/C,MAAM,WAAW,qBAAqB;IACpC,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAuBD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,C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E,MAAM,GAAG,SAAS,CAAC;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAuBD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,CA0E3E;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,gBAAgB,GAAG,SAAS,EACvC,OAAO,EAAE;IACP,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GACA,YAAY,GAAG,SAAS,CAqC1B;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAI1C"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  generateLandingPage
3
- } from "./chunk-JEVBOMCE.js";
3
+ } from "./chunk-ZJJD33SF.js";
4
4
  import {
5
5
  resolveServerOrigin
6
6
  } from "./chunk-FC2Z2VFO.js";
@@ -34,4 +34,4 @@ function createLandingPageResponse(request, basePath, config, branding, tools, p
34
34
  export {
35
35
  createLandingPageResponse
36
36
  };
37
- //# sourceMappingURL=landing-handler-Z7WDR4S2.js.map
37
+ //# sourceMappingURL=landing-handler-WE66NIGB.js.map
package/dist/landing.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  generateLandingPage
3
- } from "./chunk-JEVBOMCE.js";
3
+ } from "./chunk-ZJJD33SF.js";
4
4
  export {
5
5
  generateLandingPage
6
6
  };
@@ -1,135 +1,175 @@
1
- import type { AuthInfo } from "@modelcontextprotocol/server";
1
+ import type { AuthInfo, HandlerResultTypeMap, RequestTypeMap, ResultTypeMap } from "@modelcontextprotocol/server";
2
+ declare const MCP_MIDDLEWARE_METHODS: readonly ["tools/call", "tools/list", "resources/read", "resources/list", "prompts/get", "prompts/list"];
3
+ /** MCP methods currently intercepted by {@link MCPServer.use}. */
4
+ export type McpMiddlewareMethod = (typeof MCP_MIDDLEWARE_METHODS)[number];
5
+ /** Params exposed by the SDK for a particular MCP request method. */
6
+ export type McpMiddlewareParams<M extends McpMiddlewareMethod> = RequestTypeMap[M] extends {
7
+ params?: infer P;
8
+ } ? NonNullable<P> : Record<string, never>;
2
9
  /**
3
- * Context passed to every MCP middleware handler.
10
+ * Method-specific params and middleware result types.
4
11
  *
5
- * `params` is mutable — middleware can modify params before calling `next()`
6
- * and those changes will be visible to downstream middleware and the handler.
7
- *
8
- * `state` is a shared Map for passing arbitrary data across middleware in
9
- * the same chain.
12
+ * List middleware intentionally operates on item arrays rather than protocol
13
+ * result envelopes. The server wrapper preserves the envelope around the
14
+ * transformed array.
10
15
  */
11
- export interface MiddlewareContext {
12
- /** MCP method name, e.g. "tools/call", "tools/list", "resources/read" */
13
- method: string;
14
- /** JSON-RPC request params (mutable — mutations are passed downstream) */
15
- params: Record<string, unknown>;
16
- /** OAuth info extracted from JWT, present when OAuth is configured */
17
- auth?: AuthInfo;
18
- /** Shared state Map for passing data across middleware in the same request */
19
- state: Map<string, unknown>;
20
- }
21
- /** Params shape for `tools/call` method */
22
- interface ToolsCallParams {
23
- name: string;
24
- arguments?: Record<string, unknown>;
25
- _meta?: Record<string, unknown>;
26
- }
27
- /** Params shape for `resources/read` method */
28
- interface ResourcesReadParams {
29
- uri: string;
30
- _meta?: Record<string, unknown>;
31
- }
32
- /** Params shape for `prompts/get` method */
33
- interface PromptsGetParams {
34
- name: string;
35
- arguments?: Record<string, string>;
36
- _meta?: Record<string, unknown>;
37
- }
38
- /** Context with narrowed `params` for `tools/call` */
39
- export interface ToolsCallMiddlewareContext extends MiddlewareContext {
40
- method: "tools/call";
41
- params: ToolsCallParams & Record<string, unknown>;
42
- }
43
- /** Context with narrowed `params` for `resources/read` */
44
- export interface ResourcesReadMiddlewareContext extends MiddlewareContext {
45
- method: "resources/read";
46
- params: ResourcesReadParams & Record<string, unknown>;
47
- }
48
- /** Context with narrowed `params` for `prompts/get` */
49
- export interface PromptsGetMiddlewareContext extends MiddlewareContext {
50
- method: "prompts/get";
51
- params: PromptsGetParams & Record<string, unknown>;
16
+ export interface McpMiddlewareOperationMap {
17
+ "tools/call": {
18
+ params: McpMiddlewareParams<"tools/call">;
19
+ result: HandlerResultTypeMap["tools/call"];
20
+ };
21
+ "tools/list": {
22
+ params: McpMiddlewareParams<"tools/list">;
23
+ result: ResultTypeMap["tools/list"]["tools"];
24
+ };
25
+ "resources/read": {
26
+ params: McpMiddlewareParams<"resources/read">;
27
+ result: HandlerResultTypeMap["resources/read"];
28
+ };
29
+ "resources/list": {
30
+ params: McpMiddlewareParams<"resources/list">;
31
+ result: ResultTypeMap["resources/list"]["resources"];
32
+ };
33
+ "prompts/get": {
34
+ params: McpMiddlewareParams<"prompts/get">;
35
+ result: HandlerResultTypeMap["prompts/get"];
36
+ };
37
+ "prompts/list": {
38
+ params: McpMiddlewareParams<"prompts/list">;
39
+ result: ResultTypeMap["prompts/list"]["prompts"];
40
+ };
52
41
  }
42
+ /** Result exposed to middleware for a particular MCP method. */
43
+ export type McpMiddlewareResult<M extends McpMiddlewareMethod> = McpMiddlewareOperationMap[M]["result"];
53
44
  /**
54
- * Map from MCP middleware pattern strings to their narrowed context type.
55
- * Used by `McpMiddlewareFnFor<P>` to infer the correct `ctx` parameter.
45
+ * Rebuild an SDK request with the params currently held by middleware.
46
+ *
47
+ * Middleware may replace `ctx.params`, so forwarding the request object that
48
+ * was captured before the chain ran would silently discard that replacement.
49
+ * @internal
56
50
  */
57
- export interface McpMiddlewarePatternMap {
58
- "tools/call": ToolsCallMiddlewareContext;
59
- "resources/read": ResourcesReadMiddlewareContext;
60
- "prompts/get": PromptsGetMiddlewareContext;
51
+ export declare function withMcpMiddlewareParams<M extends McpMiddlewareMethod>(request: unknown, params: McpMiddlewareOperationMap[M]["params"]): RequestTypeMap[M];
52
+ interface MiddlewareContextCommon {
53
+ /** Session info when the underlying transport provides a session ID. */
54
+ session?: {
55
+ sessionId: string;
56
+ };
57
+ /** OAuth info extracted from the validated access token. */
58
+ auth?: AuthInfo;
59
+ /** Shared state for middleware participating in this request. */
60
+ state: Map<string, unknown>;
61
61
  }
62
62
  /**
63
- * A typed MCP middleware function whose `ctx` is narrowed based on the
64
- * pattern string `P`. Falls back to the base `MiddlewareContext` for
65
- * wildcard or unrecognized patterns.
63
+ * Context passed to MCP middleware.
64
+ *
65
+ * The conditional form preserves the correlation between `method` and
66
+ * `params` when more than one method is represented.
66
67
  */
67
- export type McpMiddlewareFnFor<P extends string> = P extends keyof McpMiddlewarePatternMap ? (ctx: McpMiddlewarePatternMap[P], next: () => Promise<unknown>) => Promise<unknown> : McpMiddlewareFn;
68
+ export type MiddlewareContext<M extends McpMiddlewareMethod = McpMiddlewareMethod> = M extends McpMiddlewareMethod ? MiddlewareContextCommon & {
69
+ method: M;
70
+ params: McpMiddlewareOperationMap[M]["params"];
71
+ } : never;
72
+ /** Preferred explicit name for the method-correlated middleware context. */
73
+ export type McpMiddlewareContext<M extends McpMiddlewareMethod = McpMiddlewareMethod> = MiddlewareContext<M>;
74
+ /** Context with narrowed params for `tools/call`. */
75
+ export type ToolsCallMiddlewareContext = MiddlewareContext<"tools/call">;
76
+ /** Context with narrowed params for `tools/list`. */
77
+ export type ToolsListMiddlewareContext = MiddlewareContext<"tools/list">;
78
+ /** Context with narrowed params for `resources/read`. */
79
+ export type ResourcesReadMiddlewareContext = MiddlewareContext<"resources/read">;
80
+ /** Context with narrowed params for `resources/list`. */
81
+ export type ResourcesListMiddlewareContext = MiddlewareContext<"resources/list">;
82
+ /** Context with narrowed params for `prompts/get`. */
83
+ export type PromptsGetMiddlewareContext = MiddlewareContext<"prompts/get">;
84
+ /** Context with narrowed params for `prompts/list`. */
85
+ export type PromptsListMiddlewareContext = MiddlewareContext<"prompts/list">;
86
+ /** Map retained for compatibility and convenient indexed lookup. */
87
+ export type McpMiddlewarePatternMap = {
88
+ [M in McpMiddlewareMethod]: MiddlewareContext<M>;
89
+ };
90
+ /** Continue the middleware chain with the result type for method `M`. */
91
+ export type McpMiddlewareNext<M extends McpMiddlewareMethod> = () => Promise<McpMiddlewareResult<M>>;
92
+ /** Middleware for one exact MCP method. */
93
+ export type McpExactMiddlewareFn<M extends McpMiddlewareMethod> = (ctx: MiddlewareContext<M>, next: McpMiddlewareNext<M>) => Promise<McpMiddlewareResult<M>>;
68
94
  /**
69
- * A single MCP middleware function.
95
+ * Type-preserving middleware over every wrapped MCP method.
70
96
  *
71
- * Call `next()` to pass control to the next middleware (or handler).
72
- * Return its result, or return a different value to override the response.
73
- * Throw an error to reject the request.
97
+ * The global wildcard cannot inspect or replace a method-specific result. Its `next`
98
+ * resolves after downstream middleware, and the composer propagates that
99
+ * downstream result unchanged. It must call `next()` or throw.
74
100
  */
75
- export type McpMiddlewareFn = (ctx: MiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>;
101
+ export type McpMiddlewareFn<Methods extends McpMiddlewareMethod = McpMiddlewareMethod> = (ctx: MiddlewareContext<Methods>, next: () => Promise<void>) => Promise<void>;
102
+ /** Exact MCP middleware methods plus the global pass-through wildcard. */
103
+ export type McpMiddlewarePatternBody = McpMiddlewareMethod | "*";
104
+ /** Canonical `mcp:` patterns plus prefixless compatibility forms. */
105
+ export type McpMiddlewarePattern = McpMiddlewarePatternBody | `mcp:${McpMiddlewarePatternBody}`;
106
+ /** Observer patterns additionally support grouping related MCP methods. */
107
+ export type McpEventPatternBody = McpMiddlewarePatternBody | "tools/*" | "resources/*" | "prompts/*";
108
+ type McpEventBasePattern = McpEventPatternBody | `mcp:${McpEventPatternBody}`;
109
+ type StripMcpPrefix<P extends string> = P extends `mcp:${infer Body}` ? Body : P;
110
+ /** Methods selected by an MCP middleware or observer pattern. */
111
+ export type McpMiddlewareMethodsForPattern<P extends string> = StripMcpPrefix<P> extends infer Body ? Body extends McpMiddlewareMethod ? Body : Body extends "tools/*" ? Extract<McpMiddlewareMethod, `tools/${string}`> : Body extends "resources/*" ? Extract<McpMiddlewareMethod, `resources/${string}`> : Body extends "prompts/*" ? Extract<McpMiddlewareMethod, `prompts/${string}`> : Body extends "*" ? McpMiddlewareMethod : never : never;
112
+ /** Infer an exact or type-preserving wildcard handler from pattern `P`. */
113
+ export type McpMiddlewareFnFor<P extends McpMiddlewarePattern> = StripMcpPrefix<P> extends infer Body ? Body extends McpMiddlewareMethod ? McpExactMiddlewareFn<Body> : McpMiddlewareFn<McpMiddlewareMethodsForPattern<P>> : never;
76
114
  /**
77
- * Internal storage entry for a registered MCP middleware.
78
- * The pattern is stored with the `mcp:` prefix already stripped.
115
+ * Type-erased middleware adapter stored after registration.
116
+ *
117
+ * Exact handlers and the global wildcard are adapted to this common callable
118
+ * shape before insertion, following the SDK's request-handler storage model.
79
119
  * @internal
80
120
  */
81
121
  export interface McpMiddlewareEntry {
82
- /** Pattern after stripping "mcp:" — e.g. "tools/call", "tools/*", "*" */
83
122
  pattern: string;
84
- handler: McpMiddlewareFn;
123
+ handler: (ctx: MiddlewareContext, next: () => Promise<unknown>) => Promise<unknown>;
85
124
  }
86
- /** Phase for MCP observer event listeners registered via `server.on()`. */
87
- export type McpEventPhase = "before" | "complete";
88
125
  /**
89
- * Internal storage entry for a registered MCP observer event listener.
90
- * @internal
126
+ * Adapt a public method-correlated handler for type-erased internal storage.
127
+ *
128
+ * The overload retains the public pattern/handler correlation. The broad
129
+ * implementation signature is the deliberate erasure boundary, like the
130
+ * official SDK's `setRequestHandler` implementation.
91
131
  */
132
+ export declare function createMcpMiddlewareEntry<P extends McpMiddlewarePattern>(pattern: P, handler: McpMiddlewareFnFor<P>): McpMiddlewareEntry;
133
+ /** Phase for MCP observer event listeners registered via `server.on()`. */
134
+ export type McpEventPhase = "before" | "complete";
135
+ /** Read-only observer context correlated by MCP method. */
136
+ export type ReadonlyMiddlewareContext<M extends McpMiddlewareMethod = McpMiddlewareMethod> = M extends McpMiddlewareMethod ? Omit<MiddlewareContext<M>, "params" | "state"> & {
137
+ readonly params: Readonly<McpMiddlewareOperationMap[M]["params"]>;
138
+ readonly state: ReadonlyMap<string, unknown>;
139
+ } : never;
140
+ /** Read-only observer invoked before an MCP handler runs. */
141
+ export type McpEventListenerFn<Methods extends McpMiddlewareMethod = McpMiddlewareMethod> = <M extends Methods>(ctx: ReadonlyMiddlewareContext<M>) => void;
142
+ /** Read-only observer invoked after an MCP handler completes. */
143
+ export type McpCompleteEventListenerFn<Methods extends McpMiddlewareMethod = McpMiddlewareMethod> = <M extends Methods>(ctx: ReadonlyMiddlewareContext<M>, result: McpMiddlewareResult<M>) => void;
144
+ type McpExactEventListenerFn<M extends McpMiddlewareMethod> = (ctx: ReadonlyMiddlewareContext<M>) => void;
145
+ type McpExactCompleteEventListenerFn<M extends McpMiddlewareMethod> = (ctx: ReadonlyMiddlewareContext<M>, result: McpMiddlewareResult<M>) => void;
146
+ /** MCP observer pattern, optionally targeting the completion phase. */
147
+ export type McpEventPattern = McpEventBasePattern | `${McpEventBasePattern}:complete`;
148
+ type StripCompleteSuffix<P extends string> = P extends `${infer Body}:complete` ? Body : P;
149
+ /** Infer a typed before/complete observer from event pattern `P`. */
150
+ export type McpEventListenerFnFor<P extends McpEventPattern> = StripCompleteSuffix<StripMcpPrefix<P>> extends infer Body ? Body extends McpMiddlewareMethod ? P extends `${string}:complete` ? McpExactCompleteEventListenerFn<Body> : McpExactEventListenerFn<Body> : P extends `${string}:complete` ? McpCompleteEventListenerFn<McpMiddlewareMethodsForPattern<StripCompleteSuffix<P>>> : McpEventListenerFn<McpMiddlewareMethodsForPattern<StripCompleteSuffix<P>>> : never;
151
+ /** Internal type-erased observer entry. @internal */
92
152
  export interface McpEventListenerEntry {
93
153
  pattern: string;
94
154
  phase: McpEventPhase;
95
- handler: McpEventListenerFn | McpCompleteEventListenerFn;
155
+ handler: (ctx: ReadonlyMiddlewareContext, result?: unknown) => void;
96
156
  }
97
- /** Read-only observer invoked before the MCP handler runs. */
98
- export type McpEventListenerFn = (ctx: Readonly<MiddlewareContext>) => void;
99
- /** Read-only observer invoked after the MCP handler completes. */
100
- export type McpCompleteEventListenerFn = (ctx: Readonly<MiddlewareContext>, result: unknown) => void;
101
- /**
102
- * Test whether a registered middleware pattern matches a given MCP method.
103
- *
104
- * Matching rules:
105
- * - `"*"` matches any method
106
- * - `"tools/*"` prefix-matches any method starting with `"tools/"`
107
- * - `"tools/call"` exact-matches only `"tools/call"`
108
- */
157
+ /** Adapt a public method-correlated observer for type-erased storage. */
158
+ export declare function createMcpEventListenerEntry<P extends McpEventPattern>(pattern: P, handler: McpEventListenerFnFor<P>): McpEventListenerEntry;
159
+ /** Test whether a registered middleware or observer pattern matches a method. */
109
160
  export declare function matchesPattern(pattern: string, method: string): boolean;
110
- /**
111
- * Compose a middleware chain for a given MCP method invocation.
112
- *
113
- * Filters `entries` to those matching `method`, then builds a `next()` chain
114
- * with `innerFn` at the center. Returns the outermost callable.
115
- *
116
- * Middleware executes in FIFO registration order (first registered = outermost).
117
- */
118
- export declare function composeMiddleware(entries: McpMiddlewareEntry[], method: string, innerFn: () => Promise<unknown>): (ctx: MiddlewareContext) => Promise<unknown>;
161
+ /** Compose matching middleware in FIFO registration order. */
162
+ export declare function composeMiddleware<M extends McpMiddlewareMethod>(entries: McpMiddlewareEntry[], method: M, innerFn: () => Promise<McpMiddlewareResult<M>>): (ctx: MiddlewareContext<M>) => Promise<McpMiddlewareResult<M>>;
119
163
  /** Build a read-only snapshot of middleware context for observer events. */
120
- export declare function freezeMiddlewareContext(ctx: MiddlewareContext): Readonly<MiddlewareContext>;
121
- /**
122
- * Run before/complete observer listeners around a middleware chain.
123
- *
124
- * Listener throws are logged and do not fail the MCP request.
125
- */
126
- export declare function runMcpOperation(middlewares: McpMiddlewareEntry[], events: McpEventListenerEntry[], method: string, ctx: MiddlewareContext, innerFn: () => Promise<unknown>): Promise<unknown>;
127
- /** Strip `mcp:` prefix and optional `:complete` suffix from observer patterns. */
164
+ export declare function freezeMiddlewareContext<M extends McpMiddlewareMethod>(ctx: MiddlewareContext<M>): ReadonlyMiddlewareContext<M>;
165
+ /** Run before/complete observers around a method-correlated middleware chain. */
166
+ export declare function runMcpOperation<M extends McpMiddlewareMethod>(middlewares: McpMiddlewareEntry[], events: McpEventListenerEntry[], method: M, ctx: MiddlewareContext<M>, innerFn: () => Promise<McpMiddlewareResult<M>>): Promise<McpMiddlewareResult<M>>;
167
+ /** Strip `mcp:` prefix and optional `:complete` suffix from event patterns. */
128
168
  export declare function parseMcpPattern(raw: string): {
129
169
  pattern: string;
130
170
  phase: McpEventPhase;
131
171
  };
132
- /** Normalize middleware pattern strings (strip `mcp:` prefix). */
172
+ /** Normalize middleware pattern strings by stripping the `mcp:` prefix. */
133
173
  export declare function normalizeMcpMiddlewarePattern(raw: string): string;
134
174
  export {};
135
175
  //# sourceMappingURL=mcp-middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/mcp-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAE7D;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,sEAAsE;IACtE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,8EAA8E;IAC9E,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7B;AAED,2CAA2C;AAC3C,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;A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C,GAAG,EAAE,MAAM,GAAG;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,aAAa,CAAC;CACtB,CASA;AAED,2EAA2E;AAC3E,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjE"}
@@ -5,6 +5,9 @@ import React from "react";
5
5
  * Subscribes to the host channel (theme, `styles.variables`, `styles.css.fonts`)
6
6
  * via {@link useHostContextSubscription}. Theme-only consumers should use
7
7
  * {@link useViewTheme} instead so locale/dimension updates do not rerender them.
8
+ *
9
+ * MCP App views render in srcdoc iframes; the document canvas stays transparent
10
+ * by default so rounded cards do not expose an opaque `color-scheme` backdrop.
8
11
  */
9
12
  export declare const ThemeProvider: React.FC<{
10
13
  children: React.ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"theme-provider.d.ts","sourceRoot":"","sources":["../../../src/react/components/theme-provider.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAIzD;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;IACnC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,yEAAyE;IACzE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAkDA,CAAC"}
1
+ {"version":3,"file":"theme-provider.d.ts","sourceRoot":"","sources":["../../../src/react/components/theme-provider.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAoC,MAAM,OAAO,CAAC;AA2DzD;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;IACnC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,yEAAyE;IACzE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CA4DA,CAAC"}
@@ -11,6 +11,11 @@ export interface HostContextHandle {
11
11
  timeZone: string;
12
12
  /** Host application user-agent string. Falls back to the browser's own user agent. */
13
13
  userAgent: string;
14
+ /**
15
+ * Host-reported platform. `"mobile"` on mobile hosts; otherwise `"web"`.
16
+ * Inspector maps Desktop → `"web"` and Mobile → `"mobile"`.
17
+ */
18
+ platform: "web" | "mobile";
14
19
  /** How the host is currently displaying the view. `"inline"` until the host reports otherwise. */
15
20
  displayMode: DisplayMode;
16
21
  /** Mobile safe area insets in pixels. All zeros when the host reports none. */
@@ -1 +1 @@
1
- {"version":3,"file":"use-host-context.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-host-context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,cAAc,EACf,MAAM,wBAAwB,CAAC;AAwChC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,uFAAuF;IACvF,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAC;IACjB,sFAAsF;IACtF,SAAS,EAAE,MAAM,CAAC;IAClB,kGAAkG;IAClG,WAAW,EAAE,WAAW,CAAC;IACzB,+EAA+E;IAC/E,QAAQ,EAAE,cAAc,CAAC;IACzB;;;;;;;;OAQG;IACH,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,oFAAoF;IACpF,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,gBAAgB,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC/C;;;;OAIG;IACH,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC;IACrC,0GAA0G;IAC1G,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,IAAI,iBAAiB,CAiClD"}
1
+ {"version":3,"file":"use-host-context.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-host-context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,cAAc,EACf,MAAM,wBAAwB,CAAC;AA8ChC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,uFAAuF;IACvF,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,QAAQ,EAAE,MAAM,CAAC;IACjB,sFAAsF;IACtF,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,EAAE,KAAK,GAAG,QAAQ,CAAC;IAC3B,kGAAkG;IAClG,WAAW,EAAE,WAAW,CAAC;IACzB,+EAA+E;IAC/E,QAAQ,EAAE,cAAc,CAAC;IACzB;;;;;;;;OAQG;IACH,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,oFAAoF;IACpF,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,kGAAkG;IAClG,gBAAgB,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC/C;;;;OAIG;IACH,WAAW,EAAE,WAAW,GAAG,SAAS,CAAC;IACrC,0GAA0G;IAC1G,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,IAAI,iBAAiB,CAkClD"}
@@ -951,7 +951,54 @@ import {
951
951
  } from "@modelcontextprotocol/ext-apps";
952
952
  import React2, { useLayoutEffect, useState } from "react";
953
953
  import { Fragment, jsx as jsx6 } from "react/jsx-runtime";
954
- var ThemeProvider = ({ children, colorScheme = true }) => {
954
+ function applyTransparentIframeCanvas() {
955
+ document.documentElement.style.background = "transparent";
956
+ document.body.style.background = "transparent";
957
+ const root = document.getElementById("root");
958
+ if (root) root.style.background = "transparent";
959
+ }
960
+ var FILL_HOST_WRAPPER_STYLE = {
961
+ position: "relative",
962
+ height: "100%",
963
+ minHeight: "100%",
964
+ display: "flex",
965
+ flexDirection: "column"
966
+ };
967
+ function useFillHostDocument(fillHost) {
968
+ useLayoutEffect(() => {
969
+ if (!fillHost || typeof document === "undefined") return;
970
+ const html = document.documentElement;
971
+ const body = document.body;
972
+ const root = document.getElementById("root");
973
+ const prev = {
974
+ htmlH: html.style.height,
975
+ bodyH: body.style.height,
976
+ htmlMin: html.style.minHeight,
977
+ bodyMin: body.style.minHeight,
978
+ rootH: root?.style.height ?? "",
979
+ rootMin: root?.style.minHeight ?? ""
980
+ };
981
+ for (const el of [html, body]) {
982
+ el.style.height = "100%";
983
+ el.style.minHeight = "100%";
984
+ }
985
+ if (root) {
986
+ root.style.height = "100%";
987
+ root.style.minHeight = "100%";
988
+ }
989
+ return () => {
990
+ html.style.height = prev.htmlH;
991
+ body.style.height = prev.bodyH;
992
+ html.style.minHeight = prev.htmlMin;
993
+ body.style.minHeight = prev.bodyMin;
994
+ if (root) {
995
+ root.style.height = prev.rootH;
996
+ root.style.minHeight = prev.rootMin;
997
+ }
998
+ };
999
+ }, [fillHost]);
1000
+ }
1001
+ var ThemeProvider = ({ children, colorScheme = false }) => {
955
1002
  const hostContext = useHostContextSubscription();
956
1003
  const [systemPreference, setSystemPreference] = useState(
957
1004
  () => {
@@ -970,9 +1017,12 @@ var ThemeProvider = ({ children, colorScheme = true }) => {
970
1017
  }, []);
971
1018
  const hostTheme = hostContext?.theme === "dark" || hostContext?.theme === "light" ? hostContext.theme : void 0;
972
1019
  const effectiveTheme = hostTheme ?? systemPreference;
1020
+ const fillHost = hostContext?.displayMode === "fullscreen" || hostContext?.displayMode === "pip";
1021
+ useFillHostDocument(fillHost);
973
1022
  useLayoutEffect(() => {
974
1023
  if (typeof document === "undefined") return;
975
1024
  applyDocumentTheme(effectiveTheme);
1025
+ applyTransparentIframeCanvas();
976
1026
  if (colorScheme) {
977
1027
  document.documentElement.style.colorScheme = effectiveTheme === "dark" ? "dark" : "light";
978
1028
  } else {
@@ -989,6 +1039,9 @@ var ThemeProvider = ({ children, colorScheme = true }) => {
989
1039
  applyHostFonts(fonts);
990
1040
  }
991
1041
  }, [hostContext]);
1042
+ if (fillHost) {
1043
+ return /* @__PURE__ */ jsx6("div", { style: FILL_HOST_WRAPPER_STYLE, children });
1044
+ }
992
1045
  return /* @__PURE__ */ jsx6(Fragment, { children });
993
1046
  };
994
1047
 
@@ -1039,6 +1092,9 @@ function readMaxWidth(hostContext) {
1039
1092
  function resolveDisplayMode2(hostContext) {
1040
1093
  return hostContext?.displayMode === "fullscreen" || hostContext?.displayMode === "pip" ? hostContext.displayMode : "inline";
1041
1094
  }
1095
+ function resolvePlatform(hostContext) {
1096
+ return hostContext?.platform === "mobile" ? "mobile" : "web";
1097
+ }
1042
1098
  function useHostContext() {
1043
1099
  const runtime = useViewRuntime();
1044
1100
  const { hostContext, isConnected } = useSyncExternalStore3(
@@ -1051,6 +1107,7 @@ function useHostContext() {
1051
1107
  locale: typeof hostContext?.locale === "string" ? hostContext.locale : "en-US",
1052
1108
  timeZone: typeof hostContext?.timeZone === "string" ? hostContext.timeZone : typeof Intl !== "undefined" ? Intl.DateTimeFormat().resolvedOptions().timeZone : "UTC",
1053
1109
  userAgent: typeof hostContext?.userAgent === "string" ? hostContext.userAgent : typeof navigator !== "undefined" ? navigator.userAgent : "",
1110
+ platform: resolvePlatform(hostContext),
1054
1111
  displayMode: resolveDisplayMode2(hostContext),
1055
1112
  safeArea: hostContext?.safeAreaInsets ?? DEFAULT_SAFE_AREA,
1056
1113
  maxHeight: readMaxHeight(hostContext),