Skip to main content
Glama
sam2332

SQLite MCP Server

by sam2332

get_table_info

Retrieve table schema, indexes, and sample data from SQLite databases to understand structure and content for analysis or troubleshooting.

Instructions

Get comprehensive information about a table including schema, indexes, and sample data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYesName of the table to analyze
sample_rowsNoNumber of sample rows to return

Implementation Reference

  • The core handler function for 'get_table_info' tool. It retrieves table schema (columns, types, constraints), row count, indexes, and optional sample rows from the connected SQLite database.
      private async getTableInfo(args: { table_name: string; sample_rows?: number }): Promise<CallToolResult> {
        if (!this.db) {
          throw new Error("No database connected. Use connect_database first.");
        }
    
        try {
          // Get table schema
          const columns = this.db
            .prepare("PRAGMA table_info(?)")
            .all(args.table_name) as {
              cid: number;
              name: string;
              type: string;
              notnull: number;
              dflt_value: any;
              pk: number;
            }[];
    
          if (columns.length === 0) {
            throw new Error(`Table '${args.table_name}' not found`);
          }
    
          // Get row count
          const countResult = this.db
            .prepare(`SELECT COUNT(*) as count FROM ${args.table_name}`)
            .get() as { count: number };
    
          // Get indexes
          const indexes = this.db
            .prepare("PRAGMA index_list(?)")
            .all(args.table_name) as { name: string; unique: number }[];
    
          // Get sample data
          const sampleRows = args.sample_rows || 5;
          const sampleData = this.db
            .prepare(`SELECT * FROM ${args.table_name} LIMIT ?`)
            .all(sampleRows);
    
          // Format schema
          const schema = columns
            .map(col => {
              const nullable = col.notnull === 0 ? "NULL" : "NOT NULL";
              const pk = col.pk > 0 ? " PRIMARY KEY" : "";
              const defaultVal = col.dflt_value !== null ? ` DEFAULT ${col.dflt_value}` : "";
              return `  ${col.name} ${col.type} ${nullable}${pk}${defaultVal}`;
            })
            .join("\n");
    
          // Format indexes
          const indexInfo = indexes.length > 0 
            ? indexes.map(idx => `  ${idx.name} (${idx.unique ? "UNIQUE" : "NON-UNIQUE"})`).join("\n")
            : "  No indexes";
    
          // Format sample data
          let sampleText = "";
          if (sampleData.length > 0) {
            const headers = Object.keys(sampleData[0] as Record<string, unknown>);
            const rows = sampleData.map((row) => 
              headers.map(header => String((row as Record<string, unknown>)[header] ?? "NULL")).join(" | ")
            );
            
            const headerRow = headers.join(" | ");
            const separator = headers.map(h => "-".repeat(Math.max(h.length, 4))).join("-|-");
            sampleText = [headerRow, separator, ...rows].join("\n");
          } else {
            sampleText = "No data in table";
          }
    
          const info = `Table: ${args.table_name}
    Row count: ${countResult.count}
    
    Schema:
    ${schema}
    
    Indexes:
    ${indexInfo}
    
    Sample data (${Math.min(sampleRows, sampleData.length)} rows):
    ${sampleText}`;
    
          return {
            content: [
              {
                type: "text",
                text: info,
              } satisfies TextContent,
            ],
          };
        } catch (error) {
          throw new Error(`Failed to get table info: ${error instanceof Error ? error.message : String(error)}`);
        }
      }
  • src/index.ts:133-151 (registration)
    Registers the 'get_table_info' tool in the ListToolsRequestHandler, defining its name, description, and input schema.
    {
      name: "get_table_info",
      description: "Get comprehensive information about a table including schema, indexes, and sample data",
      inputSchema: {
        type: "object",
        properties: {
          table_name: {
            type: "string",
            description: "Name of the table to analyze",
          },
          sample_rows: {
            type: "number",
            description: "Number of sample rows to return",
            default: 5,
          },
        },
        required: ["table_name"],
      },
    },
  • Defines the input schema for the 'get_table_info' tool, specifying required 'table_name' and optional 'sample_rows'.
    inputSchema: {
      type: "object",
      properties: {
        table_name: {
          type: "string",
          description: "Name of the table to analyze",
        },
        sample_rows: {
          type: "number",
          description: "Number of sample rows to return",
          default: 5,
        },
      },
      required: ["table_name"],
    },
  • src/index.ts:177-178 (registration)
    Dispatches calls to the 'get_table_info' handler in the CallToolRequestHandler switch statement.
    case "get_table_info":
      return await this.getTableInfo(args as { table_name: string; sample_rows?: number });
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions what information is returned but fails to describe critical traits such as whether this is a read-only operation, potential performance impacts, permissions required, or error handling. This leaves significant gaps for a tool that likely queries database metadata.

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 description is a single, efficient sentence that front-loads the key action and details. It avoids unnecessary words and directly states the tool's function, though it could be slightly more structured by separating core purpose from additional features.

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?

Given the tool's moderate complexity (2 parameters, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks completeness in behavioral context, usage guidelines, and output details, which are important for effective agent 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?

The schema description coverage is 100%, so the input schema already documents both parameters ('table_name' and 'sample_rows') with clear descriptions. The description adds no additional meaning beyond what the schema provides, such as format details or constraints, but doesn't contradict it either.

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 ('table'), specifying what information is retrieved ('comprehensive information about a table including schema, indexes, and sample data'). It distinguishes from siblings like 'describe_table' by mentioning 'sample data', but doesn't explicitly differentiate in terms of scope or depth.

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 analyzing table structure and content, but provides no explicit guidance on when to use this tool versus alternatives like 'describe_table' or 'query_data'. It lacks any mention of prerequisites, exclusions, or specific contexts for selection.

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/sam2332/mcp-quick-sqlite3'

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