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
| 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:531-570 (handler)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 }; } }
- src/index.ts:118-127 (handler)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'}`); } }
- src/index.ts:399-420 (schema)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"] } } ] }; });