Skip to main content
Glama
tndfame
by tndfame

export_mssql_knowledge

Export Microsoft SQL Server database schema to Markdown documentation for question-answering systems, specifying output path and table/column limits.

Instructions

Export MSSQL schema (tables/columns) into a Markdown knowledge file for Q/A.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
outputPathNoOutput Markdown path (relative), e.g., docs/db-knowledge.mddocs/db-knowledge.md
tableLimitNoMax number of tables to document
columnLimitNoMax number of columns to document in total

Implementation Reference

  • The main handler function for the 'export_mssql_knowledge' tool. It queries the MSSQL database for tables and columns using limited TOP queries, groups columns by table, generates a comprehensive Markdown file with table lists, column tables, and example Q/A prompts, then writes it to the specified output path. Handles errors appropriately.
    async ({ outputPath, tableLimit, columnLimit }) => {
      try {
        const tablesRes = await queryReadOnly(
          `SELECT TOP ${tableLimit} s.name AS schema_name, t.name AS table_name
           FROM sys.tables t
           JOIN sys.schemas s ON t.schema_id = s.schema_id
           WHERE t.is_ms_shipped = 0
           ORDER BY s.name, t.name`,
        );
        const tables = tablesRes.rows || [];
    
        const colsRes = await queryReadOnly(
          `SELECT TOP ${columnLimit}
             TABLE_SCHEMA AS schema_name,
             TABLE_NAME AS table_name,
             COLUMN_NAME,
             DATA_TYPE,
             IS_NULLABLE,
             CHARACTER_MAXIMUM_LENGTH
           FROM INFORMATION_SCHEMA.COLUMNS
           ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION`,
        );
        const cols = colsRes.rows || [];
    
        const byTable = new Map<string, any[]>();
        for (const c of cols) {
          const key = `${c.schema_name}.${c.table_name}`;
          if (!byTable.has(key)) byTable.set(key, []);
          byTable.get(key)!.push(c);
        }
    
        const lines: string[] = [];
        lines.push(`# Database Knowledge`);
        lines.push("");
        lines.push(`Generated at: ${new Date().toISOString()}`);
        lines.push("");
        lines.push(`## Tables (${tables.length})`);
        for (const t of tables) {
          lines.push(`- ${t.schema_name}.${t.table_name}`);
        }
        lines.push("");
    
        for (const t of tables) {
          const key = `${t.schema_name}.${t.table_name}`;
          lines.push(`## ${key}`);
          lines.push(
            `Description: (กรุณาใส่คำอธิบายตารางนี้ เช่น ใช้เก็บอะไร, ความสัมพันธ์สำคัญ)\n`,
          );
          const list = byTable.get(key) || [];
          if (list.length) {
            lines.push(`Columns (${list.length})`);
            lines.push(`| Column | Type | Nullable | Length |`);
            lines.push(`| --- | --- | --- | --- |`);
            for (const c of list) {
              lines.push(
                `| ${c.COLUMN_NAME} | ${c.DATA_TYPE} | ${c.IS_NULLABLE} | ${c.CHARACTER_MAXIMUM_LENGTH ?? ""} |`,
              );
            }
          } else {
            lines.push(`(no columns fetched)`);
          }
          lines.push("");
          lines.push(`Example questions:`);
          lines.push(`- ตารางนี้มีคอลัมน์อะไรบ้าง`);
          lines.push(
            `- ตัวอย่างข้อมูล 10 แถวแรก (ถ้าต้องการให้แสดงข้อมูลจริง ให้ใช้โหมด DB และพิมพ์เช่น \"เข้าไป ${key} แสดง10 ข้อมูล\")`,
          );
          lines.push("");
        }
    
        const fs = await import("fs");
        const path = await import("path");
        const abs = path.resolve(process.cwd(), outputPath);
        fs.mkdirSync(path.dirname(abs), { recursive: true });
        fs.writeFileSync(abs, lines.join("\n"), "utf8");
        return createSuccessResponse({
          outputPath: outputPath,
          tables: tables.length,
          columns: cols.length,
        });
      } catch (e: any) {
        return createErrorResponse(
          `Failed to export MSSQL knowledge: ${e?.message || e}`,
        );
      }
    },
  • Zod schema definitions for the tool's input parameters: outputPath, tableLimit, and columnLimit.
    const outputPathSchema = z
      .string()
      .default("docs/db-knowledge.md")
      .describe("Output Markdown path (relative), e.g., docs/db-knowledge.md");
    const tableLimitSchema = z
      .number()
      .int()
      .min(1)
      .max(500)
      .default(200)
      .describe("Max number of tables to document");
    const columnLimitSchema = z
      .number()
      .int()
      .min(100)
      .max(5000)
      .default(2000)
      .describe("Max number of columns to document in total");
  • src/index.ts:77-77 (registration)
    Registers the ExportMssqlKnowledge tool instance on the MCP server during server initialization.
    new ExportMssqlKnowledge().register(server);
  • The internal tool registration call within the ExportMssqlKnowledge class's register method, specifying name, description, input schema, and handler.
    server.tool(
      "export_mssql_knowledge",
      "Export MSSQL schema (tables/columns) into a Markdown knowledge file for Q/A.",
      {
        outputPath: outputPathSchema,
        tableLimit: tableLimitSchema,
        columnLimit: columnLimitSchema,
      },
      async ({ outputPath, tableLimit, columnLimit }) => {
        try {
          const tablesRes = await queryReadOnly(
            `SELECT TOP ${tableLimit} s.name AS schema_name, t.name AS table_name
             FROM sys.tables t
             JOIN sys.schemas s ON t.schema_id = s.schema_id
             WHERE t.is_ms_shipped = 0
             ORDER BY s.name, t.name`,
          );
          const tables = tablesRes.rows || [];
    
          const colsRes = await queryReadOnly(
            `SELECT TOP ${columnLimit}
               TABLE_SCHEMA AS schema_name,
               TABLE_NAME AS table_name,
               COLUMN_NAME,
               DATA_TYPE,
               IS_NULLABLE,
               CHARACTER_MAXIMUM_LENGTH
             FROM INFORMATION_SCHEMA.COLUMNS
             ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION`,
          );
          const cols = colsRes.rows || [];
    
          const byTable = new Map<string, any[]>();
          for (const c of cols) {
            const key = `${c.schema_name}.${c.table_name}`;
            if (!byTable.has(key)) byTable.set(key, []);
            byTable.get(key)!.push(c);
          }
    
          const lines: string[] = [];
          lines.push(`# Database Knowledge`);
          lines.push("");
          lines.push(`Generated at: ${new Date().toISOString()}`);
          lines.push("");
          lines.push(`## Tables (${tables.length})`);
          for (const t of tables) {
            lines.push(`- ${t.schema_name}.${t.table_name}`);
          }
          lines.push("");
    
          for (const t of tables) {
            const key = `${t.schema_name}.${t.table_name}`;
            lines.push(`## ${key}`);
            lines.push(
              `Description: (กรุณาใส่คำอธิบายตารางนี้ เช่น ใช้เก็บอะไร, ความสัมพันธ์สำคัญ)\n`,
            );
            const list = byTable.get(key) || [];
            if (list.length) {
              lines.push(`Columns (${list.length})`);
              lines.push(`| Column | Type | Nullable | Length |`);
              lines.push(`| --- | --- | --- | --- |`);
              for (const c of list) {
                lines.push(
                  `| ${c.COLUMN_NAME} | ${c.DATA_TYPE} | ${c.IS_NULLABLE} | ${c.CHARACTER_MAXIMUM_LENGTH ?? ""} |`,
                );
              }
            } else {
              lines.push(`(no columns fetched)`);
            }
            lines.push("");
            lines.push(`Example questions:`);
            lines.push(`- ตารางนี้มีคอลัมน์อะไรบ้าง`);
            lines.push(
              `- ตัวอย่างข้อมูล 10 แถวแรก (ถ้าต้องการให้แสดงข้อมูลจริง ให้ใช้โหมด DB และพิมพ์เช่น \"เข้าไป ${key} แสดง10 ข้อมูล\")`,
            );
            lines.push("");
          }
    
          const fs = await import("fs");
          const path = await import("path");
          const abs = path.resolve(process.cwd(), outputPath);
          fs.mkdirSync(path.dirname(abs), { recursive: true });
          fs.writeFileSync(abs, lines.join("\n"), "utf8");
          return createSuccessResponse({
            outputPath: outputPath,
            tables: tables.length,
            columns: cols.length,
          });
        } catch (e: any) {
          return createErrorResponse(
            `Failed to export MSSQL knowledge: ${e?.message || e}`,
          );
        }
      },
    );
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. While 'Export' implies a read operation, it doesn't specify whether this requires database credentials, what happens if limits are exceeded, whether the operation is idempotent, or what happens if the output path already exists. The description lacks critical behavioral context for a tool that interacts with a database system.

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 communicates the core purpose without unnecessary words. It's front-loaded with the essential information and contains zero redundant or verbose elements.

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

Completeness3/5

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

For a tool with 3 parameters, 100% schema coverage, but no annotations or output schema, the description provides basic purpose but lacks important context about behavioral characteristics, error handling, and practical usage considerations. It's minimally adequate but leaves significant gaps in understanding how the tool behaves in real scenarios.

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?

The schema description coverage is 100%, providing complete parameter documentation. The description adds no additional parameter semantics beyond what's already in the schema. The baseline score of 3 reflects adequate but minimal value addition from the description regarding parameters.

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 the specific action ('Export'), target resource ('MSSQL schema (tables/columns)'), and output format ('Markdown knowledge file for Q/A'). It distinguishes from sibling tools like 'query_mssql' and 'ai_query_mssql' by focusing on documentation export rather than query execution.

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 implies usage for creating documentation files from database schemas, but provides no explicit guidance on when to use this tool versus alternatives like querying tools. There's no mention of prerequisites, dependencies, or scenarios where this tool would be preferred over manual documentation methods.

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/tndfame/mcp_management'

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