Skip to content

[FEATURE]: MCP tool calls should carry current session context (session_id) #33035

Closed as not planned

Description

@liaosf

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Feature Request

When OpenCode calls an MCP tool, the current session ID should be injected into the request so that MCP servers can associate operations with the OpenCode session that triggered them.

Use Case

I built an MCP server (mcp-memory) that stores conversation memories. It accepts an optional session_id parameter, but when OpenCode's AI agent calls save_memory, it doesn't know the current session ID, so memories are saved without session context. This makes it impossible to group memories by the OpenCode session they originated from.

Proposed Solution

Inject the current OpenCode session ID into MCP tool call requests via the _meta field of the CallToolRequest (following MCP protocol design). This approach works for both local (stdio) and remote MCP servers, unlike solutions that only cover HTTP transport.

The MCP server would then extract the session ID from the request context.

Why this matters

Without session context, memory/stateful MCP servers have no way to correlate data with the conversations that produced them, limiting their usefulness for cross-session persistence.

Relationship to existing issues

This request differs from related issues:

Activity

  1. github-actions commented on Jun 19, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • Feature request titles must start with [FEATURE]: (e.g. [FEATURE]: MCP tool calls should carry current session context (session_id))
    • The feature request template requires a verification checkbox confirming the feature hasn't been suggested before (e.g. - [ ] I have verified this feature I'm about to request hasn't been suggested before.)

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


    This issue might be a duplicate of existing issues. Please check:

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

  2. changed the title [-]MCP tool calls should carry current session context (session_id)[/-] [+][FEATURE]: MCP tool calls should carry current session context (session_id)[/+] on Jun 19, 2026
  3. github-actions commented on Jun 19, 2026

    @github-actions
    Contributor

    Thanks for updating the issue! It now meets our contributing guidelines. Your feature request is clear, well-structured, and includes a solid use case and proposed solution. Appreciate the effort!

  4. m13v commented on Jun 20, 2026

    @m13v

    the _meta vs env-var vs plugin-hook split is really a transport argument, but the thing that actually decides whether memories group correctly is whether the session id is stable across a resume or restart. if it regenerates when the session reattaches, save_memory still lands under a fresh key and the grouping you wanted quietly splits into two. injecting the id per-request is the easy half. durable, restart-surviving session identity is the half that determines if any of the correlation holds, and that part lives in your session store, not the call envelope.

  5. liaosf commented on Jun 20, 2026

    @liaosf
    Author

    Confirmed — opencode session list returns persistent session IDs stored in OpenCode's SQLite database, which survive restarts and reconnection. The _meta approach would carry this stable ID.

  6. Necmttn commented on Jun 21, 2026

    @Necmttn

    Since the stable SQLite-backed session id is confirmed, I would make the per-call metadata carry the rest of the provenance too.

    Something like:

    {
      "session_id": "...",
      "session_run_id": "...",
      "turn_id": "...",
      "tool_call_id": "...",
      "project_id": "...",
      "parent_agent_id": null
    }

    session_run_id could also be a resume epoch if that is the local concept. The important part is that memory/stateful MCP servers can distinguish "same saved conversation after resume" from "same session id, different tool call." Keep this in MCP _meta, not model-visible tool args, and cover both stdio and HTTP transports in regression tests.


    Generated with ax.

  7. github-actions commented on Aug 21, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions