@mastra/mcp-apps-components 0.0.0 → 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,32 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named `ee/` within this
4
+ repository, including but not limited to:
5
+ - `@mastra/core/auth/ee`
6
+ - `@mastra/core/agent-builder/ee`
7
+ - `@mastra/editor/ee`
8
+
9
+ is licensed under the license defined in [`ee/LICENSE`](https://github.com/mastra-ai/mastra/blob/main/ee/LICENSE).
10
+
11
+ - All third-party components incorporated into the Mastra Software are
12
+ licensed under the original license provided by the owner of the
13
+ applicable component.
14
+
15
+ - Content outside of the above-mentioned directories or restrictions is
16
+ available under the "Apache License 2.0" as defined below.
17
+
18
+ # Apache License 2.0
19
+
20
+ Copyright (c) 2025 Kepler Software, Inc.
21
+
22
+ Licensed under the Apache License, Version 2.0 (the "License");
23
+ you may not use this file except in compliance with the License.
24
+ You may obtain a copy of the License at
25
+
26
+ http://www.apache.org/licenses/LICENSE-2.0
27
+
28
+ Unless required by applicable law or agreed to in writing, software
29
+ distributed under the License is distributed on an "AS IS" BASIS,
30
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31
+ See the License for the specific language governing permissions and
32
+ limitations under the License.
package/README.md CHANGED
@@ -1,9 +1,144 @@
1
1
  # @mastra/mcp-apps-components
2
2
 
3
- This 0.0.0 release is an empty placeholder with no code. It reserves the package name so npm trusted publishing can be configured for mastra-ai/mastra.
3
+ Prebuilt [MCP Apps](https://mastra.ai/docs/connections/mcp) that you register as app resources on an `MCPServer`. Each app is a single self-contained HTML page that follows the [MCP Apps spec](https://github.com/modelcontextprotocol/ext-apps), so it runs in any MCP Apps host, such as Mastra Studio.
4
4
 
5
- Until the first stable release, real versions are published as prereleases under the `alpha` dist-tag, and `latest` still points to this placeholder. Install with:
5
+ ## Installation
6
6
 
7
+ ```bash
8
+ npm install @mastra/mcp-apps-components
7
9
  ```
8
- npm install @mastra/mcp-apps-components@alpha
10
+
11
+ ## Usage
12
+
13
+ `greetingApp` greets someone by name. It talks to its host with standard MCP Apps messages only:
14
+
15
+ 1. The model calls the tool that opens the app. The host sends the app that tool's arguments (`ui/notifications/tool-input`); the app reads `name`.
16
+ 2. The app calls the app-only `getGreeting` tool on the same server (`tools/call`) and shows the `greeting` string from its structured content, or the tool's error.
17
+ 3. A **Say hi back** button posts a user message to the conversation (`ui/message`).
18
+
19
+ You write both tools. `getGreeting` runs on your server, so it can call any API with your server's credentials; the app's iframe has no network access.
20
+
21
+ ```typescript
22
+ import { createTool } from '@mastra/core/tools';
23
+ import { MCPServer } from '@mastra/mcp';
24
+ import { greetingApp } from '@mastra/mcp-apps-components';
25
+ import { z } from 'zod';
26
+
27
+ const uri = 'ui://mastra/greeting';
28
+
29
+ export const greetingServer = new MCPServer({
30
+ id: 'greeting',
31
+ name: 'Greeting',
32
+ version: '1.0.0',
33
+ appResources: { [uri]: greetingApp },
34
+ tools: {
35
+ // Visible to the model: opens the app.
36
+ showGreeting: createTool({
37
+ id: 'showGreeting',
38
+ description: 'Shows a greeting card for someone',
39
+ inputSchema: z.object({ name: z.string() }),
40
+ mcp: { _meta: { ui: { resourceUri: uri } } },
41
+ execute: async ({ name }) => ({ name }),
42
+ }),
43
+ // Visible to the app only: returns its data.
44
+ getGreeting: createTool({
45
+ id: 'getGreeting',
46
+ description: 'Returns the greeting for a name',
47
+ inputSchema: z.object({ name: z.string() }),
48
+ outputSchema: z.object({ greeting: z.string() }),
49
+ mcp: { _meta: { ui: { resourceUri: uri, visibility: ['app'] } } },
50
+ execute: async ({ name }) => ({ greeting: `Hello, ${name}!` }),
51
+ }),
52
+ },
53
+ });
54
+ ```
55
+
56
+ ### Observability widget
57
+
58
+ `observabilityWidgetApp` draws one Studio dashboard widget (KPIs, time series, table or scores) with the same components Studio uses.
59
+
60
+ 1. The model calls the tool that opens the app. That tool must declare an `outputSchema` so its result reaches the app as structured content: `{ widget, datePreset? }`, where `widget` is a stored dashboard widget and `datePreset` is one of `24h` (default), `3d`, `7d`, `14d` or `30d`. The window ends when the app opens.
61
+ 2. The app reads its data through the app-only `queryObservability` tool (exported as `QUERY_OBSERVABILITY_TOOL`). It calls it once per read with `{ action, args }`, where `action` is a `MastraClient` observability method (`getMetricAggregate`, `getMetricTimeSeries`, `listScores`, `aggregateTraces`, …) and `args` are that method's arguments, with dates as ISO strings. The tool returns `{ data }`, the method's result; if it throws, the widget shows as failed.
62
+
63
+ The tool runs on your server, so you decide which Mastra server the widget reads from and how it authenticates. Only allow read actions:
64
+
65
+ ```typescript
66
+ import { MastraClient } from '@mastra/client-js';
67
+ import { createTool } from '@mastra/core/tools';
68
+ import { MCPServer } from '@mastra/mcp';
69
+ import { QUERY_OBSERVABILITY_TOOL, observabilityWidgetApp } from '@mastra/mcp-apps-components';
70
+ import { z } from 'zod';
71
+
72
+ const uri = 'ui://mastra/observability-widget';
73
+ const client = new MastraClient({ baseUrl: process.env.MASTRA_URL! });
74
+ const ACTIONS = ['getMetricAggregate', 'getMetricTimeSeries'] as const;
75
+
76
+ export const observabilityServer = new MCPServer({
77
+ id: 'observability',
78
+ name: 'Observability',
79
+ version: '1.0.0',
80
+ appResources: { [uri]: observabilityWidgetApp },
81
+ tools: {
82
+ // Visible to the model: opens the app with a widget.
83
+ showObservabilityWidget: createTool({
84
+ id: 'showObservabilityWidget',
85
+ description: 'Shows agent runs over time',
86
+ inputSchema: z.object({ datePreset: z.enum(['24h', '3d', '7d', '14d', '30d']).default('24h') }),
87
+ outputSchema: z.object({ widget: z.unknown(), datePreset: z.string() }),
88
+ mcp: { _meta: { ui: { resourceUri: uri } } },
89
+ execute: async ({ datePreset }) => ({ widget: agentRunsWidget, datePreset }),
90
+ }),
91
+ // Visible to the app only: runs one read on the server's client.
92
+ [QUERY_OBSERVABILITY_TOOL]: createTool({
93
+ id: QUERY_OBSERVABILITY_TOOL,
94
+ description: 'Runs one observability read',
95
+ inputSchema: z.object({ action: z.enum(ACTIONS), args: z.record(z.string(), z.unknown()) }),
96
+ outputSchema: z.object({ data: z.unknown() }),
97
+ mcp: { _meta: { ui: { resourceUri: uri, visibility: ['app'] } } },
98
+ execute: async ({ action, args }) => {
99
+ const read = client[action].bind(client) as (args: unknown) => Promise<unknown>;
100
+ return { data: await read(args) };
101
+ },
102
+ }),
103
+ },
104
+ });
9
105
  ```
106
+
107
+ `examples/agent` has a complete version with every read action, a set of preset widgets and an agent that opens them.
108
+
109
+ #### Pinning widgets
110
+
111
+ When the chat host supports it, the widget shows a pin button. The host owns the pinned widgets: it sends their ids to the app, and the app reports each pin and unpin through `ui/update-model-context`. In a host built on `@mastra/playground-ui`, pass `observabilityWidgetPins` from `@mastra/mcp-apps-components/host` to `McpAppHostProvider`:
112
+
113
+ ```tsx
114
+ import { McpAppHostProvider } from '@mastra/playground-ui/domains/mcps';
115
+ import { observabilityWidgetPins } from '@mastra/mcp-apps-components/host';
116
+
117
+ const host = useMemo(
118
+ () =>
119
+ observabilityWidgetPins({
120
+ resourceUri: 'ui://mastra/observability-widget',
121
+ pinnedIds,
122
+ onPin: ({ widget, datePreset }) => savePin(widget, datePreset),
123
+ onUnpin: widgetId => removePin(widgetId),
124
+ }),
125
+ [pinnedIds],
126
+ );
127
+
128
+ <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>;
129
+ ```
130
+
131
+ The button only shows when the host sends pinned ids and accepts structured model context. A click shows right away and holds until the host sends new ids.
132
+
133
+ ## Documentation
134
+
135
+ - [MCP Apps in Mastra](https://mastra.ai/docs/connections/mcp)
136
+ - [MCP Apps spec](https://github.com/modelcontextprotocol/ext-apps)
137
+
138
+ ## Changelog
139
+
140
+ See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/packages/mcp-apps-components/CHANGELOG.md) for version history and release notes.
141
+
142
+ ## Support
143
+
144
+ We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
@@ -0,0 +1,20 @@
1
+ /** The app-only tool the observability widget calls, on the server that opened it, for every read. */
2
+ export declare const QUERY_OBSERVABILITY_TOOL = "queryObservability";
3
+ /**
4
+ * Host context key holding the ids of the widgets the host has pinned (`string[]`). The pin button
5
+ * only shows when the host sends it and supports `updateModelContext.structuredContent`.
6
+ */
7
+ export declare const OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY = "mastra.ai/observability-widget-pinned";
8
+ /** `structuredContent` key of the model context update the app sends when the user (un)pins. */
9
+ export declare const OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY = "mastra.ai/observability-widget-pin";
10
+ /** What the app sends under `OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY`: the state the user asked for. */
11
+ export type ObservabilityWidgetPin = {
12
+ pinned: boolean;
13
+ /** The stored dashboard widget, as the opening tool returned it. */
14
+ widget: {
15
+ id: string;
16
+ [key: string]: unknown;
17
+ };
18
+ datePreset: string;
19
+ };
20
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/apps/observability-widget/tool.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,eAAO,MAAM,wBAAwB,uBAAuB,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,uCAAuC,0CAA0C,CAAC;AAE/F,gGAAgG;AAChG,eAAO,MAAM,oCAAoC,uCAAuC,CAAC;AAEzF,qGAAqG;AACrG,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,oEAAoE;IACpE,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
package/dist/host.cjs ADDED
@@ -0,0 +1,53 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_tool = require("./tool-C6_-nIOM.cjs");
3
+ // src/host.ts
4
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
5
+ /** The app's pin update, checked by shape only: the widget itself is validated when it's drawn. */
6
+ function readPin(structuredContent) {
7
+ const pin = structuredContent?.[require_tool.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];
8
+ if (!isRecord(pin) || typeof pin.pinned !== "boolean" || typeof pin.datePreset !== "string") return void 0;
9
+ if (!isRecord(pin.widget) || typeof pin.widget.id !== "string") return void 0;
10
+ return {
11
+ pinned: pin.pinned,
12
+ widget: {
13
+ ...pin.widget,
14
+ id: pin.widget.id
15
+ },
16
+ datePreset: pin.datePreset
17
+ };
18
+ }
19
+ /**
20
+ * Lets the user pin observability widgets from the chat. The host owns the pinned widgets: it
21
+ * sends their ids to each widget app, and hears each pin and unpin.
22
+ *
23
+ * ```tsx
24
+ * const host = useMemo(
25
+ * () => observabilityWidgetPins({ resourceUri: 'ui://mastra/observability-widget', pinnedIds, onPin, onUnpin }),
26
+ * [pinnedIds, onPin, onUnpin],
27
+ * );
28
+ * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>
29
+ * ```
30
+ *
31
+ * A click shows on the button right away and holds until the host's ids next change, so a host
32
+ * that turns a click down leaves it showing until then.
33
+ */
34
+ function observabilityWidgetPins({ resourceUri, pinnedIds, onPin, onUnpin }) {
35
+ return {
36
+ hostContext: (app) => app.resourceUri === resourceUri ? { [require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pinnedIds } : void 0,
37
+ onModelContext: (app, params) => {
38
+ if (app.resourceUri !== resourceUri) return;
39
+ const pin = readPin(params.structuredContent);
40
+ if (!pin) return;
41
+ if (pin.pinned) onPin({
42
+ widget: pin.widget,
43
+ datePreset: pin.datePreset
44
+ }, app);
45
+ else onUnpin(pin.widget.id, app);
46
+ }
47
+ };
48
+ }
49
+ exports.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY;
50
+ exports.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY = require_tool.OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY;
51
+ exports.observabilityWidgetPins = observabilityWidgetPins;
52
+
53
+ //# sourceMappingURL=host.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.cjs","names":["OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY","OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY"],"sources":["../src/host.ts"],"sourcesContent":["import {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nimport type { ObservabilityWidgetPin } from './apps/observability-widget/tool';\n\nexport {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nexport type { ObservabilityWidgetPin } from './apps/observability-widget/tool';\n\n/** The MCP App instance a host callback is about: one tool call's app. */\nexport type McpAppRef = { toolName: string; toolCallId: string; resourceUri: string };\n\n/**\n * What a chat host passes to `McpAppHostProvider` from `@mastra/playground-ui/domains/mcps`. Typed\n * here by shape, so this package doesn't depend on the host's UI package.\n */\nexport type McpAppHostValue = {\n hostContext?: (app: McpAppRef) => Record<string, unknown> | undefined;\n onModelContext?: (\n app: McpAppRef,\n params: { content?: unknown[]; structuredContent?: Record<string, unknown> },\n ) => void;\n};\n\nexport type ObservabilityWidgetPinsOptions = {\n /** The `ui://` URI the observability widget app is registered under; other apps are left alone. */\n resourceUri: string;\n /** The ids of the widgets the host has pinned. Pass new ids after `onPin`/`onUnpin` to answer. */\n pinnedIds: readonly string[];\n /** The user pinned `pin.widget` over `pin.datePreset`. */\n onPin: (pin: Omit<ObservabilityWidgetPin, 'pinned'>, app: McpAppRef) => void;\n /** The user unpinned the widget with this id. */\n onUnpin: (widgetId: string, app: McpAppRef) => void;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** The app's pin update, checked by shape only: the widget itself is validated when it's drawn. */\nfunction readPin(structuredContent: Record<string, unknown> | undefined): ObservabilityWidgetPin | undefined {\n const pin = structuredContent?.[OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];\n if (!isRecord(pin) || typeof pin.pinned !== 'boolean' || typeof pin.datePreset !== 'string') return undefined;\n if (!isRecord(pin.widget) || typeof pin.widget.id !== 'string') return undefined;\n return { pinned: pin.pinned, widget: { ...pin.widget, id: pin.widget.id }, datePreset: pin.datePreset };\n}\n\n/**\n * Lets the user pin observability widgets from the chat. The host owns the pinned widgets: it\n * sends their ids to each widget app, and hears each pin and unpin.\n *\n * ```tsx\n * const host = useMemo(\n * () => observabilityWidgetPins({ resourceUri: 'ui://mastra/observability-widget', pinnedIds, onPin, onUnpin }),\n * [pinnedIds, onPin, onUnpin],\n * );\n * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>\n * ```\n *\n * A click shows on the button right away and holds until the host's ids next change, so a host\n * that turns a click down leaves it showing until then.\n */\nexport function observabilityWidgetPins({\n resourceUri,\n pinnedIds,\n onPin,\n onUnpin,\n}: ObservabilityWidgetPinsOptions): McpAppHostValue {\n return {\n hostContext: app =>\n app.resourceUri === resourceUri ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pinnedIds } : undefined,\n onModelContext: (app, params) => {\n if (app.resourceUri !== resourceUri) return;\n const pin = readPin(params.structuredContent);\n if (!pin) return;\n if (pin.pinned) onPin({ widget: pin.widget, datePreset: pin.datePreset }, app);\n else onUnpin(pin.widget.id, app);\n },\n };\n}\n"],"mappings":";;;AAsCA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,SAAS,QAAQ,mBAA4F;CAC3G,MAAM,MAAM,oBAAoBA,aAAAA;CAChC,IAAI,CAAC,SAAS,GAAG,KAAK,OAAO,IAAI,WAAW,aAAa,OAAO,IAAI,eAAe,UAAU,OAAO,KAAA;CACpG,IAAI,CAAC,SAAS,IAAI,MAAM,KAAK,OAAO,IAAI,OAAO,OAAO,UAAU,OAAO,KAAA;CACvE,OAAO;EAAE,QAAQ,IAAI;EAAQ,QAAQ;GAAE,GAAG,IAAI;GAAQ,IAAI,IAAI,OAAO;EAAG;EAAG,YAAY,IAAI;CAAW;AACxG;;;;;;;;;;;;;;;;AAiBA,SAAgB,wBAAwB,EACtC,aACA,WACA,OACA,WACkD;CAClD,OAAO;EACL,cAAa,QACX,IAAI,gBAAgB,cAAc,GAAGC,aAAAA,0CAA0C,UAAU,IAAI,KAAA;EAC/F,iBAAiB,KAAK,WAAW;GAC/B,IAAI,IAAI,gBAAgB,aAAa;GACrC,MAAM,MAAM,QAAQ,OAAO,iBAAiB;GAC5C,IAAI,CAAC,KAAK;GACV,IAAI,IAAI,QAAQ,MAAM;IAAE,QAAQ,IAAI;IAAQ,YAAY,IAAI;GAAW,GAAG,GAAG;QACxE,QAAQ,IAAI,OAAO,IAAI,GAAG;EACjC;CACF;AACF"}
package/dist/host.js ADDED
@@ -0,0 +1,50 @@
1
+ import { n as OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, t as OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY } from "./tool-BD-7EJf2.js";
2
+ // src/host.ts
3
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
+ /** The app's pin update, checked by shape only: the widget itself is validated when it's drawn. */
5
+ function readPin(structuredContent) {
6
+ const pin = structuredContent?.[OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];
7
+ if (!isRecord(pin) || typeof pin.pinned !== "boolean" || typeof pin.datePreset !== "string") return void 0;
8
+ if (!isRecord(pin.widget) || typeof pin.widget.id !== "string") return void 0;
9
+ return {
10
+ pinned: pin.pinned,
11
+ widget: {
12
+ ...pin.widget,
13
+ id: pin.widget.id
14
+ },
15
+ datePreset: pin.datePreset
16
+ };
17
+ }
18
+ /**
19
+ * Lets the user pin observability widgets from the chat. The host owns the pinned widgets: it
20
+ * sends their ids to each widget app, and hears each pin and unpin.
21
+ *
22
+ * ```tsx
23
+ * const host = useMemo(
24
+ * () => observabilityWidgetPins({ resourceUri: 'ui://mastra/observability-widget', pinnedIds, onPin, onUnpin }),
25
+ * [pinnedIds, onPin, onUnpin],
26
+ * );
27
+ * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>
28
+ * ```
29
+ *
30
+ * A click shows on the button right away and holds until the host's ids next change, so a host
31
+ * that turns a click down leaves it showing until then.
32
+ */
33
+ function observabilityWidgetPins({ resourceUri, pinnedIds, onPin, onUnpin }) {
34
+ return {
35
+ hostContext: (app) => app.resourceUri === resourceUri ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pinnedIds } : void 0,
36
+ onModelContext: (app, params) => {
37
+ if (app.resourceUri !== resourceUri) return;
38
+ const pin = readPin(params.structuredContent);
39
+ if (!pin) return;
40
+ if (pin.pinned) onPin({
41
+ widget: pin.widget,
42
+ datePreset: pin.datePreset
43
+ }, app);
44
+ else onUnpin(pin.widget.id, app);
45
+ }
46
+ };
47
+ }
48
+ export { OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY, OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY, observabilityWidgetPins };
49
+
50
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["import {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nimport type { ObservabilityWidgetPin } from './apps/observability-widget/tool';\n\nexport {\n OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY,\n OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY,\n} from './apps/observability-widget/tool';\nexport type { ObservabilityWidgetPin } from './apps/observability-widget/tool';\n\n/** The MCP App instance a host callback is about: one tool call's app. */\nexport type McpAppRef = { toolName: string; toolCallId: string; resourceUri: string };\n\n/**\n * What a chat host passes to `McpAppHostProvider` from `@mastra/playground-ui/domains/mcps`. Typed\n * here by shape, so this package doesn't depend on the host's UI package.\n */\nexport type McpAppHostValue = {\n hostContext?: (app: McpAppRef) => Record<string, unknown> | undefined;\n onModelContext?: (\n app: McpAppRef,\n params: { content?: unknown[]; structuredContent?: Record<string, unknown> },\n ) => void;\n};\n\nexport type ObservabilityWidgetPinsOptions = {\n /** The `ui://` URI the observability widget app is registered under; other apps are left alone. */\n resourceUri: string;\n /** The ids of the widgets the host has pinned. Pass new ids after `onPin`/`onUnpin` to answer. */\n pinnedIds: readonly string[];\n /** The user pinned `pin.widget` over `pin.datePreset`. */\n onPin: (pin: Omit<ObservabilityWidgetPin, 'pinned'>, app: McpAppRef) => void;\n /** The user unpinned the widget with this id. */\n onUnpin: (widgetId: string, app: McpAppRef) => void;\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** The app's pin update, checked by shape only: the widget itself is validated when it's drawn. */\nfunction readPin(structuredContent: Record<string, unknown> | undefined): ObservabilityWidgetPin | undefined {\n const pin = structuredContent?.[OBSERVABILITY_WIDGET_PIN_CONTEXT_KEY];\n if (!isRecord(pin) || typeof pin.pinned !== 'boolean' || typeof pin.datePreset !== 'string') return undefined;\n if (!isRecord(pin.widget) || typeof pin.widget.id !== 'string') return undefined;\n return { pinned: pin.pinned, widget: { ...pin.widget, id: pin.widget.id }, datePreset: pin.datePreset };\n}\n\n/**\n * Lets the user pin observability widgets from the chat. The host owns the pinned widgets: it\n * sends their ids to each widget app, and hears each pin and unpin.\n *\n * ```tsx\n * const host = useMemo(\n * () => observabilityWidgetPins({ resourceUri: 'ui://mastra/observability-widget', pinnedIds, onPin, onUnpin }),\n * [pinnedIds, onPin, onUnpin],\n * );\n * <McpAppHostProvider value={host}>{chat}</McpAppHostProvider>\n * ```\n *\n * A click shows on the button right away and holds until the host's ids next change, so a host\n * that turns a click down leaves it showing until then.\n */\nexport function observabilityWidgetPins({\n resourceUri,\n pinnedIds,\n onPin,\n onUnpin,\n}: ObservabilityWidgetPinsOptions): McpAppHostValue {\n return {\n hostContext: app =>\n app.resourceUri === resourceUri ? { [OBSERVABILITY_WIDGET_PINNED_CONTEXT_KEY]: pinnedIds } : undefined,\n onModelContext: (app, params) => {\n if (app.resourceUri !== resourceUri) return;\n const pin = readPin(params.structuredContent);\n if (!pin) return;\n if (pin.pinned) onPin({ widget: pin.widget, datePreset: pin.datePreset }, app);\n else onUnpin(pin.widget.id, app);\n },\n };\n}\n"],"mappings":";;AAsCA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,SAAS,QAAQ,mBAA4F;CAC3G,MAAM,MAAM,oBAAoB;CAChC,IAAI,CAAC,SAAS,GAAG,KAAK,OAAO,IAAI,WAAW,aAAa,OAAO,IAAI,eAAe,UAAU,OAAO,KAAA;CACpG,IAAI,CAAC,SAAS,IAAI,MAAM,KAAK,OAAO,IAAI,OAAO,OAAO,UAAU,OAAO,KAAA;CACvE,OAAO;EAAE,QAAQ,IAAI;EAAQ,QAAQ;GAAE,GAAG,IAAI;GAAQ,IAAI,IAAI,OAAO;EAAG;EAAG,YAAY,IAAI;CAAW;AACxG;;;;;;;;;;;;;;;;AAiBA,SAAgB,wBAAwB,EACtC,aACA,WACA,OACA,WACkD;CAClD,OAAO;EACL,cAAa,QACX,IAAI,gBAAgB,cAAc,GAAG,0CAA0C,UAAU,IAAI,KAAA;EAC/F,iBAAiB,KAAK,WAAW;GAC/B,IAAI,IAAI,gBAAgB,aAAa;GACrC,MAAM,MAAM,QAAQ,OAAO,iBAAiB;GAC5C,IAAI,CAAC,KAAK;GACV,IAAI,IAAI,QAAQ,MAAM;IAAE,QAAQ,IAAI;IAAQ,YAAY,IAAI;GAAW,GAAG,GAAG;QACxE,QAAQ,IAAI,OAAO,IAAI,GAAG;EACjC;CACF;AACF"}