find_context_parameter treats a Context return annotation as a parameter

オープン 初心者向け
#3,298 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api, backend

調査の方向性

mcp/server/mcpserver/utilities/context_injection.py の find_context_parameter() から始め、Context の戻り値アノテーションを含む例を再現してください。検出が実際のパラメーターだけを調べ、"return" アノテーションを無視し、"return" をコンテキストパラメーターとして報告しなくなっていることを確認してください。

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

説明

P3 v1 v2
Initial checks
  • I tested the current main branch (6e30452).
  • I searched existing issues and pull requests for this behavior.
Description

find_context_parameter() iterates over every entry returned by typing.get_type_hints(). That mapping includes the function return annotation under the special key "return", even though it is not a parameter.

As a result, a tool, prompt, or resource function whose return annotation is Context (or a union containing Context) is incorrectly recorded as having a context parameter named "return". The SDK later attempts to inject context as a keyword argument with that name, which can produce an unexpected-keyword error when the callable is invoked.

Expected: context detection only examines actual function parameters and ignores the return annotation.

Example code
from mcp.server.mcpserver import Context
from mcp.server.mcpserver.utilities.context_injection import find_context_parameter

def fn(value: int) -> Context:
    ...

print(find_context_parameter(fn))  # current: "return"; expected: None
Environment
  • Python 3.12
  • MCP Python SDK main at 6e30452

I used AI assistance while investigating this issue and reviewed and reproduced the behavior locally.

主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 19分
マージ済み PR(30日)
29

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

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

はじめの一歩

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

modelcontextprotocol/python-sdk のほかの issue

modelcontextprotocol/python-sdk の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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