Skip to main content
Glama

get_doctype_schema

Retrieve the complete schema for a Frappe DocType, including field definitions, validations, and linked DocTypes to understand document structure before creating or updating records.

Instructions

    Get the complete schema for a DocType including field definitions, validations, and linked DocTypes.
    
    Use this to understand the structure of a DocType before creating or updating documents.
    
    Args:
        doctype: DocType name
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doctypeYes

Implementation Reference

  • The handler function for the 'get_doctype_schema' tool. It retrieves the DocType schema from the Frappe API, formats the fields summary, and returns JSON. Includes error handling.
    @mcp.tool()
    async def get_doctype_schema(doctype: str) -> str:
        """
        Get the complete schema for a DocType including field definitions, validations, and linked DocTypes.
        
        Use this to understand the structure of a DocType before creating or updating documents.
        
        Args:
            doctype: DocType name
        """
        try:
            client = get_client()
            
            # Get DocType schema
            response = await client.get(f"api/resource/DocType/{doctype}")
            
            if "data" in response:
                schema_data = response["data"]
                
                # Format the response to highlight key information
                fields = schema_data.get("fields", [])
                field_summary = []
                
                for field in fields:
                    field_info = {
                        "label": field.get("label"),
                        "fieldname": field.get("fieldname"),
                        "fieldtype": field.get("fieldtype"),
                        "reqd": field.get("reqd", 0) == 1,
                        "options": field.get("options"),
                        "default": field.get("default")
                    }
                    if field.get("description"):
                        field_info["description"] = field.get("description")
                    field_summary.append(field_info)
                
                formatted_response = {
                    "doctype": doctype,
                    "module": schema_data.get("module"),
                    "naming_rule": schema_data.get("autoname"),
                    "is_submittable": schema_data.get("is_submittable", 0) == 1,
                    "is_tree": schema_data.get("is_tree", 0) == 1,
                    "track_changes": schema_data.get("track_changes", 0) == 1,
                    "allow_rename": schema_data.get("allow_rename", 0) == 1,
                    "fields": field_summary,
                    "permissions": schema_data.get("permissions", [])
                }
                
                return json.dumps(formatted_response, indent=2)
            else:
                return json.dumps(response, indent=2)
                
        except Exception as error:
            return _format_error_response(error, "get_doctype_schema")
  • src/server.py:38-42 (registration)
    Central registration point where schema.register_tools(mcp) is called to register all tools from the schema module, including 'get_doctype_schema'.
    # Register all tool modules
    helpers.register_tools(mcp)
    documents.register_tools(mcp)
    schema.register_tools(mcp)
    reports.register_tools(mcp)
  • Helper function used by get_doctype_schema to format and return error responses with authentication and API error handling.
    def _format_error_response(error: Exception, operation: str) -> str:
        """Format error response with detailed information."""
        credentials_check = validate_api_credentials()
        
        # 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)}"
  • The register_tools function in schema.py that defines and registers the get_doctype_schema tool using @mcp.tool() decorator.
    def register_tools(mcp: Any) -> None:

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