select_table_rows
Filter and retrieve specific rows from a table in Baidu Vector Database using a custom expression, with options to limit results and select output fields.
Instructions
Select rows with a filter expression in the Mochow instance.
Args:
table_name (str): Name of the table.
filter_expr (str): Filter expression to select data. Defaults to None.
limit (int): Maximum number of results. Defaults to 10.
output_fields (Optional[list[str]]): Fields to return in the results. Defaults to None.
Returns:
str: A string containing the selected rows.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter_expr | No | ||
| limit | No | ||
| output_fields | No | ||
| table_name | Yes |
Implementation Reference
- src/mochow_mcp_server/server.py:655-680 (handler)The main handler function for the 'select_table_rows' tool, decorated with @mcp.tool() for registration. It calls the connector's select_rows method and formats the output.@mcp.tool() async def select_table_rows( table_name: str, filter_expr: str = None, limit: int = 10, output_fields: Optional[list[str]] = None, ctx: Context = None, ) -> str: """ Select rows with a filter expression in the Mochow instance. Args: table_name (str): Name of the table. filter_expr (str): Filter expression to select data. Defaults to None. limit (int): Maximum number of results. Defaults to 10. output_fields (Optional[list[str]]): Fields to return in the results. Defaults to None. Returns: str: A string containing the selected rows. """ connector = ctx.request_context.lifespan_context.connector select_results = await connector.select_rows(table_name, filter_expr, limit, output_fields) output = f"Select rows results for '{table_name}':\n" for row in select_results.rows: output += f"{str(row)}\n" return output
- The supporting utility method in MochowConnector class that performs the actual row selection using the Mochow client's select method.async def select_rows( self, table_name: str, filter_expr: str = None, limit: int = 10, output_fields: Optional[list[str]] = None, ) -> HttpResponse: """ Select rows in a given table using a filter expression. Args: table_name (str): Name of the table. filter_expr (str): Filter expression to select data. limit (int): Maximum number of results. Defaults to 10. output_fields (Optional[list[str]]): Fields to return in the results. Defaults to None. Returns: HttpResponse: The HTTP response containing the selected rows. """ if self.database is None: raise ValueError("Switch to the database before select rows with filter expression.") # select data with filter expression try: return self.database.table(table_name).select(filter=filter_expr, projections=output_fields, limit=limit) except ServerError as e: raise ValueError(f"Failed to select data with filter expression: {str(e)}")
- src/mochow_mcp_server/server.py:655-655 (registration)The @mcp.tool() decorator registers the select_table_rows function as an MCP tool.@mcp.tool()