Skip to content

[FEATURE]: Port MCP plugin context sharing to the Rust MCP runtime #4119

@lucarlig

Description

@lucarlig

🧭 Type of Feature

Please select the most appropriate category:

  • Enhancement to existing functionality
  • New feature or capability
  • New MCP-compliant server
  • New component or integration
  • Developer tooling or test improvement
  • Packaging, automation and deployment (ex: pypi, docker, quay.io, kubernetes, terraform)
  • Other (please describe below)

🧭 Epic

Title: Preserve plugin cross-hook context on Rust-owned /mcp tool calls
Goal: Make the Rust MCP runtime preserve the same plugin state continuity that the Python streamable HTTP path is adding in PR #3915.
Why now: The Python fix allows data written during HTTP_PRE_REQUEST to be available during TOOL_PRE_INVOKE on /mcp. The Rust runtime currently preserves auth context, but not plugin_context_table or plugin_global_context, so behavior diverges between Python-owned and Rust-owned MCP paths.


🧑🏻‍💻 User Story 1

As a: plugin author
I want: state written in HTTP_PRE_REQUEST to be available in TOOL_PRE_INVOKE for Rust-owned /mcp requests
So that: plugins behave the same on Python and Rust MCP runtimes

✅ Acceptance Criteria

Scenario: Rust /mcp request preserves plugin context into tool pre-invoke hooks
  Given a plugin stores data in plugin-local or global context during HTTP_PRE_REQUEST
  When a client sends a tools/call request through the Rust-owned /mcp runtime
  Then TOOL_PRE_INVOKE can read the same context values
  And the tool execution sees the same plugin-modified behavior as the Python path

Scenario: Rust resolve and fallback paths share the same plugin context
  Given the Rust runtime resolves a tools/call plan through Python
  When the request falls back to Python execution after resolve
  Then TOOL_PRE_INVOKE is not re-run with missing or inconsistent context
  And plugin-visible behavior remains consistent with the direct Python /mcp path

🧑🏻‍💻 User Story 2

As a: platform maintainer
I want: Rust internal MCP forwarding to preserve plugin request lifecycle state safely
So that: enabling the Rust MCP runtime does not break plugins that rely on cross-hook context sharing

✅ Acceptance Criteria

Scenario: Rust runtime transports only trusted plugin lifecycle context
  Given a public MCP request enters through the Rust runtime
  When Python performs HTTP_PRE_REQUEST processing and authentication
  Then any context forwarded back into later trusted internal Rust-to-Python calls is derived from server-side state
  And clients cannot inject or spoof that context through public request headers

Scenario: Regression coverage exists for Python/Rust parity
  Given automated tests for the Rust MCP runtime and trusted internal MCP endpoints
  When plugin context sharing behavior changes
  Then tests fail if Rust-owned /mcp diverges from Python-owned /mcp for HTTP_PRE_REQUEST to TOOL_PRE_INVOKE continuity

📐 Design Sketch (optional)

flowchart TD
    A[Client POST /mcp] --> B[Rust MCP runtime]
    B --> C[Python internal authenticate]
    C --> D[HTTP_PRE_REQUEST hooks]
    D --> E[Trusted internal context handoff]
    E --> F[Python tools/call resolve or execute]
    F --> G[TOOL_PRE_INVOKE hooks]
Loading

🔗 MCP Standards Check

  • Change adheres to current MCP specifications
  • No breaking changes to existing MCP-compliant integrations
  • If deviations exist, please describe them below:

🔄 Alternatives Considered

  • Leave the gap as-is and accept different plugin behavior between Python and Rust /mcp paths. Rejected because it makes Rust enablement behaviorally unsafe for plugins that depend on cross-hook state.
  • Re-run hook logic independently in the Rust path without shared context. Rejected because it does not preserve plugin-local state and risks double-running hook side effects.
  • Limit support to auth-context reuse only. Rejected because PR fix/3879-mcp-plugin-context-sharing #3915 shows plugin context continuity is required beyond auth data.

📓 Additional Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestrustRust programmingtriageIssues / Features awaiting triage

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions