Skip to content

[FEATURE]: Forward request-scoped MCP _meta from incoming opencode requests to downstream MCP tool calls #16828

Closed as not planned

Description

@Rajmehta123

Issue Summary

When opencode invokes downstream MCP tools, it appears not to forward request-scoped _meta metadata received from upstream clients.

This breaks a common Model Context Protocol (MCP) pattern where hidden runtime context is passed through _meta and propagated unchanged across tool calls.

Typical flow:

UI → opencode → downstream MCP server

The UI may attach contextual metadata in _meta, such as:

  • documentId
  • containerId
  • workspaceId
  • session/auth context
  • tracing information

However, when opencode calls a downstream tool, this metadata is not preserved, causing the downstream MCP server to lose important request context.


MCP Design Pattern

MCP intentionally separates tool inputs from runtime metadata:

Field Purpose
arguments Inputs the model reasons about
_meta Hidden runtime/application context

This enables:

  • keeping sensitive IDs hidden from the LLM
  • preventing the model from inventing internal IDs
  • passing workspace/session context
  • propagating distributed tracing data
  • sending runtime hints to tools

Downstream MCP servers may use or ignore _meta safely.


Expected Behavior

If _meta is included in an incoming request to opencode:

  1. opencode captures _meta
  2. _meta is stored in request-scoped context
  3. all downstream tools/call requests forward the same _meta

Key properties:

  • _meta remains optional
  • existing behavior unchanged if _meta is absent
  • tool arguments remain separate from metadata

Example

Incoming request (UI → opencode)

{
  "method": "tools/call",
  "params": {
    "name": "docuai_agent_tool",
    "arguments": {
      "user_request": {
        "user_input": "Translate this document to French"
      }
    },
    "_meta": {
      "com.example/documentId": "doc_123",
      "com.example/containerId": "cont_456"
    }
  }
}

Expected downstream call (opencode → MCP server)

{
  "method": "tools/call",
  "params": {
    "name": "translate_document_preserving_structure",
    "arguments": {
      "destinationLanguageThreeLetterCode": "fra"
    },
    "_meta": {
      "com.example/documentId": "doc_123",
      "com.example/containerId": "cont_456"
    }
  }
}

FastMCP Compatibility

FastMCP servers already support accessing metadata through:

ctx.request_context.meta

So the missing piece appears to be client-side propagation in opencode, not server support.


Requested Change

Add request-scoped _meta propagation in opencode so that:

  • _meta from upstream requests is captured
  • it persists through the agent execution lifecycle
  • it is forwarded in all downstream tools/call requests

Why This Matters

Forwarding _meta enables reliable context propagation for:

  • document identifiers
  • workspace/container context
  • session/auth hints
  • distributed tracing

while keeping this data hidden from the LLM-visible tool schema.

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 10, 2026
  2. github-actions commented on Mar 10, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • The issue appears to be AI-generated. It contains an extremely long, over-structured description with multiple elaborate sections, JSON examples, tables, and even ends with an offer to produce a shorter version — a clear sign of AI-generated content. We do not accept AI-generated walls of text as issue reports.
    • This is filed as a bug but describes a feature/enhancement request. If this is a feature request, the title should start with [FEATURE]: and the feature request template should be used.
    • Steps to reproduce is empty. Bug reports must include reproduction steps or at minimum some context demonstrating the behavior exists.
    • The OS field lists "macOS 26.0.1" which does not exist, suggesting the content was not carefully reviewed before submission.

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.

    If you believe this was flagged incorrectly, please let a maintainer know.

  3. changed the title [-]Forward request-scoped MCP _meta from incoming opencode requests to downstream MCP tool calls[/-] [+][FEATURE]: Forward request-scoped MCP _meta from incoming opencode requests to downstream MCP tool calls[/+] on Mar 10, 2026
  4. github-actions commented on Mar 10, 2026

    @github-actions
    Contributor

    Thank you for updating the title to use the [FEATURE]: prefix. However, this issue is still not compliant.

    What still needs to be fixed:

    • AI-generated wall of text: The description is an extremely long, over-structured document with elaborate section headers, multiple JSON examples, tables, repeated explanations of the same concept, and formal acceptance criteria. This is not acceptable. The note at the very end of the issue — offering to produce "a much shorter maintainer-friendly GitHub issue (~200 words)" — directly confirms this was AI-generated and not carefully reviewed before submission.

    Please rewrite the issue in your own words, briefly and clearly. A short description (2–5 sentences) explaining what the problem is, what you expected, and what you observed is all that is needed. The ~200-word version you mentioned would be far more appropriate.

  5. github-actions commented on Mar 10, 2026

    @github-actions
    Contributor

    Thank you for updating the title to use the [FEATURE]: prefix. However, this issue is still not compliant.

    What still needs to be fixed:

    • AI-generated wall of text: The description body has not been rewritten. It remains an extremely long, over-structured document with elaborate section headers, multiple JSON examples, tables, and repeated explanations of the same concept. The note at the very end offering to produce "a much shorter maintainer-friendly GitHub issue (~200 words)" is still present and directly confirms this was AI-generated content that was not reviewed or rewritten before submission.

    Please rewrite the issue body in your own words. A short description of 2–5 sentences explaining what the problem is, what you expected, and what you observed is all that is needed. The ~200-word version you mentioned would be far more appropriate.

  6. Rajmehta123 commented on Mar 10, 2026

    @Rajmehta123
    Author

    @thdxr @palmamartin @vvarp @ndarilek Thank you for this amazing repo. Recommendation appreciated. I believe the summary of the feature is important to understand why _meta which is a standard in MCP metadata injection and how it can help in opencode

  7. github-actions commented on Mar 10, 2026

    @github-actions
    Contributor

    This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

    Feel free to open a new issue that follows our issue templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions