Skip to content

Agent with MCP in google Colab #2697

@dominicdev

Description

@dominicdev

Initial Checks

Description

I'm trying to test a MCP in google colab , using the basic code in the docs

but getting fileno error in part of MCPServerStdio

errro code in google colab

UnsupportedOperation                      Traceback (most recent call last)
[/tmp/ipython-input-3697815817.py](https://localhost:8080/#) in <cell line: 0>()
     45 
     46 if __name__ == "__main__":
---> 47     asyncio.run(main())

25 frames
[/usr/local/lib/python3.12/dist-packages/ipykernel/iostream.py](https://localhost:8080/#) in fileno(self)
    309             return self._original_stdstream_copy
    310         else:
--> 311             raise io.UnsupportedOperation("fileno")
    312 
    313     def _watch_pipe_fd(self):

UnsupportedOperation: fileno

Example Code

here is example code


import asyncio
from typing import Any
from pydantic_ai import Agent
from pydantic_ai.mcp import CallToolFunc, MCPServerStdio, ToolResult
from pydantic_ai.models.test import TestModel
from pydantic_ai.tools import RunContext
from pydantic_ai.models.google import GoogleModel
from pydantic_ai.providers.google import GoogleProvider
import os
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
provider = GoogleProvider(api_key=os.environ["GOOGLE_API_KEY"])
model = GoogleModel('gemini-1.5-flash', provider=provider)

PROMPT = 'Summarize this video into the key sections, ideas and action items. Deliver the notes from a first person perspective. If there are slides or info graphics in the video then include a description of them with any text that appears on there. Also make a transcript from the video after summarize sa it to md file,the filename will be date today in DDMMYYYY format'

import nest_asyncio
nest_asyncio.apply()
 
server = MCPServerStdio(command='python', args=['/content/yt_transcript.py'],)
print("server",server)
agent = Agent(model, toolsets=[server])



async def main():
    async with agent:
        agent.set_mcp_sampling_model()
        result = await agent.run('Create an image of a robot in a punk style.')
        print(result.output)

Python, Pydantic AI & LLM client version

Python 3.12.11

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions