spring-projects / spring-projects/spring-ai

MCP server - access to request/session scope beans

Open
#3,457 3 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Expected Behavior

My app is storing user context in request and/or session scoped beans. I'd like to access these beans from the code serving as tool in the MCP server.

Current Behavior

I'm using MCP server implementation based on Server Sent Events (WebMvcSseServerTransportProvider). The issue is that my tool code is being called from Reactor thread:

session.handle(message).block();

Because of that, my code can't access session and request scoped beans:

Error creating bean with name 'scopedTarget.requestUserDataHolder': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton

I could pass this information to Reactor's context, but I don't have the access to Reactor's pipeline.

Context

It prevents me from exposing my synchronous WebMVC API using MCP.

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

Start with WebMvcSseServerTransportProvider and trace the session.handle(message).block() call into the tool execution path. Reproduce the request/session-scoped bean failure, then verify that tool code serving an SSE request can access the relevant scopes without breaking existing MCP handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.