Skip to content

[FEATURE]: Expose session context to MCP servers via environment variables #15117

Closed as not planned

Description

@adiled

Feature hasn't been suggested before.

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

Related

Describe the enhancement you want to request

Problem

MCP servers spawned by OpenCode have no way to identify which session invoked a tool call. While #9292 and PR #9289 address this for the bash tool and prompt shell, MCP servers are spawned via StdioClientTransport in mcp/index.ts and do not receive session context.

This creates a gap for multi-session orchestration systems where:

  • Multiple OpenCode sessions run concurrently
  • A shared MCP server handles tool calls from all sessions
  • The MCP server needs to route responses or state back to the correct session

Without session identification, the MCP server cannot correlate tool calls to their originating session.

Use Case

An orchestration system manages multiple concurrent OpenCode sessions, each working on a different task. When a session calls an MCP tool (e.g., send_notification or log_progress), the MCP server needs to know which session made the call to route the output to the correct destination.

Currently, the only workaround is requiring the LLM to pass an identifier as a tool parameter, which is error-prone and adds cognitive load to the agent.

Proposed Solution

Expose session context to MCP servers, similar to PR #9289:

  • OPENCODE_SESSION_ID: The unique session identifier (e.g., ses_xyz123)
  • OPENCODE_SESSION_TITLE: The human-readable session title

Additional context

This would enable building robust multi-session orchestration systems on top of OpenCode where MCP servers can maintain session affinity for routing, logging, and state management.

Activity

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

    @github-actions
    Contributor

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

  3. assigned and unassigned on Apr 26, 2026
  4. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  5. github-actions commented on Jul 4, 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