Skip to main content

Crash-resilient wrapper for Pydantic AI MCP servers

Project description

pydantic-ai-resilient-mcp

Crash-resilient wrapper for Pydantic AI MCP servers. Handles server crashes gracefully without breaking your agent.

Installation

pip install pydantic-ai-resilient-mcp

Quick Start

from pydantic_ai import Agent
from pydantic_ai_resilient_mcp import ResilientMCPSSE

# Wrap your SSE MCP server
server = ResilientMCPSSE('http://localhost:8000/sse')

async with server:
    agent = Agent(model, toolsets=[server])

    # Use normally - crashes are handled automatically
    result = await agent.run('Your prompt here')
    print(result.output)

What It Does

When your MCP server crashes:

  • ✅ Catches the crash gracefully
  • ✅ Returns clean error message: {"error": "Host server crashed. Cannot use tools anymore"}
  • ✅ Prevents infinite retry loops
  • ✅ Agent continues running instead of crashing

Example

from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider
from resilient_mcp import ResilientMCPSSE

model = OpenAIChatModel('gpt-4o', provider=OpenAIProvider(api_key='...'))
server = ResilientMCPSSE('http://your-server:8000/sse')

async with server:
    agent = Agent(model, toolsets=[server])

    # Works before crash
    result1 = await agent.run('Use a tool')
    print(result1.output)

    # Server crashes during this call - handled gracefully
    result2 = await agent.run('Use another tool')
    print(result2.output)  # {"error": "Host server crashed..."}

    # No infinite retries - agent continues cleanly

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_ai_resilient_mcp-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_ai_resilient_mcp-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_ai_resilient_mcp-0.1.0.tar.gz.

File metadata

File hashes

Hashes for pydantic_ai_resilient_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5a033ac983219531dd6b03762c6f79e6345a44f0ed1fac42fce1a98e6683015a
MD5 856b30e36f7d75ccabc180ee92ed393b
BLAKE2b-256 7f127fb90f1dd315536e90fdc0a0f51bb25be6d21ba4d6a492919f6ce474a6b7

See more details on using hashes here.

File details

Details for the file pydantic_ai_resilient_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_ai_resilient_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7844e5d5946c51325d1aa71254e342db88280f7b608d4d7612ef85cd09d0bea3
MD5 ff1173db4587f673248d2e04f6a35cc3
BLAKE2b-256 9e7bdb103f67e94a26e19cd777cf2ca76c7270ed58860682cff3be4c64df735e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page