> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-service-account.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Tools

> Connect MCPTools to the filesystem MCP server over a stdio session and summarize a file.

```python mcp_tools.py theme={null}
"""
Mcp Tools
=============================

Demonstrates mcp tools.
"""

import asyncio
import sys
from pathlib import Path

from agno.agent import Agent
from agno.tools.mcp import MCPTools
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------


async def main(prompt: str) -> None:
    # Initialize the MCP server
    server_params = StdioServerParameters(
        command="npx",
        args=[
            "-y",
            "@modelcontextprotocol/server-filesystem",
            str(Path(__file__).parent.parent),
        ],
    )
    # Create a client session to connect to the MCP server
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            # Initialize the MCP toolkit
            mcp_tools = MCPTools(session=session)
            await mcp_tools.initialize()

            # Create an agent with the MCP toolkit
            agent = Agent(tools=[mcp_tools])

            # Run the agent
            await agent.aprint_response(prompt, stream=True)


# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    prompt = (
        sys.argv[1] if len(sys.argv) > 1 else "Read and summarize the file ./LICENSE"
    )
    asyncio.run(main(prompt))
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U "agno[mcp]" openai
    ```
  </Step>

  <Step title="Prepare Node.js">
    The MCP server runs with `npx`. Install Node.js, then verify the commands:

    ```bash theme={null}
    node --version
    npx --version
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Clone Agno and run the example from the repository root:

    ```bash theme={null}
    git clone https://github.com/agno-agi/agno.git
    cd agno
    python cookbook/91_tools/mcp_tools.py
    ```
  </Step>
</Steps>

Full source: [cookbook/91\_tools/mcp\_tools.py](https://github.com/agno-agi/agno/blob/main/cookbook/91_tools/mcp_tools.py)
