modelcontextprotocol / modelcontextprotocol/python-sdk

ServerSession methods (create_message, elicit_form) don't expose progress_callback parameter

未關閉 適合新手
#1,671 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

enhancement needs decision P2
主要語言
Python
星號
24.3k
分支
4k
平均合併
1 天 1 小時
30 天內合併 PR
31

描述

Summary

The ServerSession high-level methods for sending requests to clients (create_message, elicit_form) don't expose the progress_callback parameter, even though the underlying BaseSession.send_request() fully supports it.

This means servers can't easily receive progress notifications from clients during sampling or elicitation requests.

Current Behavior

# ServerSession.elicit_form() - no progress_callback parameter
async def elicit_form(
    self,
    message: str,
    requestedSchema: types.ElicitRequestedSchema,
    related_request_id: types.RequestId | None = None,
) -> types.ElicitResult:
    return await self.send_request(...)  # progress_callback not passed through

# ServerSession.create_message() - same issue
async def create_message(
    self,
    messages: list[types.SamplingMessage],
    *,
    max_tokens: int,
    # ... other params ...
    related_request_id: types.RequestId | None = None,
) -> types.CreateMessageResult:
    return await self.send_request(...)  # progress_callback not passed through

Expected Behavior

# Should be able to pass progress_callback
result = await server_session.elicit_form(
    message="Please provide your details",
    requestedSchema=schema,
    progress_callback=lambda progress, total, msg: print(f"Progress: {progress}/{total} - {msg}")
)

result = await server_session.create_message(
    messages=messages,
    max_tokens=1000,
    progress_callback=lambda progress, total, msg: print(f"Sampling progress: {progress}/{total}")
)

Context

  • The MCP spec supports bidirectional progress notifications - clients CAN send notifications/progress back to servers during request handling
  • BaseSession.send_request() already supports progress_callback parameter
  • ClientSession.call_tool() exposes progress_callback for the client→server direction
  • The TypeScript SDK exposes this via RequestOptions.onprogress in both createMessage() and elicitInput()
  • Tests in tests/shared/test_progress_notifications.py demonstrate the bidirectional flow works

Suggested Fix

Add progress_callback: ProgressFnT | None = None parameter to:

  • ServerSession.create_message()
  • ServerSession.elicit_form()
  • Any other ServerSession methods that send requests to clients

And pass it through to send_request().

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 ServerSession.create_message() 和 elicit_form() 入口點開始,接著將它們的呼叫與 BaseSession.send_request() 以及現有的進度回呼處理進行比較。檢視 tests/shared/test_progress_notifications.py,並在兩個方法都接受並轉送 progress_callback,且涵蓋雙向流程時,視為工作完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
api
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
冷清
描述清晰度
基本清楚
新手友好度
72/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。