From 0d4fa16ab99dc01924cc506bfcfaa13f19c19709 Mon Sep 17 00:00:00 2001 From: Omar Abdelwahab Date: Fri, 14 Nov 2025 16:56:04 -0800 Subject: [PATCH] updated the comments --- .../model_context_protocol.py | 6 ++---- .../inference/test_tools_with_schemas.py | 2 +- tests/integration/tool_runtime/test_mcp.py | 5 +---- .../tool_runtime/test_mcp_json_schema.py | 16 ++++++---------- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/llama_stack/providers/remote/tool_runtime/model_context_protocol/model_context_protocol.py b/src/llama_stack/providers/remote/tool_runtime/model_context_protocol/model_context_protocol.py index 2ba5da422..97b044dbf 100644 --- a/src/llama_stack/providers/remote/tool_runtime/model_context_protocol/model_context_protocol.py +++ b/src/llama_stack/providers/remote/tool_runtime/model_context_protocol/model_context_protocol.py @@ -48,7 +48,6 @@ class ModelContextProtocolToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime if mcp_endpoint is None: raise ValueError("mcp_endpoint is required") - # Phase 2: Only use the dedicated authorization parameter # Get other headers from provider data (but NOT authorization) provider_headers = await self.get_headers_from_request(mcp_endpoint.uri) @@ -64,7 +63,6 @@ class ModelContextProtocolToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime if urlparse(endpoint).scheme not in ("http", "https"): raise ValueError(f"Endpoint {endpoint} is not a valid HTTP(S) URL") - # Phase 2: Only use the dedicated authorization parameter # Get other headers from provider data (but NOT authorization) provider_headers = await self.get_headers_from_request(endpoint) @@ -80,7 +78,7 @@ class ModelContextProtocolToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime """ Extract headers from request provider data, excluding authorization. - Phase 2: Authorization must be provided via the dedicated authorization parameter. + Authorization must be provided via the dedicated authorization parameter. If Authorization is found in mcp_headers, raise an error to guide users to the correct approach. Args: @@ -104,7 +102,7 @@ class ModelContextProtocolToolRuntimeImpl(ToolGroupsProtocolPrivate, ToolRuntime if canonicalize_uri(uri) != canonicalize_uri(mcp_endpoint_uri): continue - # Phase 2: Reject Authorization in mcp_headers - must use authorization parameter + # Reject Authorization in mcp_headers - must use authorization parameter for key in values.keys(): if key.lower() == "authorization": raise ValueError( diff --git a/tests/integration/inference/test_tools_with_schemas.py b/tests/integration/inference/test_tools_with_schemas.py index cf2aacb3c..ab033c381 100644 --- a/tests/integration/inference/test_tools_with_schemas.py +++ b/tests/integration/inference/test_tools_with_schemas.py @@ -191,7 +191,7 @@ class TestMCPToolsInChatCompletion: mcp_endpoint=dict(uri=uri), ) - # Phase 2: Use the dedicated authorization parameter + # Use the dedicated authorization parameter # Get the tools from MCP tools_response = llama_stack_client.tool_runtime.list_tools( tool_group_id=test_toolgroup_id, diff --git a/tests/integration/tool_runtime/test_mcp.py b/tests/integration/tool_runtime/test_mcp.py index e22e96579..074a92afb 100644 --- a/tests/integration/tool_runtime/test_mcp.py +++ b/tests/integration/tool_runtime/test_mcp.py @@ -35,11 +35,8 @@ def test_mcp_invocation(llama_stack_client, text_model_id, mcp_server): mcp_endpoint=dict(uri=uri), ) - # Phase 2: Use the dedicated authorization parameter (no more provider_data headers) + # Use the dedicated authorization parameter (no more provider_data headers) # This tests direct tool_runtime.invoke_tool API calls - - # Note: tools.list() is the ToolGroups API and doesn't have authorization parameter - # Use tool_runtime.list_tools() for authorization support tools_list = llama_stack_client.tool_runtime.list_tools( tool_group_id=test_toolgroup_id, authorization=AUTH_TOKEN, # Use dedicated authorization parameter diff --git a/tests/integration/tool_runtime/test_mcp_json_schema.py b/tests/integration/tool_runtime/test_mcp_json_schema.py index 9c0bbcf0b..6be71caaf 100644 --- a/tests/integration/tool_runtime/test_mcp_json_schema.py +++ b/tests/integration/tool_runtime/test_mcp_json_schema.py @@ -120,7 +120,7 @@ class TestMCPSchemaPreservation: mcp_endpoint=dict(uri=uri), ) - # Phase 2: Use the dedicated authorization parameter + # Use the dedicated authorization parameter # List runtime tools response = llama_stack_client.tool_runtime.list_tools( tool_group_id=test_toolgroup_id, @@ -160,7 +160,7 @@ class TestMCPSchemaPreservation: mcp_endpoint=dict(uri=uri), ) - # Phase 2: Use the dedicated authorization parameter + # Use the dedicated authorization parameter # List tools response = llama_stack_client.tool_runtime.list_tools( tool_group_id=test_toolgroup_id, @@ -206,7 +206,7 @@ class TestMCPSchemaPreservation: mcp_endpoint=dict(uri=uri), ) - # Phase 2: Use the dedicated authorization parameter + # Use the dedicated authorization parameter response = llama_stack_client.tool_runtime.list_tools( tool_group_id=test_toolgroup_id, authorization=AUTH_TOKEN, @@ -249,8 +249,7 @@ class TestMCPToolInvocation: mcp_endpoint=dict(uri=uri), ) - # Phase 2: Use the dedicated authorization parameter - # List tools to populate the tool index + # Use the dedicated authorization parameter llama_stack_client.tool_runtime.list_tools( tool_group_id=test_toolgroup_id, authorization=AUTH_TOKEN, @@ -291,8 +290,7 @@ class TestMCPToolInvocation: mcp_endpoint=dict(uri=uri), ) - # Phase 2: Use the dedicated authorization parameter - # List tools to populate the tool index + # Use the dedicated authorization parameter llama_stack_client.tool_runtime.list_tools( tool_group_id=test_toolgroup_id, authorization=AUTH_TOKEN, @@ -343,9 +341,7 @@ class TestAgentWithMCPTools: mcp_endpoint=dict(uri=uri), ) - # Phase 2: Use the dedicated authorization parameter - # Note: tools.list() is the ToolGroups API and doesn't have authorization parameter - # Use tool_runtime.list_tools() instead + # Use the dedicated authorization parameter tools_list = llama_stack_client.tool_runtime.list_tools( tool_group_id=test_toolgroup_id, authorization=AUTH_TOKEN,