Skip to content

Conversation

@BryceEWatson
Copy link

Fixes #1671

Motivation and Context

The ServerSession high-level methods for sending requests to clients (create_message, elicit_form, elicit_url) 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.

ClientSession.call_tool() already exposes progress_callback for 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's RequestOptions.onprogress.

How Has This Been Tested?

  • Two new E2E tests added to tests/shared/test_progress_notifications.py:
    • test_server_create_message_progress_callback: verifies progress callbacks work during sampling requests via MCPServer + Client
    • test_server_elicit_form_progress_callback: verifies progress callbacks work during elicitation requests via MCPServer + Client
  • All 1,139 existing tests pass (uv run pytest: 1139 passed, 96 skipped, 1 xfailed)
  • uv run pyright: 0 errors
  • uv run ruff check .: clean

Breaking Changes

No. All new parameters default to None, maintaining full backward compatibility.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Approach: Mirrors the existing ClientSession.call_tool() pattern — adds progress_callback: ProgressFnT | None = None to each method signature and passes it through to send_request().

Files changed (4):

  • src/mcp/server/session.py — Core: added param to create_message() (all overloads + impl), elicit(), elicit_form(), elicit_url()
  • src/mcp/server/elicitation.py — Helpers: passthrough in elicit_with_validation() and elicit_url()
  • src/mcp/server/mcpserver/server.py — Context API: passthrough in Context.elicit() and Context.elicit_url()
  • tests/shared/test_progress_notifications.py — 2 new E2E tests

Intentionally excluded: list_roots() and send_ping() — these are short-lived requests where progress tracking isn't meaningful.

…elicit_form()

Add progress_callback parameter to ServerSession methods that send
requests to clients, matching the pattern already used by
ClientSession.call_tool(). This brings the Python SDK into parity
with the TypeScript SDK's RequestOptions.onprogress support.

The MCP spec supports bidirectional progress notifications, and
BaseSession.send_request() already accepts progress_callback, but
the ServerSession convenience methods were not exposing it.

Fixes modelcontextprotocol#1671

Github-Issue: modelcontextprotocol#1671
The if-guards checking for progress_token in context.meta always
evaluate to True when progress_callback is provided, so the false
branches are never taken. Mark with pragma: no branch to satisfy
100% coverage requirement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant