Skip to main content
Glama

create_document

Create new documents in ERPNext by specifying the DocType and providing the required data fields for records like customers or items.

Instructions

Create a new document in ERPNext

Input Schema

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

Implementation Reference

  • Primary MCP tool handler for 'create_document'. Validates authentication and parameters, invokes ERPNextClient.createDocument, handles success/error responses.
    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
        };
      }
    }
  • Core implementation in ERPNextClient that performs the HTTP POST request to ERPNext API to create a new 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'}`);
      }
    }
  • Input schema definition for the 'create_document' tool, specifying required 'doctype' and 'data' parameters.
    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"]
    }
  • src/index.ts:377-395 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining name, description, and input schema for 'create_document'.
    {
      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"]
      }
    },

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