Skip to main content

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

Metadata

Release files for pydantic-ai-resilient-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-ai-resilient-mcp 0.1.0
File Size Uploaded
pydantic_ai_resilient_mcp-0.1.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-ai-resilient-mcp 0.1.0
File Interpreter ABI Platform
pydantic_ai_resilient_mcp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / pydantic_ai_resilient_mcp-0.1.0.tar.gz

Download URL pydantic_ai_resilient_mcp-0.1.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5a033ac983219531dd6b03762c6f79e6345a44f0ed1fac42fce1a98e6683015a
BLAKE2b-256 checksum
How to use checksums
7f127fb90f1dd315536e90fdc0a0f51bb25be6d21ba4d6a492919f6ce474a6b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / pydantic_ai_resilient_mcp-0.1.0-py3-none-any.whl

Download URL pydantic_ai_resilient_mcp-0.1.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7844e5d5946c51325d1aa71254e342db88280f7b608d4d7612ef85cd09d0bea3
BLAKE2b-256 checksum
How to use checksums
9e7bdb103f67e94a26e19cd777cf2ca76c7270ed58860682cff3be4c64df735e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page