Skip to main content
Glama
call518

MCP PostgreSQL Operations

by call518

get_table_relationships

Analyze table relationships by mapping foreign keys, view dependencies, inheritance, and partitions. Use it to review schema design, spot orphaned tables, and plan migrations or schema changes.

Instructions

[Tool Purpose]: Analyze table relationships including foreign keys, dependencies, and inheritance

[Exact Functionality]:

  • Show foreign key relationships (inbound and outbound)

  • Display view dependencies and table references

  • Analyze inheritance and partition relationships

  • Identify orphaned tables and relationship patterns

[Required Use Cases]:

  • When user requests "table relationships", "foreign keys", "dependencies", etc.

  • When analyzing database schema design and data model

  • When planning data migration or schema changes

[Strictly Prohibited Use Cases]:

  • Requests for actual data inside tables

  • Requests for relationship modifications or DDL operations

  • Requests for performance statistics (use other tools for that)

Input Schema

NameRequiredDescriptionDefault
table_nameNoSpecific table name to analyze (if None, shows database-wide relationship overview)
schema_nameNoSchema name to search in (default: "public")public
database_nameYesDatabase name to query (REQUIRED - specify which database to analyze)
relationship_typeNoType of relationships to show ("all", "foreign_keys", "dependencies", "inheritance")all

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv3.4.3
    • addedInput schema / properties / database_name / description
      Added value: +"Database name to query (REQUIRED - specify which database to analyze)"
    • addedInput schema / properties / relationship_type / description
      Added value: +"Type of relationships to show (\"all\", \"foreign_keys\", \"dependencies\", \"inheritance\")"
    • addedInput schema / properties / schema_name / description
      Added value: +"Schema name to search in (default: \"public\")"
    • addedInput schema / properties / table_name / description
      Added value: +"Specific table name to analyze (if None, shows database-wide relationship overview)"
  2. Changed9 schema fields changedv3.4.2
    • addedInput schema / additionalProperties
      Added value: +false
    • removedInput schema / properties / database_name / title
      Removed value: -"Database Name"
    • removedInput schema / properties / relationship_type / title
      Removed value: -"Relationship Type"
    • removedInput schema / properties / schema_name / title
      Removed value: -"Schema Name"
    • addedInput schema / properties / table_name / anyOf
      Added value: +[
      +  {
      +    "type": "string"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • removedInput schema / properties / table_name / title
      Removed value: -"Table Name"
    • removedInput schema / properties / table_name / type
      Removed value: -"string"
    • removedOutput schema / properties / result / title
      Removed value: -"Result"
    • removedOutput schema / title
      Removed value: -"_WrappedResult"
  3. Addedv1.0.0

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must carry the behavioral burden, and it largely does: it makes clear the tool is a read-only analysis (modification/DDL is prohibited), discloses the categories of output (inbound/outbound FKs, dependencies, inheritance, orphans), and sets scope (database-wide vs. single table). It does not mention cost/latency on large schemas or required privileges, which keeps it from a 5.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The bracketed section headers make it highly scannable and front-load purpose before use cases. It is slightly verbose with some redundancy between the functionality list and the use-case examples, but every block contributes actionable information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An output schema exists, so return-value description is unnecessary, and the description fully covers purpose, scope (database-wide vs. table-specific), allowed and disallowed scenarios. Nothing an agent needs to decide to call this tool and pass correct arguments is missing.

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 100%, so all four parameters (including the optional table_name and the relationship_type filter) are already documented in the schema. The description adds no syntax, format, or behavioral nuance about these parameters beyond what the schema states, so the baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description opens with a specific verb+resource ('Analyze table relationships') and enumerates the exact relationship classes covered (foreign keys, view dependencies, inheritance/partitions, orphaned tables). This clearly separates it from neighbors like get_table_schema_info or get_table_list, which deal with structure and inventory rather than relational topology.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides explicit 'Required Use Cases' with trigger phrases ("table relationships", "foreign keys", "dependencies") and an explicit 'Strictly Prohibited Use Cases' block excluding data retrieval, DDL/modification, and performance statistics. This is the strongest form of when/when-not guidance, and it routes the agent away from misuse.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.