Skip to main content
Glama
baidu

Baidu Vector Database MCP Server

Official
by baidu

select_table_rows

Filter and retrieve specific rows from a table in Baidu Vector Database using expressions, 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
NameRequiredDescriptionDefault
table_nameYes
filter_exprNo
limitNo
output_fieldsNo

Implementation Reference

  • The main handler function for the 'select_table_rows' tool. It is registered via the @mcp.tool() decorator, receives parameters, calls the underlying connector method, and formats the results as a string.
    @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
  • Helper method in MochowConnector class that performs the actual database query to select rows from a table using filter expression, limit, and output fields.
    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)}")

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/baidu/mochow-mcp-server-python'

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