Skip to main content
FastMCP provides helper functions to create image and audio content from various sources.

imageContent()

Create image content from a buffer, file path, or URL.

Parameters

object
required
Image source (must provide exactly one)

Returns

Promise<ImageContent>
Image content object

Features

  • Auto-detection: Automatically detects MIME type using file-type package
  • Base64 encoding: Converts image data to base64 for MCP protocol
  • Format validation: Warns if content doesn’t appear to be a valid image
  • Error handling: Clear error messages for fetch failures, file read errors

Supported Formats

Any image format supported by the file-type package:
  • PNG (.png)
  • JPEG (.jpg, .jpeg)
  • GIF (.gif)
  • WebP (.webp)
  • SVG (.svg)
  • BMP (.bmp)
  • ICO (.ico)
  • And many more…

Error Handling

audioContent()

Create audio content from a buffer, file path, or URL.

Parameters

object
required
Audio source (must provide exactly one)

Returns

Promise<AudioContent>
Audio content object

Features

  • Auto-detection: Automatically detects MIME type using file-type package
  • Base64 encoding: Converts audio data to base64 for MCP protocol
  • Format validation: Warns if content doesn’t appear to be valid audio
  • Error handling: Clear error messages for fetch failures, file read errors

Supported Formats

Any audio format supported by the file-type package:
  • MP3 (.mp3)
  • WAV (.wav)
  • OGG (.ogg)
  • FLAC (.flac)
  • AAC (.aac)
  • M4A (.m4a)
  • OPUS (.opus)
  • And more…

Error Handling

Usage Examples

Return multiple content types

Download and return image

Generate and return audio

Resource with image content