Skip to main content
Glama

create_document

Create new documents in Frappe by specifying the document type and field values. Handles required fields, links, and table data for structured data entry.

Instructions

    Create a new document in Frappe.
    
    Args:
        doctype: DocType name
        values: Document field values. Required fields must be included.
               For Link fields, provide the exact document name.
               For Table fields, provide an array of row objects.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doctypeYes
valuesYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The create_document tool handler: creates a new Frappe document via POST to api/resource/{doctype}, handles errors with formatted response.
    @mcp.tool()
    async def create_document(
        doctype: str,
        values: Dict[str, Any]
    ) -> str:
        """
        Create a new document in Frappe.
        
        Args:
            doctype: DocType name
            values: Document field values. Required fields must be included.
                   For Link fields, provide the exact document name.
                   For Table fields, provide an array of row objects.
        """
        try:
            client = get_client()
            
            # Create the document data
            doc_data = {
                "doctype": doctype,
                **values
            }
            
            # Make API request to create document
            response = await client.post(
                f"api/resource/{doctype}",
                json_data=doc_data
            )
            
            if "data" in response:
                doc = response["data"]
                return f"Document created successfully: {doctype} '{doc.get('name', 'Unknown')}'"
            else:
                return json.dumps(response, indent=2)
                
        except Exception as error:
            return _format_error_response(error, "create_document")
  • src/server.py:40-40 (registration)
    Calls register_tools on the documents module to register all document tools including create_document with the MCP server.
    documents.register_tools(mcp)
  • Helper function _format_error_response used by create_document to format and return detailed error messages.
    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)}"
Behavior2/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 mentions 'Required fields must be included' which hints at validation behavior, but doesn't disclose critical traits like authentication needs, error handling, rate limits, or what happens on success (e.g., returns the created document). For a creation tool with zero annotation coverage, this is inadequate.

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

Conciseness4/5

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

The description is front-loaded with the core purpose, followed by a structured 'Args' section. It's efficient with no wasted sentences, though the formatting with indentation and line breaks slightly reduces readability compared to a single paragraph.

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

Completeness3/5

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

Given 2 parameters with nested objects, no annotations, and an output schema exists (which covers return values), the description is moderately complete. It explains parameter semantics well but lacks behavioral context like permissions or side effects, making it adequate but with clear gaps for a creation tool.

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%, so the description must compensate. It adds meaningful semantics: 'doctype' is explained as 'DocType name', and 'values' is detailed with examples for Link fields (exact document name) and Table fields (array of row objects), plus the requirement for including required fields. This goes well beyond the bare schema.

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

Purpose4/5

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

The description clearly states the action ('Create a new document') and resource ('in Frappe'), with the verb 'Create' being specific. However, it doesn't differentiate from sibling tools like 'amend_document' or 'submit_document' that also involve document creation/modification workflows, so it misses the highest tier.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'amend_document', 'submit_document', and 'update_document' available, there's no indication of prerequisites, typical use cases, or distinctions between creation and other document operations.

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