read_query
Execute SQL SELECT queries on StarRocks databases to retrieve data and return the result set.
Instructions
Execute a SELECT query or commands that return a ResultSet
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | SQL query to execute | |
| db | No | database |
Implementation Reference
- The tool handler: decorated with @mcp.tool, defines the 'read_query' tool. It takes a SQL query and optional database, executes it via db_client.execute(), and returns a ToolResult with text and structured content.
@mcp.tool(description="Execute a SELECT query or commands that return a ResultSet" + description_suffix) def read_query(query: Annotated[str, Field(description="SQL query to execute")], db: Annotated[str|None, Field(description="database")] = None) -> ToolResult: # return csv like result set, with column names as first row logger.info(f"Executing read query: {query[:100]}{'...' if len(query) > 100 else ''}") result = db_client.execute(query, db=db) if result.success: logger.info(f"Query executed successfully, returned {len(result.rows) if result.rows else 0} rows") else: logger.error(f"Query failed: {result.error_message}") return ToolResult(content=[TextContent(type='text', text=result.to_string(limit=10000))], structured_content=result.to_dict()) - src/mcp_server_starrocks/server.py:191-191 (registration)The registration decorator @mcp.tool registers 'read_query' as an MCP tool with a description. FastMCP's @mcp.tool automatically registers the function name as the tool name.
@mcp.tool(description="Execute a SELECT query or commands that return a ResultSet" + description_suffix) - Input schema: 'query' is a required string with description 'SQL query to execute', and 'db' is an optional string (str|None) with description 'database'. Defined using Annotated and Pydantic Field.
def read_query(query: Annotated[str, Field(description="SQL query to execute")], db: Annotated[str|None, Field(description="database")] = None) -> ToolResult: - The db_client used by read_query is obtained via get_db_client() which provides the execute() method.
db_client = get_db_client()