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"]
    }

Tool Definition Quality

Score is being calculated. Check back soon.

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