Skip to main content
Glama

get_doctypes

Retrieve all available document types from ERPNext to understand data structures and manage business records.

Instructions

Get a list of all available DocTypes

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler implementation for the 'get_doctypes' tool. Checks authentication, calls erpnext.getAllDocTypes(), and returns the list as JSON or error.
    case "get_doctypes": {
      if (!erpnext.isAuthenticated()) {
        return {
          content: [{
            type: "text",
            text: "Not authenticated with ERPNext. Please configure API key authentication."
          }],
          isError: true
        };
      }
      
      try {
        const doctypes = await erpnext.getAllDocTypes();
        return {
          content: [{
            type: "text",
            text: JSON.stringify(doctypes, null, 2)
          }]
        };
      } catch (error: any) {
        return {
          content: [{
            type: "text",
            text: `Failed to get DocTypes: ${error?.message || 'Unknown error'}`
          }],
          isError: true
        };
      }
    }
  • src/index.ts:327-334 (registration)
    Tool registration in ListToolsRequestSchema handler, including name, description, and empty input schema.
    {
      name: "get_doctypes",
      description: "Get a list of all available DocTypes",
      inputSchema: {
        type: "object",
        properties: {}
      }
    },
  • Input schema for get_doctypes tool (empty object).
    inputSchema: {
      type: "object",
      properties: {}
    }
  • ERPNextClient method getAllDocTypes() that fetches DocTypes via API with fallback methods. Called by the tool handler.
    // Get all available DocTypes
    async getAllDocTypes(): Promise<string[]> {
      try {
        // Use the standard REST API to fetch DocTypes
        const response = await this.axiosInstance.get('/api/resource/DocType', {
          params: {
            fields: JSON.stringify(["name"]),
            limit_page_length: 500 // Get more doctypes at once
          }
        });
        
        if (response.data && response.data.data) {
          return response.data.data.map((item: any) => item.name);
        }
        
        return [];
      } catch (error: any) {
        console.error("Failed to get DocTypes:", error?.message || 'Unknown error');
        
        // Try an alternative approach if the first one fails
        try {
          // Try using the method API to get doctypes
          const altResponse = await this.axiosInstance.get('/api/method/frappe.desk.search.search_link', {
            params: {
              doctype: 'DocType',
              txt: '',
              limit: 500
            }
          });
          
          if (altResponse.data && altResponse.data.results) {
            return altResponse.data.results.map((item: any) => item.value);
          }
          
          return [];
        } catch (altError: any) {
          console.error("Alternative DocType fetch failed:", altError?.message || 'Unknown error');
          
          // Fallback: Return a list of common DocTypes
          return [
            "Customer", "Supplier", "Item", "Sales Order", "Purchase Order",
            "Sales Invoice", "Purchase Invoice", "Employee", "Lead", "Opportunity",
            "Quotation", "Payment Entry", "Journal Entry", "Stock Entry"
          ];
        }
      }
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.8/5.0
Behavior3/5

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

With no annotations, the description must carry the behavioral burden. It clearly indicates a read operation ('Get') with no side effects, but it does not disclose potential nuances like authentication requirements, whether custom DocTypes are included, or the exact return structure. This is adequate for a simple list operation but leaves room for ambiguity.

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, front-loaded sentence with no filler. It communicates the essential purpose efficiently.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (no parameters, no output schema), the description is mostly complete. However, it does not specify the return format (e.g., array of names vs. objects) or any sorting/ordering, which could be ambiguous for an agent. Still, it is sufficient for a basic listing tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters, so there is no need for parameter descriptions. The baseline of 4 applies as the description does not need to compensate for schema gaps.

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 ('Get a list') and clearly identifies the resource ('all available DocTypes'). It is distinct from sibling tools like get_doctype_fields or get_documents, which operate on different entities.

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?

No guidance is provided on when to use this tool versus alternatives. It does not mention, for example, using get_doctype_fields to explore fields of a specific DocType, or that this is a precursor to fetching documents. The usage context is implied but not explicit.

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