How to Use the IBKR (Interactive Brokers) MCP in Mastra AI
Build resilient trading workflows that automate IBKR order execution using Mastra AI and this MCP Server.
Works with every AI agent you already use
…and any MCP-compatible client
Connect IBKR (Interactive Brokers) MCP to Mastra AI
Create your Vinkius account to connect IBKR (Interactive Brokers) to Mastra AI and route execution through our secure gateway. The platform manages server hosting, runtime updates, and security layers. Configuration requires no manual server provisioning.
Fault-Tolerant Order Routing
The `place_order` tool sends your trade execution payloads directly to the Interactive Brokers gateway. When configured inside a Mastra AI workflow, you can build conditional logic that automatically retries the trade if the initial attempt fails due to rate limits. If the market moves against your position, the agent uses `modify_order` or `cancel_order` to adjust the price or pull the ticket entirely. The built-in workflow engine handles these state changes step-by-step, ensuring your execution logic doesn't crash mid-trade.
Session Maintenance via Mastra AI MCP Server
The `tickle_session` tool maintains your active Client Portal API session by executing regular heartbeat pings. Mastra AI runs this tool as a background step in your agent workflows, preventing credential expiration during long-running trading operations. While the session remains active, the agent uses `get_account_summary` to monitor your buying power and margin cushion. If buying power falls below your specified threshold, the workflow triggers an alert step to notify your team before placing further trades.
Risk Management and Ledger Analysis
The `get_portfolio_ledger` tool retrieves your current cash balances and unrealized PnL directly from your account. Your Mastra AI agent analyzes this ledger data to calculate risk exposure before initiating new positions. To get a deeper look at historical performance, the agent triggers `send_flex_request` and retrieves the resulting file via `get_flex_statement`. You can pipe this data directly into your custom database or analytical pipelines to track your trading metrics over time.
Set up IBKR (Interactive Brokers) MCP in Mastra AI
Prerequisites
- Node.js 18+ and a TypeScript project
-
@mastra/mcp+@mastra/corepackages - Active Vinkius subscription with a valid endpoint token
- 1
Install dependencies
Run
npm install @mastra/mcp @mastra/coreplus your preferred model provider (e.g.@ai-sdk/openai). - 2
Configure the MCPClient
Create an
MCPClientwith your Vinkius endpoint as aURLobject. Replace[YOUR_TOKEN_HERE]with your token from cloud.vinkius.com. - 3
Discover and inject tools
Call
mcpClient.listTools()and spread the result into your agent'stoolsobject. All IBKR (Interactive Brokers) tools become native Mastra tools. - 4
Run with any model
Swap
openai("gpt-4o")for any AI SDK-compatible provider. Callagent.generate()and the agent routes tool calls through MCP automatically.
import { MCPClient } from "@mastra/mcp";
import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";
const mcpClient = new MCPClient({
id: "ibkr-interactive-brokers-mcp-client",
servers: {
"ibkr-interactive-brokers-mcp": {
url: new URL(
"https://edge.vinkius.com/[YOUR_TOKEN_HERE]/mcp"
),
},
},
});
const agent = new Agent({
name: "IBKR (Interactive Brokers) Agent",
model: openai("gpt-4o"),
instructions: "You have access to IBKR (Interactive Brokers) tools.",
tools: {
...(await mcpClient.listTools()),
},
});
const result = await agent.generate(
"List recent IBKR (Interactive Brokers) transactions"
);
console.log(result.text); Independent Platform Disclaimer: Vinkius is an independent platform and is not affiliated with, endorsed by, sponsored by, verified by, or otherwise authorized by Interactive Brokers. All third-party trademarks, logos, and brand names are the property of their respective owners. Their use on this website is strictly for informational purposes to identify service compatibility and interoperability.
Why Choose Vinkius
Vinkius connects your tools to AI with real-time monitoring and automatic cost savings — all from one dashboard.
Real-time monitoring
Live
visibility into every interaction
Connect your favorite tools to your AI and see exactly what's happening — every request, every response, in real time.
Built-in savings
60%
lower AI costs
Vinkius compresses data between your apps and your AI automatically. Lower bills every month — no configuration required.
Single dashboard
One
place for every integration
Every tool your AI connects to, managed from a single screen. One account, complete control.
Common questions about IBKR (Interactive Brokers) MCP in Mastra AI
Use it with your favorite AI tools
Connect this server to Cursor, Claude, VS Code, and more.
Start using the IBKR (Interactive Brokers) MCP today
We host it, we monitor it, we maintain it. You just paste one token.