@developmentseed/mcp-view 0.1.2
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/dist/host.d.ts +12 -0
- package/dist/host.js +52 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +40 -0
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set the App identity reported to the host during `ui/initialize`. Optional —
|
|
3
|
+
* call it before the first `onData`/`sendMessage`. Defaults to a generic name.
|
|
4
|
+
*/
|
|
5
|
+
export declare function configure(info: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
}): void;
|
|
9
|
+
/** Register for the tool's structuredContent, and connect to the host. */
|
|
10
|
+
export declare function onData<T>(handler: (payload: T) => void): void;
|
|
11
|
+
/** Send text back into the conversation, so the model calls the next tool. */
|
|
12
|
+
export declare function sendMessage(text: string): void;
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// The host bridge — the one seam a view shares no matter what framework it is
|
|
2
|
+
// built with. A view runs in a sandboxed iframe and talks to its host over the
|
|
3
|
+
// MCP Apps `ui/*` JSON-RPC-over-postMessage protocol, via the standard SDK
|
|
4
|
+
// (`@modelcontextprotocol/ext-apps`). That is what Claude, ChatGPT, Goose and
|
|
5
|
+
// VS Code speak, and what the bundled Chainlit host (mcp_agent/elements/McpView.jsx)
|
|
6
|
+
// implements the other end of.
|
|
7
|
+
//
|
|
8
|
+
// The SDK handles the `ui/initialize` handshake, delivers the tool's result
|
|
9
|
+
// (`ui/notifications/tool-result`), and sends a chat message (`ui/message`).
|
|
10
|
+
// This module wraps it in two tiny functions so the views stay host-agnostic:
|
|
11
|
+
//
|
|
12
|
+
// onData(handler) — the tool's structuredContent, once the host sends it
|
|
13
|
+
// sendMessage(text) — a user turn back into the chat, to run the next tool
|
|
14
|
+
import { App } from "@modelcontextprotocol/ext-apps";
|
|
15
|
+
// One App per iframe, connected once. Created lazily on first use so the
|
|
16
|
+
// tool-result handler is registered before connect() runs the handshake (the
|
|
17
|
+
// SDK warns if a handler is added after connect()).
|
|
18
|
+
let appPromise = null;
|
|
19
|
+
let dataHandler = null;
|
|
20
|
+
let appInfo = {
|
|
21
|
+
name: "mcp-view",
|
|
22
|
+
version: "0.1.0",
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Set the App identity reported to the host during `ui/initialize`. Optional —
|
|
26
|
+
* call it before the first `onData`/`sendMessage`. Defaults to a generic name.
|
|
27
|
+
*/
|
|
28
|
+
export function configure(info) {
|
|
29
|
+
appInfo = info;
|
|
30
|
+
}
|
|
31
|
+
function app() {
|
|
32
|
+
if (!appPromise) {
|
|
33
|
+
const instance = new App(appInfo);
|
|
34
|
+
// The host delivers the tool's structuredContent here; hand it to whatever
|
|
35
|
+
// onData registered. Read dataHandler lazily so a later onData still wins.
|
|
36
|
+
instance.ontoolresult = (params) => {
|
|
37
|
+
if (params.structuredContent != null)
|
|
38
|
+
dataHandler?.(params.structuredContent);
|
|
39
|
+
};
|
|
40
|
+
appPromise = instance.connect().then(() => instance);
|
|
41
|
+
}
|
|
42
|
+
return appPromise;
|
|
43
|
+
}
|
|
44
|
+
/** Register for the tool's structuredContent, and connect to the host. */
|
|
45
|
+
export function onData(handler) {
|
|
46
|
+
dataHandler = handler;
|
|
47
|
+
void app();
|
|
48
|
+
}
|
|
49
|
+
/** Send text back into the conversation, so the model calls the next tool. */
|
|
50
|
+
export function sendMessage(text) {
|
|
51
|
+
void app().then((instance) => instance.sendMessage({ role: "user", content: [{ type: "text", text }] }));
|
|
52
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { configure, onData, sendMessage } from "./host";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { configure, onData, sendMessage } from "./host";
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@developmentseed/mcp-view",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "View-side bridge for MCP Apps UI views: the ui/* postMessage protocol as two tiny functions (onData / sendMessage).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"test": "vitest run"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@modelcontextprotocol/ext-apps": "^1.7.5"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.6.3",
|
|
29
|
+
"vitest": "^4.1.10"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"registry": "https://registry.npmjs.org"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/developmentseed/mcp-toolsets-runtime.git",
|
|
38
|
+
"directory": "js/mcp-view"
|
|
39
|
+
}
|
|
40
|
+
}
|