Skip to content

feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback#704

Merged
anubhav756 merged 19 commits into
anubhav-mcp-draftfrom
anubhav-draft-negotiation
Jul 1, 2026
Merged

feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback#704
anubhav756 merged 19 commits into
anubhav-mcp-draftfrom
anubhav-draft-negotiation

Conversation

@anubhav756

Copy link
Copy Markdown
Contributor

This PR adds support for the upcoming MCP 2026 stateless draft (DRAFT-2026-v1) and introduces protocol auto-negotiation fallback to ensure smooth backward compatibility with older servers.

  • Adds MCP_DRAFT constant pointing to DRAFT-2026-v1 alongside MCP and MCP_LATEST.
  • Implements fallback protocol negotiation during client initialization.
    • If an older server returns a single version string instead of throwing an UnsupportedProtocolVersionError, the client manually triggers ProtocolNegotiationError and falls back to the server's preferred version.
  • Adds E2E test test_protocol_fallback_e2e to verify negotiation down to older versions.
  • Updates documentation across core, adk, langchain, and llamaindex integrations.

@anubhav756 anubhav756 force-pushed the anubhav-draft-negotiation branch from 9511caf to 261bb86 Compare June 30, 2026 14:25
@anubhav756 anubhav756 force-pushed the anubhav-draft-negotiation branch from e821d64 to caf7b85 Compare July 1, 2026 13:27
@anubhav756 anubhav756 merged commit 25c0c88 into anubhav-mcp-draft Jul 1, 2026
29 checks passed
@anubhav756 anubhav756 deleted the anubhav-draft-negotiation branch July 1, 2026 14:42
@anubhav756

Copy link
Copy Markdown
Contributor Author

This PR is rolled-up in #703 to override some of the intermediate changes and make it easier to review.

anubhav756 added a commit that referenced this pull request Jul 1, 2026
…tion fallback (#704)

* feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback

* fix: Keep the MCP_LATEST to stable version but point MCP_DRAFT to 2026 draft

* chore: fix integration tests

* chore: delint

* chore: fix tests

* test: increase integration test coverage

* chore: delint

* test: integrate the draft build with dual testing modes

* fix(tests): correct pytest async fixtures and auto-format with black/isort

* fix(tests): use pytest.fixture for sync fixtures and fix isort formatting

* fix(tests): update binary URL for draft testing in all packages

* chore: fix integration tests url and lint errors

* chore: test with mcp-v202606 branch to fix unknown flag error

* fix(test): core fallback and adk toolset import

* chore: format files

* Revert "chore: format files"

This reverts commit ee00b9e.

* chore(test): fix line length in bucket name selection

* chore: bump TOOLBOX_VERSION to v1.6.0

* test: parameterize integration tests to run comprehensively for both stable and draft MCP versions
anubhav756 added a commit that referenced this pull request Jul 1, 2026
…tion fallback (#704)

* feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback

* fix: Keep the MCP_LATEST to stable version but point MCP_DRAFT to 2026 draft

* chore: fix integration tests

* chore: delint

* chore: fix tests

* test: increase integration test coverage

* chore: delint

* test: integrate the draft build with dual testing modes

* fix(tests): correct pytest async fixtures and auto-format with black/isort

* fix(tests): use pytest.fixture for sync fixtures and fix isort formatting

* fix(tests): update binary URL for draft testing in all packages

* chore: fix integration tests url and lint errors

* chore: test with mcp-v202606 branch to fix unknown flag error

* fix(test): core fallback and adk toolset import

* chore: format files

* Revert "chore: format files"

This reverts commit ee00b9e.

* chore(test): fix line length in bucket name selection

* chore: bump TOOLBOX_VERSION to v1.6.0

* test: parameterize integration tests to run comprehensively for both stable and draft MCP versions
anubhav756 added a commit that referenced this pull request Jul 2, 2026
…tion fallback (#704)

* feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback

* fix: Keep the MCP_LATEST to stable version but point MCP_DRAFT to 2026 draft

* chore: fix integration tests

* chore: delint

* chore: fix tests

* test: increase integration test coverage

* chore: delint

* test: integrate the draft build with dual testing modes

* fix(tests): correct pytest async fixtures and auto-format with black/isort

* fix(tests): use pytest.fixture for sync fixtures and fix isort formatting

* fix(tests): update binary URL for draft testing in all packages

* chore: fix integration tests url and lint errors

* chore: test with mcp-v202606 branch to fix unknown flag error

* fix(test): core fallback and adk toolset import

* chore: format files

* Revert "chore: format files"

This reverts commit ee00b9e.

* chore(test): fix line length in bucket name selection

* chore: bump TOOLBOX_VERSION to v1.6.0

* test: parameterize integration tests to run comprehensively for both stable and draft MCP versions
anubhav756 added a commit that referenced this pull request Jul 3, 2026
…tion fallback (#704)

* feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback

* fix: Keep the MCP_LATEST to stable version but point MCP_DRAFT to 2026 draft

* chore: fix integration tests

* chore: delint

* chore: fix tests

* test: increase integration test coverage

* chore: delint

* test: integrate the draft build with dual testing modes

* fix(tests): correct pytest async fixtures and auto-format with black/isort

* fix(tests): use pytest.fixture for sync fixtures and fix isort formatting

* fix(tests): update binary URL for draft testing in all packages

* chore: fix integration tests url and lint errors

* chore: test with mcp-v202606 branch to fix unknown flag error

* fix(test): core fallback and adk toolset import

* chore: format files

* Revert "chore: format files"

This reverts commit ee00b9e.

* chore(test): fix line length in bucket name selection

* chore: bump TOOLBOX_VERSION to v1.6.0

* test: parameterize integration tests to run comprehensively for both stable and draft MCP versions
anubhav756 added a commit that referenced this pull request Jul 3, 2026
anubhav756 added a commit that referenced this pull request Jul 3, 2026
anubhav756 added a commit that referenced this pull request Jul 3, 2026
anubhav756 added a commit that referenced this pull request Jul 6, 2026
anubhav756 added a commit that referenced this pull request Jul 6, 2026
anubhav756 added a commit that referenced this pull request Jul 6, 2026
anubhav756 added a commit that referenced this pull request Jul 6, 2026
anubhav756 added a commit that referenced this pull request Jul 6, 2026
anubhav756 added a commit that referenced this pull request Jul 6, 2026
anubhav756 added a commit that referenced this pull request Jul 8, 2026
anubhav756 added a commit that referenced this pull request Jul 8, 2026
…tion fallback (#703)

* feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback (#704)

* chore: delint
anubhav756 added a commit that referenced this pull request Jul 8, 2026
anubhav756 added a commit that referenced this pull request Jul 9, 2026
* feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback (#704)

* feat(core): add custom protocols array support for ToolboxClient

* resolve PR 707 review comments

* remove redundant constant definitions in conftest.py

* test: fix conftest import locations and update readme links

* refactor: consolidate fallback mechanism tests into test_client.py and remove redundant test_fallback.py

* chore: delint

* refactor: centralize test constants into package-specific files and update imports across test suites

* test: update integration tests to use stable server URL constant

* refactor: remove redundant pytestmark fixture declaration in integration tests

* test: update integration tests to use TOOLBOX_SERVER_URL_STABLE for server connections

* chore: delint

* fix: add comments for dual-server to test fixtures

* fix: update protocol negotiation error code from -32004 to -32022 across all transport versions

* chore: delint

* feat: implement automated MCP protocol version negotiation for old MCP versions

* fix: update error code to -32022 for detecting server-supported protocol versions

* fix: parse standard json-rpc errors on http 400

* feat: add automated protocol version fallback negotiation for invalid protocol version errors across all MCP transports

* refactor: fix integration tests by replacing aioresponses with AsyncMock

* test: update exception match regex to include MCP invalid request code in e2e tests and add debug script

* test: use try/except for flexible auth error matching in e2e tests

* fix(core): handle json-rpc error dict for protocol version mismatch

* fix(core): match unsupported protocol version in error dict and fix lint

* Fix unit tests related to _meta JSON error parsing, mock misconfiguration, and version negotiation array index checks

* style: Run black and isort to fix lint CI errors

* style: Run black across all packages

* style: fix isort formatting with black profile

* style: reformat imports per package to respect first-party modules

* refactor: extract -32022 to constant and add missing fallback tests

* style: move UNSUPPORTED_PROTOCOL_VERSION_ERROR_CODE to top of types.py

* Extract -32022 into constant for v20260618 transport

* Add missing test_version_negotiation_raises_fallback to legacy versions
anubhav756 added a commit that referenced this pull request Jul 9, 2026
…on fallback (#699)

* feat(core): implement reference support for Stateless MCP (SEP-2575) (#648)

* feat: Add support for SEP-2575

* chore: remove error logs

* chore: fix presubmits

* chore: add todo

* feat(core): support DRAFT-2026-v1 stateless transport and version negotiation retry limit

* style: format python transport files with black and isort

* refactor: move Protocol import to the top of the file

* test: filter out draft versions in Go E2E tests, add todo remarks, and update protocol unit test expected versions

* docs: add error requirements docstring in conformance client script

* fix(core): update stateless protocol version retry logic to use spec-compliant -32004 code

* fix(core): align ClientCapabilities Pydantic schema with spec

* refactor: simplify version negotiation retry logic in MCP transport

* chore: delint

* refactor(core): implement transport proxy for protocol fallback

* chore: delint

* fix: fix integration tests

* chore: delint

* chore: fix license header

Co-authored-by: Averi Kitsch <akitsch@google.com>

* chore: remove unused retry logic from inside the transport class

* chore: delint

---------

Co-authored-by: Averi Kitsch <akitsch@google.com>

* feat(core): implement SEP-2243 routing headers for HTTP transport (#701)

* test: upgrade integration harnesses for dual-server execution (#706)

* test: upgrade integration harnesses for dual-server execution

* chore: delint

* test: update E2E protocol fallback assertions to support dynamic server URLs and ignore noise warnings in tool tests

* chore: update package dependencies and metadata across all sub-packages

* refactor: remove platform-specific .exe extension from toolbox binary path resolution in test configurations

* refactor: convert patch_toolbox_client_url to an explicit fixture and apply it to E2E tests via pytestmark

* refactor: reorder imports and constants in test conftest files for consistency

* fix: remove autouse from patch_toolbox_client_url fixture to prevent unnecessary patching in integration tests

* feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback (#703)

* feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback (#704)

* chore: delint

* feat: support user-defined fallback protocols array (#707)

* feat(core): add support for MCP 2026 stateless draft and auto-negotiation fallback (#704)

* feat(core): add custom protocols array support for ToolboxClient

* resolve PR 707 review comments

* remove redundant constant definitions in conftest.py

* test: fix conftest import locations and update readme links

* refactor: consolidate fallback mechanism tests into test_client.py and remove redundant test_fallback.py

* chore: delint

* refactor: centralize test constants into package-specific files and update imports across test suites

* test: update integration tests to use stable server URL constant

* refactor: remove redundant pytestmark fixture declaration in integration tests

* test: update integration tests to use TOOLBOX_SERVER_URL_STABLE for server connections

* chore: delint

* fix: add comments for dual-server to test fixtures

* fix: update protocol negotiation error code from -32004 to -32022 across all transport versions

* chore: delint

* feat: implement automated MCP protocol version negotiation for old MCP versions

* fix: update error code to -32022 for detecting server-supported protocol versions

* fix: parse standard json-rpc errors on http 400

* feat: add automated protocol version fallback negotiation for invalid protocol version errors across all MCP transports

* refactor: fix integration tests by replacing aioresponses with AsyncMock

* test: update exception match regex to include MCP invalid request code in e2e tests and add debug script

* test: use try/except for flexible auth error matching in e2e tests

* fix(core): handle json-rpc error dict for protocol version mismatch

* fix(core): match unsupported protocol version in error dict and fix lint

* Fix unit tests related to _meta JSON error parsing, mock misconfiguration, and version negotiation array index checks

* style: Run black and isort to fix lint CI errors

* style: Run black across all packages

* style: fix isort formatting with black profile

* style: reformat imports per package to respect first-party modules

* refactor: extract -32022 to constant and add missing fallback tests

* style: move UNSUPPORTED_PROTOCOL_VERSION_ERROR_CODE to top of types.py

* Extract -32022 into constant for v20260618 transport

* Add missing test_version_negotiation_raises_fallback to legacy versions

---------

Co-authored-by: Averi Kitsch <akitsch@google.com>
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.

2 participants