Skip to main content
Glama
smith-nathanh

Oracle MCP Server

generate_sample_queries

Create sample SQL queries for database tables to facilitate data exploration and analysis in Oracle environments.

Instructions

Generate sample SQL queries for a given table to help with exploration

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYesName of the table to generate queries for
ownerNoSchema owner (optional)

Implementation Reference

  • The main handler function for the 'generate_sample_queries' tool within the call_tool method. It fetches table columns, generates sample SQL queries based on column types (select all, count, distinct values, stats, date ranges), and returns them as JSON.
    elif name == "generate_sample_queries": table_name = arguments.get("table_name") owner = arguments.get("owner") columns = await self.inspector.get_table_columns(table_name, owner) # Generate sample queries table_ref = f"{owner}.{table_name}" if owner else table_name queries = [ f"-- Basic select all\nSELECT * FROM {table_ref} WHERE ROWNUM <= 10;", f"-- Count total rows\nSELECT COUNT(*) FROM {table_ref};", ] # Add column-specific queries for col in columns[:5]: # Limit to first 5 columns col_name = col["column_name"] if col["data_type"] in ["VARCHAR2", "CHAR", "CLOB"]: queries.append( f"-- Find distinct values for {col_name}\nSELECT DISTINCT {col_name} FROM {table_ref} WHERE {col_name} IS NOT NULL AND ROWNUM <= 20;" ) elif col["data_type"] in ["NUMBER", "INTEGER"]: queries.append( f"-- Statistics for {col_name}\nSELECT MIN({col_name}), MAX({col_name}), AVG({col_name}) FROM {table_ref};" ) elif col["data_type"] in ["DATE", "TIMESTAMP"]: queries.append( f"-- Date range for {col_name}\nSELECT MIN({col_name}), MAX({col_name}) FROM {table_ref};" ) result = {"table_name": table_name, "sample_queries": queries} return [ TextContent( type="text", text=json.dumps(result, indent=2, default=str) ) ]
  • Input schema definition for the 'generate_sample_queries' tool, specifying required 'table_name' and optional 'owner' parameters.
    "type": "object", "properties": { "table_name": { "type": "string", "description": "Name of the table to generate queries for", }, "owner": { "type": "string", "description": "Schema owner (optional)", "default": None, }, }, "required": ["table_name"], },
  • Registration of the 'generate_sample_queries' tool in the list_tools handler, including name, description, and input schema.
    Tool( name="generate_sample_queries", description="Generate sample SQL queries for a given table to help with exploration", inputSchema={ "type": "object", "properties": { "table_name": { "type": "string", "description": "Name of the table to generate queries for", }, "owner": { "type": "string", "description": "Schema owner (optional)", "default": None, }, }, "required": ["table_name"], }, ),

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/smith-nathanh/oracle-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server