update_document
Modify existing Frappe documents by specifying DocType, document name, and updated field values to maintain accurate data records.
Instructions
Update an existing document in Frappe.
Args:
doctype: DocType name
name: Document name (case-sensitive)
values: Field values to update
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doctype | Yes | ||
| name | Yes | ||
| values | Yes |
Implementation Reference
- src/tools/documents.py:148-179 (handler)The main handler function for the 'update_document' MCP tool. It performs a PUT request to the Frappe API to update the specified document with the given values.@mcp.tool() async def update_document( doctype: str, name: str, values: Dict[str, Any] ) -> str: """ Update an existing document in Frappe. Args: doctype: DocType name name: Document name (case-sensitive) values: Field values to update """ try: client = get_client() # Make API request to update document response = await client.put( f"api/resource/{doctype}/{name}", json_data=values ) if "data" in response: doc = response["data"] return f"Document updated successfully: {doctype} '{doc.get('name', name)}'" else: return json.dumps(response, indent=2) except Exception as error: return _format_error_response(error, "update_document")
- src/tools/documents.py:149-161 (schema)Type annotations and docstring define the input schema: doctype (str), name (str), values (Dict[str, Any]) and return str response.async def update_document( doctype: str, name: str, values: Dict[str, Any] ) -> str: """ Update an existing document in Frappe. Args: doctype: DocType name name: Document name (case-sensitive) values: Field values to update """
- src/server.py:40-40 (registration)Invocation of documents.register_tools(mcp) which registers the update_document tool (and others) with the MCP server.documents.register_tools(mcp)
- src/tools/documents.py:51-79 (helper)Helper function _format_error_response used by update_document (and other tools) for standardized error responses.def _format_error_response(error: Exception, operation: str) -> str: """Format error response with detailed information.""" credentials_check = validate_api_credentials() # Build diagnostic information diagnostics = [ f"Error in {operation}", f"Error type: {type(error).__name__}", f"Is FrappeApiError: {isinstance(error, FrappeApiError)}", f"API Key available: {credentials_check['details']['api_key_available']}", f"API Secret available: {credentials_check['details']['api_secret_available']}" ] # Check for missing credentials first if not credentials_check["valid"]: error_msg = f"Authentication failed: {credentials_check['message']}. " error_msg += "API key/secret is the only supported authentication method." return error_msg # Handle FrappeApiError if isinstance(error, FrappeApiError): error_msg = f"Frappe API error: {error}" if error.status_code in (401, 403): error_msg += " Please check your API key and secret." return error_msg # Default error handling return f"Error in {operation}: {str(error)}"