modelcontextprotocol / modelcontextprotocol/python-sdk

Extract OAuth flow logic into reusable components for proxy use cases

オープン
#1,743 コメント 9 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

auth enhancement P1 v2
主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

Summary

Refactor OAuth implementation so the flow logic and state machine are usable by server-side proxy services, not just client-side browser flows.

Problem

The SDK's OAuth implementation is designed for local client-side flows (opening a browser locally). The business logic is embedded inside an httpx auth module, making it hard to reuse for other scenarios.

While individual helper functions have been extracted (PKCE utilities, token exchange, discovery), the core state machine that orchestrates the OAuth flow is not reusable. Proxy services that need to perform OAuth on behalf of users currently have to reimplement significant portions of the flow themselves — and when the SDK updates its OAuth logic, those reimplementations can fall out of sync.

Goal

  • Make the OAuth portions of the SDK compatible with proxy/gateway services that currently use custom workarounds
  • When an issue is fixed in the SDK, updating the SDK version should fix it everywhere — no custom OAuth reimplementations needed
  • Keep existing client-side flows working

Design Requirements (from maintainer discussion, Feb 2026)

Modularization into zones: Break the monolithic OAuth flow into modular, overridable pieces:

  • Discovery — obtaining and potentially customizing discovery URLs
  • Client Registration — dynamic client registration
  • Interactive Flow — authorization URL generation, redirect handling
  • Token Fetching — code exchange, refresh, new token extensions (XA, WIF)
  • Token Storage — pluggable storage (already exists)

Key requirements:

  • Each zone should operate as a pure function requiring minimal state
  • Every HTTP request in the flow must be interceptable — allow injection of a custom HTTP client/fetch interface (httpx client in Python, fetch in TypeScript) for custom headers, metrics, response handling
  • Support an "Auth Required" state as an SDK primitive — when a server responds with 401/403 mid-flow, the SDK should capture discovery metadata, scope, and WWW-Authenticate info and surface it so the calling application can handle it (rather than assuming auth happens upfront)
  • The flow must be resumable — a caller should be able to pick up an auth flow at any point (e.g., after a redirect returns on a different machine/request)
  • Support bypassing discovery when configuration is provided directly (important for enterprise environments with broken discovery)
  • Support new token-getting extensions (XA, WIF) that don't require interactive flows

Next steps:

  • Draft code sketches (potentially TypeScript first) to validate the modular function approach
  • Cross-SDK coordination — this applies to both Python and TypeScript SDKs

Related

  • #1240 - Implement OAuth relying on Authlib
  • #2053 - Replace Field(description=...) with docstrings in auth models

AI Disclaimer

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

この issue ではファイルやテストが指定されていません。まず、既存の OAuth 実装と、discovery、registration、interactive flow、token fetching、storage 用の各ヘルパーを見つけ、次に #1240 と maintainer の要件を確認してください。Python の同等の変更を調整する前に、TypeScript のスケッチを使ってモジュール化された再開可能な設計を検証してください。既存の client flow が引き続き動作し、proxy のユースケースでリクエストをインターセプトして認証を再開できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python, typescript
領域
authentication, backend-api-design
issue の種類
リファクタリング
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。