Skip to main content
Glama

API-create-a-database

Build and customize databases within Notion pages using structured property schemas. Ideal for integrating AI agents with Notion workspaces for efficient data management.

Instructions

Notion | Create a database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
parentYes
propertiesYesProperty schema of database. The keys are the names of properties as they appear in Notion and the values are [property schema objects](https://developers.notion.com/reference/property-schema-object).
titleNo

Implementation Reference

  • Generic handler for executing any MCP tool, including "API-create-a-database". It resolves the tool name to the corresponding OpenAPI operation using openApiLookup, executes the HTTP request via httpClient, and returns the response as MCP content.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: params } = request.params
    
      // Find the operation in OpenAPI spec
      const operation = this.findOperation(name)
      if (!operation) {
        throw new Error(`Method ${name} not found`)
      }
    
      try {
        // Execute the operation
        const response = await this.httpClient.executeOperation(operation, params)
    
        // Convert response to MCP format
        return {
          content: [
            {
              type: 'text', // currently this is the only type that seems to be used by mcp server
              text: JSON.stringify(response.data), // TODO: pass through the http status code text?
            },
          ],
        }
      } catch (error) {
        console.error('Error in tool call', error)
        if (error instanceof HttpClientError) {
          console.error('HttpClientError encountered, returning structured error', error)
          const data = error.data?.response?.data ?? error.data ?? {}
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  status: 'error', // TODO: get this from http status code?
                  ...(typeof data === 'object' ? data : { data: data }),
                }),
              },
            ],
          }
        }
        throw error
      }
    })
  • Registration of the listTools handler, which dynamically lists all generated tools, constructing names as 'API-{operationId}' (e.g., 'API-create-a-database') from the OpenAPI spec converter.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      const tools: Tool[] = []
    
      // Add methods as separate tools to match the MCP format
      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'],
          })
        })
      })
    
      return { tools }
    })
  • Generates the tool definitions including input schemas from OpenAPI operations. Tool names are constructed as 'API-{operationId}', and inputSchema is built from parameters and requestBody for each operation like 'create-a-database'.
    convertToMCPTools(): {
      tools: Record<string, { methods: NewToolMethod[] }>
      openApiLookup: Record<string, OpenAPIV3.OperationObject & { method: string; path: string }>
      zip: Record<string, { openApi: OpenAPIV3.OperationObject & { method: string; path: string }; mcp: NewToolMethod }>
    } {
      const apiName = 'API'
    
      const openApiLookup: Record<string, OpenAPIV3.OperationObject & { method: string; path: string }> = {}
      const tools: Record<string, { methods: NewToolMethod[] }> = {
        [apiName]: { methods: [] },
      }
      const zip: Record<string, { openApi: OpenAPIV3.OperationObject & { method: string; path: string }; mcp: NewToolMethod }> = {}
      for (const [path, pathItem] of Object.entries(this.openApiSpec.paths || {})) {
        if (!pathItem) continue
    
        for (const [method, operation] of Object.entries(pathItem)) {
          if (!this.isOperation(method, operation)) continue
    
          const mcpMethod = this.convertOperationToMCPMethod(operation, method, path)
          if (mcpMethod) {
            const uniqueName = this.ensureUniqueName(mcpMethod.name)
            mcpMethod.name = uniqueName
            mcpMethod.description = this.getDescription(operation.summary || operation.description || '')
            tools[apiName]!.methods.push(mcpMethod)
            openApiLookup[apiName + '-' + uniqueName] = { ...operation, method, path }
            zip[apiName + '-' + uniqueName] = { openApi: { ...operation, method, path }, mcp: mcpMethod }
          }
        }
      }
    
      return { tools, openApiLookup, zip }
    }
  • MCPProxy constructor initializes the server, HTTP client for Notion API, converts OpenAPI spec to MCP tools using the parser, stores the mappings, and sets up handlers. This is where 'API-create-a-database' is dynamically registered.
    constructor(name: string, openApiSpec: OpenAPIV3.Document) {
      this.server = new Server({ name, version: '1.0.0' }, { capabilities: { tools: {} } })
      const baseUrl = openApiSpec.servers?.[0].url
      if (!baseUrl) {
        throw new Error('No base URL found in OpenAPI spec')
      }
      this.httpClient = new HttpClient(
        {
          baseUrl,
          headers: this.parseHeadersFromEnv(),
        },
        openApiSpec,
      )
    
      // Convert OpenAPI spec to MCP tools
      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?

With no annotations provided, the description carries full burden but only states the action without behavioral details. It does not disclose permissions required, rate limits, whether creation is idempotent, or what happens on failure. For a mutation tool, this is a significant gap in transparency.

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 two parts separated by '|', front-loading the platform and action. Every word earns its place, and there is no wasted verbiage, making it efficient for quick scanning.

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 (3 parameters with nested objects, no output schema, and no annotations), the description is incomplete. It lacks details on usage, behavioral traits, parameter meanings, and expected outcomes. For a creation tool in a rich API like Notion, this leaves critical gaps for an agent.

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 33% (only the 'properties' parameter has a description), so the description must compensate but adds no parameter details. It implies parameters through 'Create a database' but does not explain 'parent', 'title', or 'properties' beyond the schema. Baseline is 3 due to low coverage, but the description fails to enhance understanding.

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 'Notion | Create a database' clearly states the action (create) and resource (database), with 'Notion' providing platform context. It distinguishes from siblings like 'API-post-page' or 'API-update-a-database' by specifying database creation. However, it lacks specificity about what a database entails in Notion, making it slightly less precise than a 5.

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?

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites (e.g., parent page), compare to similar tools like 'API-post-database-query' or 'API-retrieve-a-database', or indicate use cases. This leaves the agent without context 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

Related 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/punkpeye/notion-mcp-server-3'

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