41 - MCP Architecture

Overview

OpenAlgo includes an MCP (Model Context Protocol) server that enables AI assistants like Claude, Cursor, and Windsurf to control trading operations through natural language commands.

Architecture Diagram

┌──────────────────────────────────────────────────────────────────────────────┐
│                          MCP Architecture                                     │
└──────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│                           AI Clients                                         │
│                                                                              │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐             │
│  │  Claude         │  │   Cursor        │  │   Windsurf      │             │
│  │  Desktop        │  │   IDE           │  │   IDE           │             │
│  └────────┬────────┘  └────────┬────────┘  └────────┬────────┘             │
│           │                    │                    │                       │
│           └────────────────────┼────────────────────┘                       │
│                                │                                             │
│                    MCP Protocol (stdio transport)                           │
│                                │                                             │
└────────────────────────────────┼────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────────────┐
│                     MCP Server (mcpserver.py)                                │
│                          FastMCP Framework                                   │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │                      50+ Trading Tools                               │   │
│  │                                                                      │   │
│  │  ┌──────────────┐ ┌──────────────┐ ┌──────────────┐                │   │
│  │  │ Order Tools  │ │ Data Tools   │ │ Account Tools│                │   │
│  │  │              │ │              │ │              │                │   │
│  │  │ place_order  │ │ get_quote    │ │ get_funds    │                │   │
│  │  │ smart_order  │ │ get_depth    │ │ get_holdings │                │   │
│  │  │ cancel_order │ │ get_history  │ │ get_positions│                │   │
│  │  │ basket_order │ │ option_chain │ │ margin_calc  │                │   │
│  │  └──────────────┘ └──────────────┘ └──────────────┘                │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘

                                 │ OpenAlgo Python Library
                                 │ (openalgo==1.0.45)


┌─────────────────────────────────────────────────────────────────────────────┐
│                       OpenAlgo REST API                                      │
│                       /api/v1/*                                              │
└─────────────────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────────────┐
│                      Broker Integration                                      │
│                      (29 Brokers)                                          │
└─────────────────────────────────────────────────────────────────────────────┘

MCP Tools

Order Management (9 tools)

Market Data (6 tools)

Account & Position (7 tools)

Instrument Search (8 tools)

Utility (9 tools)

Configuration

Claude Desktop (macOS)

Cursor IDE

Windsurf IDE

Natural Language Examples

Order Placement

Position Management

Options Trading

Market Analysis

Security

API Key Handling

  • API key passed as command-line argument

  • Never hardcoded in scripts

  • Stored securely in MCP config file

Transport Security

  • Uses stdio transport (local only)

  • No network exposure of MCP server

  • API calls use HTTPS when remote

User Context

  • All operations tied to strategy name

  • Audit trail in OpenAlgo logs

  • Rate limiting applied

Dependencies

Implementation

Server Initialization

Key Files Reference

File
Purpose

mcp/mcpserver.py

MCP server with 50+ tools

mcp/README.md

Setup documentation

External: openalgo package

Python client library

Last updated