Skip to main content
Glama

get_fields_schema

Retrieve the JSON schema of all fields in a specified database to provide AI models with the expected data structure for accurate processing and analysis.

Instructions

Returns the JSON schema of all fields within the specified database, This schema will be sent to LLM to help the AI understand the expected structure of the data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
node_idYesThe ID of the database to fetch records from.

Implementation Reference

  • src/index.ts:182-213 (registration)
    Registration of the 'get_fields_schema' MCP tool, including description, input schema, and inline handler function that delegates to AitableService helpers.
    server.tool("get_fields_schema", "Returns the JSON schema of all fields within the specified database, This schema will be sent to LLM to help the AI understand the expected structure of the data.", { node_id: z.string().describe('The ID of the database to fetch records from.'), }, async ({ node_id }) => { try { if (!node_id) { throw new Error("The datasheet ID (node_id) is required."); } const result = await aitableService.getDatasheetFieldsSchema(node_id); if (!result.success) { throw new Error(result.message || "Failed to fetch datasheet fields schema"); } const fieldsSchema: FieldFormatJSONSchema = aitableService.getFieldsJSONSchema(result.data.fields); return formatToolResponse({ success: true, data: fieldsSchema }); } catch (error) { console.error("Error in list_database_fields:", error); return formatToolResponse({ success: false, message: error instanceof Error ? error.message : "Unknown error occurred" }, true); } } );
  • Core handler logic for executing the tool: validates input, fetches raw fields schema from API via service, formats into LLM-compatible JSON schema, and returns standardized tool response.
    async ({ node_id }) => { try { if (!node_id) { throw new Error("The datasheet ID (node_id) is required."); } const result = await aitableService.getDatasheetFieldsSchema(node_id); if (!result.success) { throw new Error(result.message || "Failed to fetch datasheet fields schema"); } const fieldsSchema: FieldFormatJSONSchema = aitableService.getFieldsJSONSchema(result.data.fields); return formatToolResponse({ success: true, data: fieldsSchema }); } catch (error) { console.error("Error in list_database_fields:", error); return formatToolResponse({ success: false, message: error instanceof Error ? error.message : "Unknown error occurred" }, true); } }
  • Input validation schema using Zod, requiring a single 'node_id' string parameter.
    { node_id: z.string().describe('The ID of the database to fetch records from.'), },
  • Helper method in AitableService that performs the API call to retrieve the raw fields schema from the AITable '/v1/datasheets/{node_id}/fields' endpoint.
    public async getDatasheetFieldsSchema( node_id: string ): Promise<ResponseVO<{fields: FieldSchemaVO[]}>> { if (!node_id) { throw new Error("The datasheet ID (node_id) is required."); } const endpoint = `/v1/datasheets/${node_id}/fields`; return this.fetchFromAPI(endpoint, { method: "GET", }); }
  • Helper method that transforms raw FieldSchemaVO[] into a structured JSON schema (FieldFormatJSONSchema) suitable for LLM structured outputs, mapping field types to appropriate Zod/JSON schema keywords.
    public getFieldsJSONSchema(fields: FieldSchemaVO[]): FieldFormatJSONSchema { const schema: { type: string; properties: Record<string, unknown>; additionalProperties: boolean; required: string[]; } = { type: "object", properties: {}, additionalProperties: false, required: [], }; fields.forEach((field) => { const keywordsForField = this._getKeywordByFieldType(field); // If the field type is not supported, we skip it if (keywordsForField) { schema.properties[field.name] = keywordsForField; schema.required.push(field.name); } }); return { type: "json_schema", json_schema: { name: "fields_in_datasheet", schema, strict: true, }, }; }

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/apitable/aitable-mcp-server'

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