Skip to main content
Glama
describe-branch.ts2.45 kB
import { Api, Branch } from '@neondatabase/api-client'; import { ToolHandlerExtraParams } from '../types.js'; import { handleGetConnectionString } from './connection-string.js'; import { neon } from '@neondatabase/serverless'; import { DESCRIBE_DATABASE_STATEMENTS } from '../utils.js'; import { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import { CONSOLE_URLS, generateConsoleUrl } from './urls.js'; const branchInfo = (branch: Branch) => { return `Branch Details: Name: ${branch.name} ID: ${branch.id} Parent Branch: ${branch.parent_id} Default: ${branch.default} Protected: ${branch.protected ? 'Yes' : 'No'} ${branch.created_by ? `Created By: ${branch.created_by.name}` : ''} Created: ${new Date(branch.created_at).toLocaleDateString()} Updated: ${new Date(branch.updated_at).toLocaleDateString()} Compute Usage: ${branch.compute_time_seconds} seconds Written Data: ${branch.written_data_bytes} bytes Data Transfer: ${branch.data_transfer_bytes} bytes Console Link: ${generateConsoleUrl(CONSOLE_URLS.PROJECT_BRANCH, { projectId: branch.project_id, branchId: branch.id, })} `; }; export async function handleDescribeBranch( { projectId, databaseName, branchId, }: { projectId: string; databaseName?: string; branchId: string; }, neonClient: Api<unknown>, extra: ToolHandlerExtraParams, ): Promise<CallToolResult> { const { data: branchData } = await neonClient.getProjectBranch( projectId, branchId, ); const branch = branchData.branch; let response: Record<string, any>[][]; try { const connectionString = await handleGetConnectionString( { projectId, branchId: branch.id, databaseName, }, neonClient, extra, ); const runQuery = neon(connectionString.uri); response = await runQuery.transaction( DESCRIBE_DATABASE_STATEMENTS.map((sql) => runQuery.query(sql)), ); return { content: [ { type: 'text', text: branchInfo(branch), metadata: branch, }, { type: 'text', text: ['Database Structure:', JSON.stringify(response, null, 2)].join( '\n', ), databasetree: response, }, ], }; } catch { // Ignore database connection errors } return { content: [ { type: 'text', text: branchInfo(branch), }, ], }; }

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/neondatabase-labs/mcp-server-neon'

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