modelcontextprotocol / modelcontextprotocol/python-sdk
Refactor func_metadata() into smaller components for schema & metadata generation
オープン
まだ誰も着手していません。
enhancement
needs decision
P3
- 主要言語
- Python
- スター
- 24.3k
- フォーク
- 4k
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 31
説明
Description
Summary
func_metadata() in src/mcp/server/fastmcp/utilities/func_metadata.py is a large function that handles:
- signature introspection,
- parameter/return type analysis,
- JSON schema generation,
- special handling for various container and model types.
This centralizes important logic, but its size and responsibility make it difficult to understand, test, and extend.
Problems
- Complexity: Many branching code paths for different types (Pydantic, dataclasses, TypedDict, primitives, etc.).
- Maintenance: Adding new type handling or fixing edge cases requires navigating a large function.
- Testing: Hard to write targeted tests for individual behaviors without exercising the entire function.
Proposal
-
Decompose into smaller functions
For example:
extract_parameters(fn) -> list[Parameter]build_arg_model(params) -> PydanticModel | Nonebuild_output_model(return_type) -> PydanticModel | Nonecreate_converters(...) -> Callable
-
Use a strategy/registry for type handling
- Allow registering handlers for specific type families (Pydantic, TypedDict, dataclasses, etc.).
- This reduces the need for a long series of
if isinstance(...)checks in one place.
-
Add targeted unit tests
- Test each helper independently, covering edge cases.
- Keep some higher-level tests that ensure the overall metadata behavior remains consistent.
Why this matters
- Extensibility: Easier to support new type patterns without making
func_metadata()even larger. - Reliability: Smaller, well-tested pieces reduce the risk of regressions when making changes.
- Readability: Contributors can understand and modify the code more easily.
Acceptance criteria
-
func_metadata()is decomposed into smaller, focused helpers. - There is a clear extension mechanism for adding support for new types.
- Unit tests cover individual behaviors; existing integration tests still pass.
References
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
src/mcp/server/fastmcp/utilities/func_metadata.py から始めて、func_metadata() と、そのシグネチャのイントロスペクション、型分析、スキーマ生成、コンバーターの経路を追跡します。既存のユニットテストと統合テストをベースラインとして使用し、その後、提案されたヘルパーに対する集中的なカバレッジを追加します。また、既存のメタデータの動作を維持しつつ、新しい型ファミリーのための明確な拡張メカニズムを提供します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- リファクタリング
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100