Skip to main content
Glama

get_template

Retrieve and transform template data from the CEDAR metadata repository using template ID or URL to access structured biomedical data annotations.

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

Implementation Reference

  • The handler function for the 'get_template' MCP tool, decorated with @mcp.tool() for registration. Fetches the template from CEDAR API using the provided template_id, encodes it for URL, makes authenticated GET request, processes with clean_template_response helper, returns cleaned data or error.
    @mcp.tool() def get_template(template_id: str) -> Dict[str, Any]: """ 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 """ headers = { "Accept": "application/json", "Authorization": f"apiKey {CEDAR_API_KEY}", } # Encode the template ID for URL encoded_template_id = quote(template_id, safe="") # Build the URL with a simple query parameter base_url = ( f"https://resource.metadatacenter.org/templates/{encoded_template_id}" ) try: response = requests.get(base_url, headers=headers) response.raise_for_status() template_data = response.json() except requests.exceptions.RequestException as e: return {"error": f"Failed to fetch CEDAR template: {str(e)}"} # Always clean the response template_data = clean_template_response(template_data, BIOPORTAL_API_KEY) return template_data
  • Pydantic BaseModel defining the output schema structure for the cleaned template returned by get_template tool.
    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" )
  • Supporting helper function called by get_template to transform and clean the raw JSON-LD template response into a simplified structure using Pydantic models, handling fields, elements, controlled terms, and BioPortal integration.
    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)

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