get_doctype_fields
Retrieve field definitions for ERPNext document types to understand data structure and enable accurate data entry or integration.
Instructions
Get fields list for a specific DocType
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doctype | Yes | ERPNext DocType (e.g., Customer, Item) |
Implementation Reference
- src/index.ts:610-667 (handler)Main execution logic for the 'get_doctype_fields' tool: authenticates, fetches a sample document using erpnext.getDocList, extracts field names, types, and samples from the first document, and returns them as JSON.case "get_doctype_fields": { 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); if (!doctype) { throw new McpError( ErrorCode.InvalidParams, "Doctype is required" ); } try { // Get a sample document to understand the fields const documents = await erpnext.getDocList(doctype, {}, ["*"], 1); if (!documents || documents.length === 0) { return { content: [{ type: "text", text: `No documents found for ${doctype}. Cannot determine fields.` }], isError: true }; } // Extract field names from the first document const sampleDoc = documents[0]; const fields = Object.keys(sampleDoc).map(field => ({ fieldname: field, value: typeof sampleDoc[field], sample: sampleDoc[field]?.toString()?.substring(0, 50) || null })); return { content: [{ type: "text", text: JSON.stringify(fields, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Failed to get fields for ${doctype}: ${error?.message || 'Unknown error'}` }], isError: true }; } }
- src/index.ts:334-346 (schema)Input schema and metadata for the 'get_doctype_fields' tool, defining the required 'doctype' parameter.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"] } },