Skip to main content
Glama
jesse-smith
by jesse-smith

find_fk_candidates

Find potential foreign key targets for a source column by matching compatible data types and prioritizing primary key candidates, with optional value overlap verification.

Instructions

Discover potential foreign key relationships for a source column.

EXPERIMENTAL — Results are based on common heuristics but have not been battle-tested for utility. They may contain false positives or exclude valid candidates. Use as a starting point for investigation, not as definitive answers.

Searches for target columns that could be the referenced side of a foreign key relationship. Matches by compatible data type. By default only considers target columns that are PK candidates (constraint-backed or structurally unique); set pk_candidates_only=False to broaden the search to all type-compatible columns. Optionally computes value overlap between source and target via SQL INTERSECT.

Args: connection_id: Connection ID from connect_database table_name: Source table name. May be dotted (e.g. 'schema.table' or 'catalog.schema.table') and is resolved against the dialect. column_name: Source column name schema_name: Source schema name. Defaults to the dialect's default schema (e.g. 'dbo' on MSSQL) when omitted. target_schema: Filter targets to this schema. Defaults to source schema. target_tables: Explicit list of target table names target_table_pattern: SQL LIKE pattern for target table names pk_candidates_only: Only compare against PK-candidate columns (default: True) include_overlap: Compute value overlap metrics (default: False) limit: Maximum candidates to return, 0 = no limit (default: 100) catalog: Optional Databricks catalog name. Rejected on non-Databricks dialects (returns an error response). On Databricks the catalog is threaded end-to-end (IDENT-08): the existence check, source-column type reflection, and FK search run against the requested catalog via catalog-scoped reflection (cross-catalog supported — no default-catalog binding required).

Returns: TOON-encoded string with status, source metadata, candidates list, and search info:

    status: "success" | "error"
    source: object                     // on success only
        column_name: string
        table_name: string
        schema_name: string
        data_type: string
    candidates: list                   // on success only
        source_column: string
        source_table: string
        source_schema: string
        source_data_type: string
        target_column: string
        target_table: string
        target_schema: string
        target_data_type: string
        target_is_primary_key: bool
        target_is_unique: bool
        target_is_nullable: bool
        target_has_index: bool
        overlap_count: int             // only when include_overlap=True
        overlap_percentage: float      // only when include_overlap=True
    total_found: int                   // on success only
    was_limited: bool                  // on success only
    search_scope: string               // on success only
    type_incompatible_skipped: int     // only when > 0 (type-incompatible targets skipped)
    error_message: string              // on error only

Error conditions: - Invalid connection_id: returns status "error" with error_message - Table not found: returns status "error" with error_message - Column not found: returns status "error" with error_message - No candidates: returns status "success" with empty candidates list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
catalogNo
table_nameYes
column_nameYes
schema_nameNo
connection_idYes
target_schemaNo
target_tablesNo
include_overlapNo
pk_candidates_onlyNo
target_table_patternNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.6/5.0
Behavior5/5

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

With no annotations provided, the description carries the full behavioral burden and handles it thoroughly. It discloses the experimental/heuristic nature, false-positive risk, type-compatibility matching, default PK-candidate restriction, optional SQL INTERSECT overlap computation, Databricks catalog behavior, and complete error conditions. This gives an agent a realistic model of what the tool will and will not do.

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

Conciseness5/5

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

The description is long but well-structured into Args, Returns, and Error conditions sections. Every paragraph serves a purpose, with the core purpose front-loaded before the experimental caveat and detailed parameter semantics. No filler or redundant restatements of the schema are present.

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?

Given the tool's complexity (11 parameters, dialect-sensitive behavior, no annotations, and a bespoke TOON-encoded return format), the description is complete. It covers invocation context, parameter behavior, output shape, error handling, and edge cases such as Databricks catalog threading and empty candidate results. An agent has everything needed to select and call it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must fully compensate for the input schema's lack of per-property descriptions. The Args section explains every parameter, including dotted table name resolution, default schema behavior, target filtering options, pk_candidates_only semantics, overlap behavior, limit interpretation, and the dialect-specific catalog rule. This is exactly the compensation needed.

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 and resource: 'Discover potential foreign key relationships for a source column' and then clearly defines the tool as searching for target columns that could be the referenced side of a foreign key. This sharply distinguishes it from siblings like find_pk_candidates or get_column_info even without naming them explicitly.

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

Usage Guidelines3/5

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

The description gives strong contextual guidance: it is experimental, a starting point, not definitive, and explains how to broaden or narrow the search via pk_candidates_only, target_schema, target_tables, and target_table_pattern. However, it never explicitly names sibling tools or states when to choose this tool over get_column_info, find_pk_candidates, or execute_query, so the 'when vs alternatives' guidance is only implied.

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