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'}`);
      }
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 'Get' implies a read-only operation, it doesn't specify whether this requires authentication, has rate limits, returns paginated results, or what format the fields list takes. The description is minimal and lacks important operational context.

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 extremely concise - a single sentence that directly states the tool's purpose without any unnecessary words. It's front-loaded with the core functionality and wastes no space on redundant information.

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?

For a tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the output looks like (e.g., field names, types, properties), whether there are any constraints on which DocTypes can be queried, or what happens with invalid inputs. The agent would need to guess about important behavioral aspects.

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%, with the single parameter 'doctype' clearly documented in the schema. The description adds no additional parameter information beyond what's already in the structured schema. This meets the baseline expectation when schema coverage is complete.

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 action ('Get fields list') and target resource ('for a specific DocType'), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like 'get_doctypes' or 'get_documents', but the specificity of 'fields list' provides some implicit differentiation.

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 like 'get_doctypes' (which likely lists DocTypes rather than fields) or 'get_documents' (which retrieves actual data records). There's no mention of prerequisites, typical use cases, or limitations that would help an agent choose appropriately.

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/Web3ViraLabs/ERPNext-MCP-Server'

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