Skip to main content
Glama

API-retrieve-a-database

Retrieve structured data from a Notion database using its ID to access content through read-only queries for AI assistants.

Instructions

Retrieve a database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_idYesAn identifier for the Notion database.

Implementation Reference

  • Registers all converted OpenAPI operations as MCP tools, including 'API-retrieve-a-database' (toolName='API', method.name='retrieve-a-database').
    Object.entries(this.tools).forEach(([toolName, def]) => {
      def.methods.forEach(method => {
        const toolNameWithMethod = `${toolName}-${method.name}`;
        const truncatedToolName = this.truncateToolName(toolNameWithMethod);
        tools.push({
          name: truncatedToolName,
          description: method.description,
          inputSchema: method.inputSchema as Tool['inputSchema'],
        })
        console.log(`- ${truncatedToolName}: ${method.description}`)
      })
    })
  • Generic handler for tool calls: looks up OpenAPI operation for tool name 'API-retrieve-a-database', executes HTTP request via httpClient, updates cache, and returns JSON response.
    // Find the operation in OpenAPI spec
    const operation = this.findOperation(name)
    if (!operation) {
      const error = `Method ${name} not found.`
      console.error(error)
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              status: 'error',
              message: error,
              code: 404
            }),
          },
        ],
      }
    }
    
    // Optimized parallel processing for API-get-block-children
    if (name === 'API-get-block-children') {
      // Create basic options for logging control
      const blockOptions: RecursiveExplorationOptions = {
        runInBackground: false, // Default to not showing logs for regular API calls
      };
      
      return await this.handleBlockChildrenParallel(operation, params, blockOptions);
    }
    
    // Other regular API calls
    console.log(`Notion API call: ${operation.method.toUpperCase()} ${operation.path}`)
    const response = await this.httpClient.executeOperation(operation, params)
    
    // Log response summary
    console.log('Notion API response code:', response.status)
    if (response.status !== 200) {
      console.error('Response error:', response.data)
    } else {
      console.log('Response success')
    }
    
    // Update cache with response data
    this.updateCacheFromResponse(name, response.data);
    
    // Convert response to MCP format
    return {
      content: [
        {
          type: 'text',
          text: JSON.stringify(response.data),
        },
      ],
    }
  • Updates the database cache after a successful API-retrieve-a-database call.
    private updateCacheFromResponse(apiName: string, data: any): void {
      if (!data || typeof data !== 'object') return;
    
      try {
        // Update appropriate cache based on API response type
        if (apiName === 'API-retrieve-a-page' && data.object === 'page' && data.id) {
          this.pageCache.set(data.id, data);
        } else if (apiName === 'API-retrieve-a-block' && data.object === 'block' && data.id) {
          this.blockCache.set(data.id, data);
        } else if (apiName === 'API-retrieve-a-database' && data.object === 'database' && data.id) {
          this.databaseCache.set(data.id, data);
        } else if (apiName === 'API-retrieve-a-comment' && data.results) {
          // Cache comments from result list
          data.results.forEach((comment: any) => {
            if (comment.object === 'comment' && comment.id) {
              this.commentCache.set(comment.id, comment);
            }
          });
        } else if (apiName === 'API-retrieve-a-page-property' && data.results) {
          // Page property caching - would need params from call context
          // Skip this in current context
          console.log('Page property information has been cached');
        }
    
        // API-get-block-children handled in handleBlockChildrenParallel
      } catch (error) {
        console.warn('Error updating cache:', error);
      }
    }
  • Helper method used internally to retrieve Notion database details using the API-retrieve-a-database tool, with caching.
    private async retrieveDatabase(databaseId: string, options: RecursiveExplorationOptions): Promise<any> {
      console.log(`Retrieving database information: ${databaseId}`);
      
      // Check cache
      if (!options.skipCache && this.databaseCache.has(databaseId)) {
        console.log(`Database cache hit: ${databaseId}`);
        return this.databaseCache.get(databaseId);
      }
      
      // Get database info via API call
      const operation = this.findOperation('API-retrieve-a-database');
      if (!operation) {
        console.warn('API-retrieve-a-database method not found.');
        return { id: databaseId, note: "Database details not available" };
      }
      
      try {
        console.log(`Notion API call: ${operation.method.toUpperCase()} ${operation.path} (databaseId: ${databaseId})`);
        const response = await this.httpClient.executeOperation(operation, { database_id: databaseId });
        
        if (response.status !== 200) {
          console.error('Error retrieving database information:', response.data);
          return { id: databaseId, error: "Failed to retrieve database" };
        }
        
        const databaseData = response.data;
        this.databaseCache.set(databaseId, databaseData);
        return databaseData;
      } catch (error) {
        console.error('Error retrieving database:', error);
        return { id: databaseId, error: "Failed to retrieve database" };
      }
    }
  • Initializes the tools map including 'API-retrieve-a-database' by converting the OpenAPI specification using OpenAPIToMCPConverter.
      const converter = new OpenAPIToMCPConverter(openApiSpec)
      const { tools, openApiLookup } = converter.convertToMCPTools()
      this.tools = tools
      this.openApiLookup = openApiLookup
    
      this.setupHandlers()
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the action ('Retrieve') without detailing aspects like authentication requirements, rate limits, error handling, or what the retrieval entails (e.g., read-only operation, data format returned). This leaves significant gaps in understanding the tool's behavior.

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 extremely concise with just two words, making it front-loaded and free of unnecessary information. Every word earns its place, though this brevity contributes to gaps in other dimensions like purpose clarity and guidelines.

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 lack of annotations and output schema, the description is incomplete for a retrieval tool. It fails to explain what is retrieved (e.g., database properties, schema, content), potential side effects, or response format, leaving the agent with insufficient context to use the tool effectively.

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?

The input schema has 100% description coverage, with the single parameter 'database_id' clearly documented as 'An identifier for the Notion database.' The description adds no additional semantic context beyond this, so it meets the baseline score of 3 where the schema does the heavy lifting.

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

Purpose2/5

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

The description 'Retrieve a database' is a tautology that essentially restates the tool name 'API-retrieve-a-database' without adding meaningful specificity. While it indicates a retrieval action on a database resource, it lacks details about what exactly is retrieved (structure, content, metadata) and doesn't differentiate from sibling tools like 'API-retrieve-a-page' or 'API-retrieve-a-block' beyond the resource type.

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

Usage Guidelines1/5

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

The description provides no guidance on when to use this tool versus alternatives. There are no explicit instructions, prerequisites, or comparisons to sibling tools (e.g., when to retrieve a database vs. a page or block), leaving the agent with no contextual cues for 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/Taewoong1378/notion-readonly-mcp-server'

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