-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Inject the Request information in MCP tool calls
#11360
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
Conversation
🪼 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> |
🦄 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.
|
Request in MCP tool calls
Request in MCP tool callsRequest information in MCP tool calls
freddyaboulton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly just one question
gradio/mcp.py
Outdated
| arguments: The arguments to pass to the tool. | ||
| """ | ||
| context_request = self.mcp_server.request_context.request | ||
| assert context_request is not None # noqa: S101 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than noqa comment, raise RuntimeError if request_context is None
gradio/mcp.py
Outdated
| route_path="/gradio_api/mcp/messages", | ||
| root_path=self.root_path, | ||
| ) | ||
| print("root_url", root_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove print
gradio/mcp.py
Outdated
| assert context_request is not None # noqa: S101 | ||
| root_url = route_utils.get_root_url( | ||
| request=context_request, | ||
| route_path="/gradio_api/mcp/messages", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If using the http protocol, the path /gradio_api/mcp/http, no? is this going to cause problems?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch I'll fix this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now
freddyaboulton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean @abidlabs !
|
Thanks so much @freddyaboulton! |
* 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 <[email protected]>
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: