You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature: Pass session identifier to MCP servers #6279
OpenCode currently does not pass any session identifier to MCP servers during tool calls, preventing MCP servers from maintaining session context or tracking interactions across multiple calls within a single OpenCode session.
Current Behavior
Session IDs are generated using ses_ prefix (see /packages/opencode/src/id/id.ts)
Sessions are stored at storage/session/{projectID}/{sessionID}.json
MCP tool calls in /packages/opencode/src/mcp/index.ts only pass name and arguments to client.callTool()
No session context is available to MCP servers
Desired Behavior
MCP servers should receive the OpenCode session identifier, enabling:
Session tracking and analytics
Contextual awareness across multiple tool calls
Better debugging and monitoring
Support for session-specific state management in MCP servers
Proposed Implementation
Options to consider:
Pass session ID as a custom header for remote MCP servers
Include session ID in the request metadata for stdio MCP servers
Add a configuration option to enable/disable this feature
Related Files
Session ID generation: packages/opencode/src/id/id.ts
This feature is related to #6142, which addresses adding sessionID to plugin hooks for tracing integration. Both requests aim to pass session context to external systems (MCP servers and plugins respectively) to enable better session tracking and observability.
Consider if the implementation approach in #6142 could inform the design for passing session identifiers to MCP servers.
The linked issue (#6142) is about passing sessionId to internal plugin hooks, which is a different mechanism than MCP servers.
I researched the MCP protocol and found there's no standard convention for passing clientId/sessionId to MCP servers. For stdio transport, environment variables seem like the cleanest approach since OpenCode spawns the MCP process.
I can submit a PR that passes sessionId and projectId via environment variables (e.g., OPENCODE_SESSION_ID, OPENCODE_PROJECT_ID) when launching MCP servers. Would that approach work?
Activity
github-actions commentedon Dec 28, 2025
This feature is related to #6142, which addresses adding sessionID to plugin hooks for tracing integration. Both requests aim to pass session context to external systems (MCP servers and plugins respectively) to enable better session tracking and observability.
Consider if the implementation approach in #6142 could inform the design for passing session identifiers to MCP servers.
hosseinalipour commentedon Dec 29, 2025
The linked issue (#6142) is about passing sessionId to internal plugin hooks, which is a different mechanism than MCP servers.
I researched the MCP protocol and found there's no standard convention for passing clientId/sessionId to MCP servers. For stdio transport, environment variables seem like the cleanest approach since OpenCode spawns the MCP process.
I can submit a PR that passes sessionId and projectId via environment variables (e.g.,
OPENCODE_SESSION_ID,OPENCODE_PROJECT_ID) when launching MCP servers. Would that approach work?thdxr commentedon Mar 25, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.