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 - 1分間隔で価格履歴を取得します
  3. get_price_history_every_five_minutes - 5分間隔で価格履歴を取得します
  4. get_price_history_every_ten_minutes - 10分間隔で価格履歴を取得します
  5. get_price_history_every_fifteen_minutes - 15分間隔で価格履歴を取得します
  6. get_price_history_every_thirty_minutes - 30分間隔で価格履歴を取得します
  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