select
Retrieve data from SurrealDB tables by fetching all records or selecting specific records using their ID for display and processing.
Instructions
Select all records from a table or a specific record by ID.
This tool provides a simple way to retrieve data from SurrealDB tables. Use this when you need to:
Fetch all records from a table
Retrieve a specific record by its ID
Get data for display or further processing
Args: table: The name of the table to select from (e.g., "user", "product", "order") id: Optional ID of a specific record to select. Can be: - Just the ID part (e.g., "john") - will be combined with table name - Full record ID (e.g., "user:john") - will be used as-is - None/omitted - selects all records from the table
Returns: A dictionary containing: - success: Boolean indicating if the selection was successful - data: Array of records (even for single record selection) - count: Number of records returned - error: Error message if selection failed (only present on failure)
Examples: >>> await select("user") # Get all users {"success": true, "data": [...], "count": 42}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | ||
| table | Yes |
Implementation Reference
- surreal_mcp/server.py:154-222 (handler)The primary handler for the 'select' MCP tool. It is decorated with @mcp.tool() for registration, defines input parameters with type hints (serving as schema), constructs a SurrealQL SELECT query, executes it using repo_query from the database module, formats the response, and handles errors.async def select( table: str, id: Optional[str] = None, namespace: Optional[str] = None, database: Optional[str] = None, ) -> Dict[str, Any]: """ Select all records from a table or a specific record by ID. This tool provides a simple way to retrieve data from SurrealDB tables. Use this when you need to: - Fetch all records from a table - Retrieve a specific record by its ID - Get data for display or further processing Args: table: The name of the table to select from (e.g., "user", "product", "order") id: Optional ID of a specific record to select. Can be: - Just the ID part (e.g., "john") - will be combined with table name - Full record ID (e.g., "user:john") - will be used as-is - None/omitted - selects all records from the table namespace: Optional SurrealDB namespace override. If not provided, uses SURREAL_NAMESPACE env var. database: Optional SurrealDB database override. If not provided, uses SURREAL_DATABASE env var. Returns: A dictionary containing: - success: Boolean indicating if the selection was successful - data: Array of records (even for single record selection) - count: Number of records returned - error: Error message if selection failed (only present on failure) Examples: >>> await select("user") # Get all users {"success": true, "data": [...], "count": 42} >>> await select("user", "john") # Get specific user {"success": true, "data": [{"id": "user:john", "name": "John Doe", ...}], "count": 1} >>> await select("product", "product:laptop-123") # Using full ID {"success": true, "data": [{"id": "product:laptop-123", ...}], "count": 1} """ try: ns, db = resolve_namespace_database(namespace, database) # Build the query based on whether ID is provided if id: # Handle both "id" and "table:id" formats if ":" in id and id.startswith(f"{table}:"): record_id = id else: record_id = f"{table}:{id}" query_str = f"SELECT * FROM {record_id}" else: query_str = f"SELECT * FROM {table}" logger.info(f"Executing select: {query_str}") result = await repo_query(query_str, namespace=ns, database=db) # Ensure result is always a list if not isinstance(result, list): result = [result] if result else [] return { "success": True, "data": result, "count": len(result) } except Exception as e: logger.error(f"Select failed for {table}: {str(e)}") raise Exception(f"Failed to select from {table}: {str(e)}")