feat: support user-defined fallback protocols array#707
Conversation
docs: update README to document MCP_LATEST and MCP_DRAFT
4a5deab to
67ae062
Compare
9fc5bd7 to
4ba1f82
Compare
4ba1f82 to
da892a4
Compare
|
|
||
| def test_toolbox_client_custom_protocols_invalid(): | ||
| """Test that custom protocols array raises error on invalid inputs.""" | ||
| import pytest |
There was a problem hiding this comment.
nit: pytest is also exported at the top of the file
| should typically be managed externally. | ||
| client_headers: Headers to include in each request sent through this | ||
| client. | ||
| protocol: The communication protocol to use. |
There was a problem hiding this comment.
Can we update the docstring with info about protocol?
| if isinstance(protocol, list): | ||
| if not protocol: | ||
| raise ValueError("protocol list cannot be empty") | ||
| user_protocols = [ | ||
| p.value if isinstance(p, Protocol) else str(p) for p in protocol | ||
| ] | ||
|
|
||
| supported_mcp_versions = Protocol.get_supported_mcp_versions() | ||
| for p in user_protocols: | ||
| if p not in supported_mcp_versions: | ||
| raise ValueError( | ||
| f"Invalid protocol version '{p}'. Must be one of: {supported_mcp_versions}" | ||
| ) | ||
|
|
||
| user_protocols_set = set(user_protocols) | ||
| # Intersect with the globally sorted list to strictly enforce newest-to-oldest ordering | ||
| supported_protocols = [ | ||
| v for v in supported_mcp_versions if v in user_protocols_set | ||
| ] | ||
| if not supported_protocols: | ||
| raise ValueError("No supported protocols found in the provided list") | ||
| initial_protocol = Protocol(supported_protocols[0]) | ||
| else: | ||
| supported_protocols = None | ||
| initial_protocol = protocol | ||
|
|
There was a problem hiding this comment.
Would it be possible to document this new behaviour?
Eg.
protocol=Protocol.MCP_LATEST → supported_protocols=None → transport falls back through all older versions during negotiation.
protocol=[Protocol.MCP_LATEST] → supported_protocols =["2025-11-25"] → negotiation is restricted to that one version, no fallback.
Also that the newest version in the list is negotiated for at first
…lamaindex clients
| supported_protocols = [ | ||
| v for v in supported_mcp_versions if v in user_protocols_set | ||
| ] | ||
| if not supported_protocols: |
There was a problem hiding this comment.
Every user_protocols entry is already validated to be insupported_mcp_versions, and the list is non-empty, so the intersection can never be empty here.
Seems like unreachable code. Should we remove this?
Description
This PR introduces the ability for devs to provide a custom array of preferred protocol versions when initializing the client, rather than being forced to rely on the default SDK fallback order.
Note
This PR is stacked on top of #703.
Changes:
supported_protocolslist parameter to theToolboxClient.test_client.py):