create_session

View as MarkdownOpen in Claude

Create and register a new session. If a session with the same ID already exists, the old session is closed first. Raises RuntimeError if the total session limit or the per-service session limit is exceeded.

Parameters

session_id
strRequired

Unique session identifier, typically a SignalWire call ID.

service_name
strRequired

Name of the MCP service for this session.

process
MCPClientRequired

The MCP client process to associate with this session.

timeout
Optional[int]

Session timeout in seconds. Defaults to the manager’s default_timeout (300).

metadata
Optional[dict[str, Any]]

Arbitrary metadata to attach to the session.

Returns

Session — The newly created session object.

Example

1from signalwire.mcp_gateway import SessionManager, MCPManager
2
3config = {
4 "session": {"default_timeout": 300, "max_sessions_per_service": 100},
5 "services": {"todo": {"command": ["python3", "todo_mcp.py"], "description": "Todo", "enabled": True}}
6}
7
8manager = SessionManager(config)
9mcp = MCPManager(config)
10client = mcp.create_client("todo")
11session = manager.create_session(
12 session_id="call-abc-123",
13 service_name="todo",
14 process=client,
15 timeout=600,
16 metadata={"caller": "+15551234567"}
17)
18print(session.session_id) # "call-abc-123"