Skip to content

Timeout for initializing MCP client #1833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 27, 2025
Merged

Timeout for initializing MCP client #1833

merged 4 commits into from
May 27, 2025

Conversation

alexmojaki
Copy link
Contributor

Demo script:

import asyncio

from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStdio

server = MCPServerStdio('python', args=[], timeout=100)  # will wait this many seconds
agent = Agent('openai:gpt-4o', mcp_servers=[server])


async def main():
    async with agent.run_mcp_servers():
        ...


asyncio.run(main())

@alexmojaki alexmojaki marked this pull request as ready for review May 26, 2025 14:14
@alexmojaki alexmojaki requested a review from DouweM May 26, 2025 14:14
Copy link

github-actions bot commented May 26, 2025

Docs Preview

commit: c214e88
Preview URL: https://73d6bd2b-pydantic-ai-previews.pydantic.workers.dev

@DouweM
Copy link
Contributor

DouweM commented May 26, 2025

@alexmojaki Thanks! I just merged #1716 which changes the timeout property from a float to a timedelta, because that's what the MCP library now requires on its new StreamableHTTP transport. Can you please update this to use timedeltas as well?

@DouweM DouweM self-assigned this May 26, 2025
@DouweM DouweM merged commit c8b9ecb into main May 27, 2025
18 checks passed
@DouweM DouweM deleted the alex/timeout-mcp branch May 27, 2025 13:24
@jlaneve
Copy link

jlaneve commented May 27, 2025

heads up that when I'm running a stateless remote MCP server, this PR breaks the connection. specifically, if I comment out these 2 lines, it begins working again

I haven't had time to fully look into this, but I just get this log and then it hangs:

Connecting to StreamableHTTP endpoint: http://xxx

I wonder if it's related to modelcontextprotocol/python-sdk#815

@DouweM
Copy link
Contributor

DouweM commented May 27, 2025

@jlaneve Strange, can you please file a new issue for that bug?

@alexmojaki
Copy link
Contributor Author

This made me notice #1843, but that's probably not the issue.

Kludex pushed a commit that referenced this pull request May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants