update_document
Modify existing ERPNext records by updating document fields for customers, items, and other data types to maintain accurate business information.
Instructions
Update an existing document in ERPNext
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doctype | Yes | ERPNext DocType (e.g., Customer, Item) | |
| name | Yes | Document name/ID | |
| data | Yes | Document data to update |
Implementation Reference
- src/index.ts:529-568 (handler)MCP tool handler for 'update_document': validates authentication and parameters, calls erpnext.updateDocument, formats and returns the result or 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 }; } } - src/index.ts:397-418 (schema)Input schema definition for the 'update_document' tool, specifying required parameters: doctype, name, and 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"] } }, - src/index.ts:116-125 (helper)Core ERPNextClient method that performs the actual HTTP PUT request to update the document via ERPNext API.
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'}`); } } - src/index.ts:552-552 (registration)Invocation of the updateDocument helper within the tool handler.
const result = await erpnext.updateDocument(doctype, name, data);