Skip to main content
Glama
privetin

Dataset Viewer MCP Server

by privetin

filter

Filter rows in Hugging Face datasets using SQL-like conditions to extract specific data subsets based on column values and criteria.

Instructions

Filter rows in a Hugging Face dataset using SQL-like conditions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
datasetYesHugging Face dataset identifier in the format owner/dataset
configYesDataset configuration/subset name. Use get_info to list available configs
splitYesDataset split name. Splits partition the data for training/evaluation
whereYesSQL-like WHERE clause to filter rows
orderbyNoSQL-like ORDER BY clause to sort results
pageNoPage number for paginated results (100 rows per page)
auth_tokenNoHugging Face auth token for private/gated datasets

Implementation Reference

  • Core handler function in DatasetViewerAPI that performs the actual filtering by calling the Hugging Face dataset viewer API /filter endpoint with validated parameters.
    async def filter(self, dataset: str, config: str, split: str, where: str, orderby: str | None = None, page: int = 0) -> dict:
        """Filter dataset rows based on conditions"""
        # Validate page number
        if page < 0:
            raise ValueError("Page number must be non-negative")
            
        # Basic SQL clause validation
        if not where.strip():
            raise ValueError("WHERE clause cannot be empty")
        if orderby and not orderby.strip():
            raise ValueError("ORDER BY clause cannot be empty")
            
        params = {
            "dataset": dataset,
            "config": config,
            "split": split,
            "where": where,
            "offset": page * 100,  # 100 rows per page
            "length": 100
        }
        if orderby:
            params["orderby"] = orderby
            
        try:
            response = await self.client.get("/filter", params=params)
            response.raise_for_status()
            return response.json()
        except httpx.NetworkError as e:
            raise ConnectionError(f"Network error while filtering dataset: {e}")
        except httpx.HTTPStatusError as e:
            if e.response.status_code == 400:
                raise ValueError(f"Invalid filter query: {e.response.text}")
            elif e.response.status_code == 404:
                raise ValueError(f"Dataset, config or split not found: {dataset}/{config}/{split}")
            else:
                raise RuntimeError(f"Error filtering dataset: {e}")
  • MCP tool registration including name, description, and detailed input schema for the 'filter' tool.
    types.Tool(
        name="filter",
        description="Filter rows in a Hugging Face dataset using SQL-like conditions",
        inputSchema={
            "type": "object",
            "properties": {
                "dataset": {
                    "type": "string",
                    "description": "Hugging Face dataset identifier in the format owner/dataset",
                    "pattern": "^[^/]+/[^/]+$",
                    "examples": ["ylecun/mnist", "stanfordnlp/imdb"]
                },
                "config": {
                    "type": "string",
                    "description": "Dataset configuration/subset name. Use get_info to list available configs",
                    "examples": ["default", "en", "es"]
                },
                "split": {
                    "type": "string",
                    "description": "Dataset split name. Splits partition the data for training/evaluation",
                    "examples": ["train", "validation", "test"]
                },
                "where": {
                    "type": "string",
                    "description": "SQL-like WHERE clause to filter rows",
                    "examples": ["column = \"value\"", "score > 0.5", "text LIKE \"%query%\""]
                },
                "orderby": {
                    "type": "string",
                    "description": "SQL-like ORDER BY clause to sort results",
                    "optional": True,
                    "examples": ["column ASC", "score DESC", "name ASC, id DESC"]
                },
                "page": {
                    "type": "integer",
                    "description": "Page number for paginated results (100 rows per page)",
                    "default": 0,
                    "minimum": 0
                },
                "auth_token": {
                    "type": "string",
                    "description": "Hugging Face auth token for private/gated datasets",
                    "optional": True
                }
            },
            "required": ["dataset", "config", "split", "where"],
        }
    ),
  • MCP server @server.call_tool() dispatch branch that parses arguments and invokes the DatasetViewerAPI.filter method, returning JSON-formatted results.
    elif name == "filter":
        dataset = arguments["dataset"]
        config = arguments["config"]
        split = arguments["split"]
        where = arguments["where"]
        orderby = arguments.get("orderby")
        page = arguments.get("page", 0)
        filtered = await DatasetViewerAPI(auth_token=auth_token).filter(dataset, config=config, split=split, where=where, orderby=orderby, page=page)
        return [
            types.TextContent(
                type="text",
                text=json.dumps(filtered, indent=2)
            )
        ]
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'SQL-like conditions' but doesn't specify what happens (e.g., returns filtered rows, pagination details beyond schema's 'page' parameter, or performance implications). It lacks critical info like whether this is read-only, if it modifies data, rate limits, or error handling. The description adds minimal behavioral context beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the tool's purpose clearly without redundancy. It's front-loaded with the core action and resource, and every word earns its place by specifying the method ('SQL-like conditions'). There's no wasted text or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (7 parameters, no annotations, no output schema), the description is inadequate. It doesn't explain what the tool returns (filtered rows? metadata?), how results are structured, or behavioral traits like pagination beyond the schema. For a data filtering tool with multiple parameters and siblings, more context on output and usage is needed to be complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 7 parameters. The description adds no parameter-specific semantics beyond implying 'where' is for filtering. It doesn't explain parameter interactions, default behaviors, or provide examples not in the schema. Baseline 3 is appropriate since the schema does the heavy lifting, but the description doesn't compensate with additional insights.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('filter rows') and target resource ('Hugging Face dataset'), and specifies the method ('using SQL-like conditions'). It distinguishes from siblings like 'get_rows' or 'search_dataset' by focusing on filtering rather than retrieval or search operations. However, it doesn't explicitly contrast with all siblings, leaving some ambiguity about when to choose this over alternatives like 'search_dataset'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for filtering datasets with SQL-like syntax, but provides no explicit guidance on when to use this tool versus siblings like 'search_dataset' or 'get_rows'. It mentions using 'get_info' to list configs in the schema, but this is not in the description itself. There's no mention of prerequisites, alternatives, or exclusions, leaving usage context largely implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/privetin/dataset-viewer'

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