mcp-app-studio 0.3.2 → 0.5.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AgentbaseAI Inc.
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
@@ -20,7 +20,7 @@ npm install
20
20
  npm run dev
21
21
  ```
22
22
 
23
- Open http://localhost:3000 — you're in the workbench.
23
+ Open http://localhost:3002 — you're in the workbench.
24
24
 
25
25
  ## Universal SDK
26
26
 
@@ -36,6 +36,11 @@ declare class MCPBridge implements ExtendedBridge {
36
36
  }, appCapabilities?: AppCapabilities, options?: MCPBridgeOptions);
37
37
  connect(): Promise<void>;
38
38
  getHostContext(): HostContext | null;
39
+ /**
40
+ * Maps SDK host context to our HostContext type.
41
+ * The SDK returns a well-defined structure matching HostContext properties
42
+ * (theme, locale, displayMode, etc.), so this cast is safe at runtime.
43
+ */
39
44
  private mapHostContext;
40
45
  onToolInput(callback: ToolInputCallback): () => void;
41
46
  onToolInputPartial(callback: ToolInputPartialCallback): () => void;
@@ -22,20 +22,20 @@ var MCPBridge = class {
22
22
  { autoResize }
23
23
  );
24
24
  this.app.ontoolinput = (params) => {
25
- this.toolInputCallbacks.forEach(
26
- (cb) => cb(params.arguments)
27
- );
25
+ const args = params.arguments ?? {};
26
+ this.toolInputCallbacks.forEach((cb) => cb(args));
28
27
  };
29
28
  this.app.ontoolinputpartial = (params) => {
30
- this.toolInputPartialCallbacks.forEach(
31
- (cb) => cb(params.arguments)
32
- );
29
+ const args = params.arguments ?? {};
30
+ this.toolInputPartialCallbacks.forEach((cb) => cb(args));
33
31
  };
34
32
  this.app.ontoolresult = (params) => {
35
33
  const result = {
36
- content: params.content,
37
- structuredContent: params.structuredContent
34
+ content: params.content
38
35
  };
36
+ if (params.structuredContent !== void 0) {
37
+ result.structuredContent = params.structuredContent;
38
+ }
39
39
  if (params.isError !== void 0) {
40
40
  result.isError = params.isError;
41
41
  }
@@ -45,7 +45,8 @@ var MCPBridge = class {
45
45
  this.toolResultCallbacks.forEach((cb) => cb(result));
46
46
  };
47
47
  this.app.ontoolcancelled = (params) => {
48
- this.toolCancelledCallbacks.forEach((cb) => cb(params.reason));
48
+ const reason = params.reason ?? "";
49
+ this.toolCancelledCallbacks.forEach((cb) => cb(reason));
49
50
  };
50
51
  this.app.onhostcontextchanged = (params) => {
51
52
  const ctx = this.mapHostContext(params);
@@ -65,6 +66,11 @@ var MCPBridge = class {
65
66
  const ctx = this.app.getHostContext();
66
67
  return ctx ? this.mapHostContext(ctx) : null;
67
68
  }
69
+ /**
70
+ * Maps SDK host context to our HostContext type.
71
+ * The SDK returns a well-defined structure matching HostContext properties
72
+ * (theme, locale, displayMode, etc.), so this cast is safe at runtime.
73
+ */
68
74
  mapHostContext(ctx) {
69
75
  return ctx;
70
76
  }
@@ -132,7 +138,9 @@ var MCPBridge = class {
132
138
  }
133
139
  setCallToolHandler(handler) {
134
140
  this.app.oncalltool = async (params, extra) => {
135
- const result = await handler(params.name, params.arguments ?? {}, extra);
141
+ const name = params.name;
142
+ const args = params.arguments ?? {};
143
+ const result = await handler(name, args, extra);
136
144
  const content = result.content?.map((c) => {
137
145
  if (c.type === "text") {
138
146
  return { type: "text", text: c.text };
@@ -154,7 +162,8 @@ var MCPBridge = class {
154
162
  }
155
163
  setListToolsHandler(handler) {
156
164
  this.app.onlisttools = async (params) => {
157
- const tools = await handler(params?.cursor);
165
+ const cursor = params?.cursor;
166
+ const tools = await handler(cursor);
158
167
  return { tools };
159
168
  };
160
169
  }
@@ -3,6 +3,14 @@ import {
3
3
  } from "./chunk-4LAH4JH6.js";
4
4
 
5
5
  // src/platforms/chatgpt/bridge.ts
6
+ function hostContextChanged(prev, next) {
7
+ if (!prev) return true;
8
+ const keys = /* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(next)]);
9
+ for (const key of keys) {
10
+ if (prev[key] !== next[key]) return true;
11
+ }
12
+ return false;
13
+ }
6
14
  var ChatGPTBridge = class {
7
15
  platform = "chatgpt";
8
16
  capabilities = CHATGPT_CAPABILITIES;
@@ -37,6 +45,14 @@ var ChatGPTBridge = class {
37
45
  }
38
46
  this.connected = true;
39
47
  }
48
+ disconnect() {
49
+ if (!this.connected) return;
50
+ window.removeEventListener("openai:set_globals", this.handleGlobalsChange);
51
+ this.connected = false;
52
+ this.toolInputCallbacks.clear();
53
+ this.toolResultCallbacks.clear();
54
+ this.contextCallbacks.clear();
55
+ }
40
56
  buildHostContext() {
41
57
  const g = this.openai;
42
58
  return {
@@ -57,7 +73,7 @@ var ChatGPTBridge = class {
57
73
  }
58
74
  handleGlobalsChange = () => {
59
75
  const newContext = this.buildHostContext();
60
- if (JSON.stringify(newContext) !== JSON.stringify(this.lastContext)) {
76
+ if (hostContextChanged(this.lastContext, newContext)) {
61
77
  this.lastContext = newContext;
62
78
  this.contextCallbacks.forEach((cb) => cb(newContext));
63
79
  }
@@ -87,7 +103,13 @@ var ChatGPTBridge = class {
87
103
  onToolResult(callback) {
88
104
  this.toolResultCallbacks.add(callback);
89
105
  if (this.connected && this.openai.toolOutput) {
90
- callback({ structuredContent: this.openai.toolOutput });
106
+ const result = {
107
+ structuredContent: this.openai.toolOutput
108
+ };
109
+ if (this.openai.toolResponseMetadata) {
110
+ result._meta = this.openai.toolResponseMetadata;
111
+ }
112
+ callback(result);
91
113
  }
92
114
  return () => this.toolResultCallbacks.delete(callback);
93
115
  }