Portfolio Service Monorepo

Portfolio Service Monorepo

By itay1542 GitHub

A MCP (Model Context Protocol) server that implements popular brokers' APIs and more

Overview

What is Portfolio Service MCP Server?

Portfolio Service MCP Server is a comprehensive Model Context Protocol (MCP) server that integrates popular brokerage APIs for efficient portfolio management, access to market data, and execution of trading operations.

How to use Portfolio Service MCP Server?

To use the server, configure it with your brokerage API credentials, set up the necessary environment variables, and run the server to access various market data and trading functionalities.

Key features of Portfolio Service MCP Server?

  • Multi-Broker Support: Integrates with popular brokers like Interactive Brokers (IBKR) and TradeStation.
  • Comprehensive Market Data: Access real-time and historical market data.
  • Advanced Trading Capabilities: Programmatic execution and management of trades.
  • News Integration: Provides real-time market news and articles.
  • Options Trading Support: Access to options chains and management tools.

Use cases of Portfolio Service MCP Server?

  1. Managing multi-brokerage trading portfolios.
  2. Executing programmatic trades based on market conditions.
  3. Analyzing stock and options data for investment decisions.

FAQ from Portfolio Service MCP Server?

  • Can I integrate multiple brokerage accounts?

Yes! The server supports integration with multiple brokers.

  • Is there a need for a running IBKR TWS instance?

Yes, to utilize IBKR integration features, you need to have a running instance of IBKR TWS.

  • Is the server open-source?

Yes! The Portfolio Service MCP Server is open-source under the MIT license.

Content

Portfolio Service Monorepo

A comprehensive suite of Model Context Protocol (MCP) servers for portfolio management, market data access, and trading operations, organized as a UV workspace.

Repository Structure

portfolio_service/
├── brokerage_service/     # Order execution and portfolio management
├── market_data_service/   # Market data and technical analysis
├── research_service/      # Market research and screening
├── common/               # Shared utilities and libraries
├── pyproject.toml        # Workspace root configuration
└── uv.lock              # Shared lockfile for all workspace members

Development Setup

This repository uses UV workspaces to manage multiple interconnected packages. Each service is a separate package that shares common dependencies and utilities.

Prerequisites

  • Python 3.11+
  • UV package manager

Installation

  1. Clone the repository:
git clone https://github.com/itay1542/brokers-mcp.git portfolio_service
cd portfolio_service
  1. Install dependencies for all workspace members:
uv sync
  1. Run a specific service:
# Run the brokerage service
uv run --package brokerage_service python src/server.py

# Run the market data service
uv run --package market_data_service python src/server.py

# Run the research service
uv run --package research_service python src/server.py

Environment Configuration

Create a .env file in each service directory with the required credentials:

# TradeStation Configuration (market_data_service)
TRADESTATION_API_KEY="your_api_key"
TRADESTATION_API_SECRET="your_api_secret"
TS_REFRESH_TOKEN="your_refresh_token"
TS_ACCOUNT_ID="your_account_id"

# Interactive Brokers Configuration (shared)
IBKR_ACCOUNT_ID="your_account_id"
IBKR_CLIENT_ID="1"
IBKR_HOST="127.0.0.1"
IBKR_PORT="7496"

Services Overview

Brokerage Service

  • Order execution and management
  • Portfolio tracking
  • Account management
  • Position monitoring

Market Data Service

  • Real-time and historical market data
  • Technical analysis
  • News integration
  • Options chain data

Research Service

  • TradingView market scanning
  • Custom stock screening
  • Technical indicator analysis
  • Market research tools

Common Features

Interactive Brokers (IBKR) Integration

Note: Requires a running IBKR TWS instance

  • Market data access
  • Order management
  • News integration
  • Options trading support
  • Account monitoring

TradingView Integration

Market scanning capabilities with:

  • Custom screening queries
  • Pre-built scanners
  • Technical indicator analysis
  • Fundamental data access

Development Tools

Debugging

Use the MCP Inspector for real-time debugging:

# Debug a specific service
npx @modelcontextprotocol/inspector uv run --package market_data_service python src/server.py

Testing

Run tests for a specific package:

uv run --package common pytest

Adding Dependencies

Add dependencies to a specific service:

uv add --package market_data_service pandas

Claude Desktop Integration

Configure in the appropriate location for your OS:

MacOS

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

Windows

%APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "brokerage_service": {
      "command": "uv",
      "args": [
        "--directory",
        "<path_to_portfolio_service>",
        "run",
        "--package",
        "brokerage_service",
        "python",
        "brokerage_service/src/server.py"
      ],
      "env": {
        "IBKR_ACCOUNT_ID": "your_account_id",
        "IBKR_CLIENT_ID": "1",
        "IBKR_HOST": "127.0.0.1",
        "IBKR_PORT": "7496",
        "TRADESTATION_API_KEY": "your_api_key",
        "TRADESTATION_API_SECRET": "your_api_secret",
        "TS_REFRESH_TOKEN": "your_refresh_token",
        "TS_ACCOUNT_ID": "your_account_id",
        "IBKR_CLIENT_ID": "1",
      }
    },
    "market_data_service": {
      "command": "uv",
      "args": [
        "--directory",
        "<path_to_portfolio_service>",
        "run",
        "--package",
        "market_data_service",
        "python",
        "market_data_service/src/server.py"
      ],
      "env": {
        "TRADESTATION_API_KEY": "your_api_key",
        "TRADESTATION_API_SECRET": "your_api_secret",
        "TS_REFRESH_TOKEN": "your_refresh_token",
        "TS_ACCOUNT_ID": "your_account_id",
        "IBKR_ACCOUNT_ID": "your_account_id",
        "IBKR_CLIENT_ID": "2",
        "IBKR_HOST": "127.0.0.1",
        "IBKR_PORT": "7496",
      }
    },
    "research_service": {
      "command": "uv",
      "args": [
        "--directory",
        "<path_to_portfolio_service>",
        "run",
        "--package",
        "research_service",
        "python",
        "research_service/src/server.py"
      ]
    }
  }
}

Contributing

  1. Create a new branch for your feature
  2. Make your changes
  3. Run tests across all affected packages
  4. Submit a pull request
No tools information available.
No content found.