Skip to content

fix(test): adapt MCP integration test to rmcp Streamable HTTP protocol - #587

Merged
phodal merged 1 commit into
phodal:mainfrom
im47cn:fix/mcp-test-clean
Jul 29, 2026
Merged

fix(test): adapt MCP integration test to rmcp Streamable HTTP protocol#587
phodal merged 1 commit into
phodal:mainfrom
im47cn:fix/mcp-test-clean

Conversation

@im47cn

@im47cn im47cn commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

The /api/mcp endpoint migrated from plain JSON-RPC to rmcp's StreamableHttpService, which wraps responses in SSE framing and requires a proper session handshake. The integration test (test_rust_backend_api) was still sending bare JSON-RPC POSTs without a session ID, causing panics when serde_json::from_slice hit non-JSON response bodies.

Changes

  • Added mcp_request() helper that:
    • Sends proper initialize with protocolVersion, capabilities, and clientInfo
    • Captures mcp-session-id from the response header
    • Includes the session ID in subsequent requests
    • Sends notifications/initialized to complete the handshake
    • Parses both SSE (text/event-stream) and plain JSON responses
  • Updated all 15 /api/mcp test calls (Tests 20–46) to use the protocol-aware helper

Test plan

  • cargo test --test api_test passes (all 46 sub-tests)

Summary by CodeRabbit

  • Tests
    • Expanded API integration coverage for both standard JSON and server-sent event responses.
    • Added MCP session handling throughout initialization and tool requests.
    • Added coverage for EventBus, orchestration, and extended MCP tools.
    • Improved verification of available MCP tools and session-based request behavior.

The /api/mcp endpoint migrated from plain JSON-RPC to rmcp's
StreamableHttpService, which wraps responses in SSE framing and
requires a proper session handshake (initialize → capture session ID
→ notifications/initialized). The old test was sending bare JSON-RPC
POSTs without a session ID, causing panics on non-JSON response bodies.

Added mcp_request() helper that handles SSE parsing, session ID
extraction, and header injection. Updated all 15 /api/mcp test calls
(Tests 20-46) to use the new protocol-aware helper.

Co-authored-by: Crush (GLM 5.2) <crush@local>
@im47cn
im47cn requested a review from phodal as a code owner July 29, 2026 06:22
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

MCP API integration tests

Layer / File(s) Summary
Response parsing and MCP request helpers
apps/desktop/src-tauri/tests/api_test.rs
Shared helpers parse SSE-framed or plain JSON responses, set MCP headers, and extract session identifiers.
MCP handshake and session-scoped tools
apps/desktop/src-tauri/tests/api_test.rs
Tests establish and complete an MCP session, reuse it across tool calls, and verify the expanded tool list.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: phodal

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: updating the MCP integration test for the Streamable HTTP protocol.
Description check ✅ Passed The description covers the protocol migration, test changes, and validation, though the template's Notes section is missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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.

🧹 Nitpick comments (1)
apps/desktop/src-tauri/tests/api_test.rs (1)

437-993: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting a small helper for repeated tools/call boilerplate.

Every migrated tool-call site repeats the same jsonrpc/id/method: "tools/call"/params: {name, arguments} envelope plus Some(&mcp_session_id). A thin wrapper would remove this duplication across all ~15 sites and make future protocol changes (e.g., another header) a one-line edit.

♻️ Example helper
async fn mcp_tool_call(
    app: &axum::Router,
    session_id: &str,
    id: i64,
    name: &str,
    arguments: Value,
) -> (StatusCode, Value) {
    let (status, _, body) = mcp_request(
        app,
        serde_json::json!({
            "jsonrpc": "2.0",
            "id": id,
            "method": "tools/call",
            "params": { "name": name, "arguments": arguments }
        }),
        Some(session_id),
    )
    .await;
    (status, body)
}

This is purely cosmetic/maintainability; functionally the migration is correct.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/desktop/src-tauri/tests/api_test.rs` around lines 437 - 993, The
repeated MCP tools/call request envelope should be centralized in a small
helper. Add an async mcp_tool_call helper near the existing mcp_request utility,
accepting app, session ID, request ID, tool name, and arguments, then update the
migrated tools/call sites to use it while preserving their existing assertions
and response handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@apps/desktop/src-tauri/tests/api_test.rs`:
- Around line 437-993: The repeated MCP tools/call request envelope should be
centralized in a small helper. Add an async mcp_tool_call helper near the
existing mcp_request utility, accepting app, session ID, request ID, tool name,
and arguments, then update the migrated tools/call sites to use it while
preserving their existing assertions and response handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c70cb3f3-cf11-4acd-9dca-d4d552c84842

📥 Commits

Reviewing files that changed from the base of the PR and between 9c880e7 and 2fc5c80.

📒 Files selected for processing (1)
  • apps/desktop/src-tauri/tests/api_test.rs

@phodal
phodal merged commit f60b479 into phodal:main Jul 29, 2026
25 checks passed
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