Schwab Model Context Protocol Server

by jkoelker
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • References GitHub repositories for dependencies including schwab-py and the MCP python-sdk.

  • Integrated with pytest for testing the server functionality and API interactions.

  • Built using Python and integrates with Python SDK for the Model Context Protocol.

施瓦布模型上下文协议服务器

这是一个使用schwab-py和 MCP python-sdk为 Schwab API 实现模型上下文协议 (MCP) 的服务器。

特征

  • 通过模型上下文协议公开 Schwab API 功能
  • 获取账户信息和仓位
  • 检索股票报价和价格历史记录
  • 获取市场信息和推动者
  • 获取期权链和到期数据
  • 访问订单和交易历史记录
  • 使用特殊工具修改帐户状态(需要--jesus-take-the-wheel标志)
  • 设计用于与大型语言模型 (LLM) 集成

安装

# Install with all dependencies uv add -e . # Install development dependencies uv add -e .[dev]

用法

验证

第一步是使用 Schwab API 进行身份验证并生成令牌:

# Authenticate and generate a token uv run schwab-mcp auth --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRET --callback-url YOUR_CALLBACK_URL

您可以通过环境变量设置这些凭据,以避免每次都输入它们:

默认情况下,令牌保存在~/.local/share/schwab-mcp/token.yaml (平台相关)。您可以指定其他路径:

uv run schwab-mcp auth --token-path /path/to/token.yaml

支持 yaml 和 json 令牌格式,并将从文件扩展名推断出来。

运行服务器

验证后即可运行服务器:

# Run the server with default token path uv run schwab-mcp server --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRET --callback-url YOUR_CALLBACK_URL # Run with a custom token path uv run schwab-mcp server --token-path /path/to/token.json --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRET --callback-url YOUR_CALLBACK_URL # Run with account modification tools enabled uv run schwab-mcp server --jesus-take-the-wheel --client-id YOUR_CLIENT_ID --client-secret YOUR_CLIENT_SECRET --callback-url YOUR_CALLBACK_URL

令牌年龄已验证 - 如果超过 5 天,系统将提示您重新进行身份验证。

警告:使用--jesus-take-the-wheel标志会启用可修改您账户状态的工具。请谨慎使用,因为这允许 LLM 取消订单并可能执行其他更改账户状态的操作。

可用工具

该服务器公开以下 MCP 工具:

日期和市场信息

  1. get_datetime - 获取 ISO 格式的当前日期时间
  2. get_market_hours - 获取特定市场的市场时间
  3. get_movers - 获取特定索引的推动者
  4. get_instruments - 搜索具有特定符号的工具

帐户信息

  1. get_account_numbers - 获取帐户 ID 到帐户哈希值的映射
  2. get_accounts - 获取所有关联的 Schwab 账户的信息
  3. get_accounts_with_positions - 获取账户的持仓信息
  4. get_account获取特定帐户的信息
  5. get_account_with_positions - 获取特定账户的持仓信息
  6. get_user_preferences - 获取所有帐户的用户偏好设置,包括昵称

订单

  1. get_order获取特定订单的详细信息
  2. get_orders - 获取特定账户的订单

引号

  1. get_quotes - 获取指定符号的报价

价格历史

  1. get_advanced_price_history - 获取特定符号的高级价格历史记录
  2. get_price_history_every_minute - 以分钟频率获取价格历史记录
  3. get_price_history_every_five_minutes - 以五分钟的频率获取价格历史记录
  4. get_price_history_every_ten_minutes - 获取十分钟频率的价格历史记录
  5. get_price_history_every_fifteen_minutes - 获取每十五分钟一次的价格历史记录
  6. get_price_history_every_thirty_minutes - 获取频率为三十分钟的价格历史记录
  7. get_price_history_every_day - 获取每日频率的价格历史记录
  8. get_price_history_every_week - 获取每周价格历史记录

选项

  1. get_option_chain - 获取特定符号的期权链
  2. get_advanced_option_chain - 获取特定符号的高级期权链
  3. get_option_expiration_chain - 获取符号的期权到期信息

交易

  1. get_transactions - 获取特定账户的交易
  2. get_transaction获取特定交易的详细信息

帐户修改工具(需要--jesus-take-the-wheel标志)

  1. cancel_order - 取消特定订单

安全警告

--jesus-take-the-wheel标志使 LLM 能够执行可修改您的帐户状态的操作,包括:

  • 取消订单
  • 其他可能产生财务影响的行动(未来版本中将添加更多工具)

仅在受控环境中使用此标志并了解所涉及的风险。

发展

# Type check uv run pyright # Format code uv run ruff format . # Lint uv run ruff check . # Run tests uv run pytest

执照

该项目可在 MIT 许可下使用。

-
security - not tested
A
license - permissive license
-
quality - not tested

为 Schwab API 实现模型上下文协议的服务器,允许访问专为与大型语言模型集成而设计的帐户信息、头寸、股票报价和订单/交易历史记录。

  1. Features
    1. Installation
      1. Usage
        1. Authentication
        2. Running the Server
      2. Available Tools
        1. Date and Market Information
        2. Account Information
        3. Orders
        4. Quotes
        5. Price History
        6. Options
        7. Transactions
        8. Account Modification Tools (Requires --jesus-take-the-wheel flag)
      3. Security Warning
        1. Development
          1. License
            ID: 25m86mwq5q