Skip to content

[FEATURE]: MCP auth configuration for multi-tenant serve deployments #5784

Closed

Description

@trustbutverafy

Feature hasn't been suggested before.

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

Describe the enhancement you want to request

Problem

When running OpenCode in serve mode for multi-tenant deployments, all sessions share the same static MCP server configuration. This means MCP servers cannot distinguish which user/session is making a request, making it impossible to implement proper access control at the MCP layer.

Use Case

We're building a platform where multiple users interact with OpenCode through its HTTP API. Each user should only be able to access their own resources via MCP tools (e.g., their own files, databases, or external service credentials).

Currently, the MCP configuration is read once at startup:

  {
    "mcp": {
      "myServer": {
        "type": "remote",
        "url": "https://mcp.example.com",
        "headers": {
          "Authorization": "Bearer <static-token>"
        }
      }
    }
  }

This static token is used for all sessions, so the MCP server has no way to know which user is making a request.

Proposed Solution

Add an optional mcpAuth parameter to session creation that allows passing per-session headers to MCP servers:

  curl -X POST http://localhost:4096/sessions \
    -H "Content-Type: application/json" \
    -d '{
      "mcpAuth": {
        "myServer": {
          "headers": {
            "Authorization": "Bearer <user-specific-token>",
            "X-Session-Id": "session-123"
          }
        }
      }
    }'

These headers would be merged with (or override) the static headers from the config file for that session's MCP calls.

Implementation Notes

The change would involve:

  • Accepting mcpAuth in the session creation endpoint
  • Storing per-session MCP headers in session state
  • Merging these headers when making MCP HTTP requests for that session

Happy to submit a PR if this approach seems reasonable. I'll be forking otherwise, but thought I would mention here.

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Dec 19, 2025
  2. github-actions commented on Dec 19, 2025

    @github-actions
    Contributor

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

    Feel free to ignore if none of these address your specific case.

  3. priyankpaladiya commented on May 15, 2026

    @priyankpaladiya

    We have a similar multi-tenant use case but need to go one step further.
    Not only do we need per-session auth headers, we need per-session MCP
    server lists — different users should see different MCP servers entirely
    based on their role.

    A more complete solution would be supporting a full mcp config in
    POST /session (not just mcpAuth), which would cover both use cases:

    • Different auth tokens per user (your use case)
    • Different MCP servers per user (our use case)

    Related: #6822 (agentId in POST /session)

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

Metadata

Metadata

Assignees

Labels

discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions