feat: expose progress_callback in ServerSession methods #2041
+143
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1671
Motivation and Context
The
ServerSessionhigh-level methods for sending requests to clients (create_message,elicit_form,elicit_url) don't expose theprogress_callbackparameter, even though the underlyingBaseSession.send_request()fully supports it. This means servers can't easily receive progress notifications from clients during sampling or elicitation requests.ClientSession.call_tool()already exposesprogress_callbackfor the client→server direction. This PR adds the same support for the server→client direction, bringing the Python SDK into parity with the TypeScript SDK'sRequestOptions.onprogress.How Has This Been Tested?
tests/shared/test_progress_notifications.py:test_server_create_message_progress_callback: verifies progress callbacks work during sampling requests viaMCPServer+Clienttest_server_elicit_form_progress_callback: verifies progress callbacks work during elicitation requests viaMCPServer+Clientuv run pytest: 1139 passed, 96 skipped, 1 xfailed)uv run pyright: 0 errorsuv run ruff check .: cleanBreaking Changes
No. All new parameters default to
None, maintaining full backward compatibility.Types of changes
Checklist
Additional context
Approach: Mirrors the existing
ClientSession.call_tool()pattern — addsprogress_callback: ProgressFnT | None = Noneto each method signature and passes it through tosend_request().Files changed (4):
src/mcp/server/session.py— Core: added param tocreate_message()(all overloads + impl),elicit(),elicit_form(),elicit_url()src/mcp/server/elicitation.py— Helpers: passthrough inelicit_with_validation()andelicit_url()src/mcp/server/mcpserver/server.py— Context API: passthrough inContext.elicit()andContext.elicit_url()tests/shared/test_progress_notifications.py— 2 new E2E testsIntentionally excluded:
list_roots()andsend_ping()— these are short-lived requests where progress tracking isn't meaningful.