BuildCreate toolsBuild a tool

Return results from a tool

For agent developers who build servers, a ’s return annotation sets its output schema, and its return value is what the model reads. This guide shows how to shape and describe a result, and how to send an image the model can see.

Prerequisites

  • An Arcade MCP server.
  • arcade-mcp-server version 1.34.0 or later to use ToolResult and Image.

Return a value

Return a str, int, float, bool, list, dict, TypedDict, or Pydantic model. Annotate the return with Annotated[T, "description"] to describe the result to the model.

clients get the value as one text block and as structuredContent:

  • A string, number, or boolean arrives as text. structuredContent wraps it as {"result": value}.
  • A list arrives as JSON text. structuredContent wraps it as {"result": [...]}.
  • A dict, TypedDict, or Pydantic model arrives as JSON text, and as structuredContent as is. Keys a TypedDict doesn’t declare are dropped.

Describe each field

Prefer a TypedDict for results with several fields. A docstring under a field becomes that field’s description in the output schema, so the model knows what each field means:

tools.py
from typing import Annotated

from arcade_mcp_server import tool
from typing_extensions import TypedDict


class Weather(TypedDict):
    city: str
    temperature_c: float
    """The current temperature in degrees Celsius."""


@tool
def get_weather(
    city: Annotated[str, "The city to look up"],
) -> Annotated[Weather, "The current weather in the city"]:
    """Get the current weather in a city."""
    return {"city": city, "temperature_c": 21.5}

Send an image the model can see

Use ToolResult when the model has to see the image: to describe a photo, read a chart, or check a screenshot. If the model only needs facts about the image, such as its name, size, or URL, return them as a plain value.

The image must go in ToolResult’s content. It can’t live inside the returned TypedDict: a plain return reaches clients as one JSON text block, so an image field in it arrives as base64 text, not as an image.

Annotate the return as ToolResult[T], where T is what you would return otherwise. value is the ’s result and sets its output schema. content holds content blocks. Image(data, mime_type) builds an image block from raw bytes.

tools.py
from typing import Annotated

import httpx
from arcade_mcp_server import Image, ToolResult, tool
from typing_extensions import TypedDict


class Photo(TypedDict):
    url: str
    size_bytes: int


@tool
async def get_photo(
    url: Annotated[str, "The URL of a PNG image"],
) -> Annotated[ToolResult[Photo], "The image's details"]:
    """Fetch a PNG image so the model can see it."""
    async with httpx.AsyncClient() as client:
        response = await client.get(url)
        response.raise_for_status()
    return ToolResult(
        value={"url": url, "size_bytes": len(response.content)},
        content=[Image(response.content, mime_type="image/png")],
    )

clients get the content blocks first, then value as a text block and as structuredContent. ToolResult[T] | None also works.

If a block in content is not a valid content block, the call fails with a output error: Failed to serialize tool output.

Keep each image under 1 MB

Large images fail before or after they reach the model:

  • The caps a worker response at 10 MB, including the base64 encoding of every image.
  • chatgpt.com fails on image blocks of about 1 MB or more. An image of 0.6 MB works.
  • claude.ai reads images up to about 6 MB and downscales them to about 1568 pixels on the longest side.

Keep each image under about 1 MB. Resize or compress larger images before you return them.

Coming from FastMCP

FastMCP also has a ToolResult, with different fields: content, structured_content, and meta. Arcade’s ToolResult has value and content. Don’t pass structured_content=: put the structured result in value, and Arcade sends it as structuredContent.

Last updated on

On this page