export_query_results
Execute SQL queries and export results in JSON or CSV formats for data analysis and sharing.
Instructions
Export query results in various formats (JSON, CSV)
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sql": "<sql>"
},
"name": "export_query_results"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | SQL query to execute and export | |
| format | No | Export format | json |
Implementation Reference
- src/oracle_mcp_server/server.py:884-925 (handler)The main handler for the 'export_query_results' tool within the call_tool method. It executes the provided SQL query using the QueryExecutor, then formats and returns the results as either CSV or JSON based on the specified format.
elif name == "export_query_results": sql = arguments.get("sql") format_type = arguments.get("format", "json") result = await self.executor.execute_query(sql) if format_type == "csv": # Convert to CSV format csv_lines = [] csv_lines.append(",".join(result["columns"])) for row in result["rows"]: csv_row = [] for value in row: if value is None: csv_row.append("") else: # Escape commas and quotes str_value = str(value) if "," in str_value or '"' in str_value: str_value = ( '"' + str_value.replace('"', '""') + '"' ) csv_row.append(str_value) csv_lines.append(",".join(csv_row)) csv_content = "\n".join(csv_lines) return [ TextContent( type="text", text=f"CSV Export ({result['row_count']} rows):\n\n{csv_content}", ) ] else: return [ TextContent( type="text", text=json.dumps(result, indent=2, default=str), ) ] - src/oracle_mcp_server/server.py:742-761 (registration)Registers the 'export_query_results' tool with the MCP server in the list_tools handler, including the input schema definition for parameters 'sql' and optional 'format'.
Tool( name="export_query_results", description="Export query results in various formats (JSON, CSV)", inputSchema={ "type": "object", "properties": { "sql": { "type": "string", "description": "SQL query to execute and export", }, "format": { "type": "string", "enum": ["json", "csv"], "description": "Export format", "default": "json", }, }, "required": ["sql"], }, ), - The input schema for the 'export_query_results' tool, defining the expected parameters and validation rules.
inputSchema={ "type": "object", "properties": { "sql": { "type": "string", "description": "SQL query to execute and export", }, "format": { "type": "string", "enum": ["json", "csv"], "description": "Export format", "default": "json", }, }, "required": ["sql"], },