Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions capiscio_mcp/integrations/mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,29 @@ async def place_order(sku: str, quantity: int) -> str:
identity = MCPServerIdentity.from_env_sync()
return cls(identity=identity, **kwargs)

@classmethod
async def aconnect(cls, **kwargs: Any) -> "CapiscioMCPServer":
"""Async variant of :meth:`connect` for use in running event loops.

Unlike :meth:`connect`, which uses ``from_env_sync()`` and fails when
called from an already-running event loop (Jupyter, FastAPI, FastMCP),
this method uses the async ``MCPServerIdentity.from_env()`` directly.

Example::

server = await CapiscioMCPServer.aconnect()

@server.tool(min_trust_level=1)
async def my_tool(x: int) -> str:
return f"Result: {x}"

server.run()
"""
from capiscio_mcp.connect import MCPServerIdentity

identity = await MCPServerIdentity.from_env()
return cls(identity=identity, **kwargs)

# ------------------------------------------------------------------
# Private helpers
# ------------------------------------------------------------------
Expand Down