Repository navigation
Inject the Request information in MCP tool calls - #11360
Merged
Merged
Conversation
Collaborator
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-pypi-previews.s3.amazonaws.com/b176db9d6e1bffd36f5b2ecd54b425e4cec3dab8/gradio-5.33.0-py3-none-any.whlInstall Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@b176db9d6e1bffd36f5b2ecd54b425e4cec3dab8#subdirectory=client/python"Install Gradio JS Client from this PR npm install https://gradio-npm-previews.s3.amazonaws.com/b176db9d6e1bffd36f5b2ecd54b425e4cec3dab8/gradio-client-1.15.1.tgzUse Lite from this PR <script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/b176db9d6e1bffd36f5b2ecd54b425e4cec3dab8/dist/lite.js""></script> |
Collaborator
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
abidlabs
marked this pull request as ready for review
June 9, 2025 23:07
Request in MCP tool calls
Request in MCP tool callsRequest information in MCP tool calls
freddyaboulton
left a comment
Contributor
There was a problem hiding this comment.
Mainly just one question
| arguments: The arguments to pass to the tool. | ||
| """ | ||
| context_request = self.mcp_server.request_context.request | ||
| assert context_request is not None # noqa: S101 |
Contributor
There was a problem hiding this comment.
rather than noqa comment, raise RuntimeError if request_context is None
| route_path="/gradio_api/mcp/messages", | ||
| root_path=self.root_path, | ||
| ) | ||
| print("root_url", root_url) |
| assert context_request is not None # noqa: S101 | ||
| root_url = route_utils.get_root_url( | ||
| request=context_request, | ||
| route_path="/gradio_api/mcp/messages", |
Contributor
There was a problem hiding this comment.
If using the http protocol, the path /gradio_api/mcp/http, no? is this going to cause problems?
Member
Author
There was a problem hiding this comment.
good catch I'll fix this
freddyaboulton
approved these changes
Jun 10, 2025
freddyaboulton
left a comment
Contributor
There was a problem hiding this comment.
Clean @abidlabs !
Member
Author
|
Thanks so much @freddyaboulton! |
Oncorporation
pushed a commit
to Oncorporation/gradio
that referenced
this pull request
Jun 17, 2025
* changes * add changeset * changes * add changeset * changes * simplify * pin mcp version * changes * changes * undo * add changeset * changes * changes * format --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
dawoodkhan82
pushed a commit
that referenced
this pull request
Sep 27, 2026
* changes * add changeset * changes * add changeset * changes * simplify * pin mcp version * changes * changes * undo * add changeset * changes * changes * format --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, we were not injecting the correct
starlette.Requestobject in a user's function, even if they decorated it withgr.Request(basically the latest user's network request information would be used for all users). Here, we fix that, taking advantage of this PR introduced in the latest version ofmcp: modelcontextprotocol/python-sdk#816You can test this by running an app like this:
and then connect with two different clients, providing different values for the
fake_usernameheader: