This blog was last updated on June 4, 2026.

With the rise of large language models (LLMs) you can now use AI-assisted workflows to help analyze markets and submit trading instructions. Model Context Protocol (MCP) gives those agents one standard way to reach services. By following this guide you will connect Claude Desktop with Alpaca's Trading API and Google Sheets to build a reliable trading workflow.

This guide uses Alpaca’s MCP Server V2, a complete rewrite built with FastMCP and OpenAPI. If you previously configured V1 (cloned the repository, created a .env file, ran an init command), those steps no longer apply. See the updated GitHub for details.

What This Guide Covers

This guide shows you how to use Alpaca’s MCP server with Alpaca's Trading API to fetch stock market data, analyze trends, and generate trade recommendations. Specifically, you will learn:

  • How MCP works and why it is useful for trading workflows
  • How to set up Claude Desktop with Alpaca's MCP Server and the Google Workspace CLI for Google Sheets access
  • How to write prompts on Claude to automate stock market analysis, place trading orders, and log trading records in a spreadsheet

The aim is to understand the potential MCP has to simplify building automated or AI-assisted trading strategies, enabling smoother interactions between LLMs and your trading activities.

What Is an MCP Server? Understanding Model Context Protocol for AI Trading

MCP is a protocol that lets LLMs (like Claude or ChatGPT) connect to different applications and services, including databases, trading platforms, and tools like Slack or GitHub. The benefit of MCP is that it uses one standard interface, which avoids the need to build separate custom integrations for each tool.

MCP works like a translator between AI and applications. When you ask the AI to do something, such as get market data, place a trade, or update a spreadsheet, MCP helps it understand how to communicate with each service so it can follow through on your request without you needing to write any code.

To build an MCP environment, three key components are required:

  1. Host (MCP Client): This is the interface where a user interacts with AI, like Claude Desktop or Cursor. When a prompt is entered (for example, "Get latest quote for AAPL"), the MCP client processes the request and sends it to the MCP server.
  2. MCP Server: Acting as middleware, the MCP server receives requests from the client. It exposes tools that the AI can discover and invoke. For Alpaca's MCP Server, these tools map directly to Alpaca's Trading API endpoints, such as get_stock_latest_quote, place_stock_order, and get_all_positions. In total, Alpaca’s MCP Server supports 61 actions. 
  3. Target Systems: These are the data sources or services the AI interacts with, such as trading APIs (Alpaca's Trading API), file systems (Google Sheets), or web services (GitHub, Slack). The MCP server acts as the translation layer between the AI and these systems.

Why MCP Matters for Traders Right Now

Trading involves repetitive tasks. You used to write code to automate your trading workflow. Now you can ask an AI agent to do the job without building and maintaining that system yourself. MCP provides one integration gateway so your AI agent can access all your data sources and services through a single client.

Advantages of MCP for Traders

Natural Language Processing (NLP): You can trade using plain English. With MCP, you tell your assistant what you want, such as "Buy 10 shares of TSLA and log it on Google Sheets," and it handles everything from execution to recording.This can reduce the amount of custom code required. 

Extensible Workflows with AI Agents: MCP lets you connect multiple services to handle multi-step processes: scanning the market, applying models, placing trades, and updating logs, all in one flow. It is straightforward to expand or adjust the setup without rebuilding from scratch.

Automatic API Compatibility: When using the official Alpaca MCP Server, your workflow stays compatible even after API changes. V2 is built directly from Alpaca's OpenAPI specifications, so updates to the API surface are reflected in the server. Update the server version and no client-side changes are needed.

Traceable Decisions: MCP logs which model and settings led to each trade, giving you a clean, auditable record. You can always look back and understand exactly how a decision was made.

Use Case: Live Trading and Logging with Claude AI, Alpaca's Trading API, and Google Sheets via Google CLI

Now that you understand MCP and its potential, let’s set up a workflow that traders often do manually: analyzing the market, placing a trade, and logging the position in a spreadsheet.

Below is a demo showing how Claude Desktop can execute a full workflow: analyzing the market, placing a trade on Alpaca's Trading API via MCP, and logging the position (including price, profit target, stop loss, and timestamp) in Google Sheets via the Google Workspace CLI.

If you would like to try it yourself, follow the steps below.

Note:

  • This procedure is based on macOS. Windows or Linux users may need to adjust some steps.
  • TSLA is used as an example and should not be considered investment advice.

Workflow Overview

Set up a trading workflow using Claude Desktop as your MCP client. The objective is to:

  • Analyze the market via Alpaca's MCP Server
  • Place an order via Alpaca's MCP Server
  • Record positions in Google Sheets (with trade price, profit target, stop loss, and timestamps)

Environment Setup

You need the following accounts and tools:

Tools you will configure:

  • Alpaca's MCP Server (alpacahq/alpaca-mcp-server) — configured in Claude Desktop's claude_desktop_config.json
  • Google Workspace CLI (googleworkspace/cli) — installed locally and used by Claude Code (in the Code tab) to read/write Google Sheets

Google Workspace CLI Setup

To enable Claude to interact with Google Sheets for creating, reading, and editing spreadsheets, you will use the Google Workspace CLI (gws). This open-source CLI covers Drive, Docs, Sheets, Gmail, Calendar, and more. Claude Code (available in the Code tab of Claude Desktop) can run gws commands directly to read, write, and append data to your spreadsheets.

Note: The Google Workspace CLI is not an officially supported Google product. It is under active development (pre-v1.0), so expect possible changes. See the repository for the latest instructions.

Claude Desktop includes a Code tab that gives you Claude Code functionality directly inside the app. Open the Code tab and type a prompt like:

I want to access a Google Spreadsheet using https://github.com/googleworkspace/cli. Can you help me set it up?

Option B: Manual Setup

If you prefer to set up manually:

Install the Google Workspace CLI:

# Via npm
npm install -g @googleworkspace/cli

# Via Homebrew (macOS/Linux)
brew install googleworkspace-cli

Authenticate:

If you have gcloud installed (easiest path):

gws auth setup

If you do not have gcloud, set up manually:

  1. Go to Google Cloud Console > APIs & Services > OAuth consent screen. Set to "External" and add your Google account as a test user.
  2. Create a Desktop app OAuth credential. Download the JSON file and save it to ~/.config/gws/client_secret.json.
  3. Enable the Google Sheets API in your GCP project.
  4. Run gws auth login.

Verify it works:

gws sheets spreadsheets values get \
  --params '{"spreadsheetId": "YOUR_SHEET_ID", "range": "Sheet1!A1:C10"}'

Your spreadsheet ID is the long string in the Google Sheets URL: docs.google.com/spreadsheets/d/SPREADSHEET_ID/edit.

Once gws is installed and authenticated, Claude Code can use it to interact with Google Sheets as part of the trading workflow described in this guide.

Alpaca's Trading API MCP Server Setup

V2 of Alpaca's MCP Server does not require cloning a repository, creating a virtual environment, or managing a .env file. You install it with uvx and configure credentials directly in Claude Desktop's config file.

1. Install uv if you have not already:

curl -LsSf https://astral.sh/uv/install.sh | sh

Restart your terminal so uv/uvx are on your PATH.

2. Edit your Claude Desktop app configuration file.

On macOS, open:

~/Library/Application Support/Claude/claude_desktop_config.json

On Windows, open:

%APPDATA%\Claude\claude_desktop_config.json

3. Add Alpaca's MCP Server to the mcpServers section:

{
  "mcpServers": {
    "alpaca": {
      "command": "uvx",
      "args": ["alpaca-mcp-server"],
      "env": {
        "ALPACA_API_KEY": "your_alpaca_api_key",
        "ALPACA_SECRET_KEY": "your_alpaca_secret_key"
      }
    }
  }
}

4. Replace your_alpaca_api_key and your_alpaca_secret_key with your actual credentials from the Alpaca Dashboard.

5. Restart Claude Desktop. The Alpaca MCP Server should appear as connected. Paper trading is the default. The MCP Server runs with ALPACA_PAPER_TRADE=true by default. To switch to live trading, add "ALPACA_PAPER_TRADE": "false" to the env block and use your live API credentials. Alpaca's paper trading account is a great way to get started.

Optional: Restrict Available Tools with Toolset Filtering

By default, V2 exposes 61 tools. To limit which capabilities Claude can access, use the ALPACA_TOOLSETS environment variable:

{
  "env": {
    "ALPACA_API_KEY": "your_alpaca_api_key",
    "ALPACA_SECRET_KEY": "your_alpaca_secret_key",
    "ALPACA_TOOLSETS": "account,trading,stock-data"
  }
}

Available toolsets: account, trading, watchlists, assets, stock-data, crypto-data, options-data, corporate-actions, news. See the full toolset reference for descriptions.

This directly addresses the access control risk described in the Risks section below. Use it to enforce least-privilege access.

Managing and Troubleshooting Your Configuration

Updating Your API Key and Secret Key

If you need to rotate or replace your Alpaca credentials (for example, after regenerating keys on the Dashboard), update the claude_desktop_config.json file directly:

  1. Open the configuration file (~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows).
  2. Replace the values for ALPACA_API_KEY and ALPACA_SECRET_KEY with your new credentials.
  3. Save the file and restart Claude Desktop for the changes to take effect.

You can generate new API keys at any time from the Alpaca Dashboard under API Keys. If you are switching between paper and live trading, make sure to use the corresponding API key pair for each environment.

Resolving Duplicate MCP Server Configurations

If you previously set up V1 of Alpaca's MCP Server at the project level, it may conflict with the V2 configuration you just added at the global (user) level. Claude Desktop checks both levels, and having Alpaca's MCP Server defined in both can cause unexpected behavior such as connection failures or the older version taking precedence.

To check for duplicates, open your global configuration file:

/Users/<your_username>/.claude.json

Look for multiple entries of Alpaca's MCP Server. If a project-level configuration exists alongside the global one, remove the project-level entry so that the V2 server is the only active configuration. This also ensures you can access the MCP Server from any working directory or project without per-project setup.

Example Prompts on Claude Desktop with MCP Integration

After you set up the required environments, you can experience the integration through MCP. When making requests via Alpaca's Trading API, it is important to understand which parameters need to be included. Alpaca provides detailed guidance in the alpaca-py Documentation where you can find examples and explanations for constructing API requests effectively.

Note: TSLA is used as an example and should not be considered investment advice.

Prompt Overview

In the prompt for Claude Desktop, you cover three main requests:

  • Market Analysis: Claude Desktop extracts market data through Alpaca's Trading API via the MCP Server. Example: "Analyze current market conditions for TSLA."
  • Executing Trades: Claude Desktop places an order through Alpaca's Trading API via the MCP Server. Example: "Buy 10 shares of TSLA at a limit price of XXX."
  • Recording Positions: Claude Desktop records trade details to Google Sheets. Example: "Record this TSLA trade in my spreadsheet with entry price of $198, profit target of $210, stop loss at $190, and profit-loss ratio of 3.00."

First Prompt Example

Using Alpaca’s Trading API, please do the following:

“Extract historical market data for TSLA over the past 90 days using daily bar charts.”
“Calculate only the most recent Bollinger Bands based on that 90-day historical data.”

Second Prompt Example

  1. Place a limit order to buy 1 share of TSLA at a price equal to 97% of the current market price.
    limit_price = 0.97 × current_price
  2. Create a new sheet titled "Sheet1" in a Google Spreadsheet named "test1".
  3. Log the following trade details into the spreadsheet:
  • Asset Name: TSLA
  • Quantity: 1
  • Asset Class: Stock
  • Limit Price to Trade: 0.97 × current_price
  • Risk/Reward Ratio: 3.00
  • Stop Loss Percentage: 0.08 (8%)
  • Stop Loss Price: limit_price − (limit_price × 0.08)
  • Profit Target Percentage: 3.00 × 0.08 = 0.24 (24%)
  • Profit Target Price: limit_price × 1.24

Note: current_price should be fetched dynamically from market data. All related values (stop loss, profit target) should be calculated using this value.

Instruction: Please include column names in the first row of the spreadsheet and insert the calculated values in the row below. If you find any additional relevant information for this trade (e.g., timestamp, market signal), include those as extra columns.

Here is an example of Claude Code executing the prompt above, placing a limit order through Alpaca’s Trading API via the MCP Server and logging the trade details into a Google Spreadsheet via Google Workspace CLI in a single workflow:

The Risks and Vulnerabilities of MCP

While MCP offers useful possibilities for trading workflows and integrations, potential risks and vulnerabilities exist. It is prudent to consider these before adopting any new technology. Addressing each proactively can help traders use automated workflows more reliably.

Permission and Access Control: Use least-privilege credentials for data write operations so each action is scoped and auditable. With the Google Workspace CLI, you can limit OAuth scopes during authentication (for example, gws auth login -s drive,sheets) to restrict which Google services the AI can access. With Alpaca's MCP Server V2, you can use the ALPACA_TOOLSETS environment variable to restrict the server to only the tool categories your workflow requires (for example, account,trading,stock-data). This prevents the AI from accessing capabilities you have not explicitly enabled.

Rate Limiting and Cost Control: Enforce per-endpoint rate limits, quotas, and short-term caching to protect APIs and manage costs.

Data Quality and Consistency: Validate every required field, such as symbol, quantity (and limit price for limit orders), and buy/sell side, before sending trades through the MCP server to avoid mistakes.

Conclusion

With Alpac’s MCP Server, you can build automated trading workflows that analyze market data, place orders, and record trades in spreadsheets, all through natural language prompts. Instead of managing a web of connections between every service, MCP centralizes them through a single client, reducing complexity in your daily workflow.

In this guide, you set up Claude Desktop with Alpaca's MCP Server (V2) and the Google Workspace CLI to create an integrated trading flow, from Bollinger Band analysis to order execution and position logging in Google Sheets. V2 of the Alpaca MCP Server installs with a single uvx command, requires no repository cloning or .env files, and stays aligned with Alpaca's latest API surface through its OpenAPI-based architecture. The Google Workspace CLI (gws) provides structured access to Sheets, Drive, Docs, and other Google services, and Claude Code (available in the Code tab of Claude Desktop) can run gws commands directly to interact with your spreadsheets.

Alpaca also offers Alpaca’s command-line interface (CLI) that provides access to 108 trading functions directly from your terminal and AI agent. While the MCP Server runs as a background process within an AI host session, the CLI is a single-invocation command suited for shell scripts, cron jobs, and CI pipelines. Both are generated from Alpaca's OpenAPI specifications. Learn more in the announcement blog post.

If you have not registered for Alpaca's Trading API, you can sign up on the website. If you are building your own MCP integration with Alpaca, feel free to share it on social media and tag us or share it in our community forum, Slack community, or subreddit. For account assistance, you can contact customer support.

Frequently Asked Questions

What is MCP in simple terms?

MCP is a protocol that lets AI assistants communicate with applications (like trading platforms) using a shared, standardized interface. It acts as a translation layer between the AI and the services it needs to interact with.

Is Alpaca's MCP Server safe to use?

The server uses API key-based authentication and does not share sensitive data beyond what is requested. V2 also supports toolset filtering so you can restrict which capabilities are available to the AI.

Can I use MCP without coding knowledge?

Yes. With Claude Desktop, Cursor, or VS Code, you can set up Alpaca's MCP Server by editing a single JSON configuration file. Claude Code (built into Claude Desktop's Code tab) can also guide you through setting up tools like the Google Workspace CLI. After setup, you interact through natural language prompts with no code required.

When should I use Alpaca's MCP Server vs. Alpaca's CLI?

Use Alpaca's MCP Server when you want your AI assistant to handle trading tasks for you through conversation. You describe what you want in plain English, and the assistant figures out which API calls to make. This works inside AI tools like Claude, Codex, Cursor, or VS Code. Use Alpaca's CLI when you want to run specific trading commands yourself in the terminal. You type explicit commands like alpaca order submit --symbol AAPL --side buy --qty 10 --type market and get immediate results. Alpaca's CLI also works well for automating tasks with scripts or scheduling recurring jobs. Both tools connect to the same Alpaca's Trading API.

Where can I find the official Alpaca MCP Server?

The official server is at github.com/alpacahq/alpaca-mcp-server. Make sure you use the official repository, not third-party forks, to stay on the latest supported version.

Broker API

Execute your trading algos commission-free

Sign Up for Free

Insights, analyses, prompts, calculations, and outputs generated through Alpaca’s MCP Server, CLI, or connected AI agents are for educational and informational purposes only and may contain errors, inaccuracies, or incomplete information. Automated and AI-assisted workflows may be affected by connectivity issues, API outages, delayed data, prompt errors, software bugs, or other technical failures that could result in unintended trades or losses. Alpaca does not recommend any specific securities or investment strategies, and automated or AI-assisted trading strategies may not be appropriate for all investors. Past performance, hypothetical results, or AI-generated outputs do not guarantee future results. Investors should conduct their own due diligence and carefully consider their investment objectives, financial circumstances, and risk tolerance before making any investment decisions.

All investments involve risk, including the possible loss of principal. There is no guarantee that any investment strategy or automated workflow will achieve its objectives.

The Paper Trading API is offered by AlpacaDB, Inc. and does not require real money or permit a user to transact in real securities in the market. Providing use of the Paper Trading API is not an offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, given or in any manner endorsed by AlpacaDB, Inc. or any AlpacaDB, Inc. affiliate and the information made available through the Paper Trading API is not an offer or solicitation of any kind in any jurisdiction where AlpacaDB, Inc. or any AlpacaDB, Inc. affiliate (collectively, "Alpaca") is not authorized to do business.