Skip to main content
Glama

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
NameRequiredDescriptionDefault
methodYes
paramsNo

Implementation Reference

  • 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)
  • 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)}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/appliedrelevance/frappe-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server