Skip to main content
Glama
NightTrek

Supabase MCP Server

by NightTrek

query_table

Query a specific Supabase database table with schema selection, column filtering, and where clause conditions for precise data retrieval.

Instructions

Query a specific table with schema selection and where clause support

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaNoDatabase schema (optional, defaults to public)
tableYesName of the table to query
selectNoComma-separated list of columns to select (optional, defaults to *)
whereNoArray of where conditions (optional)

Implementation Reference

  • The main execution logic for the 'query_table' tool: validates input, constructs a Supabase query with schema, table, select columns, where conditions, limits to 25 rows, executes it, and returns JSON-stringified results.
    case "query_table": {
      if (!isValidQueryTableArgs(request.params.arguments)) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Invalid query table arguments"
        );
      }
    
      const {
        schema = "public",
        table,
        select = "*",
        where = [],
      } = request.params.arguments;
    
      // Start the query builder
      let query = this.supabase
        .schema(schema)
        .from(table)
        .select(select)
        .limit(25);
    
      // Apply where conditions
      where.forEach((condition) => {
        query = this.applyWhereCondition(query, condition);
      });
    
      const { data, error } = await query;
    
      if (error) throw error;
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(data, null, 2),
          },
        ],
      };
    }
  • TypeScript interface defining the structure of input arguments for the query_table tool, including optional schema, required table, optional select, and where clauses.
    interface QueryTableArgs {
      schema?: string;
      table: string;
      select?: string;
      where?: {
        column: string;
        operator: WhereOperator;
        value: any;
      }[];
    }
  • src/index.ts:175-230 (registration)
    Tool registration in the ListTools handler, providing the name, description, and detailed JSON schema for input validation.
      name: "query_table",
      description:
        "Query a specific table with schema selection and where clause support",
      inputSchema: {
        type: "object",
        properties: {
          schema: {
            type: "string",
            description: "Database schema (optional, defaults to public)",
          },
          table: {
            type: "string",
            description: "Name of the table to query",
          },
          select: {
            type: "string",
            description:
              "Comma-separated list of columns to select (optional, defaults to *)",
          },
          where: {
            type: "array",
            description: "Array of where conditions (optional)",
            items: {
              type: "object",
              properties: {
                column: {
                  type: "string",
                  description: "Column name",
                },
                operator: {
                  type: "string",
                  description: "Comparison operator",
                  enum: [
                    "eq",
                    "neq",
                    "gt",
                    "gte",
                    "lt",
                    "lte",
                    "like",
                    "ilike",
                    "is",
                  ],
                },
                value: {
                  type: "any",
                  description: "Value to compare against",
                },
              },
              required: ["column", "operator", "value"],
            },
          },
        },
        required: ["table"],
      },
    },
  • Type guard function to validate that tool arguments conform to the QueryTableArgs interface before execution.
    const isValidQueryTableArgs = (args: any): args is QueryTableArgs =>
      typeof args === "object" &&
      args !== null &&
      typeof args.table === "string" &&
      (args.schema === undefined || typeof args.schema === "string") &&
      (args.select === undefined || typeof args.select === "string") &&
      (args.where === undefined ||
        (Array.isArray(args.where) &&
          args.where.every(
            (w: any) =>
              typeof w === "object" &&
              w !== null &&
              typeof w.column === "string" &&
              typeof w.operator === "string" &&
              [
                "eq",
                "neq",
                "gt",
                "gte",
                "lt",
                "lte",
                "like",
                "ilike",
                "is",
              ].includes(w.operator)
          )));
  • Helper method to apply individual WHERE conditions to the Supabase query builder using the specified operator.
    private applyWhereCondition(
      query: any,
      condition: { column: string; operator: WhereOperator; value: any }
    ): any {
      switch (condition.operator) {
        case "eq":
          return query.eq(condition.column, condition.value);
        case "neq":
          return query.neq(condition.column, condition.value);
        case "gt":
          return query.gt(condition.column, condition.value);
        case "gte":
          return query.gte(condition.column, condition.value);
        case "lt":
          return query.lt(condition.column, condition.value);
        case "lte":
          return query.lte(condition.column, condition.value);
        case "like":
          return query.like(condition.column, condition.value);
        case "ilike":
          return query.ilike(condition.column, condition.value);
        case "is":
          return query.is(condition.column, condition.value);
        default:
          throw new McpError(
            ErrorCode.InvalidParams,
            `Unsupported operator: ${condition.operator}`
          );
      }
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 states the tool queries a table but doesn't mention whether this is read-only (likely but not confirmed), what permissions are required, whether it supports pagination/limits, error handling, or what the output format looks like. 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 communicates the core functionality without unnecessary words. It's appropriately sized for the tool's complexity and front-loads the main purpose immediately.

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?

For a database query tool with 4 parameters and no annotations or output schema, the description is insufficient. It doesn't address key contextual elements like: whether this is a safe read operation, what authentication/permissions are needed, how results are returned (format, size limits), error conditions, or relationship to the sibling tool. The 100% schema coverage helps with parameters but doesn't compensate for missing behavioral context.

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 already documents all 4 parameters thoroughly. The description mentions 'schema selection and where clause support' which aligns with parameters in the schema but doesn't add meaningful semantic context beyond what's already in the parameter descriptions. Baseline 3 is appropriate when schema does the heavy lifting.

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 ('Query') and resource ('a specific table'), with additional functionality mentioned ('schema selection and where clause support'). It distinguishes from the sibling 'generate_types' by focusing on data retrieval rather than type generation. However, it doesn't specify if this is a read-only query or might modify data.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. The description mentions functionality but doesn't indicate scenarios where this tool is appropriate, prerequisites for use, or limitations compared to other query methods. The sibling tool 'generate_types' serves a completely different purpose, so no comparative guidance is needed.

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/NightTrek/Supabase-MCP'

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