Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion datus/mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ def _create_context(
logger.warning(f"Failed to initialize {tool_config.name} for {datasource}: {e}")
tools[tool_config.name] = None

# Wire db_func_tool into reference_template_tool so execute_reference_template
# can run the rendered SQL directly, matching the behaviour of Chat API agents.
ref_tool = tools.get("reference_template_tool")
db_tool = tools.get("db_tool")
if ref_tool is not None and db_tool is not None:
ref_tool.db_func_tool = db_tool

return ToolContext(
datasource=datasource,
subagent=subagent,
Expand All @@ -318,7 +325,6 @@ def _create_context(
)

def close_all(self):
"""Close all managed contexts."""
for cache_key, context in list(self._contexts.items()):
try:
context.close()
Comment thread
stukid marked this conversation as resolved.
Resolved
Expand Down Expand Up @@ -905,6 +911,13 @@ def _init_tools(self):
logger.warning(f"Failed to initialize {tool_config.name}: {e}")
self.tools[tool_config.name] = None

# Wire db_func_tool into reference_template_tool so execute_reference_template
# can run the rendered SQL directly, matching the behaviour of Chat API agents.
ref_tool = self.tools.get("reference_template_tool")
db_tool = self.tools.get("db_tool")
if ref_tool is not None and db_tool is not None:
ref_tool.db_func_tool = db_tool
Comment thread
c-f-cooper marked this conversation as resolved.
Resolved

# Backward compatibility properties
@property
def db_tool(self) -> Optional[DBFuncTool]:
Expand Down
Loading