Feat: support injected arguments #344
Open
+255
−38
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.
Context
First of all, congratulations on the excellent work!
This PR is a proposal for how users can define a tool in the MCP server that receives parameters which the LLM should not be aware of.
The pseudo-code below illustrates how it works:
Implementation details
Now that MCP's Python SDK exposes
_metaincall_toolinterface, we can rely on it to hide some tools parameters from the LLM.On the MCP side, tools converted with
to_fastmcpwill returnInjectedToolArgintools/listcalls to the server:{ "meta": null, "nextCursor": null, "tools": [ { "name": "get_user_pet_name", "title": null, "description": "Returns the user's pet name", "inputSchema": { "description": "Returns the user's pet name", "properties": {}, "required": [], "title": "get_user_pet_name", "type": "object" }, "outputSchema": null, "icons": null, "annotations": null, "meta": { "langchain/injectedArgsSchema": { "user_id": { "type": "string" } } } } ] }On the client-side, LC tools created with
load_mcp_toolswill detectlangchain/injectedArgsSchemaand pass any matching input in_metaduringtools/callrequests:{ "method": "tools/call", "params": { "meta": { "progressToken": null, "langchain/injectedArgsValue": { "user_id": "user_0" } }, "name": "get_user_pet_name", "arguments": { } } }The MCP Tool will extract the values from
langchain/injectedArgsValueand inject them intoargumentsto the underlying LC Toolinvokemethod.Considerations
From my understanding, LangChain is discouraging the use of
InjectedToolArgin favor ofToolRuntimeinstead.However, it doesn’t seem that
InjectedToolArgis fully deprecated yet.