Skip to main content
Glama
dhipskind253

mssql-mcp

by dhipskind253

list_foreign_keys

Retrieve all foreign keys that originate from a specified table in the database.

Instructions

List foreign keys originating from a table.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
schemaYes
tableYes

Implementation Reference

  • The `listForeignKeys` method on `DbManager` that executes the SQL query to fetch foreign keys originating from a given schema+table. Returns rows with fk_name, parent_schema, parent_table, parent_column, referenced_schema, referenced_table, referenced_column, and ordinal.
    async listForeignKeys(schema: string, table: string) {
      const r = await (await this.getPool())
        .request()
        .input('schema', sql.NVarChar, schema)
        .input('table', sql.NVarChar, table).query(`
          SELECT
            fk.name AS fk_name,
            s_parent.name AS parent_schema,
            t_parent.name AS parent_table,
            c_parent.name AS parent_column,
            s_ref.name AS referenced_schema,
            t_ref.name AS referenced_table,
            c_ref.name AS referenced_column,
            fkc.constraint_column_id AS ordinal
          FROM sys.foreign_keys fk
          INNER JOIN sys.foreign_key_columns fkc
            ON fk.object_id = fkc.constraint_object_id
          INNER JOIN sys.tables t_parent ON fk.parent_object_id = t_parent.object_id
          INNER JOIN sys.schemas s_parent ON t_parent.schema_id = s_parent.schema_id
          INNER JOIN sys.columns c_parent
            ON fkc.parent_object_id = c_parent.object_id
           AND fkc.parent_column_id = c_parent.column_id
          INNER JOIN sys.tables t_ref ON fk.referenced_object_id = t_ref.object_id
          INNER JOIN sys.schemas s_ref ON t_ref.schema_id = s_ref.schema_id
          INNER JOIN sys.columns c_ref
            ON fkc.referenced_object_id = c_ref.object_id
           AND fkc.referenced_column_id = c_ref.column_id
          WHERE s_parent.name = @schema AND t_parent.name = @table
          ORDER BY fk.name, fkc.constraint_column_id
        `);
      return r.recordset;
    }
  • Schema definition for the 'list_foreign_keys' tool: takes 'schema' (string) and 'table' (string) as input parameters.
    {
      schema: z.string(),
      table: z.string(),
  • src/index.ts:100-108 (registration)
    Registration of the 'list_foreign_keys' tool with the MCP server, including its description, input schema, and handler that delegates to db.listForeignKeys().
    server.tool(
      'list_foreign_keys',
      'List foreign keys originating from a table.',
      {
        schema: z.string(),
        table: z.string(),
      },
      async ({ schema, table }) => runTool(() => db.listForeignKeys(schema, table))
    );
Behavior2/5

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

No annotations are provided, and the description does not disclose behavioral traits such as whether it returns only referencing foreign keys, permission requirements, or output format. The description is too minimal for a tool without annotations.

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

Conciseness3/5

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

The description is a single sentence, which is concise, but it could include more detail without becoming verbose. It is adequately structured but lacks substance.

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

Completeness2/5

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

Given no output schema and no annotations, the description should explain return values and any limitations. It does not, making it incomplete for an agent to fully understand tool behavior.

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

Parameters1/5

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

The description does not explain the two required parameters (schema and table) beyond what the schema provides. With 0% schema description coverage, the description should compensate, but it adds no additional meaning.

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 clearly states 'List foreign keys originating from a table', which is a specific verb (list) and resource (foreign keys from a table). It distinguishes from siblings like describe_table or list_indexes which have different purposes.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like list_indexes or describe_table. No exclusions or usage context are mentioned.

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

Install Server

Other Tools

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/dhipskind253/mssql-mcp'

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