Skip to main content
Glama

create_document

Create new documents in ERPNext by specifying DocType and data, enabling automated record management through structured API calls.

Instructions

Create a new document in ERPNext

Input Schema

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

Implementation Reference

  • MCP tool handler for 'create_document': authenticates, validates parameters (doctype and data), calls erpnext.createDocument, and returns the result or error.
    case "create_document": {
      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 data = request.params.arguments?.data as Record<string, any> | undefined;
      
      if (!doctype || !data) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Doctype and data are required"
        );
      }
      
      try {
        const result = await erpnext.createDocument(doctype, data);
        return {
          content: [{
            type: "text",
            text: `Created ${doctype}: ${result.name}\n\n${JSON.stringify(result, null, 2)}`
          }]
        };
      } catch (error: any) {
        return {
          content: [{
            type: "text",
            text: `Failed to create ${doctype}: ${error?.message || 'Unknown error'}`
          }],
          isError: true
        };
      }
    }
  • ERPNextClient helper method that implements the core logic: HTTP POST to /api/resource/{doctype} with document data, returns the created document.
    async createDocument(doctype: string, doc: Record<string, any>): Promise<any> {
      try {
        const response = await this.axiosInstance.post(`/api/resource/${doctype}`, {
          data: doc
        });
        return response.data.data;
      } catch (error: any) {
        throw new Error(`Failed to create ${doctype}: ${error?.message || 'Unknown error'}`);
      }
    }
  • src/index.ts:379-397 (registration)
    Tool registration in ListToolsRequestSchema handler: defines name, description, and input schema for create_document tool.
    {
      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"]
      }
    },
  • Input schema definition for the create_document tool, specifying required doctype (string) and data (object).
    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"]
    }
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. It states 'Create a new document' which implies a write/mutation operation, but doesn't disclose any behavioral traits such as permissions required, whether creation is idempotent, error handling, or what happens on success/failure. For a mutation tool with zero annotation coverage, this is inadequate.

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, efficient sentence with zero waste. It's appropriately sized and front-loaded with the core purpose, making it easy to parse quickly without unnecessary elaboration.

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 this is a mutation tool (creating documents) with no annotations and no output schema, the description is incomplete. It doesn't explain what happens after creation (e.g., returns document ID, success status), error conditions, or dependencies. For a tool that modifies data in ERPNext, more context about behavioral outcomes is needed.

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%, so the schema already documents both parameters ('doctype' and 'data') with descriptions. The description adds no additional meaning about parameters beyond what the schema provides, such as examples of valid doctypes beyond 'Customer, Item' or constraints on data structure. Baseline 3 is appropriate when 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 ('Create a new document') and target resource ('in ERPNext'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from its sibling 'update_document' beyond the basic verb difference, missing explicit differentiation about when to create versus update.

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 'update_document' or 'get_documents'. It lacks context about prerequisites (e.g., needing valid doctype and data) or exclusions, offering only a basic statement of function without usage context.

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