restatedev / restatedev/sdk-python
restate.ext.pydantic requires pydantic-ai-slim[mcp] because _toolset.py imports pydantic_ai.mcp unguarded
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 81
- Forks
- 22
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 2
Description
restate.ext.pydantic can't be imported without pydantic-ai-slim[mcp], even with no MCP toolsets.
What happens
restate/ext/pydantic/__init__.py imports ._toolset, and _toolset.py:14 does an unguarded
from pydantic_ai.mcp import MCPToolset
pydantic_ai/mcp.py raises ImportError at import time when the mcp / fastmcp packages are absent, so with restate-sdk[pydantic-ai] + plain pydantic-ai-slim the whole extension fails to import:
$ pip install 'restate-sdk[pydantic-ai]==1.0.3' 'pydantic-ai-slim==2.12.0'
$ python -c "import restate.ext.pydantic"
ImportError: Please install the `mcp` package to use `MCPToolset`, you can use the `mcp` optional group — pip install "pydantic-ai-slim[mcp]"
Why it looks unintended
_agent.py already treats the same import as optional:
try:
from pydantic_ai.mcp import MCPToolset
from ._toolset import RestateMCPToolset
except ImportError:
pass
else:
if isinstance(toolset, MCPToolset):
return RestateMCPToolset(toolset, run_options)
…but that guard can't help, because _agent.py unconditionally imports ._toolset a few lines earlier, and _toolset.py pulls pydantic_ai.mcp at module scope for RestateMCPToolset.
Impact
Anyone using RestateAgent with function tools only has to install pydantic-ai-slim[mcp] — 28 extra transitive packages in our case (fastmcp-slim, mcp, authlib, keyring, jsonschema, sse-starlette, secretstorage, …) — purely to satisfy an import for a class they never instantiate.
Suggested fix
Move RestateMCPToolset (and its MCPToolset import) into its own module imported lazily, or guard the import in _toolset.py the way _agent.py does and define RestateMCPToolset only when it succeeds.
Environment
restate-sdk 1.0.3, pydantic-ai-slim 2.12.0, Python 3.14.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with restate/ext/pydantic/init.py, _toolset.py, and _agent.py, then reproduce the import using the pip install and python command shown in the issue. Trace how the optional MCP import is handled and preserve the existing MCP toolset behavior. Done means restate.ext.pydantic imports with plain pydantic-ai-slim while MCP support remains available when its optional dependencies are installed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100