@mastra/mcp 2.2.0-alpha.0 → 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 = {
@@ -26526,7 +26525,11 @@ var MCPServer = class extends MCPServerBase {
26526
26525
  createServerInstance() {
26527
26526
  const server = new Server({
26528
26527
  name: this.name,
26529
- version: this.version
26528
+ version: this.version,
26529
+ title: this.title,
26530
+ description: this.description,
26531
+ websiteUrl: this.websiteUrl,
26532
+ icons: this.icons
26530
26533
  }, {
26531
26534
  capabilities: this.capabilities(),
26532
26535
  instructions: this.instructions,
@@ -26785,12 +26788,18 @@ var MCPServer = class extends MCPServerBase {
26785
26788
  this.logger.warn(`Tool '${name}' rejected its input.`, { error: value.message });
26786
26789
  return errorResult(value.message);
26787
26790
  }
26791
+ const resourceUri = uiResourceUri(tool.mcp?._meta);
26792
+ const meta = resourceUri ? { _meta: {
26793
+ ui: { resourceUri },
26794
+ [RESOURCE_URI_META_KEY]: resourceUri
26795
+ } } : {};
26788
26796
  if (!tool.outputSchema) return {
26789
26797
  isError: false,
26790
26798
  content: [{
26791
26799
  type: "text",
26792
26800
  text: typeof value === "string" ? value : JSON.stringify(value)
26793
- }]
26801
+ }],
26802
+ ...meta
26794
26803
  };
26795
26804
  const structuredContent = value;
26796
26805
  return {
@@ -26799,7 +26808,8 @@ var MCPServer = class extends MCPServerBase {
26799
26808
  content: [{
26800
26809
  type: "text",
26801
26810
  text: JSON.stringify(structuredContent)
26802
- }]
26811
+ }],
26812
+ ...meta
26803
26813
  };
26804
26814
  }
26805
26815
  registerResourceHandlers(server) {
@@ -27144,17 +27154,15 @@ var MCPServer = class extends MCPServerBase {
27144
27154
  /** Reads an `ui://` app resource; application resources require a protocol request. */
27145
27155
  async readResource(uri) {
27146
27156
  const html = this.appResourceHtml.get(uri);
27147
- 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({
27148
27159
  id: "MCP_SERVER_RESOURCE_NOT_FOUND",
27149
27160
  domain: ErrorDomain.MCP,
27150
27161
  category: ErrorCategory.USER,
27151
27162
  text: `Resource '${uri}' not found; application resources are only readable through an MCP request`,
27152
27163
  details: { uri }
27153
27164
  });
27154
- return { contents: [{
27155
- uri,
27156
- text: html
27157
- }] };
27165
+ return { contents: [this.resourceContents(resource, { text: html })] };
27158
27166
  }
27159
27167
  /** Lists `ui://` app resources; application resources require a protocol request. */
27160
27168
  async listResources() {
@@ -27174,23 +27182,23 @@ function errorResult(text) {
27174
27182
  isError: true
27175
27183
  };
27176
27184
  }
27177
- /** 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. */
27178
27190
  function normalizeUiMeta(meta) {
27179
- if (!meta) return void 0;
27191
+ const resourceUri = uiResourceUri(meta);
27192
+ if (!meta || !resourceUri) return meta;
27180
27193
  const ui = meta.ui;
27181
- const flat = meta[RESOURCE_URI_META_KEY];
27182
- if (ui?.resourceUri && !flat) return {
27183
- ...meta,
27184
- [RESOURCE_URI_META_KEY]: ui.resourceUri
27185
- };
27186
- if (flat && !ui?.resourceUri) return {
27194
+ return {
27187
27195
  ...meta,
27188
27196
  ui: {
27189
- ...ui ?? {},
27190
- resourceUri: flat
27191
- }
27197
+ ...ui,
27198
+ resourceUri
27199
+ },
27200
+ [RESOURCE_URI_META_KEY]: resourceUri
27192
27201
  };
27193
- return meta;
27194
27202
  }
27195
27203
  //#endregion
27196
27204
  //#region src/server/types.ts