Skip to content

Add support context propagation #225

Description

@He-Pin

Motivation:
When using the transport, we always need to pass some context from the context to the sessionFactory or handler, but with the current implementation, the original ServerRequest is completely been ignored, it would be nice that we pass this information down.

we have some kind of options:

  1. with ThreadLocal
  2. With reactor's contextWrite and deferContext
  3. with an additional parameter.

I think the 3 is better, which will not bound to any implementation.

Activity

  1. He-Pin commented on May 8, 2025

    @He-Pin
    ContributorAuthor

    I'm doing some prototyping, will send a pr later.

  2. chemicL commented on May 30, 2025

    @chemicL
    Member

    @He-Pin thanks for providing the proposed implementation. I am thinking more about extending the McpServerExchange type to be per-request and encapsulate multiple concerns instead of adding more arguments. The exact shape will reveal itself once we have streamable http for stateless servers, which is coming.

  3. Randgalt commented on Jul 15, 2025

    @Randgalt
    Contributor

    This is really needed. Note: because of the use of the Mono/Reactor framework one cannot even use ThreadLocals as internal threads are used for everything. Separately, the use of that framework is a major limitation of this library and should be reconsidered IMO.

  4. He-Pin commented on Jul 16, 2025

    @He-Pin
    ContributorAuthor

    That's true, without this, we currently have to encode our context in the arguments (path the JSON string, and then extract from the JSON string), which is a huge pain.

  5. He-Pin commented on Jul 16, 2025

    @He-Pin
    ContributorAuthor

    @chemicL I'm totally fine and thankful if you can get this in the next 0.11.0 release, thanks.

  6. 134130 commented on Jul 29, 2025

    @134130
    Contributor

    @chemicL If you don't mind, I want to take care of it.

  7. chemicL commented on Aug 13, 2025

    @chemicL
    Member

    In #420 I added McpTransportContext and an McpTransportContextExtractor. Can you please have a look at it and provide feedback whether something is missing/impossible to achieve with this? There is also #477 now to backport it for SSE.

  8. He-Pin commented on Aug 13, 2025

    @He-Pin
    ContributorAuthor

    @chemicL Thanks, we are actually starting using it, but I think we should add some type safe method for this, eg:

     public <T> T get(@NonNull final TypedKey<T> key) 
    
    

    Which is more like Netty's AttributeKey and AttributeMap, which is typesafe.

  9. chemicL commented on Feb 17, 2026

    @chemicL
    Member

    I suppose some time has passed since McpTransportContext was introduced to address the concern from this issue and I'd like to close it.

    @He-Pin in case you feel the above type-safety proposal is still required, can you please open this as a new issue for the community to comment on? I suppose there might be more feedback on extracting the context by now.

  10. modified the milestones: 0.11.3, 0.11.0 on Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions