[Python] Error implementing MCP Python sandbox with asyncio on Windows: NotImplementedError

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to implement a MCP Python sandbox for my agent to run Python scripts, but I am getting errors like this:

    File "C:\Users\f\anaconda3\Lib\asyncio\base_events.py", line 524, in _make_subprocess_transport raise NotImplementedError

    This is the tool that I am trying to build (MCP run-python tool):

    self.server_params = StdioServerParameters(
    command='deno',
    args=[
    'run',
    '-N', '-R=node_modules',
    '-W=node_modules',
    '--node-modules-dir=auto',
    'jsr:mad:pydantic/mcp-run-python',
    'stdio'
    ]
    )`

    @self.agent.tool
    async def execute_script(ctx: RunContext, code: str) -> Dict[str, Any]:
    async with stdio_client(self.server_params) as (read, write):
    async with ClientSession(read, write) as session:
    await session.initialize()
    result = await session.call_tool("run_python", {"code": code})
    if result.get("success"):
    return {"status": "success", "output": result.get("stdout")}
    raise RuntimeError(f"Error during execution: {result.get('stderr', Unknown error')}")`


    The error seems to be related to the asyncio event loop.

    Has anyone successfully implemented the MCP run-python tool on Windows using asyncio? Are there any specific configurations or workarounds required to handle subprocesses in this context?

    Continue reading...

Compartilhe esta Página