Skip to main content
Glama

get_doctype_fields

Retrieve field definitions for ERPNext document types to understand data structure and enable accurate API interactions.

Instructions

Get fields list for a specific DocType

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doctypeYesERPNext DocType (e.g., Customer, Item)

Implementation Reference

  • The handler for the 'get_doctype_fields' tool within the CallToolRequestSchema switch statement. It retrieves a sample document for the specified doctype using getDocList, extracts field names, types, and sample values from it, and returns them as JSON.
    case "get_doctype_fields": {
      if (!erpnext.isAuthenticated()) {
        return {
          content: [{
            type: "text",
            text: "Not authenticated with ERPNext. Please configure API key authentication."
          }],
          isError: true
        };
      }
      
      const doctype = String(request.params.arguments?.doctype);
      
      if (!doctype) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Doctype is required"
        );
      }
      
      try {
        // Get a sample document to understand the fields
        const documents = await erpnext.getDocList(doctype, {}, ["*"], 1);
        
        if (!documents || documents.length === 0) {
          return {
            content: [{
              type: "text",
              text: `No documents found for ${doctype}. Cannot determine fields.`
            }],
            isError: true
          };
        }
        
        // Extract field names from the first document
        const sampleDoc = documents[0];
        const fields = Object.keys(sampleDoc).map(field => ({
          fieldname: field,
          value: typeof sampleDoc[field],
          sample: sampleDoc[field]?.toString()?.substring(0, 50) || null
        }));
        
        return {
          content: [{
            type: "text",
            text: JSON.stringify(fields, null, 2)
          }]
        };
      } catch (error: any) {
        return {
          content: [{
            type: "text",
            text: `Failed to get fields for ${doctype}: ${error?.message || 'Unknown error'}`
          }],
          isError: true
        };
      }
    }
  • src/index.ts:335-348 (registration)
    Registration of the 'get_doctype_fields' tool in the ListToolsRequestSchema handler, including its name, description, and input schema.
    {
      name: "get_doctype_fields",
      description: "Get fields list for a specific DocType",
      inputSchema: {
        type: "object",
        properties: {
          doctype: {
            type: "string",
            description: "ERPNext DocType (e.g., Customer, Item)"
          }
        },
          required: ["doctype"]
      }
    },
  • Input schema definition for the 'get_doctype_fields' tool, specifying the required 'doctype' parameter.
    inputSchema: {
      type: "object",
      properties: {
        doctype: {
          type: "string",
          description: "ERPNext DocType (e.g., Customer, Item)"
        }
      },
        required: ["doctype"]
    }
  • ERPNextClient.getDocList method used by the handler to fetch a sample document and infer fields.
    // Get list of documents for a doctype
    async getDocList(doctype: string, filters?: Record<string, any>, fields?: string[], limit?: number): Promise<any[]> {
      try {
        let params: Record<string, any> = {};
        
        if (fields && fields.length) {
          params['fields'] = JSON.stringify(fields);
        }
        
        if (filters) {
          params['filters'] = JSON.stringify(filters);
        }
        
        if (limit) {
          params['limit_page_length'] = limit;
        }
        
        const response = await this.axiosInstance.get(`/api/resource/${doctype}`, { params });
        return response.data.data;
      } catch (error: any) {
        throw new Error(`Failed to get ${doctype} list: ${error?.message || 'Unknown error'}`);
      }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.3/5.0
Behavior2/5

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

With no annotations, the description carries the full burden of behavioral disclosure. It only states the raw action without mentioning whether the operation is read-only, what the response contains, or any authentication/error behavior. This is a minimal disclosure with no behavioral context beyond the action itself.

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 concise sentence that front-loads the verb and object. Every word earns its place, and there is no redundancy or filler. It is appropriately sized for the tool's simplicity.

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 simple one-parameter tool, the description is adequate but has gaps. It does not specify what the returned fields list includes (e.g., field names, types, required flags) or explain error handling for invalid doctypes. With no output schema, the description could benefit from a brief note on return structure, but the core purpose is clear.

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% (the 'doctype' parameter has a clear description). The description does not add any additional parameter meaning beyond the schema, but it also doesn't need to since the schema fully explains the parameter. Baseline of 3 is appropriate.

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 uses a specific verb+resource construction: 'Get fields list for a specific DocType'. This clearly distinguishes it from sibling tools like get_doctypes (which lists doctypes) and get_documents (which retrieves document data). The scope is well-defined.

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 offers no guidance on when to use this tool versus alternatives. It implicitly implies use when needing fields of a specific doctype, but does not state any exclusions or mention sibling tools. No explicit context or prerequisites are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.