mastra-ai/mastra · error · Error

Resource '${uri}' returned content with neither text nor blo

Error message

Resource '${uri}' returned content with neither text nor blob

What it means

Resource content returned by `getResourceContent` must include either a `text` or a `blob` field per the MCP resource-contents shape. If neither is present after checking `text`, the server throws this Error because it cannot construct valid ResourceContents for the client.

Source

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

            ? resourcesOrResourceContent
            : [resourcesOrResourceContent];
          // Preserve the resource's `_meta` on the read contents. MCP Apps hosts
          // read the UI CSP (connectDomains) from `contents[]._meta.ui.csp`, so
          // dropping it here silently ignores appResources CSP config.
          const resourceMeta = resource._meta ? { _meta: resource._meta } : {};
          const contents: (TextResourceContents | BlobResourceContents)[] = resourcesContent.map(resourceContent => {
            if ('text' in resourceContent && resourceContent.text !== undefined) {
              return {
                uri: resource.uri,
                mimeType: resource.mimeType,
                ...resourceMeta,
                text: resourceContent.text,
              } as TextResourceContents;
            }

            const blob = (resourceContent as { blob?: string }).blob;
            if (blob === undefined) {
              throw new Error(`Resource '${uri}' returned content with neither text nor blob`);
            }

            return {
              uri: resource.uri,
              mimeType: resource.mimeType,
              ...resourceMeta,
              blob,
            } as BlobResourceContents;
          });
          const duration = Date.now() - startTime;
          this.logger.info('Resource read successfully', { uri, duration });
          return {
            contents,
          };
        } catch (error) {
          const duration = Date.now() - startTime;
          this.logger.error('Failed to get content for resource', { uri, duration, error });
          throw error;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Return `{ text: '...' }` for textual content or `{ blob: base64String }` for binary content from getResourceContent.
  2. If the data is binary, base64-encode it and pass it as `blob` with an appropriate mimeType.
  3. Add a sanity check/test asserting every resource content result has text or blob before serving.

Example fix

// before
return { uri, mimeType: 'image/png', data: buffer };
// after
return { uri, mimeType: 'image/png', blob: buffer.toString('base64') };
Defensive patterns

Strategy: type-guard

Validate before calling

const content = await getResourceContent({ uri }); if (!('text' in content) && !('blob' in content)) throw new Error('getResourceContent must return text or blob');

Type guard

function hasValidContent(c: unknown): c is { text?: string; blob?: string } { const o = c as any; return typeof o?.text === 'string' || typeof o?.blob === 'string'; }

Try / catch

try { return await client.readResource({ uri }); } catch (e) { if (String(e?.message).includes('neither text nor blob')) { logger.error('server getResourceContent returned invalid shape for ' + uri); } throw e; }

Prevention

When it happens

Trigger: Your `getResourceContent` callback returns an object lacking both `text` and `blob` — e.g. `{}` or an object with only `uri`/`mimeType`, or a field name typo like `content` instead of `text`.

Common situations: Wrapping raw file/binary data under a custom key, returning metadata-only objects, or returning null-coerced content from a storage layer without converting to base64 blob.

Related errors


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