call_method
Execute whitelisted Frappe Framework methods by specifying the method name and optional parameters to interact with Frappe sites programmatically.
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-446 (handler)The core handler function for the 'call_method' tool. It is decorated with @mcp.tool() for automatic registration and implements calling whitelisted Frappe methods via the /api/method endpoint, with proper error handling using a shared helper.@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:40-40 (registration)Invocation of documents.register_tools(mcp) in the main server setup, which triggers the registration of the 'call_method' tool (and other document tools) with the MCP server instance.documents.register_tools(mcp)
- src/tools/documents.py:51-78 (helper)Helper function used by call_method (and other tools) to format detailed error responses, including credential 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)}"