Skip to main content
Glama

get_template

Retrieve and transform template data from the CEDAR metadata repository by providing a template ID or URL for biomedical data annotation workflows.

Instructions

Get a template from the CEDAR repository.

Args: template_id: The template ID or full URL from CEDAR repository (e.g., "https://repo.metadatacenter.org/templates/e019284e-48d1-4494-bc83-ddefd28dfbac")

Returns: Template data from CEDAR, cleaned and transformed

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
template_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Registration and handler for the 'get_template' MCP tool using @mcp.tool() decorator. Fetches template from CEDAR API and applies cleaning.
    @mcp.tool()
  • Helper function clean_template_response that transforms and cleans the raw CEDAR template JSON-LD into a simplified structure using Pydantic models for output schema validation.
    def clean_template_response(
        template_data: Dict[str, Any], bioportal_api_key: str
    ) -> Dict[str, Any]:
        """
        Clean and transform the raw CEDAR template JSON-LD to simplified YAML structure.
        Now supports nested objects, arrays, and template elements.
    
        Args:
            template_data: Raw template data from CEDAR (JSON-LD format)
            bioportal_api_key: BioPortal API key for fetching controlled term values
        Returns:
            Cleaned and transformed template data as dictionary (ready for YAML export)
        """
        # Extract template name, preferring schema:name for correct casing
        template_name = template_data.get("schema:name", "")
        if not template_name:
            # Fallback to title if schema:name is empty
            title = template_data.get("title", "")
            template_name = (
                title.replace(" template schema", "").replace("template schema", "").strip()
            )
            if not template_name:
                template_name = "Unnamed Template"
    
        # Get field order from UI configuration
        ui_config = template_data.get("_ui", {})
        field_order = ui_config.get("order", [])
    
        # Get properties section
        properties = template_data.get("properties", {})
    
        # Transform fields and elements in the specified order
        output_children: List[Union[FieldDefinition, ElementDefinition]] = []
    
        # Process fields/elements only in UI order since it covers all template items
        for item_name in field_order:
            if item_name in properties:
                item_data = properties[item_name]
                if isinstance(item_data, dict):
                    item_type = item_data.get("@type", "")
    
                    if item_type == "https://schema.metadatacenter.org/core/TemplateField":
                        # It's a simple field
                        field_child = _transform_field(
                            item_name, item_data, bioportal_api_key
                        )
                        output_children.append(field_child)
                    elif (
                        item_type
                        == "https://schema.metadatacenter.org/core/TemplateElement"
                    ):
                        # It's a template element (possibly an array)
                        element_child = _transform_element(
                            item_name, item_data, bioportal_api_key
                        )
                        output_children.append(element_child)
                    elif item_data.get("type") == "array" and "items" in item_data:
                        # It's an array - check what type of items it contains
                        items_type = item_data["items"].get("@type", "")
                        if (
                            items_type
                            == "https://schema.metadatacenter.org/core/TemplateField"
                        ):
                            # Array of fields - treat as a field with array marker
                            field_child = _transform_field(
                                item_name, item_data, bioportal_api_key
                            )
                            output_children.append(field_child)
                        elif (
                            items_type
                            == "https://schema.metadatacenter.org/core/TemplateElement"
                        ):
                            # Array of elements - treat as an element
                            element_child = _transform_element(
                                item_name, item_data, bioportal_api_key
                            )
                            output_children.append(element_child)
    
        # Create output template
        output_template = SimplifiedTemplate(
            type="template", name=template_name, children=output_children
        )
    
        # Convert to dictionary for YAML export
        return output_template.model_dump(exclude_none=True)
  • Pydantic model defining the output schema for cleaned templates, used by clean_template_response.
    class SimplifiedTemplate(BaseModel):
        """
        Represents the complete simplified template structure.
        """
    
        type: str = Field("template", description="Template type")
        name: str = Field(..., description="Template name")
        children: List[Union[FieldDefinition, ElementDefinition]] = Field(
            ..., description="Template fields and elements"
        )

Tool Definition Quality

Score is being calculated. Check back soon.

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/BACH-AI-Tools/cedar-mcp'

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