{"record":{"id":"eca7ba2fd7a32d44","repo":"mastra-ai/mastra","slug":"failed-to-fetch-resource-templates-from-server-t","errorCode":null,"errorMessage":"Failed to fetch resource templates from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)}","messagePattern":"Failed to fetch resource templates from server (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/client/actions/resource.ts","lineNumber":111,"sourceCode":"      if (response && response.resourceTemplates && Array.isArray(response.resourceTemplates)) {\n        return response.resourceTemplates;\n      } else {\n        this.logger.warn('Resource templates response did not have expected structure', {\n          server: this.client.name,\n          response,\n        });\n        return [];\n      }\n    } catch (e: any) {\n      // MCP Server might not support resources, so we return an empty array\n      if (e.code === ProtocolErrorCode.MethodNotFound) {\n        return [];\n      }\n      this.logger.error('Error getting resource templates from server', {\n        server: this.client.name,\n        error: e instanceof Error ? e.message : String(e),\n      });\n      throw new Error(\n        `Failed to fetch resource templates from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)}`,\n      );\n    }\n  }\n\n  /**\n   * Reads the content of a specific resource from the MCP server.\n   *\n   * @param uri - URI of the resource to read (e.g., 'file://path/to/file.txt')\n   * @returns Promise resolving to the resource content\n   * @throws {Error} If reading the resource fails or resource not found\n   *\n   * @example\n   * ```typescript\n   * const result = await client.resources.read('file://data/config.json');\n   * console.log(result.contents[0].text); // Resource text content\n   * ```\n   */","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/client/actions/resource.ts#L93-L129","documentation":"InternalMastraMCPClient's resources.templates() wraps any failure from the MCP resources/templates/list request in this Error after logging it. It signals the resource-template listing round-trip with the named server did not succeed, with the underlying error preserved in the message/stack.","triggerScenarios":"Calling client.resources.templates() when resources/templates/list throws — server unreachable, transport closed, JSON-RPC error, or the server does not support resource templates.","commonSituations":"Older MCP servers that predate the resource-templates capability; flaky network to a remote server; server restarted between connect() and the templates call.","solutions":["Check the inner error for the true cause","Confirm the server advertises resource template support; fall back to resources.list() if not","Reconnect the client if the transport dropped","Retry with backoff on transient failures"],"exampleFix":"// before\nconst templates = await client.resources.templates();\n// after\ntry {\n  var templates = await client.resources.templates();\n} catch (e) {\n  templates = await client.resources.list(); // fallback\n}","handlingStrategy":"fallback","validationCode":"if (!client.isConnected()) await client.connect();","typeGuard":null,"tryCatchPattern":"let templates;\ntry {\n  templates = await client.resources.templates();\n} catch (e) {\n  logger.warn('templates/list failed, falling back to resources.list()', e instanceof Error ? e.message : e);\n  templates = await client.resources.list();\n}","preventionTips":["Check server capabilities for resource template support before calling","Provide a fallback to plain resources.list() for older servers","Retry transient network failures with backoff"],"tags":["mcp","network","resources","templates","wrapped-error"],"backgroundTag":"failed-to-fetch-from-server","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}