Skip to main content
Glama
LiusCraft

Superset MCP Server

by LiusCraft

list-fields

Retrieve the field list of a specified table in a database by providing the database ID, schema name, and table name, enabling structured data access for analysis.

Instructions

获取指定表的字段列表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseIdYes数据库ID
schemaYesSchema名称
tableNameYes表名

Implementation Reference

  • The main handler function for the 'list-fields' MCP tool. It fetches fields using getTableFields helper, formats them into a text list, and returns as MCP content.
    async ({ databaseId, schema, tableName }) => {
      try {
        const fields = await getTableFields(databaseId, schema, tableName);
    
        if (fields.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `表 ${schema}.${tableName} 中没有找到字段`,
              },
            ],
          };
        }
        
        const fieldsList = fields.map(field => `名称: ${field.name}, 类型: ${field.type}`).join("\n");
        
        return {
          content: [
            {
              type: "text",
              text: `表 ${schema}.${tableName} 的字段列表:\n\n${fieldsList}`,
            },
          ],
        };
      } catch (error) {
        console.error("获取字段列表失败:", error);
        return {
          content: [
            {
              type: "text",
              text: `获取字段列表失败: ${(error as Error).message}`,
            },
          ],
        };
      }
    }
  • Zod schema defining the input parameters for the list-fields tool: databaseId (number), schema (string), tableName (string).
    {
      databaseId: z.number().describe("数据库ID"),
      schema: z.string().describe("Schema名称"),
      tableName: z.string().describe("表名"),
    },
  • src/index.ts:420-465 (registration)
    Registers the 'list-fields' tool on the MCP server with name, description, input schema, and handler function.
    server.tool(
      "list-fields",
      "获取指定表的字段列表",
      {
        databaseId: z.number().describe("数据库ID"),
        schema: z.string().describe("Schema名称"),
        tableName: z.string().describe("表名"),
      },
      async ({ databaseId, schema, tableName }) => {
        try {
          const fields = await getTableFields(databaseId, schema, tableName);
    
          if (fields.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: `表 ${schema}.${tableName} 中没有找到字段`,
                },
              ],
            };
          }
          
          const fieldsList = fields.map(field => `名称: ${field.name}, 类型: ${field.type}`).join("\n");
          
          return {
            content: [
              {
                type: "text",
                text: `表 ${schema}.${tableName} 的字段列表:\n\n${fieldsList}`,
              },
            ],
          };
        } catch (error) {
          console.error("获取字段列表失败:", error);
          return {
            content: [
              {
                type: "text",
                text: `获取字段列表失败: ${(error as Error).message}`,
              },
            ],
          };
        }
      }
    );
  • Helper function to retrieve and cache table fields using Superset API.
    async function getTableFields(databaseId: number, schema: string, tableName: string): Promise<Field[]> {
      const cacheKey = `${databaseId}:${schema}:${tableName}`;
      
      if (fieldsCache.has(cacheKey)) {
        return fieldsCache.get(cacheKey) || [];
      }
      
      try {
        const metadata = await supersetApi.getTableMetadata(databaseId, schema, tableName);
        fieldsCache.set(cacheKey, metadata.columns);
        return metadata.columns;
      } catch (error) {
        console.error(`获取表 ${schema}.${tableName} 的字段失败:`, error);
        return [];
      }
    }
  • SupersetApiService method that calls the Superset API to get table metadata (including columns/fields).
    public async getTableMetadata(databaseId: number, schemaName: string, tableName: string): Promise<TableMetadata> {
      try {
        // 使用新的 API 路径格式
        console.log(`尝试使用表元数据API: /api/v1/database/${databaseId}/table/${tableName}/${schemaName}/`);
        
        const response = await this.client.get<TableMetadata>(
          `/api/v1/database/${databaseId}/table/${tableName}/${schemaName}/`
        );
        
        if (!response.success || !response.data) {
          throw new Error(response.error?.message || `获取表 ${schemaName}.${tableName} 的元数据失败`);
        }
        
        return response.data;
      } catch (error) {
        console.error('获取表元数据失败:', error);
        throw error;
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool '获取' (gets) a field list, implying a read-only operation, but doesn't clarify aspects like whether it requires authentication, has rate limits, returns paginated results, or what the output format is (e.g., list of field names with types). For a tool with no annotations, this leaves significant gaps in understanding its behavior and constraints.

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 in Chinese ('获取指定表的字段列表') that directly states the tool's purpose without unnecessary words. It's front-loaded with the core action and resource. However, it could be slightly more structured by explicitly mentioning the parameters or context, but as is, it avoids waste and is appropriately concise for a simple tool.

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 the tool's moderate complexity (3 required parameters, no output schema, and no annotations), the description is incomplete. It lacks details on behavioral traits (e.g., read-only nature, potential errors), usage guidelines, and output expectations. While the schema covers parameters well, the description doesn't compensate for the absence of annotations or output schema, making it insufficient for full contextual understanding.

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%, with clear descriptions for all three parameters (databaseId, schema, tableName). The description adds no additional parameter semantics beyond what the schema provides (e.g., it doesn't explain relationships between parameters or provide examples). According to the rules, when schema coverage is high (>80%), the baseline score is 3, as the schema adequately documents the parameters without needing extra detail in the description.

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

Purpose3/5

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

The description '获取指定表的字段列表' (Get the field list of the specified table) states the verb ('获取' - get) and resource ('字段列表' - field list) with a scope ('指定表' - specified table), making the purpose clear. However, it doesn't differentiate from sibling tools like 'list-tables' or 'list-databases', which also list resources but at different levels. The description is functional but lacks specificity about what distinguishes this tool from its siblings.

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. It doesn't mention prerequisites (e.g., needing a valid databaseId, schema, and tableName), exclusions, or comparisons to siblings like 'list-tables' (which might list tables instead of fields) or 'query-superset' (which might query data). Without such context, users must infer usage from the tool name and parameters alone.

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

Related 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/LiusCraft/superset-mcp-server'

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