This is the mcp to fetch and get order flow information
Documentation
MCP Order Flow Server
A high-performance Model Context Protocol (MCP) server that provides real-time order flow analysis for algorithmic trading applications. This server connects to market data brokers via gRPC to deliver institutional-grade market microstructure insights.
Features
- Real-time Order Flow Analysis: Live market microstructure data processing
- High-Performance gRPC Integration: Sub-millisecond latency data retrieval
- Institutional Pattern Detection: Absorption, stacking, and sweep patterns
- Support/Resistance Levels: Algorithmically derived key price levels
- Market Momentum Metrics: Bid/ask dynamics and size acceleration
- MCP Protocol Compliance: Seamless integration with AI agents and LLMs
Quick Start
Prerequisites
- Python 3.10 or higher
- A compatible market data broker (gRPC endpoint)
- Basic understanding of market microstructure concepts
Installation
1. Clone the repository:
git clone
cd mcp-order-flow-server2. Install dependencies:
pip install -r requirements.txt3. Generate protobuf files (if using gRPC data source):
./generate_proto.sh4. Configure environment (optional):
export DATA_BROKER_GRPC_URL=localhost:9090
export LOG_LEVEL=INFO5. Start the server:
python src/mcp_server.pyUsage
MCP Tool: analyze_order_flow_tool
The server exposes a single MCP tool for order flow analysis:
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
ticker | string | required | Stock/ETF ticker symbol (e.g., "SPY", "QQQ") |
history | string | "5mins" | Analysis time window (e.g., "30s", "10mins", "1h") |
include_patterns | boolean | true | Include pattern detection in response |
Example Request
{
"method": "tools/call",
"params": {
"name": "analyze_order_flow_tool",
"arguments": {
"ticker": "SPY",
"history": "5mins",
"include_patterns": true
}
}
}Example Response
1847
300s
3
485.230
485.250
1800
1200
0.020
0.050
0.045
3
2
1650
1250
1
0
YES
YES
bullish
strong
Strong bid absorption at 485.20Configuration
Environment Variables
# Data source configuration
DATA_SOURCE=grpc # Use 'grpc' (recommended) or 'redis'
DATA_BROKER_GRPC_URL=localhost:9090 # gRPC endpoint for market data
# Redis fallback (if DATA_SOURCE=redis)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
# Logging
LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERRORData Sources
| Source | Latency | Throughput | Use Case |
|---|---|---|---|
| gRPC | 0.1-0.5ms | 2000+ req/s | Production (Recommended) |
| Redis | 0.5-2ms | 500+ req/s | Development/Fallback |
Architecture
┌─────────────────┐ ┌──────────────────┐ ┌───────────────────┐
│ MCP Client │───▶│ MCP Server │───▶│ Market Data │
│ (AI Agent) │ │ (This Repo) │ │ Broker (gRPC) │
└─────────────────┘ └──────────────────┘ └───────────────────┘
│
▼
┌──────────────────┐
│ Order Flow │
│ Analysis Engine │
└──────────────────┘Key Components
- MCP Server: FastMCP-based server handling tool requests
- gRPC Client: High-performance data retrieval from market broker
- State Manager: XML response formatting and data aggregation
- Pattern Detector: Real-time institutional pattern recognition
Development
Project Structure
mcp-order-flow-server/
├── src/
│ ├── mcp_server.py # Main MCP server entry point
│ ├── config.py # Configuration management
│ ├── proto/ # Generated protobuf files
│ ├── storage/
│ │ ├── grpc_client.py # gRPC data client
│ │ └── redis_client.py # Redis fallback client
│ ├── formatters/
│ │ └── state_manager.py # XML response formatting
│ └── tools/
│ └── order_flow_tool.py # MCP tool implementation
├── generate_proto.sh # Protobuf generation script
├── test_tool.py # Development testing
└── requirements.txt # Python dependenciesTesting
# Run development tests
python test_tool.py
# Test specific ticker
python -c "
import asyncio
from src.tools.order_flow_tool import analyze_order_flow
result = asyncio.run(analyze_order_flow('SPY', '1min', True))
print(result)
"Regenerating Protobuf Files
If the market data broker's protobuf definitions change:
./generate_proto.shPerformance
Benchmarks
- Analysis Latency:
No data available for ticker
Invalid ticker symbol
Market data broker not running
Network connectivity issues
Verify ticker symbol is correct
Check market data broker status
Ensure network connectivity
// Code blockSimilar MCP
Based on tags & features
Trending MCP
Most active this week