-
Notifications
You must be signed in to change notification settings - Fork 204
feat: Add state-based configuration support to MCPToolset #2689
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
base: main
Are you sure you want to change the base?
Conversation
integrations/mcp/src/haystack_integrations/tools/mcp/mcp_toolset.py
Outdated
Show resolved
Hide resolved
| # Map tool outputs to state keys | ||
| outputs_to_state={ | ||
| "git_status": {"status_result": {"source": "status"}}, | ||
| "git_diff": {"diff_result": {}}, |
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.
Could we add a dev comment here explaining why one might provide an empty dict here?
integrations/mcp/src/haystack_integrations/tools/mcp/mcp_toolset.py
Outdated
Show resolved
Hide resolved
integrations/mcp/src/haystack_integrations/tools/mcp/mcp_toolset.py
Outdated
Show resolved
Hide resolved
|
@vblagoje looking good! I wanted to ask if you could add an integration test using these configs to see if everything works as expected? |
…et.py Co-authored-by: Sebastian Husch Lee <[email protected]>
…et.py Co-authored-by: Sebastian Husch Lee <[email protected]>
…et.py Co-authored-by: Sebastian Husch Lee <[email protected]>
mpangrazzi
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.
Looks already good! I've added a few comments. +1 on adding an integration test as @sjrl mentioned.
| :param config: The state configuration dictionary to serialize | ||
| :returns: The serialized configuration dictionary, or None if empty | ||
| """ | ||
| if not config: |
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.
More a type checker thing: the function accepts and handles None correctly, but the type hint says it only accepts dict.
|
|
||
| # Check if this is outputs_to_string format (flat with optional source/handler) | ||
| # or outputs_to_state format (nested with state keys) | ||
| if "source" in tool_config or "handler" in tool_config: |
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.
Edge case: what if someone use source or handler as keys in state? May worth documenting?
| assert isinstance(toolset_dict["data"]["outputs_to_string"]["add"]["handler"], str) | ||
|
|
||
| # Test deserialization | ||
| with patch("haystack_integrations.tools.mcp.mcp_toolset.MCPToolset.__init__", return_value=None) as mock_init: |
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.
I may miss something, but why not doing a full roundtrip of to_dict() / from_dict() here (so without mocking)?
Why
Agents need tools that seamlessly share data through state.
MCPToolalready supportsinputs_from_stateandoutputs_to_statefor automatic parameter injection and output handling.MCPToolsetcouldn't use these features - breaking Agent workflows that rely on state propagation across multiple MCP tools.This PR completes MCP's Agent integration story.
MCPToolsetnow dynamically configures state mappings for each discovered tool, enabling the same seamless state-based coordination thatMCPToolprovides.inputs_from_stateandoutputs_to_statesupport toMCPToolset#2677What
Added per-tool state configuration to
MCPToolset:inputs_from_state,outputs_to_state,outputs_to_stringparameters (dict mapping tool names to configs)_serialize_state_config()/_deserialize_state_config()helpers handle both nested (outputs_to_state) and flat (outputs_to_string) formats_validate_state_configs()warns on unknown tool nameshaystack-ai>=2.19.0(supports state params)How can it be used
How did you test it
Notes for the reviewer
Parameter validation behavior: