-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Description
Proposed amendment to the runtool function within _agent_graph.py
model_args = args # Parameters generated by large language models (LLMs)
client_deps = ctx.deps # Locally passed client parameters
merged_arguments = {**model_args, **client_deps} # type: ignore
result = await server.call_tool(tool_name, merged_arguments) # type: ignoreKey Improvements
- Parameter Merging Mechanism
Combines LLM-generated arguments (model_args) with local client dependencies (ctx.deps) using dictionary unpacking
- Precedence Rule
Implements override logic where client_deps values take priority over conflicting model_args
3. Context Preservation
Maintains type safety through # type: ignore annotations while enabling local parameter propagation to MCP server
Technical Rationale
This modification addresses the current limitation where:
MCP servers receive only LLM-generated parameters
Local context variables (ctx.deps) remain inaccessible at server-side
Client-specific configurations (auth tokens, environment variables) require workarounds
The merged dictionary approach aligns with Pydantic-AI's dependency injection system while maintaining MCP protocol compliance
. Implementation would enhance scenarios like:
ctx.deps = {"api_key": "SECRET_123"} Server-side: Directly access merged_arguments['api_key']
Instead of separate auth handling10
References
No response