Skip to main content
Glama

get_table_relationships

Extract and analyze foreign key relationships between tables in Cloudflare D1 databases to understand data connections and dependencies.

Instructions

Extract and analyze foreign key relationships between tables in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
environmentYesDatabase environment to analyze
tableNameNoOptional: Filter relationships for specific table

Implementation Reference

  • Core handler function that fetches cached schema, extracts relationships via analyzer, filters by optional tableName if provided, formats into DTOs, and returns the structured response.
    async execute(request: GetRelationshipsRequest): Promise<RelationshipsResponse> { const environment = request.environment; // Get or fetch schema (with caching) const schema = await this.getSchema(environment); // Extract relationships using domain service const allRelationships = this.relationshipAnalyzer.extractRelationships([...schema.tables]); // Filter by table if specified const relationships = request.tableName ? this.filterRelationshipsByTable(allRelationships, request.tableName) : allRelationships; // Format and return response return { databaseName: schema.name, environment: schema.environment, relationships: relationships.map((rel) => this.formatRelationship(rel)), relationshipCount: relationships.length, }; }
  • MCP-specific tool handler that validates/parses input arguments, invokes the GetRelationshipsUseCase, serializes the result to JSON, and returns it in MCP content format.
    private async handleGetRelationships(args: unknown) { const { environment, tableName } = args as { environment: string; tableName?: string; }; const result = await this.getRelationshipsUseCase.execute({ environment: parseEnvironment(environment), tableName, }); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
  • Registers the "get_table_relationships" MCP tool including its name, description, and input schema validation.
    { name: 'get_table_relationships', description: 'Extract and analyze foreign key relationships between tables in the database', inputSchema: { type: 'object', properties: { environment: { type: 'string', enum: ['development', 'staging', 'production'], description: 'Database environment to analyze', }, tableName: { type: 'string', description: 'Optional: Filter relationships for specific table', }, }, required: ['environment'], }, },
  • TypeScript interface defining the input parameters for the relationships extraction use case, matching the MCP tool inputSchema.
    export interface GetRelationshipsRequest { environment: Environment; tableName?: string; }
  • Domain service method that constructs Relationship domain entities from foreign key constraints in table metadata.
    extractRelationships(tables: TableInfo[]): Relationship[] { const relationships: Relationship[] = []; for (const table of tables) { for (const fk of table.foreignKeys) { relationships.push( new Relationship(fk.table, fk.column, fk.referencesTable, fk.referencesColumn, fk.onDelete, fk.onUpdate) ); } } return relationships; }

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/semanticintent/semantic-d1-mcp'

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