connect
Establish connection to Interactive Brokers TWS or Gateway to enable account management, market data access, and trade execution through the ib-async MCP server.
Instructions
Connect to TWS or IB Gateway. Must be called before using other tools.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "connect"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | No | TWS/Gateway host | 127.0.0.1 |
| port | No | Port (7496 for TWS, 4001 for Gateway) | |
| client_id | No | Client ID | |
| readonly | No | Read-only mode |
Implementation Reference
- src/ib_async_mcp/server.py:450-460 (handler)The handler logic for the 'connect' tool in _handle_tool function, which manages the connection to TWS/Gateway using IB.connectAsync.
if name == "connect": if ib is not None and ib.isConnected(): return {"status": "already_connected"} ib = IB() await ib.connectAsync( host=args.get("host", "127.0.0.1"), port=args.get("port", 7496), clientId=args.get("client_id", 1), readonly=args.get("readonly", True), ) return {"status": "connected", "accounts": ib.managedAccounts()} - src/ib_async_mcp/server.py:67-79 (schema)Definition and schema of the 'connect' tool.
Tool( name="connect", description="Connect to TWS or IB Gateway. Must be called before using other tools.", inputSchema={ "type": "object", "properties": { "host": {"type": "string", "default": "127.0.0.1", "description": "TWS/Gateway host"}, "port": {"type": "integer", "default": 7496, "description": "Port (7496 for TWS, 4001 for Gateway)"}, "client_id": {"type": "integer", "default": 1, "description": "Client ID"}, "readonly": {"type": "boolean", "default": True, "description": "Read-only mode"}, }, }, ),