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
int | float | NoneDefaults to None

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

metadata
dict[str, Any] | NoneDefaults to None

Arbitrary metadata to attach to the session.

Returns

Session — The newly created session object.

Example

from signalwire.mcp_gateway import SessionManager, MCPManager
config = {
"session": {"default_timeout": 300, "max_sessions_per_service": 100},
"services": {"todo": {"command": ["python3", "todo_mcp.py"], "description": "Todo", "enabled": True}}
}
manager = SessionManager(config)
mcp = MCPManager(config)
client = mcp.create_client("todo")
session = manager.create_session(
session_id="call-abc-123",
service_name="todo",
process=client,
timeout=600,
metadata={"caller": "+15551234567"}
)
print(session.session_id) # "call-abc-123"