What is MCP?
Model Context Protocol (MCP) is an open standard that enables communication between AI models and external tools and services. Thousands of MCP servers exist for filesystems, databases, browsers, SaaS APIs, and more. Timbal agents can connect to any MCP server withMCPServer. The server’s tools are discovered at runtime and exposed to the LLM exactly like native tools — schemas, streaming, tracing, and error handling included.
This page covers consuming MCP servers from your agents. For the reverse direction — connecting your editor to the Timbal platform’s MCP server — see MCP Integration.
Basic Usage
Add anMCPServer to the agent’s tools list. Two transports are supported:
name= set, a tool declared as list_files on the filesystem server appears to the LLM as filesystem__list_files. The bare name is still used on the wire.
Configuration
Authentication
For servers that require auth, pass headers (http) or environment variables (stdio). Read secrets from the environment instead of hardcoding them:How Results Are Handled
MCP tool results are converted so the LLM always receives something useful:- Text content becomes a plain string (or a list of strings for multiple blocks)
- Images, audio, and binary resources become Timbal
Files, forwarded to the model as file content — vision models can see returned images directly - Structured content is returned as-is when the server sends no text representation
- Errors (
isError) raise inside the tool call, so the model receives a proper error tool result and can self-correct
Connection Lifecycle
Connections are lazy: nothing is spawned or contacted until the agent first needs the server’s tools. The tool list is fetched once and cached for the life of the connection. Close the connection when you’re done:Dynamic Resolution
MCPServer is a ToolSet: tools are resolved at runtime, not import time. This means the available tools always reflect what the server currently offers, and you can mix MCP servers freely with functions, built-in tools, and other agents in the same tools list.
Codegen CLI
The codegen CLI can add MCP servers to an agent’s source file:add-mcp with the same --name replaces the server spec. Remove a server with remove-tool --name <server_name> — the assignment and import are cleaned up automatically.