You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> **⚠️ DISCLAIMER**: This is an **unofficial**, community-developed MCP server and is **NOT** affiliated with or endorsed by Interactive Brokers. This software is in **Alpha state** and may not work perfectly.
7
+
> **DISCLAIMER**: This is an **unofficial**, community-developed MCP server
8
+
> and is **NOT** affiliated with or endorsed by Interactive Brokers. This
9
+
> software is in **Alpha state** and may not work perfectly.
8
10
9
-
A Model Context Protocol (MCP) server that provides integration with Interactive Brokers' trading platform. This server allows AI assistants to interact with your IB account to retrieve market data, check positions, and place trades.
11
+
A Model Context Protocol (MCP) server that provides integration with Interactive
12
+
Brokers' trading platform. This server allows AI assistants to interact with
13
+
your IB account to retrieve market data, check positions, and place trades.
<imgwidth="380"height="200"src="https://glama.ai/mcp/servers/@code-rabi/interactive-brokers-mcp/badge"alt="Interactive Brokers Server MCP server" />
13
17
</a>
14
18
15
19
## 🔒 Security Notice
20
+

16
21
17
-
**This MCP server is designed to run locally only** for security reasons. Never deploy this to remote servers or cloud platforms as it handles sensitive trading credentials and financial data.
18
22
19
-
## ✨ Features
23
+
## Features
20
24
21
-
-**Account Management**: Get account information and balances
22
-
-**Position Tracking**: View current positions and P&L
23
-
-**Market Data**: Real-time market data for stocks and instruments
24
-
-**Order Management**: Place market, limit, and stop orders
25
-
-**Order Monitoring**: Check order status and execution details
25
+
-**Interactive Brokers API Integration**: Full trading capabilities including account management, position tracking, real-time market data, and order management (market, limit, and stop orders)
26
+
-**Flex Query Support**: Execute Flex Queries to retrieve account statements, trade confirmations, and historical data. Queries are automatically remembered for easy reuse
27
+
-**Flexible Authentication**: Choose between browser-based OAuth authentication or headless mode with credentials for automated environments
28
+
-**Simple Setup**: Run directly with `npx` - no Docker or additional installations required. Includes pre-configured IB Gateway and Java runtime for all platforms
29
+
30
+
## Security Notice
31
+
32
+
**IMPORTANT WARNINGS:**
33
+
34
+
-**Financial Risk**: Trading involves substantial risk of loss. Always test
35
+
with paper trading first.
36
+
-**Security**: This software handles sensitive financial data. Only run
37
+
locally, never on public servers.
38
+
-**No Warranty**: This unofficial software comes with no warranties. Use at
39
+
your own risk.
40
+
-**Not Financial Advice**: This tool is for automation only, not financial
41
+
advice.
26
42
27
43
## Prerequisites
28
44
29
45
**No additional installations required!** This package includes:
46
+
30
47
- Pre-configured IB Gateway for all platforms (Linux, macOS, Windows)
31
48
- Java Runtime Environment (JRE) for IB Gateway
32
49
- All necessary dependencies
33
50
34
51
You only need:
52
+
35
53
- Interactive Brokers account (paper or live trading)
36
54
- Node.js 18+ (for running the MCP server)
37
55
@@ -50,40 +68,156 @@ Add this MCP server to your Cursor/Claude configuration:
50
68
}
51
69
```
52
70
53
-
When you first use the server, a web browser window will automatically open for the Interactive Brokers OAuth authentication flow. Log in with your IB credentials to authorize the connection.
71
+
When you first use the server, a web browser window will automatically open for
72
+
the Interactive Brokers OAuth authentication flow. Log in with your IB
73
+
credentials to authorize the connection.
74
+
75
+
## Headless Mode Configuration
76
+
77
+
For automated environments or when you prefer not to use a browser for
78
+
authentication, you can enable headless mode by configuring it in your MCP
79
+
server configuration:
80
+
81
+
```json
82
+
{
83
+
"mcpServers": {
84
+
"interactive-brokers": {
85
+
"command": "npx",
86
+
"args": ["-y", "interactive-brokers-mcp"],
87
+
"env": {
88
+
"IB_HEADLESS_MODE": "true",
89
+
"IB_USERNAME": "your_ib_username",
90
+
"IB_PASSWORD_AUTH": "your_ib_password"
91
+
}
92
+
}
93
+
}
94
+
}
95
+
96
+
```
97
+
98
+
In headless mode, the server will automatically authenticate using your
99
+
credentials without opening a browser window. This is useful for:
100
+
101
+
- Automated trading systems
102
+
- Server environments without a display
103
+
- CI/CD pipelines
104
+
- Situations where browser interaction is not desired
105
+
106
+
**Important**: Even in headless mode, Interactive Brokers may still require
107
+
two-factor authentication (2FA). When 2FA is triggered, the headless
108
+
authentication will wait for you to complete the 2FA process through your
109
+
configured method (mobile app, SMS, etc.) before proceeding.
110
+
111
+
To enable paper trading, add `"IB_PAPER_TRADING": "true"` to your environment variables:
112
+
113
+
```json
114
+
{
115
+
"mcpServers": {
116
+
"interactive-brokers": {
117
+
"command": "npx",
118
+
"args": ["-y", "interactive-brokers-mcp"],
119
+
"env": {
120
+
"IB_HEADLESS_MODE": "true",
121
+
"IB_USERNAME": "your_ib_username",
122
+
"IB_PASSWORD_AUTH": "your_ib_password",
123
+
"IB_PAPER_TRADING": "true"
124
+
}
125
+
}
126
+
}
127
+
}
128
+
```
129
+
130
+
**Security Note**: Store credentials securely and never commit them to version
131
+
control. Consider using environment variable files or secure credential
132
+
management systems.
133
+
134
+
## Flex Query Configuration (Optional)
135
+
136
+
To use Flex Queries for retrieving account statements and historical data, you need to configure your Flex Web Service Token:
137
+
138
+
```json
139
+
{
140
+
"mcpServers": {
141
+
"interactive-brokers": {
142
+
"command": "npx",
143
+
"args": ["-y", "interactive-brokers-mcp"],
144
+
"env": {
145
+
"IB_FLEX_TOKEN": "your_flex_token_here"
146
+
}
147
+
}
148
+
}
149
+
}
150
+
```
151
+
152
+
### How to Get Your Flex Token:
153
+
154
+
1. Log in to [Interactive Brokers Account Management](https://www.interactivebrokers.com/portal)
155
+
2. Go to **Settings** → **Account Settings**
156
+
3. Navigate to **Reporting** → **Flex Web Service**
157
+
4. Generate or retrieve your Flex Web Service Token
158
+
159
+
For detailed instructions on enabling Flex Web Service, see the [IB Flex Web Service Guide](https://www.ibkrguides.com/orgportal/performanceandstatements/flex-web-service.htm).
160
+
161
+
### Creating Flex Queries:
162
+
163
+
1. Go to **Reports** → **Flex Queries** in Account Management
164
+
2. Create or customize your query template
165
+
3. Click the info icon next to your query to find its Query ID
166
+
167
+
For a complete guide on creating and customizing Flex Queries, see the [IB Flex Queries Guide](https://www.ibkrguides.com/orgportal/performanceandstatements/flex.htm).
168
+
169
+
**Note**: When you execute a Flex Query for the first time, the MCP server automatically saves it with its name from the API. Future executions can reference the query by either its ID or its saved name.
170
+
171
+
### Flex Query Features:
172
+
173
+
-**Automatic Memory**: When you execute a Flex Query, it's automatically saved for future use
174
+
-**Easy Reuse**: Previously used queries are remembered - no need to copy query IDs repeatedly
175
+
-**Friendly Names**: Optionally provide a friendly name when first executing a query
176
+
-**Forget Queries**: Remove queries you no longer need with the `forget_flex_query` tool
177
+
178
+
## Configuration Variables
179
+
180
+
| Feature | Environment Variable | Command Line Argument |
0 commit comments