Get the FREE Ultimate OpenClaw Setup Guide →

alpaca

A Model Context Protocol (MCP) server implementation for Alpaca trading that enables Large Language Models (LLMs) like Anthropic Claude to interact with Alpaca's trading API. The instructions and commands provided in this README are primarily for MacOS/Linux users.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio mardiantos-alpaca-mcp-server uv --directory /ABSOLUTE/PATH/TO/PARENT/FOLDER/alpaca-mcp-server run alpaca_mcp_server.py

How to use

The Alpaca MCP Server exposes Alpaca's trading capabilities through the Model Context Protocol, allowing LLMs to interact with Alpaca's API for account data, market data, and trading actions. This Python-based MCP server supports common MCP resources such as account information, portfolio positions, market quotes and historical bars, and trading operations like placing market or limit orders, canceling orders, and retrieving a portfolio summary. To use it, configure the MCP client (e.g., Claude for Desktop) to point at the server by providing the uv command path and the server directory, as demonstrated in the included config snippet. Once the MCP server is running, you can query resources like account://info or market://quote/{symbol}, and invoke tools such as place_market_order or place_limit_order to execute trades (in paper trading by default).

To test with Claude for Desktop, ensure the server is reachable byClaude’s MCP config and that your Alpaca credentials are supplied via environment variables. Common workflows include checking your Alpaca portfolio balance, placing a buy/sell order, or canceling an order. The server includes safety features such as paper trading by default and robust error handling to help prevent unintended trades during testing.

How to install

Prerequisites:

  • Python installed (recommended 3.8+)
  • uv (Python project manager) installed per the Pre-requisites below
  • Git installed
  • An Alpaca account with API credentials (API key and secret)

Installation steps:

  1. Clone the repository git clone https://github.com/MardiantoS/alpaca-mcp-server.git cd alpaca-mcp-server

  2. Install uv (Python project manager) per the Pre-requisites in the README: curl -LsSf https://astral.sh/uv/install.sh | sh

  3. Create and activate a Python virtual environment (optional but recommended): uv venv source .venv/bin/activate

  4. Install dependencies using uv (it reads uv.lock): uv sync

  5. Create a .env file in the project root with Alpaca credentials: ALPACA_API_KEY=your_api_key ALPACA_API_SECRET=your_api_secret ALPACA_PAPER=TRUE

  6. Run the MCP server via uv from the parent directory (the command used in MCP config): uv --directory /ABSOLUTE/PATH/TO/PARENT/FOLDER/alpaca-mcp-server run alpaca_mcp_server.py

Note:

  • Replace the absolute paths with actual paths on your machine.
  • Ensure your environment variables are set (either in .env or your shell) before starting the server.

Additional notes

Tips and caveats:

  • The MCP server is designed around a Python implementation. Use uv to manage the project and run the server with the appropriate directory pointing to the alpaca-mcp-server folder.
  • By default, the server uses paper trading (ALPACA_PAPER=TRUE). Change this to live trading only after thorough testing.
  • Ensure your environment variables (ALPACA_API_KEY, ALPACA_API_SECRET) are kept secure and not committed to version control.
  • If you encounter issues connecting from Claude for Desktop, verify that the absolute path references in the Claude MCP config are correct and that the server process is reachable on the same environment where Claude runs.
  • Real-time market data availability may depend on your Alpaca account type and subscription level.

Related MCP Servers

Sponsor this space

Reach thousands of developers