xmcp 0.6.7 → 0.6.9

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.
Files changed (41) hide show
  1. package/dist/cli.js +36 -15
  2. package/dist/compiler/config/index.d.ts +7 -0
  3. package/dist/compiler/config/schemas/template.d.ts +5 -0
  4. package/dist/host-bridge.d.ts +4 -0
  5. package/dist/host-bridge.js +1 -0
  6. package/dist/index.d.ts +4 -0
  7. package/dist/index.js +5 -5
  8. package/dist/runtime/adapter-express.js +21 -19
  9. package/dist/runtime/adapter-nestjs.js +21 -19
  10. package/dist/runtime/adapter-nextjs.js +21 -19
  11. package/dist/runtime/contexts/client-info-context.d.ts +8 -0
  12. package/dist/runtime/http.js +26 -24
  13. package/dist/runtime/stdio.js +32 -30
  14. package/dist/runtime/utils/mcp-app-protocol.d.ts +14 -0
  15. package/dist/runtime/utils/mcp-app-types.d.ts +103 -0
  16. package/dist/runtime/utils/mcp-host-bridge.d.ts +43 -0
  17. package/dist/runtime/utils/server.d.ts +3 -1
  18. package/dist/types/ui-meta.d.ts +15 -0
  19. package/package.json +12 -1
  20. package/src/compiler/client/component-compiler.ts +26 -5
  21. package/src/compiler/config/injection.ts +1 -0
  22. package/src/compiler/config/schemas/template.ts +13 -0
  23. package/src/compiler/get-bundler-config/index.ts +1 -0
  24. package/src/host-bridge.ts +36 -0
  25. package/src/index.ts +36 -0
  26. package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +2 -1
  27. package/src/runtime/contexts/client-info-context.ts +16 -0
  28. package/src/runtime/transports/http/stateless-streamable-http.ts +11 -89
  29. package/src/runtime/transports/stdio/index.ts +40 -7
  30. package/src/runtime/utils/__tests__/client-info.test.ts +19 -0
  31. package/src/runtime/utils/__tests__/tool-extra.test.ts +39 -0
  32. package/src/runtime/utils/client-info.ts +7 -0
  33. package/src/runtime/utils/mcp-app-protocol.ts +16 -0
  34. package/src/runtime/utils/mcp-app-types.ts +113 -0
  35. package/src/runtime/utils/mcp-host-bridge.ts +473 -0
  36. package/src/runtime/utils/react/generate-html.ts +12 -4
  37. package/src/runtime/utils/server.ts +3 -2
  38. package/src/runtime/utils/transformers/tool.ts +10 -1
  39. package/src/runtime/utils/ui/__tests__/split-meta.test.ts +42 -0
  40. package/src/runtime/utils/ui/split-meta.ts +4 -1
  41. package/src/types/ui-meta.ts +17 -1
@@ -1,3 +1,9 @@
1
+ import {
2
+ INITIALIZE_METHOD,
3
+ INITIALIZED_METHOD,
4
+ MCP_APPS_PROTOCOL_VERSION,
5
+ } from "../mcp-app-protocol";
6
+
1
7
  export function generateUIHTML(
2
8
  componentCode: string,
3
9
  css: string | undefined
@@ -16,11 +22,13 @@ export function generateUIHTML(
16
22
  window.parent.postMessage({
17
23
  jsonrpc: "2.0",
18
24
  id: nextId++,
19
- method: "ui/initialize",
25
+ method: ${JSON.stringify(INITIALIZE_METHOD)},
20
26
  params: {
21
- appCapabilities: {},
27
+ appCapabilities: {
28
+ availableDisplayModes: ["inline", "fullscreen", "pip"]
29
+ },
22
30
  appInfo: { name: "xmcp React Widget", version: "1.0.0" },
23
- protocolVersion: "2025-06-18"
31
+ protocolVersion: ${JSON.stringify(MCP_APPS_PROTOCOL_VERSION)}
24
32
  }
25
33
  }, "*");
26
34
 
@@ -33,7 +41,7 @@ export function generateUIHTML(
33
41
  if (data?.result?.hostContext && data?.id === 1) {
34
42
  window.parent.postMessage({
35
43
  jsonrpc: "2.0",
36
- method: "ui/notifications/initialized",
44
+ method: ${JSON.stringify(INITIALIZED_METHOD)},
37
45
  params: {}
38
46
  }, "*");
39
47
  }
@@ -52,7 +52,7 @@ export const injectedResources = INJECTED_RESOURCES as Record<
52
52
  () => Promise<ResourceFile>
53
53
  >;
54
54
 
55
- export const INJECTED_CONFIG = SERVER_INFO as Implementation;
55
+ export const INJECTED_CONFIG = SERVER_INFO as Implementation & { instructions?: string };
56
56
 
57
57
  /* Loads all modules and injects them into the server */
58
58
  // would be better as a class and use dependency injection perhaps
@@ -93,7 +93,8 @@ export async function loadResources() {
93
93
  }
94
94
 
95
95
  export async function createServer() {
96
- const server = new McpServer(INJECTED_CONFIG);
96
+ const { instructions, ...serverInfo } = INJECTED_CONFIG;
97
+ const server = new McpServer(serverInfo, { instructions });
97
98
  const toolModulesPromise = loadTools();
98
99
  const promptModulesPromise = loadPrompts();
99
100
  const resourceModulesPromise = loadResources();
@@ -7,6 +7,7 @@ import { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol";
7
7
  import { ZodRawShape } from "zod/v3";
8
8
  import type { ToolExtraArguments } from "@/types/tool";
9
9
  import { getHttpRequestContext } from "@/runtime/contexts/http-request-context";
10
+ import { getClientInfoContext } from "@/runtime/contexts/client-info-context";
10
11
  import { elicitFromTool } from "../elicitation";
11
12
  import { validateContent } from "../validators";
12
13
 
@@ -79,7 +80,15 @@ function createToolExtraArguments(
79
80
  try {
80
81
  clientInfo = getHttpRequestContext().clientInfo;
81
82
  } catch {
82
- // no request context available (for example, stdio transport)
83
+ // no HTTP request context available (for example, stdio transport)
84
+ }
85
+
86
+ if (!clientInfo) {
87
+ try {
88
+ clientInfo = getClientInfoContext().clientInfo;
89
+ } catch {
90
+ // no client info context available
91
+ }
83
92
  }
84
93
 
85
94
  return {
@@ -80,6 +80,22 @@ describe("splitUIMetaNested", () => {
80
80
  );
81
81
  }
82
82
  });
83
+
84
+ it("should split visibility to toolMeta", () => {
85
+ const meta = {
86
+ ui: {
87
+ visibility: ["model", "app"],
88
+ },
89
+ };
90
+ const result = splitUIMetaNested(meta);
91
+
92
+ assert.deepStrictEqual(result.toolMeta, {
93
+ ui: {
94
+ visibility: ["model", "app"],
95
+ },
96
+ });
97
+ assert.deepStrictEqual(result.resourceMeta, {});
98
+ });
83
99
  });
84
100
 
85
101
  describe("Resource Metadata Keys (CSP and Display)", () => {
@@ -121,6 +137,8 @@ describe("splitUIMetaNested", () => {
121
137
  csp: {
122
138
  connectDomains: ["https://api.weather.com"],
123
139
  resourceDomains: ["https://cdn.jsdelivr.net"],
140
+ frameDomains: ["https://widgets.example.com"],
141
+ baseUriDomains: ["https://assets.example.com"],
124
142
  },
125
143
  },
126
144
  };
@@ -132,6 +150,30 @@ describe("splitUIMetaNested", () => {
132
150
  csp: {
133
151
  connectDomains: ["https://api.weather.com"],
134
152
  resourceDomains: ["https://cdn.jsdelivr.net"],
153
+ frameDomains: ["https://widgets.example.com"],
154
+ baseUriDomains: ["https://assets.example.com"],
155
+ },
156
+ },
157
+ });
158
+ });
159
+
160
+ it("should split permissions to resourceMeta", () => {
161
+ const meta = {
162
+ ui: {
163
+ permissions: {
164
+ camera: {},
165
+ microphone: {},
166
+ },
167
+ },
168
+ };
169
+ const result = splitUIMetaNested(meta);
170
+
171
+ assert.deepStrictEqual(result.toolMeta, {});
172
+ assert.deepStrictEqual(result.resourceMeta, {
173
+ ui: {
174
+ permissions: {
175
+ camera: {},
176
+ microphone: {},
135
177
  },
136
178
  },
137
179
  });
@@ -10,7 +10,7 @@ export interface SplitMetadata {
10
10
  /**
11
11
  * Tool-specific metadata keys in nested format
12
12
  */
13
- const TOOL_META_KEYS_NESTED = ["ui/resourceUri"];
13
+ const TOOL_META_KEYS_NESTED = ["ui/resourceUri", "resourceUri", "visibility"];
14
14
 
15
15
  /**
16
16
  * Resource-specific metadata keys in nested format
@@ -19,8 +19,11 @@ const RESOURCE_META_KEYS_NESTED = [
19
19
  "prefersBorder",
20
20
  "domain",
21
21
  "csp",
22
+ "permissions",
22
23
  "connectDomains",
23
24
  "resourceDomains",
25
+ "frameDomains",
26
+ "baseUriDomains",
24
27
  ];
25
28
 
26
29
  /**
@@ -5,12 +5,29 @@ export interface UIMetadata {
5
5
  */
6
6
  resourceUri?: string;
7
7
 
8
+ /**
9
+ * Visibility hint for how prominently hosts should surface the widget entry point.
10
+ */
11
+ visibility?: Array<"model" | "app">;
12
+
8
13
  /**
9
14
  * Content Security Policy configuration for widget resources.
10
15
  */
11
16
  csp?: {
12
17
  connectDomains?: string[];
13
18
  resourceDomains?: string[];
19
+ frameDomains?: string[];
20
+ baseUriDomains?: string[];
21
+ };
22
+
23
+ /**
24
+ * Browser permission hints requested by the widget iframe.
25
+ */
26
+ permissions?: {
27
+ camera?: Record<string, never>;
28
+ microphone?: Record<string, never>;
29
+ geolocation?: Record<string, never>;
30
+ clipboardWrite?: Record<string, never>;
14
31
  };
15
32
 
16
33
  /**
@@ -23,4 +40,3 @@ export interface UIMetadata {
23
40
  */
24
41
  prefersBorder?: boolean;
25
42
  }
26
-