Skip to main content
Content helpers provide convenient functions for creating MCP-compliant content blocks and resource links. These utilities make it easy to construct messages with text, images, videos, audio, and other resources.

Text Content

text_content()

Create a TextContent block from a string.
text
str
required
The text content to include in the message
Returns: TextContent - An MCP TextContent block
from fast_agent import text_content

message_content = text_content("Hello, world!")
Resource links allow you to reference external resources (images, videos, audio, documents) in messages. Fast Agent automatically infers MIME types from URLs and extracts filenames. Create a ResourceLink from a URL with automatic MIME type inference.
url
str
required
The URL to the resource
name
str | None
Optional name for the resource. If not provided, extracts filename from URL
mime_type
str | None
Optional MIME type. If not provided, infers from file extension
description
str | None
Optional description of the resource
Returns: ResourceLink - An MCP ResourceLink object
from fast_agent import resource_link

# Basic usage - name and MIME type auto-inferred
doc = resource_link("https://example.com/report.pdf")

# With custom metadata
doc = resource_link(
    "https://example.com/data.json",
    name="Analytics Data",
    mime_type="application/json",
    description="Q4 2024 analytics results"
)
Create a ResourceLink for an image URL. Ensures the MIME type is set to an image format.
url
str
required
The URL to the image
name
str | None
Optional name for the image. If not provided, extracts filename from URL
mime_type
str | None
Optional MIME type. If not provided, infers from extension (defaults to image/jpeg)
description
str | None
Optional description of the image
Returns: ResourceLink - An MCP ResourceLink object with image MIME type
from fast_agent import image_link

photo = image_link(
    "https://example.com/chart.png",
    description="Sales performance chart"
)
Create a ResourceLink for a video URL. Ensures the MIME type is set to a video format.
url
str
required
The URL to the video
name
str | None
Optional name for the video. If not provided, extracts filename from URL
mime_type
str | None
Optional MIME type. If not provided, infers from extension (defaults to video/mp4)
description
str | None
Optional description of the video
Returns: ResourceLink - An MCP ResourceLink object with video MIME type
YouTube URLs are automatically detected and set to video/mp4 MIME type for optimal compatibility.
from fast_agent import video_link

# Regular video file
video = video_link(
    "https://example.com/tutorial.mp4",
    description="Product tutorial video"
)

# YouTube video - automatically handled
youtube = video_link(
    "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
    description="Introduction video"
)
Create a ResourceLink for an audio URL. Ensures the MIME type is set to an audio format.
url
str
required
The URL to the audio file
name
str | None
Optional name for the audio. If not provided, extracts filename from URL
mime_type
str | None
Optional MIME type. If not provided, infers from extension (defaults to audio/mpeg)
description
str | None
Optional description of the audio
Returns: ResourceLink - An MCP ResourceLink object with audio MIME type
from fast_agent import audio_link

podcast = audio_link(
    "https://example.com/episode-42.mp3",
    description="Latest podcast episode"
)

Complete Example

Here’s how to use content helpers to build rich messages:
from fast_agent import FastAgent, text_content, image_link, video_link

agent = FastAgent()

# Send a message with mixed content
response = await agent.run(
    messages=[
        {
            "role": "user",
            "content": [
                text_content("Please analyze this chart and video:"),
                image_link(
                    "https://example.com/sales-chart.png",
                    description="Q4 sales data visualization"
                ),
                video_link(
                    "https://example.com/presentation.mp4",
                    description="Executive summary presentation"
                )
            ]
        }
    ]
)

MIME Type Inference

Fast Agent automatically infers MIME types from file extensions:
  • Images: .jpg, .jpeg, .png, .gif, .webp, .svg, etc.
  • Videos: .mp4, .webm, .mov, .avi, etc.
  • Audio: .mp3, .wav, .ogg, .m4a, etc.
  • Documents: .pdf, .json, .xml, .csv, etc.
If the extension is unknown, you can explicitly set the mime_type parameter.

Build docs developers (and LLMs) love