call_method
Execute whitelisted Frappe methods with optional parameters to automate backend operations and integrate with Frappe Framework functionality.
Instructions
Execute a whitelisted Frappe method.
Args:
method: Method name to call (whitelisted)
params: Parameters to pass to the method (optional)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method | Yes | ||
| params | No |
Implementation Reference
- src/tools/documents.py:417-447 (handler)The core handler implementation for the 'call_method' MCP tool. This function calls whitelisted Frappe methods via the REST API endpoint /api/method, handling parameters and returning formatted JSON responses or errors.@mcp.tool() async def call_method( method: str, params: Optional[Dict[str, Any]] = None ) -> str: """ Execute a whitelisted Frappe method. Args: method: Method name to call (whitelisted) params: Parameters to pass to the method (optional) """ try: client = get_client() # Prepare request data request_data = {"cmd": method} if params: request_data.update(params) # Make API request to call method response = await client.post("api/method", json_data=request_data) if "message" in response: return json.dumps(response["message"], indent=2) else: return json.dumps(response, indent=2) except Exception as error: return _format_error_response(error, "call_method")
- src/server.py:39-42 (registration)The registration point where documents.register_tools(mcp) is called, which in turn defines and registers the call_method tool among others using @mcp.tool() decorators.helpers.register_tools(mcp) documents.register_tools(mcp) schema.register_tools(mcp) reports.register_tools(mcp)
- src/tools/documents.py:51-79 (helper)Shared helper function used by call_method (and other tools) to format and return detailed error responses, including authentication checks and Frappe-specific error handling.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)}"