Conversation
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
…lehttp transport - Add None check before model_dump() to prevent AttributeError when meta is not present - Pass _meta_data to prompt_service.get_prompt() call - Pass meta_data to resource_service.read_resource() call This completes the _meta field propagation for streamablehttp transport that was partially implemented in the original PR. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
MCP SDK 1.25.0 ClientSession.read_resource() only accepts uri parameter, not meta. The meta parameter is only supported by call_tool(). Remove meta=meta_data from all 4 read_resource() calls to prevent TypeError at runtime. Add comments explaining the SDK limitation. Note: _meta propagation for resources will require a future MCP SDK version that adds meta support to read_resource(). Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
The internal helper functions connect_to_sse_session() and connect_to_streamablehttp_server() had meta_data parameters that were unused after removing the unsupported meta kwarg from read_resource() calls. - Remove meta_data parameter from both helper function signatures - Update docstrings to note MCP SDK 1.25.0 limitation - Update call sites to not pass meta_data - Keep meta_data parameter in invoke_resource() and read_resource() service methods for future SDK compatibility Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Remove the problematic fallback to ctx.request.params.meta which could
raise AttributeError if ctx.request is None. The ctx.meta field on
RequestContext is the canonical source for _meta and is always available.
Simplified pattern:
if ctx and ctx.meta is not None:
meta_data = ctx.meta.model_dump()
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Code Review Fixes AppliedThis PR has been rebased onto main and several issues identified during code review have been fixed. Bugs Fixed1.
2. Missing
3. Missing
4. Unsupported
5. Unused
6. Pylint W0613 unused-argument warning
7. Problematic fallback to
MCP SDK 1.25.0 LimitationVerified via introspection of installed SDK: # call_tool - HAS meta support ✅
call_tool(self, name, arguments=None, ..., *, meta=None)
# read_resource - NO meta support ❌
read_resource(self, uri: AnyUrl)
# get_prompt - NO meta support ❌
get_prompt(self, name, arguments=None)Impact: The Verification
|
894cf37 to
b766038
Compare
|
@crivetimihai @kevalmahajan The Please have a look at this Resources spec that says these methods support You can do something like |
* added _meta support for streamable http
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* updated test cases with meta field
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* _meta extraction for sse
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* handle _meta field with resources and prompts
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* update test cases to test _meta field
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* linting
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* linting fixes
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* fix test cases
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* extract _meta for fallback
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* linting fixes
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
* fix: Complete _meta propagation for prompts and resources in streamablehttp transport
- Add None check before model_dump() to prevent AttributeError when meta is not present
- Pass _meta_data to prompt_service.get_prompt() call
- Pass meta_data to resource_service.read_resource() call
This completes the _meta field propagation for streamablehttp transport that was
partially implemented in the original PR.
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
* fix: Remove unsupported meta parameter from read_resource calls
MCP SDK 1.25.0 ClientSession.read_resource() only accepts uri parameter,
not meta. The meta parameter is only supported by call_tool().
Remove meta=meta_data from all 4 read_resource() calls to prevent TypeError
at runtime. Add comments explaining the SDK limitation.
Note: _meta propagation for resources will require a future MCP SDK version
that adds meta support to read_resource().
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
* chore: Remove unused meta_data params from resource helper functions
The internal helper functions connect_to_sse_session() and
connect_to_streamablehttp_server() had meta_data parameters that
were unused after removing the unsupported meta kwarg from
read_resource() calls.
- Remove meta_data parameter from both helper function signatures
- Update docstrings to note MCP SDK 1.25.0 limitation
- Update call sites to not pass meta_data
- Keep meta_data parameter in invoke_resource() and read_resource()
service methods for future SDK compatibility
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
* fix: Simplify _meta extraction to use ctx.meta directly
Remove the problematic fallback to ctx.request.params.meta which could
raise AttributeError if ctx.request is None. The ctx.meta field on
RequestContext is the canonical source for _meta and is always available.
Simplified pattern:
if ctx and ctx.meta is not None:
meta_data = ctx.meta.model_dump()
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
---------
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
🐛 Bug-fix PR
📌 Summary
Closes #2094
Refactored the mcpgateway RPC handlers and service layers to correctly propagate the _meta field from incoming JSON-RPC requests to upstream MCP servers. This change aligns the gateway with the MCP Specification for tools, resources and prompts for both sse as well as streamable http transports.
🐞 Root Cause
The standard JSON-RPC handlers in mcpgateway/main.py for tools/call, resources/read and prompts/get were retrieving specific arguments (like uri, name, arguments) from the params dictionary but ignoring the
_metafield. Furthermore, the underlying service methods (ToolService.call_tool, ResourceService.read_resource, PromptService.get_prompt) and their helper functions (e.g., invoke_tool, get_prompt and invoke_resource) did not accept or propagate this metadata to the mcp.ClientSession.💡 Fix Description
Implemented a comprehensive propagation path for _meta in the json rpc:
tools/call,resources/readandprompts/getinvoke_tool,get_promptandinvoke_resourceconnect_to_sse_session,connect_to_streamablehttp_server) to pass the extracted meta_data to themcp.ClientSession.call_toolmethod as the meta argument.This design ensures that _meta allows context such as progress tokens and distributed tracing IDs to flow transparently through the gateway to the destination server, preserving the fidelity of the MCP protocol.
🧪 Testing:
Use this MCP server to test client to server _meta propagation via gateway, as well as server to client via gateway.
Metadata in MCP inspector:

MCP Server to Test with:
🧪 Verification
make lintmake testmake coverage📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)