get_document
Retrieve specific documents from Frappe Framework by providing DocType and document name for data access and management.
Instructions
Retrieve a document from Frappe.
Args:
doctype: DocType name
name: Document name (case-sensitive)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doctype | Yes | ||
| name | Yes |
Implementation Reference
- src/tools/documents.py:123-147 (handler)The main execution logic for the 'get_document' tool. Fetches the specified Frappe document using the API client and returns JSON-formatted data or error.async def get_document( doctype: str, name: str ) -> str: """ Retrieve a document from Frappe. Args: doctype: DocType name name: Document name (case-sensitive) """ try: client = get_client() # Make API request to get document response = await client.get(f"api/resource/{doctype}/{name}") if "data" in response: return json.dumps(response["data"], indent=2) else: return json.dumps(response, indent=2) except Exception as error: return _format_error_response(error, "get_document")
- src/server.py:38-43 (registration)The 'documents.register_tools(mcp)' call registers all document-related tools, including 'get_document', with the MCP server.# Register all tool modules helpers.register_tools(mcp) documents.register_tools(mcp) schema.register_tools(mcp) reports.register_tools(mcp)
- src/tools/documents.py:51-79 (helper)Helper function called by get_document in error cases to format and return detailed 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)}"