@mastra/mcp 2.2.0-alpha.1 → 2.2.0-alpha.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/index.js CHANGED
@@ -24796,6 +24796,8 @@ var MCPClientServerProxy = class extends MCPServerBase {
24796
24796
  async readResource(uri) {
24797
24797
  return { contents: (await (await this.getClient()).resources.read(uri)).contents.map((c) => ({
24798
24798
  uri: c.uri ?? uri,
24799
+ ...c.mimeType !== void 0 ? { mimeType: c.mimeType } : {},
24800
+ ...c._meta !== void 0 ? { _meta: c._meta } : {},
24799
24801
  ..."text" in c && c.text !== void 0 ? { text: c.text } : {},
24800
24802
  ..."blob" in c && c.blob !== void 0 ? { blob: c.blob } : {}
24801
24803
  })) };
@@ -26505,10 +26507,7 @@ var MCPServer = class extends MCPServerBase {
26505
26507
  return validation.value;
26506
26508
  }
26507
26509
  hasUiMetadata() {
26508
- return Object.values(this.convertedTools).some((tool) => {
26509
- const meta = tool.mcp?._meta;
26510
- return Boolean(meta?.ui?.resourceUri);
26511
- });
26510
+ return Object.values(this.convertedTools).some((tool) => Boolean(uiResourceUri(tool.mcp?._meta)));
26512
26511
  }
26513
26512
  capabilities() {
26514
26513
  const capabilities = {
@@ -26789,12 +26788,18 @@ var MCPServer = class extends MCPServerBase {
26789
26788
  this.logger.warn(`Tool '${name}' rejected its input.`, { error: value.message });
26790
26789
  return errorResult(value.message);
26791
26790
  }
26791
+ const resourceUri = uiResourceUri(tool.mcp?._meta);
26792
+ const meta = resourceUri ? { _meta: {
26793
+ ui: { resourceUri },
26794
+ [RESOURCE_URI_META_KEY]: resourceUri
26795
+ } } : {};
26792
26796
  if (!tool.outputSchema) return {
26793
26797
  isError: false,
26794
26798
  content: [{
26795
26799
  type: "text",
26796
26800
  text: typeof value === "string" ? value : JSON.stringify(value)
26797
- }]
26801
+ }],
26802
+ ...meta
26798
26803
  };
26799
26804
  const structuredContent = value;
26800
26805
  return {
@@ -26803,7 +26808,8 @@ var MCPServer = class extends MCPServerBase {
26803
26808
  content: [{
26804
26809
  type: "text",
26805
26810
  text: JSON.stringify(structuredContent)
26806
- }]
26811
+ }],
26812
+ ...meta
26807
26813
  };
26808
26814
  }
26809
26815
  registerResourceHandlers(server) {
@@ -27148,17 +27154,15 @@ var MCPServer = class extends MCPServerBase {
27148
27154
  /** Reads an `ui://` app resource; application resources require a protocol request. */
27149
27155
  async readResource(uri) {
27150
27156
  const html = this.appResourceHtml.get(uri);
27151
- if (html === void 0) throw new MastraError({
27157
+ const resource = this.appResourceList.find((r) => r.uri === uri);
27158
+ if (html === void 0 || !resource) throw new MastraError({
27152
27159
  id: "MCP_SERVER_RESOURCE_NOT_FOUND",
27153
27160
  domain: ErrorDomain.MCP,
27154
27161
  category: ErrorCategory.USER,
27155
27162
  text: `Resource '${uri}' not found; application resources are only readable through an MCP request`,
27156
27163
  details: { uri }
27157
27164
  });
27158
- return { contents: [{
27159
- uri,
27160
- text: html
27161
- }] };
27165
+ return { contents: [this.resourceContents(resource, { text: html })] };
27162
27166
  }
27163
27167
  /** Lists `ui://` app resources; application resources require a protocol request. */
27164
27168
  async listResources() {
@@ -27178,23 +27182,23 @@ function errorResult(text) {
27178
27182
  isError: true
27179
27183
  };
27180
27184
  }
27181
- /** Keeps `_meta.ui.resourceUri` and the flat MCP Apps key in sync for older hosts. */
27185
+ /** The tool's MCP App URI; the nested key wins over the flat one, as in ext-apps' `getToolUiResourceUri`. */
27186
+ function uiResourceUri(meta) {
27187
+ return (meta?.ui)?.resourceUri || meta?.[RESOURCE_URI_META_KEY] || void 0;
27188
+ }
27189
+ /** Writes the tool's MCP App URI to both the nested and the flat key, so every host opens the same app. */
27182
27190
  function normalizeUiMeta(meta) {
27183
- if (!meta) return void 0;
27191
+ const resourceUri = uiResourceUri(meta);
27192
+ if (!meta || !resourceUri) return meta;
27184
27193
  const ui = meta.ui;
27185
- const flat = meta[RESOURCE_URI_META_KEY];
27186
- if (ui?.resourceUri && !flat) return {
27187
- ...meta,
27188
- [RESOURCE_URI_META_KEY]: ui.resourceUri
27189
- };
27190
- if (flat && !ui?.resourceUri) return {
27194
+ return {
27191
27195
  ...meta,
27192
27196
  ui: {
27193
- ...ui ?? {},
27194
- resourceUri: flat
27195
- }
27197
+ ...ui,
27198
+ resourceUri
27199
+ },
27200
+ [RESOURCE_URI_META_KEY]: resourceUri
27196
27201
  };
27197
- return meta;
27198
27202
  }
27199
27203
  //#endregion
27200
27204
  //#region src/server/types.ts