alpaca-mcp-server
alpaca-mcp-server
README
Alpaca MCP Server
This is a Model Context Protocol (MCP) server implementation for Alpaca's Trading API. It enables large language models (LLMs) on Claude Desktop, Cursor, or VScode to interact with Alpaca's trading infrastructure using natural language. This server supports stock trading, options trading, portfolio management, watchlist handling, and real-time market data access.
Features
- Market Data
- Real-time quotes, trades, and price bars for stocks
- Historical price data and trading history
- Option contract quotes and Greeks (via snapshots)
- Account Management
- View balances, buying power, and account status
- Inspect all open and closed positions
- Position Management
- Get detailed info on individual holdings
- Liquidate all or partial positions by share count or percentage
- Order Management
- Place stock and option orders (market or limit)
- Cancel orders individually or in bulk
- Retrieve full order history
- Options Trading
- Search and view option contracts by expiration or strike price
- Place multi-leg options strategies
- Get latest quotes and Greeks for contracts
- Market Status & Corporate Actions
- Check if markets are open
- Fetch market calendar and trading sessions
- View upcoming corporate announcements (earnings, splits, dividends)
- Watchlist Management
- Create, update, and view personal watchlists
- Manage multiple watchlists for tracking assets
- Asset Search
- Query details for stocks and other Alpaca-supported assets
Prerequisites
- Python 3.10+
- Alpaca API keys (with paper or live trading access)
- Claude for Desktop or another compatible MCP client
Installation
-
Clone the repository and move to the repository:
git clone https://github.com/YOUR_USERNAME/alpaca-mcp-server.git cd alpaca-mcp-server -
Install the required packages:
pip install mcp alpaca-py python-dotenv
Usage (for Paper Trading) with Claude Desktop
Edit a .env file for your credentials in the project directory
ALPACA_API_KEY = "your_alpaca_api_key_for_paper_account"
ALPACA_SECRET_KEY = "your_alpaca_secret_key_for_paper_account"
Start the MCP Server
Open a terminal and run the command below from the project directory:
python alpaca_mcp_server.py
Or use a module invocation:
python -m alpaca_mcp_server
Claude for Desktop Configuration
- Open Claude Desktop
- Navigate to:
Settings → Developer → Edit Config - Update your
claude_desktop_config.json:
{
"mcpServers": {
"alpaca": {
"command": "python",
"args": [
"/path/to/alpaca_mcp_server.py"
],
"env": {
"ALPACA_API_KEY": "your_alpaca_api_key_for_paper_account",
"ALPACA_SECRET_KEY": "your_alpaca_secret_key_for_paper_account"
}
}
}
}
API Key Configuration for Live Trading
This MCP server connects to Alpaca's paper trading API by default for safe testing. To enable live trading with real funds, update the following configuration files:
🔐 Set Your API Credentials in Two Places:
-
Claude for Desktop Configuration
In
claude_desktop_config.json, provide your keys for your live account as environment variables:{ "mcpServers": { "alpaca": { "command": "python", "args": [ "/path/to/alpaca_mcp_server.py" ], "env": { "ALPACA_API_KEY": "your_alpaca_api_key_for_live_account", "ALPACA_SECRET_KEY": "your_alpaca_secret_key_for_live_account" } } } } -
.envin the project directoryALPACA_API_KEY = "your_alpaca_api_key_for_live_account" ALPACA_SECRET_KEY = "your_alpaca_secret_key_for_live_account" PAPER = False
Available Tools
Account & Positions
get_account_info()– View balance, margin, and account statusget_positions()– List all held assetsget_open_position(symbol)– Detailed info on a specific positionclose_position(symbol, qty|percentage)– Close part or all of a positionclose_all_positions(cancel_orders)– Liquidate entire portfolio
Stock Market Data
get_stock_quote(symbol)– Real-time bid/ask quoteget_stock_bars(symbol, start_date, end_date)– OHLCV historical barsget_stock_latest_trade(symbol)– Latest market trade priceget_stock_latest_bar(symbol)– Most recent OHLC barget_stock_trades(symbol, start_time, end_time)– Trade-level history
Orders
get_orders(status, limit)– Retrieve all or filtered ordersplace_stock_order(symbol, side, quantity, order_type="market", limit_price=None, stop_price=None, trail_price=None, trail_percent=None, time_in_force="day", extended_hours=False, client_order_id=None)– Place a stock order of any type (market, limit, stop, stop_limit, trailing_stop)cancel_order_by_id(order_id)– Cancel a specific ordercancel_all_orders()– Cancel all open orders
Options
get_option_contracts(underlying_symbol, expiration_date)– Fetch contractsget_option_latest_quote(option_symbol)– Latest bid/ask on contractget_option_snapshot(symbol_or_symbols)– Get Greeks and underlyingplace_option_market_order(legs, order_class, quantity)– Execute option strategy
Market Info & Corporate Actions
get_market_clock()– Market open/close scheduleget_market_calendar(start, end)– Holidays and trading daysget_corporate_announcements(...)– Earnings, dividends, splits
Watchlists
create_watchlist(name, symbols)– Create a new listupdate_watchlist(id, name, symbols)– Modify an existing listget_watchlists()– Retrieve all saved watchlists
Assets
get_asset_info(symbol)– Search asset metadataget_all_assets(status)– List all tradable instruments
Example Natural Language Queries
See the "Example Queries" section below for 50 real examples covering everything from trading to corporate data to option strategies.
Basic Trading
- What's my current account balance and buying power?
- Show me my current positions.
- Buy 10 shares of AAPL at market price.
- Sell 5 shares of TSLA with a limit price of $300.
- Cancel all open stock orders.
- Cancel the order with ID abc123.
- Liquidate my entire position in GOOGL.
- Close 10% of my position in NVDA.
- How many shares of AMZN do I currently hold?
- Place a limit order to buy 100 shares of MSFT at $450.
- Place a market order to sell 25 shares of META.
Option Trading
- Show me available option contracts for AAPL expiring next month.
- Get the latest quote for AAPL250613C00200000.
- Retrieve the option snapshot for SPY250627P00400000.
- Liquidate my position in 2 contracts of QQQ calls expiring next week.
- Place a market order to buy 1 call option on AAPL expiring next Friday.
- What are the option Greeks for TSLA250620P00500000?
- Find all TSLA option contracts with strike prices within 5% of the current market price.
- Get all contracts for SPY expiring in June that are call options.
- Place a bull call spread using AAPL June 6th options: one with a 190.00 strike and the other with a 200.00 strike.
Market Information
- Is the US stock market currently open?
- What are the market open and close times today?
- Show me the market calendar for next week.
- Are there any corporate announcements for major tech stocks this month?
- What are the next dividend announcements for SPY?
- List earnings announcements coming tomorrow.
Historical & Real-time Data
- Show me AAPL's daily price history for the last 5 trading days.
- What was the closing price of TSLA yesterday?
- Get the latest bar for GOOG.
- What was the latest trade price for NVDA?
- Show me the most recent quote for MSFT.
- Retrieve the last 100 trades for AMD.
- Show me intraday bars for AMZN from last Tuesday through last Friday.
Orders
- Show me all my open and filled orders from this week.
- What orders do I have for AAPL?
- List all limit orders I placed in the past 3 days.
- Filter all orders by status: filled.
- Get me the order history for yesterday.
Watchlists
- Create a new watchlist called "Tech Stocks" with AAPL, MSFT, and NVDA.
- Update my "Tech Stocks" watchlist to include TSLA and AMZN.
- What stocks are in my "Dividend Picks" watchlist?
- Remove META from my "Growth Portfolio" watchlist.
- List all my existing watchlists.
Asset Information
- Search for details about the asset 'AAPL'.
- List all tradeable US Large-cap stocks.
- Show me the top 5 tradable crypto assets by trading volume.
- Filter all assets with status 'active'.
- Show me details for the stock with symbol 'GOOGL'.
Combined Scenarios
- Get today's market clock and show me my buying power before placing a limit buy order for TSLA at $340.
- Place a bull call spread with SPY July 3rd options: buy one 5% above and sell one 3% below the current SPY price.
Example Outputs
The MCP server provides detailed, well-formatted responses for various trading queries. Here are some examples:
Option Greeks Analysis
Query: "What are the option Greeks for TSLA250620P00500000?"
Response: Option Details:
- Current Bid/Ask: $142.62 / $143.89
- Last Trade: $138.85
- Implied Volatility: 92.54%
Greeks:
- Delta: -0.8968 (Very Bearish)
- Gamma: 0.0021 (Low Rate of Change)
- Theta: -0.2658 (Time Decay: $26.58/day)
- Vega: 0.1654 (Volatility Sensitivity)
- Rho: -0.3060 (Interest Rate Sensitivity)
Key Insights:
- High Implied Volatility (92.54%)
- Deep In-the-Money (Delta: -0.90)
- Significant Time Decay ($27/day)
Multi-Leg Option Order
Query: "Place a bull call spread using AAPL June 6th options: one with a 190.00 strike and the other with a 200.00 strike."
Response: Order Details:
- Order ID: fc1c04b1-8afa-4b2d-aab1-49613bbed7cb
- Order Class: Multi-Leg (MLEG)
- Status: Pending New
- Quantity: 1 spread
Spread Legs:
-
Long Leg (BUY):
- AAPL250606C00190000 ($190.00 strike)
- Status: Pending New
-
Short Leg (SELL):
- AAPL250606C00200000 ($200.00 strike)
- Status: Pending New
Strategy Summary:
- Max Profit: $10.00 per spread
- Max Loss: Net debit paid
- Breakeven: $190 + net debit paid
These examples demonstrate the server's ability to provide:
- Detailed market data analysis
- Comprehensive order execution details
- Clear strategy explanations
- Well-formatted, easy-to-read responses
The server maintains this level of detail and formatting across all supported queries, making it easy to understand and act on the information provided.
⚠️ Security Notice
This server can place real trades and access your portfolio. Treat your API keys as sensitive credentials. Review all actions proposed by the LLM carefully, especially for complex options strategies or multi-leg trades.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。