Skip to main content
Glama

get_field_options

Retrieve available options for Link or Select fields in Frappe Framework. For Link fields, returns documents from the linked DocType; for Select fields, returns predefined options.

Instructions

    Get available options for a Link or Select field.
    
    For Link fields, returns documents from the linked DocType.
    For Select fields, returns the predefined options.
    
    Args:
        doctype: DocType name
        fieldname: Field name
        limit: Maximum number of options to return (default: 20)
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doctypeYes
fieldnameYes
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function implementing the get_field_options tool. It fetches the DocType schema, identifies the field type (Link or Select), and retrieves either linked documents or static options.
    async def get_field_options(
        doctype: str,
        fieldname: str,
        limit: Optional[int] = 20
    ) -> str:
        """
        Get available options for a Link or Select field.
        
        For Link fields, returns documents from the linked DocType.
        For Select fields, returns the predefined options.
        
        Args:
            doctype: DocType name
            fieldname: Field name
            limit: Maximum number of options to return (default: 20)
        """
        try:
            client = get_client()
            
            # First get the field definition to understand its type
            schema_response = await client.get(f"api/resource/DocType/{doctype}")
            
            if "data" not in schema_response:
                return f"Could not get schema for DocType: {doctype}"
            
            fields = schema_response["data"].get("fields", [])
            target_field = None
            
            for field in fields:
                if field.get("fieldname") == fieldname:
                    target_field = field
                    break
            
            if not target_field:
                return f"Field '{fieldname}' not found in DocType '{doctype}'"
            
            fieldtype = target_field.get("fieldtype")
            options = target_field.get("options", "")
            
            if fieldtype == "Link":
                # Get documents from linked DocType
                if not options:
                    return f"Link field '{fieldname}' has no linked DocType defined"
                
                params = {
                    "fields": json.dumps(["name", "title"]),
                    "limit": str(limit)
                }
                
                response = await client.get(f"api/resource/{options}", params=params)
                
                if "data" in response:
                    documents = response["data"]
                    return f"Available {options} documents for field '{fieldname}':\n\n" + json.dumps(documents, indent=2)
                else:
                    return json.dumps(response, indent=2)
            
            elif fieldtype == "Select":
                # Parse select options
                if not options:
                    return f"Select field '{fieldname}' has no options defined"
                
                select_options = [opt.strip() for opt in options.split("\n") if opt.strip()]
                return f"Select options for field '{fieldname}':\n\n" + json.dumps(select_options, indent=2)
            
            else:
                return f"Field '{fieldname}' is of type '{fieldtype}' which doesn't have predefined options"
                
        except Exception as error:
            return _format_error_response(error, "get_field_options")
  • src/server.py:41-41 (registration)
    Registers the schema tools module, which includes the get_field_options tool, with the MCP server instance.
    schema.register_tools(mcp)
  • Utility function used by get_field_options (and other tools) to format and return detailed error responses.
    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)}"
  • src/server.py:38-42 (registration)
    Block where all tools are registered during server creation, specifically including schema tools containing get_field_options.
    # Register all tool modules
    helpers.register_tools(mcp)
    documents.register_tools(mcp)
    schema.register_tools(mcp)
    reports.register_tools(mcp)
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that the tool returns data (not modifies) and describes the behavioral difference between Link and Select fields, but lacks details on permissions, rate limits, error handling, or pagination. It adds some context but is incomplete for a read operation.

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?

The description is appropriately sized and front-loaded, with the purpose stated first, followed by clarifying details and parameter explanations. Every sentence adds value without redundancy, and the structure is clear and efficient.

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's moderate complexity, no annotations, and an output schema (which handles return values), the description is mostly complete. It covers purpose, usage context, and parameter semantics, but could improve by adding more behavioral details like error cases or performance hints.

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 meaning by explaining each parameter's role: 'doctype' and 'fieldname' identify the target, and 'limit' controls result count with a default. However, it doesn't specify data formats or constraints beyond the schema's basic types.

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 tool's purpose with specific verbs ('Get available options') and resources ('Link or Select field'), distinguishing it from siblings like get_doctype_schema or get_document. It explicitly differentiates between Link fields (returns documents) and Select fields (returns predefined options), providing precise scope.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (for Link or Select fields) but does not explicitly mention when not to use it or name alternatives. It implies usage by specifying the field types, though lacks explicit exclusions or sibling tool comparisons.

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