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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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:
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It describes what the tool returns (schema details) but lacks behavioral traits like error handling, permissions required, or performance characteristics. It doesn't contradict annotations, but misses key operational details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences total, each earning its place: first states purpose, second provides usage guidance, third documents the parameter. No wasted words, well-structured with clear sections.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which handles return values), the description is reasonably complete for a read-only schema tool. It covers purpose, usage, and parameter, but could benefit from more behavioral context like authentication or error cases.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description compensates by explaining the single parameter 'doctype' as 'DocType name' in the Args section. This adds meaning beyond the bare schema, though it could specify format or examples. With 0 parameters documented in schema, baseline is 4.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get' and the resource 'complete schema for a DocType', specifying it includes field definitions, validations, and linked DocTypes. It distinguishes from siblings like get_doctype_list (which lists DocTypes) and get_document (which retrieves document instances).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly states when to use this tool: 'to understand the structure of a DocType before creating or updating documents.' This provides clear context for usage versus alternatives like create_document or update_document, which require schema knowledge.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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