Skip to main content
Glama

Was ist das?

alpaka-mcp ist ein produktionsreifer MCP-Server + CLI, der KI-Assistenten (Claude Desktop, Cursor, VS Code Copilot) und Ihr Terminal direkt mit der Alpaca Trading API verbindet. Handeln Sie Aktien, ETFs und Krypto mit natürlicher Sprache – oder über die Befehlszeile.

Basiert auf alpaca-py und dem MCP Python SDK.

Standardmäßig Paper-Trading – echte Marktdaten, simulierte Gelder, kein echtes Geld auf dem Spiel.


Related MCP server: alpaca-mcp-server

Schnellstart

1. Alpaca-API-Schlüssel erhalten (kostenlos)

Registrieren Sie sich bei alpaca.markets → Paper Trading → API Keys

2. Installieren

git clone https://github.com/vikrambtech2025-png/alpaka-mcp.git
cd alpaka-mcp
uv sync

3. Konfigurieren

cp .env.example .env
# Add your API keys to .env

4. Ausführen

uv run alpaka-mcp          # MCP server (stdio for Claude/Cursor)
uv run alpaka account      # CLI — check account
uv run mcp dev src/alpaka_mcp/server.py  # MCP Inspector

Verbindung zu KI-Assistenten

Hinzufügen zu %AppData%\Claude\claude_desktop_config.json:

{
  "mcpServers": {
    "alpaka": {
      "command": "uv",
      "args": ["--directory", "C:\\path\\to\\alpaka-mcp", "run", "alpaka-mcp"],
      "env": {
        "ALPACA_API_KEY": "your_key",
        "ALPACA_SECRET_KEY": "your_secret",
        "ALPACA_PAPER": "true"
      }
    }
  }
}

Hinzufügen zu .cursor/mcp.json im Projektstamm:

{
  "mcpServers": {
    "alpaka": {
      "command": "uv",
      "args": ["--directory", "/path/to/alpaka-mcp", "run", "alpaka-mcp"],
      "env": {
        "ALPACA_API_KEY": "your_key",
        "ALPACA_SECRET_KEY": "your_secret",
        "ALPACA_PAPER": "true"
      }
    }
  }
}

Hinzufügen zu .vscode/mcp.json:

{
  "servers": {
    "alpaka": {
      "command": "uv",
      "args": ["--directory", "/path/to/alpaka-mcp", "run", "alpaka-mcp"],
      "env": {
        "ALPACA_API_KEY": "your_key",
        "ALPACA_SECRET_KEY": "your_secret",
        "ALPACA_PAPER": "true"
      }
    }
  }
}

MCP-Tools (16)

Tool

Beschreibung

get_account

Saldo, Eigenkapital, Kaufkraft, Day-Trades

get_portfolio

Alle offenen Positionen mit Gewinn/Verlust

Tool

Beschreibung

buy

Kaufauftrag platzieren (Market/Limit/Stop/Stop-Limit)

sell

Verkaufsauftrag platzieren (Market/Limit)

get_orders

Aufträge nach Status und Symbolen auflisten

cancel_order

Einen bestimmten Auftrag stornieren

cancel_all_orders

Alle offenen Aufträge stornieren

Tool

Beschreibung

get_position

Details einer einzelnen Position

close_position

Liquidieren (vollständig oder teilweise)

Tool

Beschreibung

get_stock_quote

Aktueller Geld-/Briefkurs

get_stock_bars

Historische OHLCV-Balken

get_stock_snapshot

Vollständiger Schnappschuss (Handel, Kurs, täglich, 1-Minute)

Tool

Beschreibung

get_crypto_quote

Aktueller Krypto-Geld-/Briefkurs

get_crypto_bars

Historische Krypto-OHLCV-Balken

Tool

Beschreibung

search_assets

Aktien/ETFs/Krypto nach Name oder Symbol suchen

get_market_clock

Status der Marktöffnung/-schließung


CLI-Befehle (12)

alpaka account                    # Account balance & buying power
alpaka portfolio                  # Open positions with color-coded P&L
alpaka quote AAPL                 # Bid/ask quote (stocks or crypto)
alpaka buy AAPL --qty 10          # Buy 10 shares
alpaka buy BTC/USD -n 500         # Buy $500 of Bitcoin
alpaka sell AAPL --qty 5          # Sell 5 shares
alpaka orders                     # List open orders
alpaka orders --status closed     # List filled orders
alpaka cancel <order-id>          # Cancel specific order
alpaka cancel-all                 # Cancel everything open
alpaka bars AAPL --tf 1Day        # Historical bars
alpaka clock                      # Is the market open?
alpaka search apple               # Find tradeable assets

Alle Befehle unterstützen --json für maschinenlesbare Ausgabe:

$ uv run alpaka account --json
{
  "status": "ACTIVE",
  "equity": "100000.00",
  "buying_power": "200000.00",
  "cash": "100000.00",
  "portfolio_value": "100000.00",
  "daytrade_count": 0,
  "pattern_day_trader": false,
  "mode": "paper"
}

Produktionsfunktionen

Funktion

Funktionsweise

Robuster Client

Transparenter Proxy umhüllt jeden API-Aufruf mit Ratenbegrenzung + Wiederholung

Ratenbegrenzung

3 unabhängige Token-Buckets (je 200 Anfragen/Minute) – Handel, Aktiendaten, Krypto

Wiederholung + Backoff

3 Versuche mit exponentiellem Backoff von 1s/2s/4s bei 429, 500, Verbindungsfehlern

Nicht blockierendes Async

MCP-Tools verwenden asyncio.to_thread() – die Ereignisschleife blockiert nie

Strukturierte Protokollierung

JSON-Prüfpfad: logs/trades.jsonl + logs/errors.jsonl

Eingabevalidierung

Symbole, Mengen, Preise, Auftragstypen werden vor API-Aufrufen validiert

Live-Handels-Schutz

Erfordert ALPACA_LIVE_CONFIRM=true + 5-Sekunden-Countdown für echtes Geld

Konfigurationsvalidierung

Lehnt Platzhalter-API-Schlüssel mit klaren Einrichtungsanweisungen ab

Thread-Sicherheit

lru_cache-Client-Initialisierung, kein veränderlicher globaler Zustand

CLI-Fehlerbehandlung

Jeder Befehl umhüllt – saubere Fehler, keine Tracebacks


Architektur

src/alpaka_mcp/
├── server.py          # MCP server entry point (stdio)
├── cli.py             # 12 Typer commands + JSON output
├── config.py          # pydantic-settings + credential validation
├── clients.py         # ResilientClient proxy (rate limit + retry + async)
├── utils.py           # Response formatting
├── logging.py         # Structured JSON logging
├── rate_limiter.py    # Token bucket rate limiters (sync + async)
├── retry.py           # Exponential backoff (sync + async)
├── validation.py      # Input validation
└── tools/             # 16 MCP tools
    ├── account.py     # get_account, get_portfolio
    ├── trading.py     # buy, sell, get_orders, cancel_order, cancel_all
    ├── positions.py   # get_position, close_position
    ├── stock_data.py  # get_stock_quote, get_stock_bars, get_stock_snapshot
    ├── crypto_data.py # get_crypto_quote, get_crypto_bars
    └── discovery.py   # search_assets, get_market_clock

Docker

# MCP server
docker compose up alpaka-mcp

# CLI via docker
docker compose run --rm alpaka-cli account
docker compose run --rm alpaka-cli portfolio

Protokolle werden in einem Docker-Volume unter /app/logs gespeichert.


Umgebungsvariablen

Variable

Standard

Beschreibung

ALPACA_API_KEY

(erforderlich)

Ihr Alpaca-API-Schlüssel

ALPACA_SECRET_KEY

(erforderlich)

Ihr Alpaca-Geheimschlüssel

ALPACA_PAPER

true

Paper-Trading-Modus

ALPACA_LIVE_CONFIRM

false

Muss für Live-Handel true sein

ALPACA_LOG_DIR

logs

Protokolldatei-Verzeichnis

ALPACA_LOG_LEVEL

INFO

Protokollierungsgrad


Testen

# Unit tests (no API keys needed)
uv run pytest tests/ --ignore=tests/test_integration.py -v

# Integration tests (needs real paper API keys)
ALPACA_API_KEY=pk_xxx ALPACA_SECRET_KEY=sk_xxx uv run pytest tests/test_integration.py -v

Sicherheit

  • Paper-Trading standardmäßig – echtes Geld erfordert ausdrückliche Zustimmung

  • Live-Handel erfordert sowohl ALPACA_PAPER=false als auch ALPACA_LIVE_CONFIRM=true

  • 5-Sekunden-Countdown beim Start des Live-Handels

  • Alle Fehler sauber formatiert – keine Tracebacks an LLMs gesendet

  • Ratenbegrenzung verhindert versehentlichen API-Missbrauch

  • Strukturierter Prüfpfad für jeden Handel


Lizenz

MIT


Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      D
      quality
      D
      maintenance
      MCP server that exposes Alpaca Market Data & Broker API as tools, enabling access to financial data like stock bars, assets, market days, and news through the Message Control Protocol.
      4
      2
      ISC
    • A
      license
      B
      quality
      B
      maintenance
      Alpaca’s official MCP Server lets you trade stocks, ETFs, crypto, and options, run data analysis, and build strategies in plain English directly from your favorite LLM tools and IDEs
      72
      12,182 PyPI
      1,104
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server implementation for Alpaca's Trading API that enables LLMs to interact with Alpaca's trading infrastructure using natural language, supporting stock, options, and crypto trading, portfolio management, watchlists, and market data.
      4
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      This MCP server connects AI assistants to a Public.com brokerage account, enabling natural language trading of stocks, options, and crypto, along with portfolio management, quotes, and orders.
      46
      914 PyPI
      67
      Apache 2.0