alpaca-mcp-server

MCP.Pizza Chef: tedlikeskix

The alpaca-mcp-server is a Model Context Protocol server that integrates the Alpaca trading API with LLMs like Claude, enabling natural language interaction for stock trading. It provides real-time market data, account information, position management, and order placement and tracking, allowing users to manage their trading activities through conversational AI interfaces securely and efficiently.

Use This MCP server To

Fetch real-time stock quotes and historical price data Check account balances and buying power via natural language View and analyze current stock positions and performance Place market and limit orders using conversational commands List, track, and cancel active trading orders through LLMs

README

Alpaca MCP Server

This is a Model Context Protocol (MCP) server for Alpaca, allowing LLMs like Claude to interact with the Alpaca trading API. It enables trading stocks, checking positions, fetching market data, and managing your account - all through natural language.

Features

  • πŸ“Š Market Data - Get real-time stock quotes and historical price data
  • πŸ’΅ Account Information - Check your balances, buying power, and status
  • πŸ“ˆ Position Management - View current positions and their performance
  • πŸ›’ Order Placement - Place market and limit orders through natural language
  • πŸ“‹ Order Management - List, track, and cancel orders

Prerequisites

  • Python 3.10+
  • Alpaca API keys
  • Claude for Desktop or another MCP client

Installation

  1. Clone this repository:

    git clone https://github.com/YOUR_USERNAME/alpaca-mcp.git
    cd alpaca-mcp
  2. Install the required packages:

    pip install mcp alpaca-py python-dotenv
  3. Create a .env file with your Alpaca API credentials:

    API_KEY_ID=your_alpaca_api_key
    API_SECRET_KEY=your_alpaca_secret_key
    

Usage

Running the server

Start the server by running:

python alpaca_mcp_server.py

Configuring Claude for Desktop

  1. Open Claude for Desktop
  2. Go to Settings
  3. Click on "Developer" and then "Edit Config"
  4. Add the server configuration to claude_desktop_config.json:
{
  "mcpServers": {
    "alpaca": {
      "command": "python",
      "args": [
        "/path/to/alpaca_mcp_server.py"
      ],
      "env": {
        "API_KEY_ID": "your_alpaca_api_key",
        "API_SECRET_KEY": "your_alpaca_secret_key"
      }
    }
  }
}
  1. Save and restart Claude for Desktop

Available Tools

The server exposes the following tools:

  • get_account_info() - Get account balances and status
  • get_positions() - List all current positions in the portfolio
  • get_stock_quote(symbol) - Get the latest quote for a stock
  • get_stock_bars(symbol, days) - Get historical price bars for a stock
  • get_orders(status, limit) - List orders with specified status
  • place_market_order(symbol, side, quantity) - Place a market order
  • place_limit_order(symbol, side, quantity, limit_price) - Place a limit order
  • cancel_all_orders() - Cancel all open orders
  • close_all_positions(cancel_orders) - Close all open positions

Example Queries

Once the server is connected to Claude, you can ask questions like:

  • "What's my current account balance and buying power?"
  • "Show me my current positions"
  • "Get the latest quote for AAPL"
  • "Show me the price history for TSLA over the last 10 days"
  • "Buy 5 shares of MSFT at market price"
  • "Sell 10 shares of AMZN with a limit price of $130"
  • "Cancel all my open orders"

Note

This server uses Alpaca's paper trading by default. To use real money trading, change paper=True to paper=False in the TradingClient initialization.

Security Notice

This MCP server will have access to your Alpaca account and can place real trades. Always review what Claude is suggesting before approving any trades.

License

MIT

alpaca-mcp-server FAQ

How do I set up the alpaca-mcp-server?
Clone the repository, install dependencies with pip, and configure your Alpaca API keys in environment variables before running the server.
Which programming language is required to run this MCP server?
Python 3.10 or higher is required to run the alpaca-mcp-server.
Can I use this MCP server with LLMs other than Claude?
Yes, it supports any MCP-compatible client, including those using OpenAI, Claude, and Gemini models.
What trading functionalities does this MCP server support?
It supports fetching market data, checking account info, managing positions, placing orders, and order management.
Is real-time market data available through this server?
Yes, it provides real-time stock quotes and historical price data for informed trading decisions.
How secure is the alpaca-mcp-server when handling API keys?
API keys are managed via environment variables and should be kept secure; the server follows MCP principles for scoped and secure interactions.
Can I cancel orders using natural language commands?
Yes, the server allows listing, tracking, and canceling orders through conversational commands.
What are the prerequisites for running this MCP server?
You need Python 3.10+, Alpaca API keys, and an MCP client like Claude for Desktop.