Skip to main content
Glama

update_document

Modify existing ERPNext documents like customers or items by specifying the document type, name, and updated data fields.

Instructions

Update an existing document in ERPNext

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doctypeYesERPNext DocType (e.g., Customer, Item)
nameYesDocument name/ID
dataYesDocument data to update

Implementation Reference

  • MCP CallToolRequestSchema handler case for 'update_document': checks authentication, validates arguments (doctype, name, data), invokes erpnext.updateDocument, and returns formatted success/error response.
    case "update_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 name = String(request.params.arguments?.name);
      const data = request.params.arguments?.data as Record<string, any> | undefined;
      
      if (!doctype || !name || !data) {
        throw new McpError(
          ErrorCode.InvalidParams,
          "Doctype, name, and data are required"
        );
      }
      
      try {
        const result = await erpnext.updateDocument(doctype, name, data);
        return {
          content: [{
            type: "text",
            text: `Updated ${doctype} ${name}\n\n${JSON.stringify(result, null, 2)}`
          }]
        };
      } catch (error: any) {
        return {
          content: [{
            type: "text",
            text: `Failed to update ${doctype} ${name}: ${error?.message || 'Unknown error'}`
          }],
          isError: true
        };
      }
    }
  • Core ERPNextClient.updateDocument method: executes the HTTP PUT request to the ERPNext REST API endpoint `/api/resource/{doctype}/{name}` with the provided document data.
    async updateDocument(doctype: string, name: string, doc: Record<string, any>): Promise<any> {
      try {
        const response = await this.axiosInstance.put(`/api/resource/${doctype}/${name}`, {
          data: doc
        });
        return response.data.data;
      } catch (error: any) {
        throw new Error(`Failed to update ${doctype} ${name}: ${error?.message || 'Unknown error'}`);
      }
    }
  • Tool specification in ListToolsRequestSchema response: defines name, description, and input schema (doctype, name, data as object) for the update_document tool.
      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"]
      }
    },
  • src/index.ts:324-442 (registration)
    Registration of all tools including 'update_document' via the ListToolsRequestSchema handler, which lists available tools with their schemas.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        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"]
            }
          }
        ]
      };
    });
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. While 'Update' implies a mutation operation, the description doesn't disclose critical behavioral traits: whether this requires specific permissions, whether updates are partial or complete, what happens on validation errors, if there are rate limits, or what the response looks like. For a mutation tool with zero annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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 that states the core purpose without unnecessary words. It's appropriately sized for a tool with three parameters and good schema coverage. Every word earns its place, and the structure is front-loaded with the essential information.

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 with no annotations and no output schema, the description is incomplete. It doesn't address what happens after the update (success/failure responses), doesn't mention error conditions, and provides no context about the ERPNext document system's constraints. For a tool that modifies data, more behavioral and contextual information would be helpful to the agent.

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%, so all parameters are documented in the schema itself. The description adds no additional parameter semantics beyond what's already in the schema descriptions (doctype, name, data). It doesn't explain relationships between parameters, provide examples of valid 'data' objects, or clarify parameter interactions. The baseline score of 3 reflects adequate but minimal value addition.

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 verb ('Update') and resource ('an existing document in ERPNext'), making the purpose immediately understandable. It distinguishes from sibling 'create_document' by specifying 'existing document' rather than creation. However, it doesn't fully differentiate from other potential update operations beyond the ERPNext context.

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. There's no mention of prerequisites (like needing an existing document), no comparison with sibling tools like 'create_document' or 'get_documents', and no context about when this tool is appropriate versus other operations. The agent receives no usage direction beyond the basic purpose.

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