Skip to content

feat: Add request with context support. #226

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

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

Conversation

He-Pin
Copy link
Contributor

@He-Pin He-Pin commented May 8, 2025

Motivation and Context

refs: #225

  1. We will need some context information when handling the request*
  2. Once this gets merged, the implementation in Spring-Ai will need changed too.
				String callResult = toolCallback.call(ModelOptionsUtils.toJsonString(request),
						new ToolContext(Map.of(TOOL_CONTEXT_MCP_EXCHANGE_KEY, exchange)));

How Has This Been Tested?

During development.

Breaking Changes

Yes, binary not compatibility

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • [ x] Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • [ x] I have read the MCP Documentation
  • [ x] My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@He-Pin
Copy link
Contributor Author

He-Pin commented May 8, 2025

@tzolov Wdyt about this, I would like to push this, thank you.

Another way to handle it is extends the WebFluxSseServerTransportProvider and then wrapping my ctx into the params of JSONRPCRequest, eg:

        final Map<String, Object> argumentsMap = new HashMap<>(callToolArguments);
        if (myMcpContext != null) {
            argumentsMap.put(CONTEXT_KEY, myMcpContext);
        }
        final var newCallToolRequest = new McpSchema.CallToolRequest(callToolRequest.name(), argumentsMap);

@qnnn
Copy link

qnnn commented May 12, 2025

We would also like to use this feature. If this PR is being blocked due to the breaking changes it introduces, perhaps the alternative approach mentioned in the referenced issue—based on Reactor context and ThreadLocal-based implementation could be considered instead.

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