Skip to content

Support specifying custom mcp-session-id via McpClientOptions #745

@E1adi

Description

@E1adi

Hi team 👋

I'd like to propose adding support for specifying a desired mcp-session-id when initializing an McpClient. This could be exposed as an optional field in McpClientOptions.

Motivation

In some scenarios, it's useful to associate a client session with a pre-defined or externally managed session ID—for example, for debugging, tracing, or coordinating across services. Currently, the session ID appears to be auto-generated internally, which limits flexibility in these cases.

Suggested Change

Extend McpClientOptions to include an optional sessionId (or mcpSessionId) field. If provided, the client should use this value instead of generating a new one.

public sealed class McpClientOptions 
{
  // ...existing fields
  public string? SessionId { get; set; } // optional override for mcp-session-id
}

Benefits

  • Enables better traceability across systems
  • Facilitates integration with external session management tools
  • Adds flexibility without breaking existing behavior

Let me know if this sounds reasonable or if there's a preferred way to approach it. Happy to help with a PR if needed!

Thanks 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions