xmcp 0.6.7 → 0.6.8
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/cli.js +36 -15
- package/dist/compiler/config/index.d.ts +7 -0
- package/dist/compiler/config/schemas/template.d.ts +5 -0
- package/dist/host-bridge.d.ts +4 -0
- package/dist/host-bridge.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -5
- package/dist/runtime/adapter-express.js +21 -19
- package/dist/runtime/adapter-nestjs.js +21 -19
- package/dist/runtime/adapter-nextjs.js +21 -19
- package/dist/runtime/contexts/client-info-context.d.ts +8 -0
- package/dist/runtime/http.js +26 -24
- package/dist/runtime/stdio.js +32 -30
- package/dist/runtime/utils/mcp-app-protocol.d.ts +14 -0
- package/dist/runtime/utils/mcp-app-types.d.ts +103 -0
- package/dist/runtime/utils/mcp-host-bridge.d.ts +43 -0
- package/dist/runtime/utils/server.d.ts +3 -1
- package/dist/types/ui-meta.d.ts +15 -0
- package/package.json +12 -1
- package/src/compiler/client/component-compiler.ts +26 -5
- package/src/compiler/config/injection.ts +1 -0
- package/src/compiler/config/schemas/template.ts +13 -0
- package/src/compiler/get-bundler-config/index.ts +1 -0
- package/src/host-bridge.ts +36 -0
- package/src/index.ts +36 -0
- package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +2 -1
- package/src/runtime/contexts/client-info-context.ts +16 -0
- package/src/runtime/transports/stdio/index.ts +40 -7
- package/src/runtime/utils/__tests__/client-info.test.ts +19 -0
- package/src/runtime/utils/__tests__/tool-extra.test.ts +39 -0
- package/src/runtime/utils/client-info.ts +7 -0
- package/src/runtime/utils/mcp-app-protocol.ts +16 -0
- package/src/runtime/utils/mcp-app-types.ts +113 -0
- package/src/runtime/utils/mcp-host-bridge.ts +473 -0
- package/src/runtime/utils/react/generate-html.ts +12 -4
- package/src/runtime/utils/server.ts +3 -2
- package/src/runtime/utils/transformers/tool.ts +10 -1
- package/src/runtime/utils/ui/__tests__/split-meta.test.ts +42 -0
- package/src/runtime/utils/ui/split-meta.ts +4 -1
- package/src/types/ui-meta.ts +17 -1
|
@@ -167,6 +167,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
167
167
|
sizes?: string[] | undefined;
|
|
168
168
|
theme?: "light" | "dark" | undefined;
|
|
169
169
|
}>, "many">>>;
|
|
170
|
+
instructions: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
170
171
|
homePage: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
171
172
|
}, "strip", z.ZodTypeAny, {
|
|
172
173
|
name?: string | undefined;
|
|
@@ -177,6 +178,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
177
178
|
sizes?: string[] | undefined;
|
|
178
179
|
theme?: "light" | "dark" | undefined;
|
|
179
180
|
}[] | undefined;
|
|
181
|
+
instructions?: string | undefined;
|
|
180
182
|
homePage?: string | undefined;
|
|
181
183
|
}, {
|
|
182
184
|
name?: string | undefined;
|
|
@@ -187,6 +189,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
187
189
|
sizes?: string[] | undefined;
|
|
188
190
|
theme?: "light" | "dark" | undefined;
|
|
189
191
|
}[] | undefined;
|
|
192
|
+
instructions?: string | undefined;
|
|
190
193
|
homePage?: string | undefined;
|
|
191
194
|
}>, {
|
|
192
195
|
name: string;
|
|
@@ -197,6 +200,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
197
200
|
sizes?: string[] | undefined;
|
|
198
201
|
theme?: "light" | "dark" | undefined;
|
|
199
202
|
}[] | undefined;
|
|
203
|
+
instructions?: string | undefined;
|
|
200
204
|
homePage?: string | undefined;
|
|
201
205
|
}, {
|
|
202
206
|
name?: string | undefined;
|
|
@@ -207,6 +211,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
207
211
|
sizes?: string[] | undefined;
|
|
208
212
|
theme?: "light" | "dark" | undefined;
|
|
209
213
|
}[] | undefined;
|
|
214
|
+
instructions?: string | undefined;
|
|
210
215
|
homePage?: string | undefined;
|
|
211
216
|
}>>;
|
|
212
217
|
typescript: z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
@@ -230,6 +235,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
230
235
|
sizes?: string[] | undefined;
|
|
231
236
|
theme?: "light" | "dark" | undefined;
|
|
232
237
|
}[] | undefined;
|
|
238
|
+
instructions?: string | undefined;
|
|
233
239
|
homePage?: string | undefined;
|
|
234
240
|
} | undefined;
|
|
235
241
|
stdio?: boolean | {
|
|
@@ -273,6 +279,7 @@ export declare const configSchema: z.ZodObject<{
|
|
|
273
279
|
sizes?: string[] | undefined;
|
|
274
280
|
theme?: "light" | "dark" | undefined;
|
|
275
281
|
}[] | undefined;
|
|
282
|
+
instructions?: string | undefined;
|
|
276
283
|
homePage?: string | undefined;
|
|
277
284
|
} | undefined;
|
|
278
285
|
stdio?: boolean | {
|
|
@@ -18,6 +18,7 @@ export declare const templateConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
18
18
|
sizes?: string[] | undefined;
|
|
19
19
|
theme?: "light" | "dark" | undefined;
|
|
20
20
|
}>, "many">>>;
|
|
21
|
+
instructions: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
21
22
|
homePage: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
22
23
|
}, "strip", z.ZodTypeAny, {
|
|
23
24
|
name?: string | undefined;
|
|
@@ -28,6 +29,7 @@ export declare const templateConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
28
29
|
sizes?: string[] | undefined;
|
|
29
30
|
theme?: "light" | "dark" | undefined;
|
|
30
31
|
}[] | undefined;
|
|
32
|
+
instructions?: string | undefined;
|
|
31
33
|
homePage?: string | undefined;
|
|
32
34
|
}, {
|
|
33
35
|
name?: string | undefined;
|
|
@@ -38,6 +40,7 @@ export declare const templateConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
38
40
|
sizes?: string[] | undefined;
|
|
39
41
|
theme?: "light" | "dark" | undefined;
|
|
40
42
|
}[] | undefined;
|
|
43
|
+
instructions?: string | undefined;
|
|
41
44
|
homePage?: string | undefined;
|
|
42
45
|
}>, {
|
|
43
46
|
name: string;
|
|
@@ -48,6 +51,7 @@ export declare const templateConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
48
51
|
sizes?: string[] | undefined;
|
|
49
52
|
theme?: "light" | "dark" | undefined;
|
|
50
53
|
}[] | undefined;
|
|
54
|
+
instructions?: string | undefined;
|
|
51
55
|
homePage?: string | undefined;
|
|
52
56
|
}, {
|
|
53
57
|
name?: string | undefined;
|
|
@@ -58,6 +62,7 @@ export declare const templateConfigSchema: z.ZodEffects<z.ZodObject<{
|
|
|
58
62
|
sizes?: string[] | undefined;
|
|
59
63
|
theme?: "light" | "dark" | undefined;
|
|
60
64
|
}[] | undefined;
|
|
65
|
+
instructions?: string | undefined;
|
|
61
66
|
homePage?: string | undefined;
|
|
62
67
|
}>;
|
|
63
68
|
export type TemplateConfig = z.infer<typeof templateConfigSchema>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createMcpHostBridge } from "./runtime/utils/mcp-host-bridge";
|
|
2
|
+
export type { McpHostBridge, McpHostBridgeState, CreateMcpHostBridgeOptions, } from "./runtime/utils/mcp-host-bridge";
|
|
3
|
+
export type { McpHostCallToolParams, McpHostContext, McpHostCapabilities, McpHostContainerDimensions, McpHostOpenLinkParams, McpHostReadResourceResult, McpHostRequestDisplayModeParams, McpHostRequestDisplayModeResult, McpHostSendMessageParams, McpHostMessageResult, McpHostModelContextResult, McpHostToolContentItem, McpHostToolResult, McpUiDisplayMode, McpHostUpdateModelContextParams, } from "./runtime/utils/mcp-app-types";
|
|
4
|
+
export { MCP_APPS_PROTOCOL_VERSION, INITIALIZE_METHOD, INITIALIZED_METHOD, REQUEST_DISPLAY_MODE_METHOD, OPEN_LINK_METHOD, UPDATE_MODEL_CONTEXT_METHOD, UI_MESSAGE_METHOD, LOG_MESSAGE_METHOD, RESOURCES_READ_METHOD, HOST_CONTEXT_CHANGED_METHOD, SIZE_CHANGED_METHOD, } from "./runtime/utils/mcp-app-protocol";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var s=t();for(var o in s)("object"==typeof exports?exports:e)[o]=s[o]}}(this,()=>(()=>{"use strict";var e={};e.d=(t,s)=>{for(var o in s)e.o(s,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:s[o]})},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var t={};e.r(t),e.d(t,{SIZE_CHANGED_METHOD:()=>p,HOST_CONTEXT_CHANGED_METHOD:()=>c,UI_MESSAGE_METHOD:()=>l,RESOURCES_READ_METHOD:()=>u,UPDATE_MODEL_CONTEXT_METHOD:()=>a,MCP_APPS_PROTOCOL_VERSION:()=>s,createMcpHostBridge:()=>h,INITIALIZE_METHOD:()=>o,LOG_MESSAGE_METHOD:()=>d,INITIALIZED_METHOD:()=>i,OPEN_LINK_METHOD:()=>r,REQUEST_DISPLAY_MODE_METHOD:()=>n});let s="2026-01-26",o="ui/initialize",i="ui/notifications/initialized",n="ui/request-display-mode",r="ui/open-link",a="ui/update-model-context",l="ui/message",d="notifications/message",u="resources/read",c="ui/notifications/host-context-changed",p="ui/notifications/size-changed";function C(e){return!!e&&"object"==typeof e}function f(e,t){return e instanceof Error&&e.message?e.message:t}function h(e={}){let t=e.targetWindow??("undefined"==typeof window?null:window),s=e.requestTimeoutMs??15e3,o=e.connectionTimeoutMs??2e3,i=100,m=!1,E=!1,b={isConnected:!!t&&t.parent!==t,hostContext:null,hostCapabilities:null},y=new Set,M=new Map,g=e=>{if(e.isConnected!==b.isConnected||e.hostContext!==b.hostContext||e.hostCapabilities!==b.hostCapabilities)for(let t of(b=e,y))t(b)},T=e=>{var t,s;let o;g({isConnected:!0,hostContext:e.hostContext?(t=b.hostContext,s=e.hostContext,o={...t??{},...s},(t?.safeAreaInsets||s.safeAreaInsets)&&(o.safeAreaInsets={...t?.safeAreaInsets??{},...s.safeAreaInsets??{}}),(t?.containerDimensions||s.containerDimensions)&&(o.containerDimensions={...t?.containerDimensions??{},...s.containerDimensions??{}}),(t?.styles||s.styles)&&(o.styles={...t?.styles??{},...s.styles??{},variables:t?.styles?.variables||s.styles?.variables?{...t?.styles?.variables??{},...s.styles?.variables??{}}:void 0,css:t?.styles?.css||s.styles?.css?{...t?.styles?.css??{},...s.styles?.css??{}}:void 0}),o):b.hostContext,hostCapabilities:e.hostCapabilities?{...b.hostCapabilities??{},...e.hostCapabilities}:b.hostCapabilities})},O=e=>{if(!t||e.source!==t.parent||!C(e.data))return;E=!0,b.isConnected||g({...b,isConnected:!0});let s=e.data;if("id"in s&&null!=s.id&&"number"==typeof s.id){let e=M.get(s.id);e&&(clearTimeout(e.timeoutId),M.delete(s.id),C(s.error)?e.reject(Error("string"==typeof s.error.message?s.error.message:"MCP request failed")):e.resolve(s.result))}1===s.id&&C(s.result)&&T({hostContext:C(s.result.hostContext)?s.result.hostContext:void 0,hostCapabilities:C(s.result.hostCapabilities)?s.result.hostCapabilities:void 0}),s.method===c&&C(s.params)&&T({hostContext:s.params}),"ui/hostContextChanged"===s.method&&C(s.params)&&C(s.params.hostContext)&&T({hostContext:s.params.hostContext})};t&&(t.addEventListener("message",O),t.parent!==t&&setTimeout(()=>{m||E||b.hostContext||g({...b,isConnected:!1})},o));let _=()=>{if(m)throw Error("MCP host bridge has been disposed");if(!t)throw Error("MCP host bridge requires a browser window");return t},w=(e,t)=>{_().parent.postMessage({jsonrpc:"2.0",method:e,params:t},"*")},x=(e,t={})=>{let o=_();return new Promise((n,r)=>{let a=i++,l=setTimeout(()=>{M.has(a)&&(M.delete(a),r(Error(`MCP request timed out: ${e}`)))},s);M.set(a,{resolve:n,reject:r,timeoutId:l}),o.parent.postMessage({jsonrpc:"2.0",id:a,method:e,params:t},"*")})},D=async(e,t)=>{let s;for(let o of e)try{return await x(o,t)}catch(t){s=t;let e=f(t,"MCP request failed");if(!/method not found|unknown method/i.test(e))throw t}throw s instanceof Error?s:Error("MCP request failed")},v=async e=>{if(t?.open)return void t.open(e,"_blank","noopener,noreferrer");throw Error("Unable to open link without a browser window")};return{callTool:(e,t)=>x("tools/call",{name:e,arguments:t??{}}),requestDisplayMode:e=>D([n,"ui/requestDisplayMode"],{mode:e}),async openLink(e){try{await D([r,"ui/openLink"],{url:e})}catch(s){if(!b.isConnected||!t)return void await v(e);throw Error(f(s,"Failed to open link"))}},readResource:e=>x(u,{uri:e}),sendMessage:e=>x(l,e),updateModelContext:e=>x(a,e),async logMessage(e){w(d,e)},async notifySizeChanged(e){w(p,e)},getState:()=>b,getHostContext:()=>b.hostContext,getHostCapabilities:()=>b.hostCapabilities,isConnected:()=>b.isConnected,subscribe:e=>(y.add(e),()=>{y.delete(e)}),dispose(){if(!m){for(let[e,s]of(m=!0,t&&t.removeEventListener("message",O),M.entries()))clearTimeout(s.timeoutId),s.reject(Error("MCP host bridge has been disposed")),M.delete(e);y.clear()}}}}return t})());
|
package/dist/index.d.ts
CHANGED
|
@@ -17,3 +17,7 @@ export type { StdioClientConnection, StdioClientOptions } from "./client";
|
|
|
17
17
|
export type { CustomHeaders, CustomHeader, StaticHeader, EnvHeader, } from "./client/headers";
|
|
18
18
|
export { isEnvHeader, headersToRecord } from "./client/headers";
|
|
19
19
|
export { extractToolNamesFromRequest } from "./runtime/utils/request-tool-names";
|
|
20
|
+
export { createMcpHostBridge } from "./runtime/utils/mcp-host-bridge";
|
|
21
|
+
export type { McpHostBridge, McpHostBridgeState, CreateMcpHostBridgeOptions, } from "./runtime/utils/mcp-host-bridge";
|
|
22
|
+
export type { McpHostCallToolParams, McpHostContext, McpHostCapabilities, McpHostContainerDimensions, McpHostOpenLinkParams, McpHostReadResourceResult, McpHostRequestDisplayModeParams, McpHostRequestDisplayModeResult, McpHostSendMessageParams, McpHostMessageResult, McpHostModelContextResult, McpHostToolContentItem, McpHostToolResult, McpUiDisplayMode, McpHostUpdateModelContextParams, } from "./runtime/utils/mcp-app-types";
|
|
23
|
+
export { MCP_APPS_PROTOCOL_VERSION, INITIALIZE_METHOD, INITIALIZED_METHOD, REQUEST_DISPLAY_MODE_METHOD, OPEN_LINK_METHOD, UPDATE_MODEL_CONTEXT_METHOD, UI_MESSAGE_METHOD, LOG_MESSAGE_METHOD, RESOURCES_READ_METHOD, HOST_CONTEXT_CHANGED_METHOD, SIZE_CHANGED_METHOD, } from "./runtime/utils/mcp-app-protocol";
|