Problem
CapiscioMCPServer.connect() and the underlying MCPServerIdentity.from_env_sync() / connect_sync() use asyncio.run(), which raises RuntimeError: asyncio.run() cannot be called from a running event loop when invoked from:
- Jupyter notebooks
- ASGI frameworks (FastAPI, Starlette)
- FastMCP setups that already have an event loop
- Any
async def entrypoint
This is a common usage pattern for MCP server bootstrapping code.
Proposed fix
- Add
CapiscioMCPServer.connect_async() (or make connect() async and provide connect_sync())
- Alternatively, detect a running loop and use
run_coroutine_threadsafe as other sync wrappers in the repo do
- Document the limitation prominently in the meantime
Affected methods
CapiscioMCPServer.connect() → integrations/mcp.py:418
MCPServerIdentity.from_env_sync() → connect.py:687
MCPServerIdentity.connect_sync() → connect.py:687
Context
Identified during PR #32 code review (Copilot review comments on connect.py:687 and mcp.py:418).
Problem
CapiscioMCPServer.connect()and the underlyingMCPServerIdentity.from_env_sync()/connect_sync()useasyncio.run(), which raisesRuntimeError: asyncio.run() cannot be called from a running event loopwhen invoked from:async defentrypointThis is a common usage pattern for MCP server bootstrapping code.
Proposed fix
CapiscioMCPServer.connect_async()(or makeconnect()async and provideconnect_sync())run_coroutine_threadsafeas other sync wrappers in the repo doAffected methods
CapiscioMCPServer.connect()→integrations/mcp.py:418MCPServerIdentity.from_env_sync()→connect.py:687MCPServerIdentity.connect_sync()→connect.py:687Context
Identified during PR #32 code review (Copilot review comments on
connect.py:687andmcp.py:418).