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

# Model Context Protocol (MCP)

The Model Context Protocol (MCP) is an open standard that defines how applications expose tools, resources, and prompts to language models. By connecting to MCP servers, agents can access external capabilities without requiring custom integration code for each service.

## Transport Types

MCP supports three transport types for connecting to servers:

| Transport         | Use Case                     | Example                           |
| ----------------- | ---------------------------- | --------------------------------- |
| `streamable_http` | Remote HTTP servers          | Cloud-based MCP services          |
| `sse`             | Server-Sent Events streaming | Real-time data connections        |
| `stdio`           | Local processes              | Command-line tools, local servers |

**Choosing a Transport:**

* Use `streamable_http` for remote MCP servers (most common)
* Use `sse` for streaming data or real-time updates
* Use `stdio` for local processes or command-line tools

## Basic Setup

Configure and connect to MCP servers:

```python theme={null} theme={null}
import asyncio
import os
from hypertic.agents import Agent
from hypertic.models import XAI
from hypertic.mcp import MCPServers

async def main():
    # MCP configuration
    config = {
        "exa": {
            "url": "https://mcp.exa.ai/mcp?exaApiKey=your-api-key",
            "transport": "streamable_http"
        },
    }

    # Get tools from MCP servers
    mcp_tools = await MCPServers(config).get_tools(["web_search_exa"])

    # Create agent with MCP tools
agent = Agent(
        model=XAI(
            model="grok-3",
            max_tokens=4096,
        ),
    tools=[mcp_tools],
)

    # Agent can use MCP tools automatically
    response = await agent.arun("Search for the latest AI news")
    print(response.content)

asyncio.run(main())
```

## Multiple MCP Servers

Connect to multiple MCP servers in a single configuration:

```python theme={null} theme={null}
import asyncio
import os
from hypertic.agents import Agent
from hypertic.models import XAI
from hypertic.mcp import MCPServers

async def main():
    # Configure multiple MCP servers
    config = {
        "exa": {
            "url": "https://mcp.exa.ai/mcp?exaApiKey=your-api-key",
            "transport": "streamable_http"
        },
        "playwright": {
            "command": "npx",
            "args": ["@playwright/mcp@latest"],
            "env": {"DISPLAY": ":1"}
        },
    }

    # Get tools from multiple servers
    mcp_tools = await MCPServers(config).get_tools()

    agent = Agent(
        model=XAI(model="grok-3"),
        tools=[mcp_tools],
    )

    response = await agent.arun("Search for AI news and calculate 15 * 3")
    print(response.content)

asyncio.run(main())
```

## Using Context Managers

Use async context managers for automatic resource cleanup:

```python theme={null} theme={null}
import asyncio
import os
from hypertic.agents import Agent
from hypertic.models import XAI
from hypertic.mcp import MCPServers

async def main():
    config = {
        "exa": {
            "url": "https://mcp.exa.ai/mcp?exaApiKey=your-api-key",
            "transport": "streamable_http"
        },
    }

    # Use context manager for automatic cleanup
    async with MCPServers(config) as mcp_servers:
        mcp_tools = await mcp_servers.get_tools(["web_search_exa"])

        agent = Agent(
            model=XAI(model="grok-3"),
            tools=[mcp_tools],
        )

        response = await agent.arun("Search for the latest AI developments")
        print(response.content)

asyncio.run(main())
```
