> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeroruntime.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate MCP

> Attach Model Context Protocol servers to extend your agent with external tools.

MCP is an open standard for securely connecting AI assistants to external data sources and tools. In Zero Runtime AI Agents, attach MCP servers to auto-discover services, databases, and APIs. The agent picks and runs the right tools and turns results into natural responses.

## How It Works

MCP tools are automatically discovered and made available to your agent, which intelligently chooses which tools to use based on user requests. When a user asks for information that requires external data, the agent will:

<Steps>
  <Step title="Identify the need">
    Detect that the user's request requires external data.
  </Step>

  <Step title="Select tools">
    Choose the appropriate tools from the available MCP servers.
  </Step>

  <Step title="Execute">
    Run the tools with the relevant parameters.
  </Step>

  <Step title="Respond">
    Process the results and provide a natural language response.
  </Step>
</Steps>

This integration allows your voice agent to access real-time data and external services while maintaining a natural conversational flow.

## Transport Methods

Zero Runtime supports two transport methods for MCP servers.

| Transport                         | Communication                                          | Best For                                             |
| :-------------------------------- | :----------------------------------------------------- | :--------------------------------------------------- |
| **STDIO**                         | Direct process communication with local Python scripts | Custom tools and functions, server-side integrations |
| **HTTP** (Streamable HTTP or SSE) | Network-based communication with external MCP services | Third-party integrations, remote MCP servers         |

## Example

Pass MCP servers to the agent via the `mcp_servers` parameter. Use `MCPServerStdio` for local scripts and `MCPServerHTTP` for remote services.

<CodeGroup>
  ```python title="main.py" Python theme={null}
  import sys
  from zrt import Agent, MCPServerStdio, MCPServerHTTP

  class MyVoiceAgent(Agent):
      def __init__(self, pipeline):
          super().__init__(
              agent_id="assistant",
              instructions="You are a helpful assistant with access to real-time data.",
              pipeline=pipeline,
              mcp_servers=[
                  # STDIO - local script
                  MCPServerStdio(
                      command=sys.executable,
                      args=["mcp_stdio_example.py"],
                  ),
                  # HTTP - remote service
                  MCPServerHTTP(
                      url="https://your-mcp-service.com/api/mcp",
                      headers={"Authorization": "Bearer <token>"},
                  ),
              ],
          )
  ```
</CodeGroup>

The agent auto-discovers every tool exposed by each server and chooses among them at
runtime, so you don't register tools individually.

## Server options

### `MCPServerStdio` (local process)

| Parameter | Type             | Description                                                         |
| :-------- | :--------------- | :------------------------------------------------------------------ |
| `command` | `str`            | Command to launch the server (e.g. `sys.executable` for Python).    |
| `args`    | `list[str]`      | Arguments passed to the command (typically the server script path). |
| `env`     | `dict[str, str]` | Extra environment variables for the server process.                 |

### `MCPServerHTTP` (remote service)

| Parameter | Type             | Description                                                  |
| :-------- | :--------------- | :----------------------------------------------------------- |
| `url`     | `str`            | URL of the remote MCP service (Streamable HTTP or SSE).      |
| `headers` | `dict[str, str]` | HTTP headers to send (e.g. an `Authorization` bearer token). |

<Note>
  The parameter names above are for the Python SDK. The JavaScript and Go SDKs use
  `command` + `args` (+ `env`) for STDIO and `url` + `headers` for HTTP. For example,
  `MCPServerStdio('python', { args: [...] })` and `MCPServerHTTP(url, { headers })` in JS, or
  `&zrt.MCPServerStdio{Command, Args, Env}` and `&zrt.MCPServerHTTP{URL, Headers}` in Go.
</Note>

## What's Next

<CardGroup cols={2}>
  <Card title="Function Tools" icon="wrench" href="/build/tools-and-capabilities/function-tools">
    Add custom Python functions as tools.
  </Card>

  <Card title="RAG" icon="database" href="/build/tools-and-capabilities/rag">
    Ground responses in a knowledge base.
  </Card>
</CardGroup>

## References

<Tabs>
  <Tab title="Python">
    #### Examples

    <CardGroup cols={2}>
      <Card title="MCP Client" icon="github" href="https://github.com/ZeroRuntimeAI/zrt-python-sdk-examples/blob/main/features/mcp_tools.py">
        Consume tools from an MCP server.
      </Card>
    </CardGroup>

    #### SDK Reference

    <CardGroup cols={2}>
      <Card title="MCP" icon="plug" href="/api-reference/python/core/tools-and-mcp#mcpserverstdio">
        `MCP` in the Python API reference.
      </Card>
    </CardGroup>
  </Tab>
</Tabs>
