set_dataset
Switch the active dataset for querying clinical data like MIMIC-IV and eICU through natural language, enabling access to different healthcare data sources.
Instructions
🔄 Switch the active dataset.
Args: dataset_name: The name of the dataset to switch to (e.g., 'mimic-iv-demo').
Returns: Confirmation message with supported tools snapshot, or error if not found.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dataset_name | Yes |
Implementation Reference
- src/m4/core/tools/management.py:108-140 (handler)Core handler logic in SetDatasetTool.invoke method that performs dataset switching, validation, and status reporting.def invoke(self, dataset: DatasetDefinition, params: SetDatasetInput) -> ToolOutput: """Switch to a different dataset.""" dataset_name = params.dataset_name.lower() availability = detect_available_local_datasets() backend_name = os.getenv("M4_BACKEND", "duckdb") if dataset_name not in availability: supported = ", ".join(availability.keys()) return ToolOutput( result=( f"❌ Error: Dataset '{dataset_name}' not found. " f"Supported datasets: {supported}" ) ) set_active_dataset(dataset_name) # Get details about the new dataset to provide context info = availability[dataset_name] status_msg = f"✅ Active dataset switched to '{dataset_name}'." if not info["db_present"] and backend_name == "duckdb": status_msg += ( "\n⚠️ Note: Local database not found. " "You may need to run initialization if using DuckDB." ) ds_def = DatasetRegistry.get(dataset_name) if ds_def and not ds_def.bigquery_dataset_ids and backend_name == "bigquery": status_msg += "\n⚠️ Warning: This dataset is not configured for BigQuery." return ToolOutput(result=status_msg)
- SetDatasetInput dataclass defining the input schema (dataset_name: str) for the tool.class SetDatasetInput(ToolInput): """Input for set_dataset tool.""" dataset_name: str
- src/m4/core/tools/__init__.py:60-62 (registration)Registration of SetDatasetTool instance in the core ToolRegistry during init_tools().ToolRegistry.register(ListDatasetsTool()) ToolRegistry.register(SetDatasetTool())
- src/m4/mcp_server.py:80-102 (handler)MCP-specific handler for set_dataset tool, which delegates to core tool and appends supported tools snapshot.def set_dataset(dataset_name: str) -> str: """🔄 Switch the active dataset. Args: dataset_name: The name of the dataset to switch to (e.g., 'mimic-iv-demo'). Returns: Confirmation message with supported tools snapshot, or error if not found. """ # Check if target dataset exists before switching target_dataset_def = DatasetRegistry.get(dataset_name.lower()) tool = ToolRegistry.get("set_dataset") dataset = DatasetRegistry.get_active() result = tool.invoke(dataset, SetDatasetInput(dataset_name=dataset_name)).result # Append supported tools snapshot if dataset is valid if target_dataset_def is not None: result += _tool_selector.get_supported_tools_snapshot( target_dataset_def, _MCP_TOOL_NAMES ) return result
- src/m4/mcp_server.py:24-24 (schema)Import of SetDatasetInput schema used in MCP handler.from m4.core.tools.management import ListDatasetsInput, SetDatasetInput