@zebric/mcp-apps 0.0.0-stage → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +75 -2
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +181 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/render.d.ts +7 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +20 -0
- package/dist/render.js.map +1 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Biscotti Labs LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zebric/mcp-apps
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Declarative [MCP Apps](https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx) views for Zebric's Agent API. Declare a table or detail view in your Blueprint, then register it on an existing `@zebric/mcp-server` transport. MCP Apps hosts render the HTML resource in their sandbox and deliver tool results to it. Text-only clients keep the existing tool response.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @zebric/mcp-apps @zebric/mcp-server
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
For setup, regression commands, host configurations, and expected results across local Node, stdio, VS Code, Claude, ChatGPT, and Workers/Hono, see the [testing guide](https://docs.zebric.dev/building/mcp-apps-testing/). It distinguishes protocol checks from visual host checks and includes troubleshooting.
|
|
10
|
+
|
|
11
|
+
## Declare views
|
|
12
|
+
|
|
13
|
+
```toml
|
|
14
|
+
[[mcp_apps]]
|
|
15
|
+
name = "tasks"
|
|
16
|
+
title = "Tasks"
|
|
17
|
+
operation = "task_tracker_list_tasks" # Exact OpenAPI operationId from /api/openapi.json
|
|
18
|
+
layout = "table"
|
|
19
|
+
fields = ["title", { field = "status", label = "Status" }]
|
|
20
|
+
empty = "No tasks found."
|
|
21
|
+
resource_uri = "ui://tasks/list-v1.html" # Optional; default: ui://zebric/tasks.html
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`layout` supports `table` and `detail`. `fields` accepts field names or `{ field, label }` objects; omit it to use the first record's keys. `data_path` and fields accept dot-separated paths. Views consume the operation's result, so use its actual response shape. Names, operation IDs, and resource URIs must be unique within the declarations. Blueprint JSON, TOML arrays, and imported TOML fragments preserve and validate `mcp_apps`.
|
|
25
|
+
|
|
26
|
+
## Register with a transport
|
|
27
|
+
|
|
28
|
+
Pass your loaded Blueprint declarations to `createMcpAppsExtension`. For example, after loading `blueprint` with `BlueprintLoader` from `@zebric/runtime-node`:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { startZebricMcpHttpServer } from '@zebric/mcp-server/node'
|
|
32
|
+
import { createMcpAppsExtension } from '@zebric/mcp-apps'
|
|
33
|
+
|
|
34
|
+
const server = await startZebricMcpHttpServer({
|
|
35
|
+
applicationUrl: 'http://127.0.0.1:3000',
|
|
36
|
+
credential: () => process.env.ZEBRIC_API_KEY,
|
|
37
|
+
configureServer: createMcpAppsExtension(blueprint.mcp_apps ?? []),
|
|
38
|
+
// Bind address defaults to loopback. For a public listener, configure
|
|
39
|
+
// authorize or authenticate at your gateway as described by mcp-server.
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The same option works with `createZebricMcpServer` for stdio and `createZebricMcpHttpHandler` for Workers/Hono. There is no Node-only import in this package. HTTP authentication, origin/host checks, body limits, discovery caching, and per-request credentials remain those of `@zebric/mcp-server`.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
47
|
+
import { createZebricMcpServer } from '@zebric/mcp-server'
|
|
48
|
+
import { createMcpAppsExtension } from '@zebric/mcp-apps'
|
|
49
|
+
|
|
50
|
+
const server = await createZebricMcpServer({
|
|
51
|
+
applicationUrl: 'http://127.0.0.1:3000',
|
|
52
|
+
credential: () => process.env.ZEBRIC_API_KEY,
|
|
53
|
+
configureServer: createMcpAppsExtension(blueprint.mcp_apps ?? []),
|
|
54
|
+
})
|
|
55
|
+
await server.connect(new StdioServerTransport())
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Only explicitly configured views are registered. A missing or disabled operation fails server creation with a clear error. Views do not enable mutations: `allowedMutations` must still allow each mutation operation separately. To compose an existing configuration hook, call both hooks from an async `configureServer(server, context)` function.
|
|
59
|
+
|
|
60
|
+
## View behavior
|
|
61
|
+
|
|
62
|
+
Tools advertise `_meta.ui.resourceUri`. Read tools use `model` and `app` visibility so the view can refresh them; mutation tools use `model` only, so the view can never call them. Resources use `text/html;profile=mcp-app`, contain self-contained HTML/CSS/JavaScript, and declare no external network or resource domains. The client performs the MCP Apps `2026-01-26` lifecycle handshake, renders tool results, follows host theme variables, and reports its height.
|
|
63
|
+
|
|
64
|
+
Refresh appears when the bound operation is read-only and the host supports server tool calls. It repeats the original arguments through the host's `tools/call` bridge. Mutation result views have no refresh action. Views use `textContent` for result values and do not embed API credentials or initial records in cacheable resources.
|
|
65
|
+
|
|
66
|
+
This version provides result tables and details. It does not embed existing Zebric pages or provide forms, board interactions, custom HTML templates, or an MCP Apps host. Use an MCP Apps capable client to display the views. Registration is programmatic; the existing `zebric-mcp-server` CLI does not load view declarations. Change `resource_uri` when deploying a changed view if your host caches resources by URI.
|
|
67
|
+
|
|
68
|
+
## Repository example
|
|
69
|
+
|
|
70
|
+
The Task Tracker Blueprint includes a task table declaration. Start and seed `examples/task-tracker` following its README, then, from the repository root after building the packages, run:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
TASK_TRACKER_API_KEY=your-key node packages/mcp-apps/examples/task-tracker.mjs
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Connect an MCP Apps client to `http://127.0.0.1:3001/mcp` and invoke `task_tracker_list_tasks`. The example exposes reads; the existing Task Tracker mutation example remains available separately.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,eAAO,MAAM,cAAc,QAkL1B,CAAA"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/** Self-contained MCP Apps bridge; no CDN, network requests, or runtime dependencies. */
|
|
2
|
+
export const MCP_APP_CLIENT = String.raw `
|
|
3
|
+
(() => {
|
|
4
|
+
const config = JSON.parse(document.getElementById('config').textContent);
|
|
5
|
+
const content = document.getElementById('content');
|
|
6
|
+
const status = document.getElementById('status');
|
|
7
|
+
const refresh = document.getElementById('refresh');
|
|
8
|
+
const pending = new Map();
|
|
9
|
+
let nextId = 1;
|
|
10
|
+
let initialized = false;
|
|
11
|
+
let args;
|
|
12
|
+
let hasInput = false;
|
|
13
|
+
let serverTools = false;
|
|
14
|
+
let busy = false;
|
|
15
|
+
let cancelled = false;
|
|
16
|
+
// Bumped by host input, results, or cancellation so a slower refresh cannot overwrite newer state.
|
|
17
|
+
let generation = 0;
|
|
18
|
+
// The parent is the host's sandbox proxy; its origin may be opaque.
|
|
19
|
+
function send(message) { window.parent.postMessage({ jsonrpc: '2.0', ...message }, '*'); }
|
|
20
|
+
function notify(method, params = {}) { send({ method, params }); }
|
|
21
|
+
function request(method, params) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const id = nextId++;
|
|
24
|
+
const timer = setTimeout(() => {
|
|
25
|
+
pending.delete(id);
|
|
26
|
+
reject(new Error('The host did not respond.'));
|
|
27
|
+
}, 15000);
|
|
28
|
+
pending.set(id, { resolve, reject, timer });
|
|
29
|
+
send({ id, method, params });
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function updateRefresh() {
|
|
33
|
+
refresh.hidden = !serverTools || config.binding?.readOnly !== true;
|
|
34
|
+
refresh.disabled = !initialized || !hasInput || busy || cancelled;
|
|
35
|
+
}
|
|
36
|
+
function hostContext(context) {
|
|
37
|
+
if (!context) return;
|
|
38
|
+
if (context.theme === 'dark' || context.theme === 'light') document.documentElement.style.colorScheme = context.theme;
|
|
39
|
+
for (const [name, value] of Object.entries(context.styles?.variables || {})) {
|
|
40
|
+
if (/^--(color-|font-|border-|radius-|spacing-)/.test(name) && typeof value === 'string') {
|
|
41
|
+
document.documentElement.style.setProperty(name, value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
updateRefresh();
|
|
45
|
+
}
|
|
46
|
+
function valueAt(value, path) {
|
|
47
|
+
return path.split('.').reduce((result, key) => result !== null && typeof result === 'object' &&
|
|
48
|
+
Object.prototype.hasOwnProperty.call(result, key) ? result[key] : undefined, value);
|
|
49
|
+
}
|
|
50
|
+
function text(value) {
|
|
51
|
+
return value === undefined || value === null ? '' : typeof value === 'object' ? JSON.stringify(value) : String(value);
|
|
52
|
+
}
|
|
53
|
+
function element(tag, value) {
|
|
54
|
+
const node = document.createElement(tag);
|
|
55
|
+
if (value !== undefined) node.textContent = text(value);
|
|
56
|
+
return node;
|
|
57
|
+
}
|
|
58
|
+
function resultData(result) {
|
|
59
|
+
if (result.structuredContent !== undefined) return result.structuredContent;
|
|
60
|
+
const value = (result.content || []).filter(item => item.type === 'text').map(item => item.text).join('\n');
|
|
61
|
+
try { return JSON.parse(value); } catch { return value; }
|
|
62
|
+
}
|
|
63
|
+
function render(result) {
|
|
64
|
+
content.replaceChildren();
|
|
65
|
+
if (result.isError) {
|
|
66
|
+
status.textContent = text(resultData(result)?.error?.message || resultData(result) || 'The operation failed.');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
let data = resultData(result);
|
|
70
|
+
if (config.data_path) data = valueAt(data, config.data_path);
|
|
71
|
+
const rows = Array.isArray(data) ? data : data === undefined || data === null ? [] : [data];
|
|
72
|
+
if (!rows.length) {
|
|
73
|
+
status.textContent = config.empty || 'No records to display.';
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const first = rows[0];
|
|
77
|
+
const fields = (config.fields || (first && typeof first === 'object' ? Object.keys(first) : ['value']))
|
|
78
|
+
.map(field => typeof field === 'string' ? { field, label: field } : { ...field, label: field.label || field.field });
|
|
79
|
+
const cell = (row, field) => row !== null && typeof row === 'object' ? valueAt(row, field) : field === 'value' ? row : undefined;
|
|
80
|
+
if (config.layout === 'table') {
|
|
81
|
+
const table = element('table');
|
|
82
|
+
const head = element('thead');
|
|
83
|
+
const header = element('tr');
|
|
84
|
+
fields.forEach(field => { const th = element('th', field.label); th.scope = 'col'; header.append(th); });
|
|
85
|
+
head.append(header);
|
|
86
|
+
const body = element('tbody');
|
|
87
|
+
rows.forEach(row => { const tr = element('tr'); fields.forEach(field => tr.append(element('td', cell(row, field.field)))); body.append(tr); });
|
|
88
|
+
table.append(head, body);
|
|
89
|
+
content.append(table);
|
|
90
|
+
} else {
|
|
91
|
+
rows.forEach(row => {
|
|
92
|
+
const list = element('dl');
|
|
93
|
+
fields.forEach(field => list.append(element('dt', field.label), element('dd', cell(row, field.field))));
|
|
94
|
+
content.append(list);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
status.textContent = '';
|
|
98
|
+
}
|
|
99
|
+
window.addEventListener('message', event => {
|
|
100
|
+
if (event.source !== window.parent) return;
|
|
101
|
+
const message = event.data;
|
|
102
|
+
if (!message || message.jsonrpc !== '2.0') return;
|
|
103
|
+
if (!message.method && pending.has(message.id)) {
|
|
104
|
+
const call = pending.get(message.id);
|
|
105
|
+
pending.delete(message.id);
|
|
106
|
+
clearTimeout(call.timer);
|
|
107
|
+
if (message.error) call.reject(new Error(message.error.message || 'The host rejected the request.'));
|
|
108
|
+
else call.resolve(message.result);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (message.method === 'ping' && message.id !== undefined) {
|
|
112
|
+
send({ id: message.id, result: {} });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (message.method === 'ui/resource-teardown' && message.id !== undefined) {
|
|
116
|
+
for (const call of pending.values()) { clearTimeout(call.timer); call.reject(new Error('View closed.')); }
|
|
117
|
+
pending.clear();
|
|
118
|
+
initialized = false;
|
|
119
|
+
observer?.disconnect();
|
|
120
|
+
updateRefresh();
|
|
121
|
+
send({ id: message.id, result: {} });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!initialized) return;
|
|
125
|
+
if (message.method === 'ui/notifications/tool-input') {
|
|
126
|
+
generation++;
|
|
127
|
+
args = message.params?.arguments || {};
|
|
128
|
+
hasInput = true;
|
|
129
|
+
cancelled = false;
|
|
130
|
+
updateRefresh();
|
|
131
|
+
} else if (message.method === 'ui/notifications/tool-result') {
|
|
132
|
+
generation++;
|
|
133
|
+
render(message.params || {});
|
|
134
|
+
} else if (message.method === 'ui/notifications/tool-cancelled') {
|
|
135
|
+
generation++;
|
|
136
|
+
cancelled = true;
|
|
137
|
+
status.textContent = message.params?.reason || 'Operation cancelled.';
|
|
138
|
+
updateRefresh();
|
|
139
|
+
} else if (message.method === 'ui/notifications/host-context-changed') {
|
|
140
|
+
hostContext(message.params);
|
|
141
|
+
} else if (message.id !== undefined) {
|
|
142
|
+
send({ id: message.id, error: { code: -32601, message: 'Method not found' } });
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
refresh.addEventListener('click', async () => {
|
|
146
|
+
if (refresh.disabled || refresh.hidden) return;
|
|
147
|
+
busy = true;
|
|
148
|
+
updateRefresh();
|
|
149
|
+
status.textContent = 'Refreshing…';
|
|
150
|
+
const started = generation;
|
|
151
|
+
try {
|
|
152
|
+
const result = await request('tools/call', { name: config.binding.toolName, arguments: args });
|
|
153
|
+
if (started === generation) render(result);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (started === generation) status.textContent = error.message;
|
|
156
|
+
} finally { busy = false; updateRefresh(); }
|
|
157
|
+
});
|
|
158
|
+
const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(() => {
|
|
159
|
+
if (initialized) notify('ui/notifications/size-changed', { height: document.documentElement.scrollHeight });
|
|
160
|
+
});
|
|
161
|
+
observer?.observe(document.body);
|
|
162
|
+
request('ui/initialize', {
|
|
163
|
+
appInfo: { name: 'zebric-' + config.name, version: config.version },
|
|
164
|
+
appCapabilities: { availableDisplayModes: ['inline'] },
|
|
165
|
+
protocolVersion: '2026-01-26',
|
|
166
|
+
}).then(result => {
|
|
167
|
+
// Hosts may negotiate a newer version. The messages used here are part of every
|
|
168
|
+
// version so far, so render anyway rather than blanking the view.
|
|
169
|
+
if (typeof result?.protocolVersion !== 'string') throw new Error('The host did not report an MCP Apps protocol version.');
|
|
170
|
+
if (result.protocolVersion !== '2026-01-26') console.warn('MCP Apps host negotiated protocol ' + result.protocolVersion + '; this view targets 2026-01-26.');
|
|
171
|
+
serverTools = Boolean(result.hostCapabilities?.serverTools);
|
|
172
|
+
hostContext(result.hostContext);
|
|
173
|
+
initialized = true;
|
|
174
|
+
status.textContent = 'Waiting for results…';
|
|
175
|
+
updateRefresh();
|
|
176
|
+
notify('ui/notifications/initialized');
|
|
177
|
+
notify('ui/notifications/size-changed', { height: document.documentElement.scrollHeight });
|
|
178
|
+
}).catch(error => { status.textContent = error.message; });
|
|
179
|
+
})();
|
|
180
|
+
`;
|
|
181
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkLvC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type McpAppView } from '@zebric/runtime-core';
|
|
2
|
+
import type { ConfigureZebricMcpServer } from '@zebric/mcp-server';
|
|
3
|
+
export type { McpAppView } from '@zebric/runtime-core';
|
|
4
|
+
export { renderMcpApp } from './render.js';
|
|
5
|
+
export declare const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app";
|
|
6
|
+
/** Compose with any Zebric MCP transport using its configureServer option. */
|
|
7
|
+
export declare function createMcpAppsExtension(views: readonly McpAppView[]): ConfigureZebricMcpServer;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACrE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAGlE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,eAAO,MAAM,iBAAiB,8BAA8B,CAAA;AAE5D,8EAA8E;AAC9E,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,wBAAwB,CA6B7F"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { McpAppsSchema } from '@zebric/runtime-core';
|
|
2
|
+
import { renderMcpApp } from './render.js';
|
|
3
|
+
export { renderMcpApp } from './render.js';
|
|
4
|
+
export const MCP_APP_MIME_TYPE = 'text/html;profile=mcp-app';
|
|
5
|
+
/** Compose with any Zebric MCP transport using its configureServer option. */
|
|
6
|
+
export function createMcpAppsExtension(views) {
|
|
7
|
+
// Validate and snapshot once; retained HTTP handlers must not observe caller mutations.
|
|
8
|
+
const config = McpAppsSchema.parse(views);
|
|
9
|
+
return (server, { tools }) => {
|
|
10
|
+
// Check all bindings before changing the server. Disabled mutations never become available.
|
|
11
|
+
for (const view of config) {
|
|
12
|
+
if (!tools.has(view.operation)) {
|
|
13
|
+
throw new Error(`MCP App "${view.name}" references unavailable operation "${view.operation}"; check discovery and allowedMutations`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
for (const view of config) {
|
|
17
|
+
const { name, registration: tool } = tools.get(view.operation);
|
|
18
|
+
const uri = view.resource_uri ?? `ui://zebric/${view.name}.html`;
|
|
19
|
+
// Resolve the real tool name from registration; applicationName can change its prefix.
|
|
20
|
+
const readOnly = tool.annotations?.readOnlyHint === true;
|
|
21
|
+
const html = renderMcpApp(view, { toolName: name, readOnly });
|
|
22
|
+
const ui = { csp: { connectDomains: [], resourceDomains: [] }, prefersBorder: true };
|
|
23
|
+
server.registerResource(view.name, uri, {
|
|
24
|
+
title: view.title,
|
|
25
|
+
mimeType: MCP_APP_MIME_TYPE,
|
|
26
|
+
_meta: { ui },
|
|
27
|
+
}, async () => ({
|
|
28
|
+
contents: [{ uri, mimeType: MCP_APP_MIME_TYPE, text: html, _meta: { ui } }],
|
|
29
|
+
}));
|
|
30
|
+
// The view only ever calls read tools, so mutations stay model-only.
|
|
31
|
+
const visibility = readOnly ? ['model', 'app'] : ['model'];
|
|
32
|
+
tool.update({ _meta: { ...tool._meta, ui: { resourceUri: uri, visibility } } });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmB,MAAM,sBAAsB,CAAA;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,2BAA2B,CAAA;AAE5D,8EAA8E;AAC9E,MAAM,UAAU,sBAAsB,CAAC,KAA4B;IACjE,wFAAwF;IACxF,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACzC,OAAO,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QAC3B,4FAA4F;QAC5F,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC/B,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,CAAC,IAAI,uCAAuC,IAAI,CAAC,SAAS,yCAAyC,CAAC,CAAA;YACtI,CAAC;QACH,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAE,CAAA;YAC/D,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,IAAI,eAAe,IAAI,CAAC,IAAI,OAAO,CAAA;YAChE,uFAAuF;YACvF,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,YAAY,KAAK,IAAI,CAAA;YACxD,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;YAC7D,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAA;YACpF,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE;gBACtC,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,QAAQ,EAAE,iBAAiB;gBAC3B,KAAK,EAAE,EAAE,EAAE,EAAE;aACd,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;gBACd,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;aAC5E,CAAC,CAAC,CAAA;YACH,qEAAqE;YACrE,MAAM,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;YAC1D,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAA;QACjF,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type McpAppView } from '@zebric/runtime-core';
|
|
2
|
+
/** Generate static HTML only. Caller credentials and application data never enter the resource. */
|
|
3
|
+
export declare function renderMcpApp(view: McpAppView, binding?: {
|
|
4
|
+
toolName: string;
|
|
5
|
+
readOnly: boolean;
|
|
6
|
+
}): string;
|
|
7
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGxF,mGAAmG;AACnG,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAYxG"}
|
package/dist/render.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { McpAppViewSchema, ZEBRIC_VERSION } from '@zebric/runtime-core';
|
|
2
|
+
import { MCP_APP_CLIENT } from './client.js';
|
|
3
|
+
/** Generate static HTML only. Caller credentials and application data never enter the resource. */
|
|
4
|
+
export function renderMcpApp(view, binding) {
|
|
5
|
+
const config = McpAppViewSchema.parse(view);
|
|
6
|
+
const json = JSON.stringify({ ...config, binding, version: ZEBRIC_VERSION }).replace(/</g, '\\u003c').replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029');
|
|
7
|
+
return `<!DOCTYPE html>
|
|
8
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
<title>${escapeHtml(config.title)}</title>
|
|
10
|
+
<style>
|
|
11
|
+
:root{color-scheme:light dark;font-family:var(--font-sans,system-ui,sans-serif);color:var(--color-text-primary,CanvasText);background:var(--color-background-primary,Canvas)}
|
|
12
|
+
body{margin:0;padding:16px}header{display:flex;align-items:center;justify-content:space-between;gap:16px}h1{font-size:1.1rem;margin:0}button{font:inherit;padding:6px 12px;border:1px solid var(--color-border-primary,GrayText);border-radius:6px;cursor:pointer;color:inherit;background:transparent}button:disabled{opacity:.5;cursor:default}#content{overflow:auto}table{border-collapse:collapse;width:100%;margin-top:12px}th,td{padding:8px;text-align:left;border-bottom:1px solid var(--color-border-primary,GrayText);white-space:pre-wrap;overflow-wrap:anywhere}dt{font-weight:600;margin-top:12px}dd{margin:4px 0;white-space:pre-wrap;overflow-wrap:anywhere}#status{font-size:.9rem;color:var(--color-text-secondary,GrayText)}
|
|
13
|
+
</style></head><body><header><h1>${escapeHtml(config.title)}</h1><button id="refresh" disabled>Refresh</button></header>
|
|
14
|
+
<p id="status" role="status">Connecting…</p><div id="content"></div>
|
|
15
|
+
<script type="application/json" id="config">${json}</script><script>${MCP_APP_CLIENT}</script></body></html>`;
|
|
16
|
+
}
|
|
17
|
+
function escapeHtml(value) {
|
|
18
|
+
return value.replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAmB,MAAM,sBAAsB,CAAA;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,mGAAmG;AACnG,MAAM,UAAU,YAAY,CAAC,IAAgB,EAAE,OAAiD;IAC9F,MAAM,MAAM,GAAG,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IACjK,OAAO;;SAEA,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC;;;;mCAIE,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC;;8CAEb,IAAI,oBAAoB,cAAc,yBAAyB,CAAA;AAC7G,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,CAAE,CAAC,CAAA;AAC5H,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zebric/mcp-apps",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Declarative MCP App views for Zebric applications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/ZapCircleHQ/zebric.git",
|
|
25
|
+
"directory": "packages/mcp-apps"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@zebric/mcp-server": "0.10.0",
|
|
29
|
+
"@zebric/runtime-core": "0.10.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
33
|
+
"@types/node": "^22.19.17",
|
|
34
|
+
"typescript": "^6.0.3",
|
|
35
|
+
"vitest": "^4.1.12",
|
|
36
|
+
"zod": "^4.3.6"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22.0.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"lint": "eslint src --ext .ts"
|
|
45
|
+
}
|
|
6
46
|
}
|