Skip to content

test(mcp): pin GET/DELETE on /mcp as 405, behind authentication - #994

Open
moonming wants to merge 1 commit into
mainfrom
test/991-mcp-405
Open

test(mcp): pin GET/DELETE on /mcp as 405, behind authentication#994
moonming wants to merge 1 commit into
mainfrom
test/991-mcp-405

Conversation

@moonming

@moonming moonming commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Closes #991.

What

/mcp serves POST only — GET (the SSE stream a stateful server would offer) and DELETE (session teardown) return 405. The docs state it, but no test in this repo pinned it: the behavior came from the vendored SDK's dispatch arm under legacy_session_mode = false + no event store, so an SDK upgrade that started serving either verb by default would have changed the endpoint's wire surface with nothing going red.

Two layers, matching where each guarantee actually lives:

  • crates/aisix-mcp/tests/protocol_generations.rs — the gateway service answers 405 for both verbs. Revert-checked: flipping legacy_session_mode to true fails it.
  • crates/aisix-proxy/src/mcp.rs — the ordering. An anonymous GET/DELETE is 401; only an authenticated one reaches 405, so the endpoint doesn't disclose which paths exist to an unauthenticated caller.

Verification

cargo test -p aisix-mcp -p aisix-proxy green; both new tests confirmed to fail when the behavior they pin is reverted.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of unsupported GET and DELETE requests to the MCP endpoint.
    • Unauthenticated requests now correctly return an authorization error before method validation.
  • Tests

    • Added regression coverage for sessionless and authenticated MCP request handling.

The sessionless posture means only POST carries MCP protocol messages,
but nothing in this repo asserted it — the guarantee rested on the
vendored SDK's dispatch arm, so an upgrade that started serving GET
(SSE streams) or DELETE (session teardown) by default would have
changed the wire surface silently.

Two layers: the gateway service answers 405 for both verbs (flipping
legacy_session_mode fails it), and the proxy pins the ordering —
anonymous GET/DELETE is 401, authenticated is 405, so the endpoint
never reveals which paths exist to an unauthenticated caller.
Copilot AI lite review requested due to automatic review settings August 19, 2026 07:13
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c2ad1d2c-52ec-48b3-af84-407c043f95e6

📥 Commits

Reviewing files that changed from the base of the PR and between 7a9fc86 and f226356.

📒 Files selected for processing (2)
  • crates/aisix-mcp/tests/protocol_generations.rs
  • crates/aisix-proxy/src/mcp.rs

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The pull request adds regression coverage for GET and DELETE requests to the sessionless /mcp endpoint. Tests verify 405 Method Not Allowed responses and confirm that authentication occurs before method handling.

Changes

MCP method handling

Layer / File(s) Summary
Endpoint method contract
crates/aisix-mcp/tests/protocol_generations.rs, crates/aisix-proxy/src/mcp.rs
Tests verify that sessionless GET and DELETE requests return 405. Proxy tests verify that unauthenticated requests return 401 before authenticated requests reach method handling and return 405.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to f2263

This PR adds localized regression coverage for authenticated and unauthenticated /mcp method handling; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: jarvis9443, membphis

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes tests that pin GET and DELETE behavior on the authenticated /mcp endpoint.
Linked Issues check ✅ Passed The tests cover authenticated GET and DELETE responses of 405 and unauthenticated responses of 401 as required by issue #991.
Out of Scope Changes check ✅ Passed The changes add only focused regression tests for the sessionless /mcp endpoint behavior described in issue #991.
E2e Test Quality Review ✅ Passed Both tests are focused and readable: one drives a real TCP gateway, and the proxy test drives build_router through auth and MCP dispatch, asserting 401/405 for both methods.
Security Check ✅ Passed The diff adds only two tests (+26/+45); no production handlers, persistence, logging, TLS, ownership, or secret-resolution code changed, and the test token is an existing fixture.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/991-mcp-405

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copilot AI 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.

Pull request overview

This PR adds regression tests to pin the /mcp endpoint’s intended HTTP-method surface: POST only, with GET/DELETE returning 405, and ensures the proxy’s authentication runs before method handling so unauthenticated callers see 401 rather than learning method availability.

Changes:

  • Added an aisix-mcp integration test that asserts GET /mcp and DELETE /mcp return 405 for the sessionless Streamable HTTP service configuration.
  • Added an aisix-proxy test that asserts GET/DELETE are rejected as 401 when anonymous, and as 405 only after a valid Authorization header is provided.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/aisix-proxy/src/mcp.rs Adds a proxy-level test pinning auth-before-method behavior for GET/DELETE on /mcp (401 anonymous, 405 authenticated).
crates/aisix-mcp/tests/protocol_generations.rs Adds a gateway-level test pinning GET/DELETE on /mcp to 405 for the sessionless serving posture.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

test: pin authenticated GET/DELETE on /mcp returning 405

2 participants