Skip to main content
Glama

get_documents

Retrieve filtered lists of ERPNext documents by doctype, with options to specify fields, apply filters, and set limits for targeted data access.

Instructions

Get a list of documents for a specific doctype

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doctypeYesERPNext DocType (e.g., Customer, Item)
fieldsNoFields to include (optional)
filtersNoFilters in the format {field: value} (optional)
limitNoMaximum number of documents to return (optional)

Implementation Reference

  • Tool handler for 'get_documents': validates authentication and parameters, calls erpnext.getDocList to fetch documents, and returns JSON stringified result or error.
    case "get_documents": {
      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);
      const fields = request.params.arguments?.fields as string[] | undefined;
      const filters = request.params.arguments?.filters as Record<string, any> | undefined;
      const limit = request.params.arguments?.limit as number | undefined;
      
      if (!doctype) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Doctype is required"
        );
      }
      
      try {
        const documents = await erpnext.getDocList(doctype, filters, fields, limit);
        return {
          content: [{
            type: "text",
            text: JSON.stringify(documents, null, 2)
          }]
        };
      } catch (error: any) {
        return {
          content: [{
            type: "text",
            text: `Failed to get ${doctype} documents: ${error?.message || 'Unknown error'}`
          }],
          isError: true
        };
      }
    }
  • Input schema definition for the 'get_documents' tool, specifying required 'doctype' and optional fields, filters, limit.
      name: "get_documents",
      description: "Get a list of documents for a specific doctype",
      inputSchema: {
        type: "object",
        properties: {
          doctype: {
            type: "string",
            description: "ERPNext DocType (e.g., Customer, Item)"
          },
          fields: {
            type: "array",
            items: {
              type: "string"
            },
            description: "Fields to include (optional)"
          },
          filters: {
            type: "object",
            additionalProperties: true,
            description: "Filters in the format {field: value} (optional)"
          },
          limit: {
            type: "number",
            description: "Maximum number of documents to return (optional)"
          }
        },
        required: ["doctype"]
      }
    },
  • src/index.ts:324-439 (registration)
    Registration of 'get_documents' tool in the list of available tools returned by ListToolsRequestSchema handler.
      tools: [
        {
          name: "get_doctypes",
          description: "Get a list of all available DocTypes",
          inputSchema: {
            type: "object",
            properties: {}
          }
        },
        {
          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"]
          }
        },
        {
          name: "get_documents",
          description: "Get a list of documents for a specific doctype",
          inputSchema: {
            type: "object",
            properties: {
              doctype: {
                type: "string",
                description: "ERPNext DocType (e.g., Customer, Item)"
              },
              fields: {
                type: "array",
                items: {
                  type: "string"
                },
                description: "Fields to include (optional)"
              },
              filters: {
                type: "object",
                additionalProperties: true,
                description: "Filters in the format {field: value} (optional)"
              },
              limit: {
                type: "number",
                description: "Maximum number of documents to return (optional)"
              }
            },
            required: ["doctype"]
          }
        },
        {
          name: "create_document",
          description: "Create a new document in ERPNext",
          inputSchema: {
            type: "object",
            properties: {
              doctype: {
                type: "string",
                description: "ERPNext DocType (e.g., Customer, Item)"
              },
              data: {
                type: "object",
                additionalProperties: true,
                description: "Document data"
              }
            },
            required: ["doctype", "data"]
          }
        },
        {
          name: "update_document",
          description: "Update an existing document in ERPNext",
          inputSchema: {
            type: "object",
            properties: {
              doctype: {
                type: "string",
                description: "ERPNext DocType (e.g., Customer, Item)"
              },
              name: {
                type: "string",
                description: "Document name/ID"
              },
              data: {
                type: "object",
                additionalProperties: true,
                description: "Document data to update"
              }
            },
            required: ["doctype", "name", "data"]
          }
        },
        {
          name: "run_report",
          description: "Run an ERPNext report",
          inputSchema: {
            type: "object",
            properties: {
              report_name: {
                type: "string",
                description: "Name of the report"
              },
              filters: {
                type: "object",
                additionalProperties: true,
                description: "Report filters (optional)"
              }
            },
            required: ["report_name"]
          }
        }
      ]
    };
  • ERPNextClient.getDocList method: performs the actual API request to fetch document list for a doctype with optional filters, fields, and limit.
    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 the full burden of behavioral disclosure. It states it 'gets a list,' implying a read-only operation, but doesn't mention potential side effects, authentication needs, rate limits, pagination, or error handling. For a tool with 4 parameters and no annotation coverage, this is a significant gap in transparency.

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, clear sentence that efficiently conveys the core purpose without any wasted words. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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 has 4 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the returned list looks like, how results are structured, or any behavioral nuances. For a data retrieval tool with this complexity, more context is needed to help the agent use it effectively.

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%, meaning all parameters are documented in the schema itself. The description adds no additional semantic context about the parameters beyond what's in the schema (e.g., it doesn't explain 'doctype' further or provide examples for 'filters'). Baseline 3 is appropriate as the schema does the heavy lifting.

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 a list of documents') and the target resource ('for a specific doctype'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get_doctypes' or 'run_report' which also retrieve data, so it doesn't reach the highest score.

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 lists doctypes) or 'run_report' (which might retrieve documents in a different way). There's no mention of prerequisites, limitations, or typical use cases, leaving the agent with minimal context for selection.

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/rakeshgangwar/erpnext-mcp-server'

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