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
| Name | Required | Description | Default |
|---|---|---|---|
| environment | Yes | Database environment to analyze | |
| tableName | No | Optional: Filter relationships for specific table |
Implementation Reference
- Core handler logic that executes the tool: fetches schema from cache or repository, extracts relationships using RelationshipAnalyzer, filters by optional tableName, formats into DTOs, and returns 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, }; }
- src/presentation/mcp/MCPServer.ts:103-122 (registration)Registers the get_table_relationships tool in the MCP server's listTools response, defining its name, description, and input schema.{ 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'], }, },
- MCP-specific tool handler that parses tool call arguments, invokes GetRelationshipsUseCase, and formats response as MCP content.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), }, ], }; }
- Type definition for the input parameters to the use case handler, matching the MCP input schema.export interface GetRelationshipsRequest { environment: Environment; tableName?: string; }