modelcontextprotocol / modelcontextprotocol/java-sdk

Should McpTransportContextExtractor contain default methods for protocol version, lastEventId and sessionId

Open
#492 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting for triage
Dominant language
Java
Stars
3.7k
Forks
1.1k
Avg merge
1d 15h
Merged PRs (30d)
9

Description

I am defining my McpTransportContextExtractor implementation as:

@Internal
@Singleton
class DefaultMcpTransportContextExtractor implements McpTransportContextExtractor<HttpRequest<?>> {
    public static final String HTTP_HEADER_MCP_PROTOCOL_VERSION = "MCP-Protocol-Version";
    public static final String DEFAULT_PROTOCOL_VERSION = "2025-03-26";
    public static final String HTTP_HEADER_MCP_SESSION_ID = "Mcp-Session-Id";
    public static final String HTTP_HEADER_DEFAULT_LAST_EVENT_ID = "Last-Event-ID";

    @Override
    public McpTransportContext extract(HttpRequest<?> request, McpTransportContext transportContext) {
        transportContext.put(HTTP_HEADER_MCP_PROTOCOL_VERSION,
            request.getHeaders().get(HTTP_HEADER_MCP_PROTOCOL_VERSION, String.class)
                .orElse(DEFAULT_PROTOCOL_VERSION));
        request.getHeaders().get(HTTP_HEADER_MCP_SESSION_ID, String.class)
            .ifPresent(v -> transportContext.put(HTTP_HEADER_MCP_SESSION_ID, v));
        request.getHeaders().get(HTTP_HEADER_DEFAULT_LAST_EVENT_ID, String.class)
            .ifPresent(v -> transportContext.put(HTTP_HEADER_DEFAULT_LAST_EVENT_ID, v));
        return transportContext;
    }
}

But given that the specification defines session id, last event and protocol version. I think it would be good if the McpTransportContextExtractor contained default methods:

default String getSessionId() {
   return null;
}

default String getLastEventId() {
   return null;
}

default String getProtocolVersion() {
   return "2025-03-26";
}

I can submit a PR if you think it is a good idea. With this change the TransportContext will have a clear API for those spec defined concepts.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate McpTransportContextExtractor and review its existing implementations alongside McpTransportContext usage. Check whether default accessors for protocol version, session ID, and last event ID fit the current API and protocol concepts; done means the interface exposes a consistent, compatible API.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.