mastra-ai/mastra · error · MastraError

MCP_SERVER_RESOURCES_NOT_CONFIGURED

MCP_SERVER_RESOURCES_NOT_CONFIGURED

Error message

MCP_SERVER_RESOURCES_NOT_CONFIGURED

What it means

readResource() on MCPServer requires a `getResourceContent` handler supplied via resourceOptions at construction. If none was configured, the server cannot resolve any resource URI and throws MCP_SERVER_RESOURCES_NOT_CONFIGURED (ErrorCategory.USER) with the requested uri in details. It signals a server configuration gap, not a bad URI.

Source

Thrown at packages/mcp/src/server/server.ts:3052

        },
        error,
      );
      this.logger.trackException(mastraError);
      throw mastraError;
    }
  }

  /**
   * Reads the content of a resource by URI.
   *
   * Used by the Studio API to proxy `ui://` resource reads for MCP Apps rendering.
   *
   * @param uri - The resource URI to read (e.g. `ui://weather/dashboard`)
   * @returns Promise resolving to the resource content
   */
  public async readResource(uri: string): Promise<{ contents: Array<{ uri: string; text?: string; blob?: string }> }> {
    if (!this.resourceOptions?.getResourceContent) {
      throw new MastraError({
        id: 'MCP_SERVER_RESOURCES_NOT_CONFIGURED',
        domain: ErrorDomain.MCP,
        category: ErrorCategory.USER,
        details: { uri },
      });
    }

    const extra = {} as any;
    const result = await this.resourceOptions.getResourceContent({ uri, extra });
    const contents = Array.isArray(result) ? result : [result];

    return {
      contents: contents.map(c => ({
        uri,
        ...('text' in c && c.text !== undefined ? { text: c.text } : {}),
        ...('blob' in c && c.blob !== undefined ? { blob: c.blob } : {}),
      })),
    };

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass `resourceOptions: { getResourceContent: async (uri) => ... }` when constructing the MCPServer
  2. Implement getResourceContent to return `{ contents: [{ uri, text }] }` for the URIs you serve
  3. If resources are not intended to be supported, remove/guard the readResource call on the client side

Example fix

// before
const server = new MCPServer({ name: 'my-server', version: '1.0.0', tools });
await server.readResource('ui://weather/dashboard'); // throws
// after
const server = new MCPServer({
  name: 'my-server',
  version: '1.0.0',
  tools,
  resourceOptions: {
    getResourceContent: async (uri: string) => ({
      contents: [{ uri, text: JSON.stringify({ dashboard: 'data' }) }],
    }),
  },
});
Defensive patterns

Strategy: validation

Validate before calling

if (typeof server.readResource === 'function' && serverHasResourceOptions(server)) {
  await server.readResource(uri);
} else {
  console.warn('This MCPServer has no resource support configured');
}

Type guard

function supportsResources(server: any): server is { readResource: (uri: string) => Promise<any> } & { resourceOptions: { getResourceContent: Function } } {
  return !!server?.resourceOptions?.getResourceContent;
}

Try / catch

try {
  const res = await server.readResource(uri);
} catch (e) {
  if ((e as any).id === 'MCP_SERVER_RESOURCES_NOT_CONFIGURED') {
    console.error(`Resource support not configured on this server (uri: ${e.details.uri})`);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `server.readResource(uri)` (e.g. readResource('ui://weather/dashboard')) on an MCPServer instance constructed without `resourceOptions.getResourceContent`.

Common situations: Creating an MCPServer with tools/prompts only, then later adding resource reads without updating the constructor options; copying server bootstrap code that omits resourceOptions; a framework/deployment path instantiating the server without resource support.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/91905038dadf332b. Report an issue: GitHub.