Skip to content

feat(anthropic): add X-SMG-MCP header for MCP passthrough - #517

Merged
key4ng merged 11 commits into
mainfrom
keyang/ant-passthru
Feb 24, 2026
Merged

key4ng merged 11 commits into
mainfrom
keyang/ant-passthru

Conversation

@key4ng

@key4ng key4ng commented Feb 23, 2026 •

Copy link
Copy Markdown
Member

Description

Problem

SMG automatically intercepts and handles MCP orchestration whenever mcp_toolset tools are present in the Anthropic Messages API request body. There is no way for clients to pass MCP fields (mcp_servers, mcp_toolset) through to the Anthropic backend for native handling via anthropic-beta: mcp-client-2025-11-20

Solution

Introduce a X-SMG-MCP header to control MCP behavior. When present, SMG handles MCP orchestration (existing behavior). When absent, the request passes through to the Anthropic backend untouched, enabling Anthropic's native MCP support.

Changes

  • model_gateway/src/routers/anthropic/router.rs: Gate MCP interception on the X-SMG-MCP header — only enter the MCP server connection path when the header is present
  • protocols/src/messages.rs: Add server_type field (serde-renamed to type, defaults to "url") to McpServerConfig so the required type field round-trips through serialization
  • e2e_test/messages/test_mcp_tool.py: Add x-smg-mcp: enabled to existing SMG-orchestrated tests; add passthrough E2E tests (streaming and non-streaming) using the public DMCP dice-rolling server

Test Plan

Checklist
  • cargo +nightly fmt passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • (Optional) Documentation updated

Summary by CodeRabbit

  • New Features

    • MCP server configs now include a server-type setting (defaults to "url").
    • MCP activation is now gated by an x-smg-mcp request header so MCP behavior runs only when explicitly enabled.
  • Tests

    • MCP tests reorganized into shared configurations covering handled and passthrough modes.
    • Added helpers to validate streaming and non-streaming MCP responses and simplified test flows.
  • Chores

    • Added pytest marker for external-service tests.

@coderabbitai

coderabbitai Bot commented Feb 23, 2026 •

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Replaces ad-hoc MCP e2e test scaffolding with data-driven McpTestConfig-based tests (SMG-handled and passthrough modes); adds x-smg-mcp header detection and gates MCP server construction in the Anthropic router on that header plus presence of an MCP toolset; adds server_type (serde name "type", default "url") to McpServerConfig.

Changes

Cohort / File(s) Summary
MCP Test Infrastructure
e2e_test/messages/test_mcp_tool.py
Introduce McpTestConfig, SMG_HANDLED / PASSTHROUGH configs, _extra_body(cfg), streaming collectors/assertions, consolidate tests into TestMcpTool and TestMcpToolPassthrough with non-streaming and streaming variants; remove hard-coded per-test values.
Anthropic Router & Header Utils
model_gateway/src/routers/header_utils.rs, model_gateway/src/routers/anthropic/router.rs
Add HEADER_MCP and is_smg_mcp_enabled(...); Anthropic router now builds MCP servers only when x-smg-mcp header indicates enabled AND an MCP toolset is present.
MCP Protocol Definition
protocols/src/messages.rs
Add public server_type: String to McpServerConfig (serde rename "type") with default_type() returning "url" used as the default.
Test config
e2e_test/pyproject.toml
Add pytest marker external for tests depending on external services.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant AnthropicRouter
    participant MCP_Server
    participant UpstreamModel

    Client->>AnthropicRouter: POST request (may include `x-smg-mcp` header + MCP toolset)
    alt header == "enabled" AND MCP toolset present
        AnthropicRouter->>MCP_Server: construct MCP server (config includes "type":"url")
        AnthropicRouter->>UpstreamModel: forward request referencing MCP_Server
        UpstreamModel-->>AnthropicRouter: model response / stream
        MCP_Server-->>AnthropicRouter: MCP events/responses (streaming or non-streaming)
        AnthropicRouter-->>Client: aggregated response/events
    else header missing/disabled OR no MCP toolset
        AnthropicRouter->>UpstreamModel: forward request without MCP servers
        UpstreamModel-->>AnthropicRouter: model response
        AnthropicRouter-->>Client: model response
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

mcp

Suggested reviewers

  • CatherineSue
  • XinyueZhang369

Poem

🐇 I hopped through headers, tests, and type,
I nudged the flow to choose when MCP’s ripe,
Two modes now twirl — handled and passed through,
Streams and asserts tidy the view,
A carrot-coded cheer — hops for the crew!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 78.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: introducing an X-SMG-MCP header for MCP passthrough control, which is reflected in code changes across router, protocols, and test files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch keyang/ant-passthru

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @key4ng, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the MCP (Multi-Cloud Proxy) passthrough functionality by introducing support for the 'X-SMG-MCP' header, which dictates whether the SMG intercepts or forwards MCP fields to the Anthropic backend. To validate this behavior, new end-to-end tests have been implemented for both non-streaming and streaming request scenarios.

Highlights

  • X-SMG-MCP Header Support: Implemented logic to recognize and utilize the 'x-smg-mcp' header to determine whether the Service Mesh Gateway (SMG) should intercept and process MCP fields or forward them directly to the Anthropic backend.
  • Non-Streaming Passthrough Test: Added a new test suite to verify correct MCP passthrough behavior in non-streaming requests when the 'x-smg-mcp' header is absent, ensuring Anthropic handles MCP orchestration natively.
  • Streaming Passthrough Test: Introduced a new test suite to confirm proper MCP passthrough functionality for streaming requests, validating that Anthropic handles MCP orchestration natively via Server-Sent Events (SSE) when the 'x-smg-mcp' header is not present.
  • Header Configuration Update: Updated the 'MCP_EXTRA_HEADERS' configuration in the test environment to include the 'x-smg-mcp' header, enabling testing of SMG interception.
Changelog
  • e2e_test/messages/test_mcp_tool.py
    • Added the 'x-smg-mcp' header with 'enabled' value to MCP_EXTRA_HEADERS.
    • Introduced TestMcpPassthroughNonStream class to test non-streaming MCP passthrough.
    • Added test_mcp_passthrough_non_streaming method to verify native Anthropic MCP handling.
    • Created TestMcpPassthroughStream class for streaming MCP passthrough tests.
    • Implemented test_mcp_passthrough_streaming method to validate streaming MCP passthrough via SSE.
  • model_gateway/src/routers/anthropic/router.rs
    • Modified the MCP server logic to conditionally process mcp_toolset based on the presence of the x-smg-mcp header.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@github-actions github-actions Bot added tests Test changes model-gateway Model gateway crate changes anthropic Anthropic router changes labels Feb 23, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the MCP functionality by making it opt-in via an x-smg-mcp header. When the header is absent, MCP-related fields are passed through to the Anthropic backend. The changes in the Rust router correctly implement this conditional logic. The PR also adds comprehensive e2e tests for both streaming and non-streaming passthrough scenarios. While the new tests are functionally correct and provide good coverage, they introduce significant code duplication with existing tests. I've left a comment suggesting a refactor to improve maintainability.

Comment thread e2e_test/messages/test_mcp_tool.py Outdated
@github-actions github-actions Bot added the protocols Protocols crate changes label Feb 23, 2026
@key4ng key4ng changed the title Enhance MCP passthrough functionality by adding support for X-SMG-MCP… feat(anthropic): add X-SMG-MCP header for MCP passthrough Feb 24, 2026
@key4ng
key4ng marked this pull request as ready for review February 24, 2026 02:51
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
model_gateway/src/routers/anthropic/router.rs (2)

128-138: 🧹 Nitpick | 🔵 Trivial

Add a log when an MCP-toolset request enters passthrough mode

When smg_mcp_enabled is false but the request has mcp_toolset tools, the existing info! at line 133 logs mcp = false with no distinction from a plain non-MCP request. A brief log in the else branch would make passthrough-mode routing visible in production traces.

💬 Suggested addition
         } else {
+            if request.has_mcp_toolset() {
+                info!("MCP: x-smg-mcp header absent; forwarding mcp_toolset request to Anthropic backend");
+            }
             None
         };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@model_gateway/src/routers/anthropic/router.rs` around lines 128 - 138, Add an
explicit log when a request with mcp_toolset tools is routed in passthrough
mode: inside the branch where smg_mcp_enabled is false but request.mcp_toolset
is present, emit an info! log (similar to the existing info! that logs model,
streaming, mcp) indicating that the request is entering MCP passthrough mode;
reference the same context variables (model_id, is_streaming,
request.mcp_toolset, and mcp_servers) so the log appears alongside the existing
"Processing Messages API request" entry and makes passthrough routing visible in
production traces.

128-138: 🧹 Nitpick | 🔵 Trivial

No log when an MCP-toolset request is entering passthrough mode

When smg_mcp_enabled is false and the request carries mcp_toolset tools, the existing info! at line 133 only reports mcp = false — indistinguishable from a plain non-MCP request. Adding a trace-level log in the else branch would make passthrough routing visible in production traces without adding noise to the happy path.

💬 Suggested addition
         } else {
+            if request.has_mcp_toolset() {
+                info!("MCP passthrough: x-smg-mcp header absent, forwarding mcp_toolset request to Anthropic backend");
+            }
             None
         };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@model_gateway/src/routers/anthropic/router.rs` around lines 128 - 138, The
info! currently logs mcp = false and thus hides when an MCP-toolset request is
being routed in passthrough mode; update the code so that when smg_mcp_enabled
is false but the incoming request contains mcp_toolset (i.e. the branch that
sets mcp_servers to None), emit a trace!-level log indicating "MCP toolset
detected; entering passthrough mode" (or similar) including model_id and whether
request.stream (is_streaming) to make passthrough routing visible; keep the
existing info! block unchanged and add the trace! call in the else branch that
sets mcp_servers = None so it only fires for passthrough cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@e2e_test/messages/test_mcp_tool.py`:
- Around line 39-47: SMG_HANDLED McpTestConfig currently defaults server_url to
localhost so tests like test_mcp_non_streaming and test_mcp_streaming try to
connect in CI; update the test parametrization to skip the SMG_HANDLED path when
no external MCP server is intended by wrapping that param with
pytest.mark.skipif(not os.environ.get("MCP_SERVER_URL"), reason="MCP_SERVER_URL
not set") or change SMG_HANDLED to set
server_url=os.environ.get("MCP_SERVER_URL") (no default) and add a
pytest.skip/skipif guard in the parametrize or test so both
test_mcp_non_streaming and test_mcp_streaming will be skipped unless
MCP_SERVER_URL is provided.
- Around line 39-47: SMG_HANDLED currently defaults server_url to localhost so
tests fail when the local MCP server is down; add a skip guard: define a
module-level _smg_server_available (e.g., bool(os.environ.get("MCP_SERVER_URL"))
or a light connectivity check) alongside the McpTestConfig definitions, then
apply pytest.mark.skipif(not _smg_server_available and mcp_mode ==
"smg_handled", reason="MCP_SERVER_URL not set; skipping smg_handled tests") to
the test class or the parametrized test functions that use SMG_HANDLED so
smg_handled variants are cleanly skipped when the server is unavailable.
- Around line 50-55: The PASSTHROUGH McpTestConfig currently points to an
external uncontrolled server_url ("https://dmcp-server.deno.dev/sse"), causing
flaky CI; update tests using PASSTHROUGH to not call that external endpoint by
default: either add a custom pytest marker (e.g., `@pytest.mark.external`) to all
tests parametrized with PASSTHROUGH and configure pytest.ini to exclude that
marker in CI, or replace PASSTHROUGH.server_url with a locally hosted/test
fixture SSE MCP endpoint (or a mock SSE server) and wire the fixture into the
test harness so CI runs deterministically; update references to PASSTHROUGH and
any test parametrization so the external calls are only run when the marker is
explicitly requested.
- Around line 50-55: The PASSTHROUGH McpTestConfig uses a public server_url
("https://dmcp-server.deno.dev/sse") which introduces flaky CI failures; update
the test to avoid calling that external service by marking PASSTHROUGH with a
skip/marker (e.g., add `@pytest.mark.skipif` or `@pytest.mark.external` on the
parametrized variant that references PASSTHROUGH) driven by an environment flag
(e.g., RUN_EXTERNAL_TESTS) so it is excluded in default CI, or replace
PASSTHROUGH with a local DMCP test fixture endpoint under test control (create a
local/mock server used by the same PASSTHROUGH symbol) and ensure the test
harness/CI config excludes or enables the external marker accordingly.

In `@model_gateway/src/routers/anthropic/router.rs`:
- Line 91: smg_mcp_enabled is currently a presence-only check using
headers.and_then(|h| h.get("x-smg-mcp")).is_some(); add an inline comment next
to the smg_mcp_enabled declaration (referencing the smg_mcp_enabled variable and
the get("x-smg-mcp") call) that explicitly states this header is treated as a
presence flag (any value, including "false"/"disabled", enables SMG MCP) and, if
you want value-based behavior instead, suggest parsing the header value (e.g.,
checking for "true"/"1"/"enabled") rather than is_some().
- Line 91: The current check (let smg_mcp_enabled = headers.and_then(|h|
h.get("x-smg-mcp")).is_some();) treats any presence of the header as enabling
SMG MCP (so values like "false" or "disabled" still enable it); fix this by
reading and normalizing the header value instead of only testing presence:
replace the expression using headers.and_then(|h| h.get("x-smg-mcp")) to extract
a string (to_str().ok()), lowercase it, and match against an explicit allow-list
(e.g., "1","true","enabled","on") to set smg_mcp_enabled = true, treat known
deny values ("0","false","disabled","off","") as false, and default to false on
parse errors; alternatively, if presence-only semantics are intentional, add a
clear inline comment above the smg_mcp_enabled binding documenting that any
presence (regardless of value) enables SMG orchestration.

---

Outside diff comments:
In `@model_gateway/src/routers/anthropic/router.rs`:
- Around line 128-138: Add an explicit log when a request with mcp_toolset tools
is routed in passthrough mode: inside the branch where smg_mcp_enabled is false
but request.mcp_toolset is present, emit an info! log (similar to the existing
info! that logs model, streaming, mcp) indicating that the request is entering
MCP passthrough mode; reference the same context variables (model_id,
is_streaming, request.mcp_toolset, and mcp_servers) so the log appears alongside
the existing "Processing Messages API request" entry and makes passthrough
routing visible in production traces.
- Around line 128-138: The info! currently logs mcp = false and thus hides when
an MCP-toolset request is being routed in passthrough mode; update the code so
that when smg_mcp_enabled is false but the incoming request contains mcp_toolset
(i.e. the branch that sets mcp_servers to None), emit a trace!-level log
indicating "MCP toolset detected; entering passthrough mode" (or similar)
including model_id and whether request.stream (is_streaming) to make passthrough
routing visible; keep the existing info! block unchanged and add the trace! call
in the else branch that sets mcp_servers = None so it only fires for passthrough
cases.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbbb99b and 72bc266.

📒 Files selected for processing (3)
  • e2e_test/messages/test_mcp_tool.py
  • model_gateway/src/routers/anthropic/router.rs
  • protocols/src/messages.rs

Comment thread e2e_test/messages/test_mcp_tool.py
Comment thread e2e_test/messages/test_mcp_tool.py
Comment thread model_gateway/src/routers/anthropic/router.rs Outdated
Comment thread model_gateway/src/routers/anthropic/router.rs Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@model_gateway/src/routers/anthropic/router.rs`:
- Around line 91-96: The header-check for x-smg-mcp (building smg_mcp_enabled)
is case- and whitespace-sensitive; normalize the header value before matching by
converting to lowercase and trimming whitespace so values like "True", " enabled
", or "1" still enable MCP. Locate the smg_mcp_enabled computation (the headers
-> and_then -> to_str().ok() chain) and replace the predicate with a
normalization step (trim and to_ascii_lowercase) and then match against
"enabled" | "true" | "1"; keep the existing conditional that checks
request.has_mcp_toolset() and only enable mcp_servers when both are true.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72bc266 and acde317.

📒 Files selected for processing (1)
  • model_gateway/src/routers/anthropic/router.rs

Comment thread model_gateway/src/routers/anthropic/router.rs Outdated
… header and implementing non-streaming and streaming tests. Update MCP_EXTRA_HEADERS to include "x-smg-mcp" and validate tool usage in both test scenarios.

Signed-off-by: key4ng <rukeyang@gmail.com>
…t value "url"

This update introduces a new field, server_type, to the McpServerConfig struct, ensuring it defaults to "url". This enhancement improves the configuration clarity for MCP server types.

Signed-off-by: [Your Name] [Your Email]
Signed-off-by: key4ng <rukeyang@gmail.com>
…larity

This update simplifies the assertion statements in the MCP passthrough tests by removing unnecessary line breaks, enhancing readability without altering functionality.

Signed-off-by: key4ng <rukeyang@gmail.com>
This update refactors the MCP tool test suite by introducing a new McpTestConfig dataclass for better configuration management. It also streamlines the assertion logic for non-streaming responses, improving clarity and maintainability. The documentation has been updated to reflect the changes in server handling modes.

Signed-off-by: key4ng <rukeyang@gmail.com>
This update refines the MCP tool test assertions by consolidating multiline statements into single lines for improved readability. The changes enhance the clarity of the assertions without affecting the functionality of the tests.

Signed-off-by: key4ng <rukeyang@gmail.com>
This update improves the handling of the X-SMG-MCP header by ensuring it checks for specific string values ("enabled", "true", "1") after converting the header value to a string. This change enhances the clarity and robustness of the MCP toolset request validation.

Signed-off-by: key4ng <rukeyang@gmail.com>
…lidation

Signed-off-by: key4ng <rukeyang@gmail.com>
@key4ng
key4ng force-pushed the keyang/ant-passthru branch from f3eab1c to 512ede5 Compare February 24, 2026 06:18
This update simplifies the MCP server handling logic by directly integrating the check for the X-SMG-MCP header within the conditional statement. This change enhances code clarity and maintains the functionality of the MCP toolset request validation.

Signed-off-by: key4ng <rukeyang@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
model_gateway/src/routers/header_utils.rs (1)

228-305: 🧹 Nitpick | 🔵 Trivial

Missing unit tests for is_smg_mcp_enabled.

The test module covers extract_routing_key, extract_target_worker, and should_forward_request_header thoroughly, but is_smg_mcp_enabled has no test coverage. Consider adding tests for the accepted values, rejected values (e.g., "false", "disabled", empty string), None headers, and missing header.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@model_gateway/src/routers/header_utils.rs` around lines 228 - 305, Add unit
tests for is_smg_mcp_enabled: create tests that pass a HeaderMap with
"x-smg-mcp-enabled" set to accepted true-like values (e.g.,
"true","1","enabled") and assert Some(true), tests with rejected values
("false","disabled","", "0") assert Some(false), a test with the header absent
and with None headers asserting None; reference the function is_smg_mcp_enabled
to locate where to call it and mirror the style of existing tests (using
HeaderMap::new(), headers.insert(... .parse().unwrap()), and assert_eq!).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@model_gateway/src/routers/header_utils.rs`:
- Around line 27-34: The check in is_smg_mcp_enabled incorrectly uses matches!
for exact, case-sensitive matching; change the final predicate to perform ASCII
case-insensitive comparisons on the header string (use
v.eq_ignore_ascii_case("enabled") || v.eq_ignore_ascii_case("true") ||
v.eq_ignore_ascii_case("1")) while keeping the existing header extraction via
headers.and_then(|h| h.get(&HEADER_MCP)).and_then(|v|
v.to_str().ok()).is_some_and(...) so the function uses eq_ignore_ascii_case
against HEADER_MCP's value.

---

Outside diff comments:
In `@model_gateway/src/routers/header_utils.rs`:
- Around line 228-305: Add unit tests for is_smg_mcp_enabled: create tests that
pass a HeaderMap with "x-smg-mcp-enabled" set to accepted true-like values
(e.g., "true","1","enabled") and assert Some(true), tests with rejected values
("false","disabled","", "0") assert Some(false), a test with the header absent
and with None headers asserting None; reference the function is_smg_mcp_enabled
to locate where to call it and mirror the style of existing tests (using
HeaderMap::new(), headers.insert(... .parse().unwrap()), and assert_eq!).

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between acde317 and 677ed92.

📒 Files selected for processing (4)
  • e2e_test/messages/test_mcp_tool.py
  • model_gateway/src/routers/anthropic/router.rs
  • model_gateway/src/routers/header_utils.rs
  • protocols/src/messages.rs

Comment thread model_gateway/src/routers/header_utils.rs Outdated
…or 'enabled' header value

This change modifies the is_smg_mcp_enabled function to specifically check for the 'enabled' value in the X-SMG-MCP header, simplifying the validation logic and improving clarity.

Signed-off-by: key4ng <rukeyang@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@model_gateway/src/routers/header_utils.rs`:
- Around line 27-33: Add unit tests for the public function is_smg_mcp_enabled
to match coverage of the other public helpers (extract_routing_key,
extract_target_worker, should_forward_request_header): create tests that assert
true when the header X-SMG-MCP is present with values "enabled" in different
casings (e.g., "ENABLED", "Enabled"), and assert false for missing header, empty
value, and other values (e.g., "disabled"). Place tests in the same test module
pattern used for the other functions in header_utils.rs and use HeaderMap to
construct headers to exercise Option<&HeaderMap> inputs and ensure behavior
matches existing helpers.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 677ed92 and 287b34f.

📒 Files selected for processing (1)
  • model_gateway/src/routers/header_utils.rs

Comment thread model_gateway/src/routers/header_utils.rs
…er and simplify configurations

This update introduces a new test marker for external dependencies in the MCP tool tests, allowing for better categorization of tests that require third-party services. Additionally, the configuration management is simplified by removing the unnecessary MCP_CONFIGS dictionary, streamlining the test setup for both SMG-handled and passthrough modes.

Signed-off-by: key4ng <rukeyang@gmail.com>
@github-actions github-actions Bot added the dependencies Dependency updates label Feb 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@e2e_test/messages/test_mcp_tool.py`:
- Around line 116-177: The test currently silently skips empty reassembled JSON
in assert_streaming_mcp_response (variable full_json built from
input_json_deltas_by_index) which can hide dropped fragments; update
assert_streaming_mcp_response to log a warning when full_json == "" (include idx
and the fragments list from input_json_deltas_by_index[idx]) so empty inputs are
visible during debugging while still allowing legitimate empty tool inputs;
locate this in assert_streaming_mcp_response (and use the module logger already
used at the end) and emit logger.warning with clear context instead of silently
continuing.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 287b34f and 54ae4bf.

📒 Files selected for processing (2)
  • e2e_test/messages/test_mcp_tool.py
  • e2e_test/pyproject.toml

Comment thread e2e_test/messages/test_mcp_tool.py
…Rust CI workflow

This update introduces a test filter in the Rust CI workflow to exclude tests marked as external, enhancing the focus on internal test execution. This change aims to streamline the testing process and improve efficiency in the CI pipeline.

Signed-off-by: key4ng <rukeyang@gmail.com>
@github-actions github-actions Bot added the ci CI/CD configuration changes label Feb 24, 2026
@key4ng
key4ng merged commit 324f4d3 into main Feb 24, 2026
24 checks passed
@key4ng
key4ng deleted the keyang/ant-passthru branch February 24, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

anthropic Anthropic router changes ci CI/CD configuration changes dependencies Dependency updates model-gateway Model gateway crate changes protocols Protocols crate changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants