Skip to main content
Glama

notion_query_database

Retrieve and filter data from Notion databases using queries, sorting, and pagination to access structured information.

Instructions

Query a database in Notion

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_idYesThe ID of the database to query.It should be a 32-character string (excluding hyphens) formatted as 8-4-4-4-12 with hyphens (-).
filterNoFilter conditions
sortsNoSort conditions
start_cursorNoPagination cursor for next page of results
page_sizeNoNumber of results per page (max 100)
formatNoSpecify the response format. 'json' returns the original data structure, 'markdown' returns a more readable format. Use 'markdown' when the user only needs to read the page and isn't planning to write or modify it. Use 'json' when the user needs to read the page with the intention of writing to or modifying it.markdown

Implementation Reference

  • Core implementation of the notion_query_database tool: makes POST request to Notion API /databases/{database_id}/query with optional filter, sorts, pagination.
    async queryDatabase(
      database_id: string,
      filter?: Record<string, any>,
      sorts?: Array<{
        property?: string;
        timestamp?: string;
        direction: "ascending" | "descending";
      }>,
      start_cursor?: string,
      page_size?: number
    ): Promise<ListResponse> {
      const body: Record<string, any> = {};
      if (filter) body.filter = filter;
      if (sorts) body.sorts = sorts;
      if (start_cursor) body.start_cursor = start_cursor;
      if (page_size) body.page_size = page_size;
    
      const response = await fetch(
        `${this.baseUrl}/databases/${database_id}/query`,
        {
          method: "POST",
          headers: this.headers,
          body: JSON.stringify(body),
        }
      );
    
      return response.json();
    }
  • MCP server handler for notion_query_database: validates database_id and delegates to NotionClientWrapper.queryDatabase.
    case "notion_query_database": {
      const args = request.params
        .arguments as unknown as args.QueryDatabaseArgs;
      if (!args.database_id) {
        throw new Error("Missing required argument: database_id");
      }
      response = await notionClient.queryDatabase(
        args.database_id,
        args.filter,
        args.sorts,
        args.start_cursor,
        args.page_size
      );
      break;
  • Tool schema definition including name, description, and input schema for notion_query_database.
    export const queryDatabaseTool: Tool = {
      name: "notion_query_database",
      description: "Query a database in Notion",
      inputSchema: {
        type: "object",
        properties: {
          database_id: {
            type: "string",
            description: "The ID of the database to query." + commonIdDescription,
          },
          filter: {
            type: "object",
            description: "Filter conditions",
          },
          sorts: {
            type: "array",
            description: "Sort conditions",
            items: {
              type: "object",
              properties: {
                property: { type: "string" },
                timestamp: { type: "string" },
                direction: {
                  type: "string",
                  enum: ["ascending", "descending"],
                },
              },
              required: ["direction"],
            },
          },
          start_cursor: {
            type: "string",
            description: "Pagination cursor for next page of results",
          },
          page_size: {
            type: "number",
            description: "Number of results per page (max 100)",
          },
          format: formatParameter,
        },
        required: ["database_id"],
      },
    };
  • Registration of notion_query_database tool (as queryDatabaseTool) in the MCP server's listTools handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      const allTools = [
        schemas.appendBlockChildrenTool,
        schemas.retrieveBlockTool,
        schemas.retrieveBlockChildrenTool,
        schemas.deleteBlockTool,
        schemas.updateBlockTool,
        schemas.retrievePageTool,
        schemas.updatePagePropertiesTool,
        schemas.listAllUsersTool,
        schemas.retrieveUserTool,
        schemas.retrieveBotUserTool,
        schemas.createDatabaseTool,
        schemas.queryDatabaseTool,
        schemas.retrieveDatabaseTool,
        schemas.updateDatabaseTool,
        schemas.createDatabaseItemTool,
        schemas.createCommentTool,
        schemas.retrieveCommentsTool,
        schemas.searchTool,
      ];
      return {
        tools: filterTools(allTools, enabledToolsSet),
      };
    });
  • TypeScript interface for QueryDatabaseArgs used in tool handler for type casting.
    export interface QueryDatabaseArgs {
      database_id: string;
      filter?: Record<string, any>;
      sorts?: Array<{
        property?: string;
        timestamp?: string;
        direction: "ascending" | "descending";
      }>;
      start_cursor?: string;
      page_size?: number;
      format?: "json" | "markdown";
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the action without behavioral details. It doesn't disclose whether this is a read-only operation, potential rate limits, authentication needs, pagination behavior, or error handling, leaving critical operational context unspecified.

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 with zero waste—it directly states the tool's function without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 (6 parameters with nested objects, no output schema, and no annotations), the description is incomplete. It fails to explain the tool's behavior, output format, or interaction with sibling tools, leaving gaps that could hinder an AI agent's ability to use it effectively in 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 parameters are well-documented in the schema itself. The description adds no additional meaning beyond the schema, such as explaining the purpose of 'filter' or 'sorts' in practical terms, but the schema provides sufficient detail, meeting the baseline for high coverage.

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

Purpose3/5

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

The description 'Query a database in Notion' states the basic action and resource but is vague about scope and functionality. It doesn't specify what querying entails (e.g., retrieving filtered/sorted records) or distinguish it from sibling tools like 'notion_retrieve_database' or 'notion_search', leaving ambiguity about when to use each.

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 lacks context about prerequisites, typical use cases, or comparisons to siblings like 'notion_retrieve_database' (which might fetch metadata) or 'notion_search' (which searches across workspaces), offering no help in tool selection.

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/kimjungyeol/mcp-notion-server'

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