Skip to main content
Glama

get_data

Retrieve biological data from Biomart by specifying attributes and filters, returning results in CSV format. Use this tool to query datasets efficiently and apply custom filters for targeted data extraction.

Instructions

Queries Biomart for data using specified attributes and filters. This function performs the main data retrieval from Biomart, allowing you to query biological data by specifying which attributes to return and which filters to apply. Includes automatic retry logic for resilience. Args: mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL") dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl") attributes (list[str]): List of attributes to retrieve (e.g., ["ensembl_gene_id", "external_gene_name"]) filters (dict[str, str]): Dictionary of filters to apply (e.g., {"chromosome_name": "1"}) Returns: str: CSV-formatted results of the query. Example: get_data( "ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl", ["ensembl_gene_id", "external_gene_name", "chromosome_name"], {"chromosome_name": "X", "biotype": "protein_coding"} ) >>> "ensembl_gene_id,external_gene_name,chromosome_name ENSG00000000003,TSPAN6,X ENSG00000000005,TNMD,X ..."

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
attributesYes
datasetYes
filtersYes
martYes

Implementation Reference

  • The get_data tool handler: decorated with @mcp.tool() for MCP registration. Executes Biomart query with retry logic using pybiomart, returns CSV data.
    @mcp.tool() def get_data(mart: str, dataset: str, attributes: list[str], filters: dict[str, str]): """ Queries Biomart for data using specified attributes and filters. This function performs the main data retrieval from Biomart, allowing you to query biological data by specifying which attributes to return and which filters to apply. Includes automatic retry logic for resilience. Args: mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL") dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl") attributes (list[str]): List of attributes to retrieve (e.g., ["ensembl_gene_id", "external_gene_name"]) filters (dict[str, str]): Dictionary of filters to apply (e.g., {"chromosome_name": "1"}) Returns: str: CSV-formatted results of the query. Example: get_data( "ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl", ["ensembl_gene_id", "external_gene_name", "chromosome_name"], {"chromosome_name": "X", "biotype": "protein_coding"} ) >>> "ensembl_gene_id,external_gene_name,chromosome_name ENSG00000000003,TSPAN6,X ENSG00000000005,TNMD,X ..." """ for attempt in range(MAX_RETRIES): try: server = get_server() return ( server[mart][dataset] .query(attributes=attributes, filters=filters) .to_csv(index=False) .replace("\r", "") ) except Exception as e: print( f"Error getting data (attempt {attempt+1}/{MAX_RETRIES}): {str(e)}", file=sys.stderr, ) if attempt < MAX_RETRIES - 1: print(f"Retrying in {RETRY_DELAY} seconds...", file=sys.stderr) time.sleep(RETRY_DELAY) else: return f"Error: {str(e)}"
  • Cached helper function to create and retrieve the pybiomart Server connection, used by get_data.
    @lru_cache() def get_server(): """Create and cache a server connection with error handling""" try: return pybiomart.Server(host=DEFAULT_HOST) except Exception as e: print(f"Error connecting to Biomart server: {str(e)}", file=sys.stderr) raise
  • Type hints and docstring defining input schema (mart:str, dataset:str, attributes:list[str], filters:dict[str,str]) and output (str: CSV). Note: schema embedded in handler.
    def get_data(mart: str, dataset: str, attributes: list[str], filters: dict[str, str]): """ Queries Biomart for data using specified attributes and filters. This function performs the main data retrieval from Biomart, allowing you to query biological data by specifying which attributes to return and which filters to apply. Includes automatic retry logic for resilience. Args: mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL") dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl") attributes (list[str]): List of attributes to retrieve (e.g., ["ensembl_gene_id", "external_gene_name"]) filters (dict[str, str]): Dictionary of filters to apply (e.g., {"chromosome_name": "1"}) Returns: str: CSV-formatted results of the query. Example: get_data( "ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl", ["ensembl_gene_id", "external_gene_name", "chromosome_name"], {"chromosome_name": "X", "biotype": "protein_coding"} ) >>> "ensembl_gene_id,external_gene_name,chromosome_name ENSG00000000003,TSPAN6,X ENSG00000000005,TNMD,X ..." """

Other Tools

Related 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/jzinno/biomart-mcp'

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