Describe the Bug
MCP tools that depend on auto-injected context params (data_dir, etc.) fail with "Missing required argument: data_dir" when called during agent execution. Tools like save_data, serve_file_to_user, and append_data are affected. The agent falls back to writing files to /tmp instead of the session data directory.
To Reproduce
- Run any agent that uses
save_data or serve_file_to_user via quickstart
- Observe the error in logs:
MCP tool 'save_data' execution failed: MCP tool 'save_data' failed: 1 validation error for call[save_data]
data_dir
Missing required argument [type=missing_argument, ...]
Expected Behavior
data_dir should be auto-injected by the framework via execution context. Tools should write to the session-scoped data directory (~/.hive/agents/{agent}/sessions/{session}/data/).
Root Cause
tool_result_handler.py offloads tool executor calls to a thread pool via loop.run_in_executor(). Python's contextvars do not propagate to worker threads by default. The execution context (set by GraphExecutor via set_execution_context(data_dir=...)) is lost when the tool executor runs in the thread pool.
Call chain:
GraphExecutor.execute() sets _execution_context with data_dir (contextvar)
tool_result_handler.execute_tool() calls loop.run_in_executor(None, tool_executor, tool_use)
- Worker thread:
_execution_context.get() returns None (contextvar not propagated)
- MCP executor builds
merged_inputs without data_dir
client_ref.call_tool() fails: "Missing required argument: data_dir"
Note: workspace_id, agent_id, session_id are unaffected because they use _session_context (a regular dict attribute), not contextvars.
Fix
Wrap the executor call in contextvars.copy_context().run() so the current context propagates into the worker thread:
ctx = contextvars.copy_context()
result = await loop.run_in_executor(None, ctx.run, tool_executor, tool_use)
File: core/framework/graph/event_loop/tool_result_handler.py
Logs
2026-03-29 22:15:01 [ERROR] MCP tool 'save_data' execution failed: MCP tool 'save_data' failed: 1 validation error for call[save_data]
data_dir
Missing required argument [type=missing_argument, input_value={'filename': 'risk_assess...'], input_type=dict]
Additional Context
- All 4 tool executor definitions in
tool_registry.py are synchronous (def, not async def), so ctx.run() works correctly.
- Fix verified by running
vulnerability_assessment agent end-to-end: save_data and serve_file_to_user work correctly after the fix.
Describe the Bug
MCP tools that depend on auto-injected context params (
data_dir, etc.) fail with "Missing required argument: data_dir" when called during agent execution. Tools likesave_data,serve_file_to_user, andappend_dataare affected. The agent falls back to writing files to/tmpinstead of the session data directory.To Reproduce
save_dataorserve_file_to_uservia quickstartExpected Behavior
data_dirshould be auto-injected by the framework via execution context. Tools should write to the session-scoped data directory (~/.hive/agents/{agent}/sessions/{session}/data/).Root Cause
tool_result_handler.pyoffloads tool executor calls to a thread pool vialoop.run_in_executor(). Python'scontextvarsdo not propagate to worker threads by default. The execution context (set byGraphExecutorviaset_execution_context(data_dir=...)) is lost when the tool executor runs in the thread pool.Call chain:
GraphExecutor.execute()sets_execution_contextwithdata_dir(contextvar)tool_result_handler.execute_tool()callsloop.run_in_executor(None, tool_executor, tool_use)_execution_context.get()returnsNone(contextvar not propagated)merged_inputswithoutdata_dirclient_ref.call_tool()fails: "Missing required argument: data_dir"Note:
workspace_id,agent_id,session_idare unaffected because they use_session_context(a regular dict attribute), not contextvars.Fix
Wrap the executor call in
contextvars.copy_context().run()so the current context propagates into the worker thread:File:
core/framework/graph/event_loop/tool_result_handler.pyLogs
Additional Context
tool_registry.pyare synchronous (def, notasync def), soctx.run()works correctly.vulnerability_assessmentagent end-to-end:save_dataandserve_file_to_userwork correctly after the fix.