
What if I told you that you could build a sophisticated options trading algorithm in just minutes using nothing but AI prompts? Today, I'm going to show you how to set up Alpaca’s MCP server with Cursor AI, then use that connection to create a bull call spread algorithm that automatically finds option contracts, calculates strikes based on strategy structure, and executes multi-leg trades.
You can also find the video tutorial on YouTube.
To get the most out of this guide, explore the following resources first:
To use Alpaca’s MCP Server on Cursor, make sure you have the following tools ready:
- Alpaca API keys (with paper or live trading access)
- Python
- GitHub account
- Cursor (MCP Client)
- Terminal
If you’ve already connected Alpaca’s MCP server to Cursor, you can jump ahead to the prompt section below.
How Alpaca’s MCP Server Helps Algo Traders with AI

Alpaca's MCP server acts as a bridge between AI assistants like Cursor, Claude, and ChatGPT, and Alpaca's Trading API. Instead of you going through various API documents and SDKs, writing hundreds or thousands of lines of code, you can simply import three functions from the MCP server to build a trading strategy.
Example Vibe Coding Prompt to Build a Bull Call Spread Trading Algorithm
To get production-ready code, structuring your prompt correctly is key. Let me break down the essential components:
Code Generation Preferences
- AI tends to produce comprehensive but often redundant codebases by default.
- You can ask Cursor to generate a SIMPLE, FUNCTIONAL, and MINIMAL algorithm that prioritizes core functionality over extensive features.
Core Strategy Section
- This defines exactly what we want - a bull call spread with customizable parameters. We specify buying calls above current price and selling calls below current price.
Essential Variables to Replace
- Key input variables are essential for customizing the strategy. You can adjust them to change the underlying asset, price levels for strike selection, or the expiration timeframe.
Command-Line Interface
- This is what makes it production-ready. We specify argparse integration like --symbol, --buy-pct, and --dry-run. Argparse is a tool in Python that lets you pass in values when you run your script, so you don’t have to change the code every time
Implementation details
- This lets AI focus on a clear, functional prototype without over-engineering. The file must be in the same directory as the .env file to load credentials correctly.
After putting all of the pieces together, you should get a prompt that looks something like this:
Create a Python script that implements an automated bull call spread trading algorithm using Alpaca's MCP server (alpaca_mcp_server.py). The algorithm should be SIMPLE, FUNCTIONAL, and MINIMAL - focus on core functionality over comprehensive features.
Core Strategy (Debit Spread):
- Buy call option with strike [BUY_PERCENTAGE]% below current [UNDERLYING_SYMBOL] price (lower strike, long position)
- Sell call option with strike [SELL_PERCENTAGE]% above current [UNDERLYING_SYMBOL] price (higher strike, short position)
- Target expiration: approximately [WEEKS_AHEAD] weeks from now
- Execute as single multi-leg order for atomic execution
- This creates a debit spread where you pay net premium upfront
Essential Variables to Replace:
- [BUY_PERCENTAGE]: 3 (percentage below current price for long call - lower strike)
- [SELL_PERCENTAGE]: 5 (percentage above current price for short call - higher strike)
- [UNDERLYING_SYMBOL]: "SPY" (stock symbol to trade)
- [WEEKS_AHEAD]: 2 (weeks until expiration)
Error Handling:
- Try-catch around load_dotenv() with permission error handling
- Handle API response format: use contracts.option_contracts if attribute exists
- Market hours errors are normal (options only trade during market hours)
- Basic positive number validation
Command-Line Interface:
- `--symbol, -s`: Underlying symbol to trade (default: [UNDERLYING_SYMBOL])
- `--buy-pct, --buy-percentage`: Percentage below current price for long call (default: [BUY_PERCENTAGE])
- `--sell-pct, --sell-percentage`: Percentage above current price for short call (default: [SELL_PERCENTAGE])
- `--weeks, -w`: Weeks until expiration (default: [WEEKS_AHEAD])
- `--quantity, -q`: Number of spreads to trade (default: 1)
- `--dry-run`: Show strategy parameters without executing (default: False)
- `--help, -h`: Show help with basic examples
Critical: File must be in same directory as .env file or credential loading will fail. Focus on creating a working prototype that demonstrates the core functionality without over-engineering. The code should be straightforward, easy to understand, and functional rather than production-ready.
*Please note that we are using SPY as an example, and it should not be considered investment advice.
This is just one use case of using Alpaca’s MCP Server and Cursor. You can create strategies for any type of options trading strategy, or even use it for US stocks and ETFs.
How to Set Up Alpaca’s MCP Server on Cursor
Now, let’s see how we can use a prompt on Cursor AI to generate the options algorithm using Alpaca’s official MCP server. First, we’re going to set up the MCP server on Cursor AI.
Note:
- Please read through the detailed installation instructions provided here: https://github.com/alpacahq/alpaca-mcp-server?tab=readme-ov-file#1-installation
- Alpaca's paper trading account can be a great way to get started: https://alpaca.markets/learn/start-paper-trading?ref=alpaca.markets
1. Go to Alpaca’s MCP Server Github page and click the “Code” button:

2. Copy and paste the following url: https://github.com/alpacahq/alpaca-mcp-server.git

3. Open your terminal and move to your preferred working directory (folder). In this tutorial, I created a folder named “tutorial-alpaca-mcp-server.”

4. Run the command: `git clone https://github.com/alpacahq/alpaca-mcp-server.git` to download the Alpaca’s MCP Server in your working directory. You should be able to see the MCP server is successfully downloaded to the directory.

5. Create and activate the virtual environment by running the following commands one by one:
# Create a virtual environment named 'venv' (feel free to rename it)
python3 -m venv venv
# Activate the virtual environment named 'venv'
source venv/bin/activate
You will see that the virtual environment is activated under the name “venv” on your terminal.

5. After activating the virtual environment, install the necessary python libraries by running the following command:
pip install -r requirements.txt
This command installs “alpaca-py,” “mcp,” and “python-dotenv.” Depending on your working environment, you may need to install other packages as well.
6. Create a .env file by copying the example file .env.example. You can do this by running the following command:
cp .env.example .env
7. Open Cursor and open the working directory. You should be able to find the ".env” file. Open the file and replace the API keys with your Alpaca API keys. You can obtain the API keys from Alpaca’s dashboard (https://app.alpaca.markets/dashboard/overview).

8. Follow the instructions written in the README file here: https://github.com/alpacahq/alpaca-mcp-server?tab=readme-ov-file#cursor-usage and open the “Cursor Settings” in the Settings section.

9. Type “MCP” or “Tools” and you’ll find the MCP Tools section in “Tools & Integrations” to configure Alpaca’s MCP server. Click “Add Custom MCP” or “New MCP Server”; that opens the mcp.json file.

10. Copy and paste the configuration snippet into your mcp.json file.

11. Replace the paths with your actual project directory paths and API credentials. For example:
"command": "/Users/<Your user name>/Downloads/tutorial-alpaca-mcp-server/alpaca-mcp-server/venv/bin/python3",
"args": ["/Users/<Your user name>/Downloads/tutorial-alpaca-mcp-server/alpaca-mcp-server/alpaca_mcp_server.py"],
ALPACA_API_KEY = "<Your Alpaca API Key>"
ALPACA_SECRET_KEY = "<Your Alpaca Secret Key>"
After you’ve properly set up the Alpaca MCP server, you’ll see that it’s enabled in Cursor.
12. Finally, open Cursor Chat and paste the prompt we introduced above to experience the power of Vibe Coding with an AI agent — building a customizable trading algorithm in just minutes!

Conclusion
With Alpaca's MCP server and AI assistance, we went from idea to working algorithm in just minutes. Want to try it yourself? Explore the GitHub repository to get started.
If you're new to Alpaca, sign up on our website and embark on your own trading journey!
As we put these concepts into practice, feel free to share your feedback and experiences on our forum, Slack community, or subreddit! For those looking to algorithmic trading with Alpaca’s Trading API, here are some additional resources:
- Alpaca-py SDKs Documentation
- Sign up for an Alpaca Trading API account
- How to Connect to Alpaca's Trading API
- How to Start Paper Trading with Alpaca's Trading API
- How to Trade Options with Alpaca’s Trading API
- Read more Options Trading Tutorials
- API Reference Documentation: Options Trading
Frequently Asked Questions
What makes the MCP server different from just using Alpaca’s API directly?
The MCP server simplifies trading with Alpaca’s API by handling the heavy lifting for you. Instead of writing low-level code or reading docs, you can send a prompt to an AI assistant, and the MCP server connects it to Alpaca’s API using a few clean functions. It might be suitable for fast prototyping without diving into SDK details.
What is “Vibe Coding,” and how is it different from traditional coding?
Vibe Coding is a way to build trading algorithms by using AI prompts instead of writing everything by hand. You describe the strategy in natural language, and tools like Cursor + MCP server generate the working code. It’s faster, more intuitive, and might be beneficial for people who want to focus on the idea, not the syntax.
Can I modify this prompt to create other strategies like iron condors, straddles, or vertical puts?
Yes, you can! The prompt is fully customizable. Just describe the strategy you want — whether it’s an iron condor, straddle, or vertical put — and the AI will adjust the logic using the MCP server. The setup is flexible enough to handle a wide range of multi-leg strategies.
Disclosure
*Please note that we are using SPY as an example, and it should not be considered investment advice.
Please note that this content is for educational and informational purposes only. All screenshots and examples are for illustrative purposes only. Alpaca does not recommend any specific securities or investment strategies.
Options trading is not suitable for all investors due to its inherent high risk, which can potentially result in significant losses. Please read Characteristics and Risks of Standardized Options (https://www.theocc.com/company-information/documents-and-archives/options-disclosure-document?ref=alpaca.markets ) before investing in options.
Alpaca is not affiliated with Cursor AI or any of the companies or creators referenced in this article and is not responsible for the liabilities of the others.
Alpaca does not prepare, edit, endorse, or approve Third Party Content. Alpaca does not guarantee the accuracy, timeliness, completeness or usefulness of Third Party Content, and is not responsible or liable for any content, advertising, products, or other materials on or available from third party sites.
All investments involve risk, and the past performance of a security, or financial product does not guarantee future results or returns. There is no guarantee that any investment strategy will achieve its objectives. Please note that diversification does not ensure a profit, or protect against loss. There is always the potential of losing money when you invest in securities, or other financial products. Investors should consider their investment objectives and risks carefully before investing.
The algorithm’s calculations are based on historical and real-time market data but may not account for all market factors, including sudden price moves, liquidity constraints, or execution delays. Model assumptions, such as volatility estimates and dividend treatments, can impact performance and accuracy. Trades generated by the algorithm are subject to brokerage execution processes, market liquidity, order priority, and timing delays. These factors may cause deviations from expected trade execution prices or times. Users are responsible for monitoring algorithmic activity and understanding the risks involved. Alpaca is not liable for any losses incurred through the use of this system.
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.
Commission-free trading means that there are no commission charges for Alpaca self-directed individual cash brokerage accounts that trade U.S.-listed securities and options through an API. Relevant regulatory fees may apply. Commission-free trading is available to Alpaca's retail customers. Alpaca reserves the right to charge additional fees if it is determined that order flow is non-retail in nature.
Securities brokerage services are provided by Alpaca Securities LLC ("Alpaca Securities"), member FINRA (https://www.finra.org/) / SIPC (https://www.sipc.org/), a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.
This is not an offer, solicitation of an offer, or advice to buy or sell securities or open a brokerage account in any jurisdiction where Alpaca Securities is not registered or licensed, as applicable.