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() }

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