Skip to main content
Glama
michaelyuwh

Enhanced MCP MSSQL Server

by michaelyuwh

mssql_get_relationships

Retrieve foreign key relationships between tables in a Microsoft SQL Server database to understand data dependencies and schema structure.

Instructions

Get foreign key relationships for tables

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serverYesMSSQL Server hostname or IP address
portNoPort number (default: 1433)
userYesUsername for authentication
passwordYesPassword for authentication
databaseYesDatabase name
tableNoTable name (optional - if not provided, gets all relationships)
encryptNoUse encrypted connection (default: true)
trustServerCertificateNoTrust server certificate (default: true)

Implementation Reference

  • The handler function that implements the core logic of the mssql_get_relationships tool by querying the database's INFORMATION_SCHEMA views for foreign key relationships.
    private async handleGetRelationships(args: any) {
      const config = ConnectionSchema.parse(args);
      const { table } = args;
      const pool = await this.getConnection(config);
      
      const request = pool.request();
      let whereClause = '';
      if (table) {
        whereClause = `AND fk.TABLE_NAME = '${table}'`;
      }
    
      const result = await request.query(`
        USE [${config.database}];
        SELECT 
          fk.TABLE_NAME as table_name,
          fk.COLUMN_NAME as column_name,
          pk.TABLE_NAME as referenced_table,
          pk.COLUMN_NAME as referenced_column,
          fk.CONSTRAINT_NAME as constraint_name
        FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc
        INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE fk
          ON rc.CONSTRAINT_NAME = fk.CONSTRAINT_NAME
        INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE pk
          ON rc.UNIQUE_CONSTRAINT_NAME = pk.CONSTRAINT_NAME
        WHERE 1=1 ${whereClause}
        ORDER BY fk.TABLE_NAME, fk.COLUMN_NAME
      `);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              server: config.server,
              database: config.database,
              table: table || 'all',
              relationships: result.recordset,
            }, null, 2),
          },
        ],
      };
    }
  • src/index.ts:447-448 (registration)
    The switch case in the CallToolRequestHandler that dispatches calls to the mssql_get_relationships handler function.
    case 'mssql_get_relationships':
      return await this.handleGetRelationships(args);
  • src/index.ts:361-378 (registration)
    The tool registration in ListToolsRequestHandler, defining the name, description, and input schema for mssql_get_relationships.
    {
      name: 'mssql_get_relationships',
      description: 'Get foreign key relationships for tables',
      inputSchema: {
        type: 'object',
        properties: {
          server: { type: 'string', description: 'MSSQL Server hostname or IP address' },
          port: { type: 'number', description: 'Port number (default: 1433)', default: 1433 },
          user: { type: 'string', description: 'Username for authentication' },
          password: { type: 'string', description: 'Password for authentication' },
          database: { type: 'string', description: 'Database name' },
          table: { type: 'string', description: 'Table name (optional - if not provided, gets all relationships)' },
          encrypt: { type: 'boolean', description: 'Use encrypted connection (default: true)', default: true },
          trustServerCertificate: { type: 'boolean', description: 'Trust server certificate (default: true)', default: true },
        },
        required: ['server', 'user', 'password', 'database'],
      },
    },
  • Shared Zod schema used for parsing connection parameters in the mssql_get_relationships handler.
    const ConnectionSchema = z.object({
      server: z.string().describe('MSSQL Server hostname or IP address'),
      port: z.number().default(1433).describe('Port number (default: 1433)'),
      user: z.string().describe('Username for authentication'),
      password: z.string().describe('Password for authentication'),
      database: z.string().optional().describe('Database name (optional)'),
      encrypt: z.boolean().default(true).describe('Use encrypted connection'),
      trustServerCertificate: z.boolean().default(true).describe('Trust server certificate'),
    });
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but offers minimal information. It doesn't indicate whether this is a read-only operation, what format the relationships are returned in, whether it requires specific permissions, or any performance considerations. The description states what the tool does but not how it behaves.

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 a single, efficient sentence that states the core purpose without unnecessary words. It's appropriately sized for a straightforward data retrieval tool and gets directly to the point with zero waste.

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?

For a database tool with 8 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't address what the output looks like (structure, format), error conditions, authentication requirements beyond what's in the schema, or how it differs from related tools. The agent lacks critical context for proper tool selection and invocation.

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 the schema already fully documents all 8 parameters. The description adds no additional parameter semantics beyond what's in the schema - it doesn't explain the optional 'table' parameter's effect on scope or provide context about relationship types. Baseline 3 is appropriate when schema does all the work.

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

Purpose4/5

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

The description clearly states the verb ('Get') and resource ('foreign key relationships for tables'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like mssql_describe_table or mssql_list_tables, but the specific focus on foreign key relationships provides reasonable distinction.

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?

The description provides no guidance on when to use this tool versus alternatives like mssql_describe_table (which might include relationship info) or mssql_list_tables. There's no mention of prerequisites, use cases, or comparison with sibling tools, leaving the agent to infer usage context.

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

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