modelcontextprotocol / modelcontextprotocol/python-sdk

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

Aperta Adatta ai principianti
#1,671 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

enhancement needs decision P2
Lingua principale
Python
Stelle
24.3k
Fork
4k
Merge medio
1g 1h
PR unite (30g)
31

Descrizione

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().

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dai punti di ingresso ServerSession.create_message() ed elicit_form(), quindi confronta le relative chiamate con BaseSession.send_request() e la gestione esistente della callback di avanzamento. Esamina tests/shared/test_progress_notifications.py e considera concluso il lavoro quando entrambi i metodi accettano e inoltrano progress_callback, con una copertura del flusso bidirezionale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
72/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.