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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_ai_resilient_mcp-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_ai_resilient_mcp-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a033ac983219531dd6b03762c6f79e6345a44f0ed1fac42fce1a98e6683015a
|
|
| MD5 |
856b30e36f7d75ccabc180ee92ed393b
|
|
| BLAKE2b-256 |
7f127fb90f1dd315536e90fdc0a0f51bb25be6d21ba4d6a492919f6ce474a6b7
|
File details
Details for the file pydantic_ai_resilient_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_ai_resilient_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7844e5d5946c51325d1aa71254e342db88280f7b608d4d7612ef85cd09d0bea3
|
|
| MD5 |
ff1173db4587f673248d2e04f6a35cc3
|
|
| BLAKE2b-256 |
9e7bdb103f67e94a26e19cd777cf2ca76c7270ed58860682cff3be4c64df735e
|