Skip to content

McpSyncServer: set immediate execution when in a servlet context #3794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Kehrlann
Copy link
Contributor

@Kehrlann Kehrlann commented Jul 11, 2025

When using an MCP sync server, in a servlet environment, use SyncSpecification#immediateExecution(true), introduced in modelcontextprotocol/java-sdk#371 .

This allows to propagate thread-locals to the @Tool method; granting access to e.g. Framework's RequestContextHolder#getRequestAttributes() or Security's SecurityContextHolder#getContext().

This, in turn, allows users to use Spring Security's method-level security, e.g.:

@PreAuthorize("hasScope('widget.read')")
@Tool(description = "...")
public Widget getWidget(...) {
    // ...
}

@PreAuthorize("hasScope('widget.admin')")
@Tool(description = "...")
public Widget addWidget(...) {
    // ...
}

@tzolov tzolov self-assigned this Jul 11, 2025
@tzolov tzolov added this to the 1.1.x milestone Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants