生物数据助手
一个模型上下文协议服务器,用于与Biomart数据库接口,允许模型发现生物数据集、探索属性/过滤器、检索生物数据以及在不同生物标识符之间进行转换。
可用工具 (8 个)
该服务在 MCP 协议中暴露的工具,AI 可按需调用
list_marts
Lists all available Biomart marts (databases) from Ensembl. Biomart organizes biological data in a hierarchy: MART -> DATASET -> ATTRIBUTES/FILTERS. This function returns all available marts as a CSV string. Returns: str: CSV-formatted table of all marts with their display names and descriptions. Example: list_marts() >>> "name,display_name,description ENSEMBL_MART_ENSEMBL,Ensembl Genes,Gene annotation from Ensembl ENSEMBL_MART_MOUSE,Mouse strains,Strain-specific data for mouse ..."
该工具无需必填参数,直接调用即可
list_datasets 1 个参数 需填 1 项
Lists all available biomart datasets for a given mart. Each mart contains multiple datasets. This function returns all datasets available in the specified mart as a CSV string. Args: mart (str): The mart identifier to list datasets from. Valid values include: ENSEMBL_MART_ENSEMBL, ENSEMBL_MART_MOUSE, ENSEMBL_MART_ONTOLOGY, ENSEMBL_MART_GENOMIC, ENSEMBL_MART_SNP, ENSEMBL_MART_FUNCGEN Returns: str: CSV-formatted table of all datasets with their display names and descriptions. Example: list_datasets("ENSEMBL_MART_ENSEMBL") >>> "name,display_name,description hsapiens_gene_ensembl,Human genes,Human genes (GRCh38.p13) mmusculus_gene_ensembl,Mouse genes,Mouse genes (GRCm39) ..."
必填参数:mart
list_common_attributes 2 个参数 需填 2 项
Lists commonly used attributes available for a given dataset. This function returns only the most frequently used attributes (defined in COMMON_ATTRIBUTES) to avoid overwhelming the model with too many options. For a complete list, use list_all_attributes. Args: mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL") dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl") Returns: str: CSV-formatted table of common attributes with their display names and descriptions. Example: list_common_attributes("ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl") >>> "name,display_name,description ensembl_gene_id,Gene stable ID,Ensembl stable ID for the gene external_gene_name,Gene name,The gene name ..."
必填参数:mart、dataset
list_all_attributes 2 个参数 需填 2 项
Lists all available attributes for a given dataset with some filtering. This function returns a filtered list of all attributes available for the specified dataset. Some less commonly used attributes (homologs, microarray probes) are filtered out to reduce the response size. CAUTION: This function can return a large number of attributes and may be unstable for certain datasets. Consider using list_common_attributes first. Args: mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL") dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl") Returns: str: CSV-formatted table of all filtered attributes. Example: list_all_attributes("ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl")
必填参数:mart、dataset
list_filters 2 个参数 需填 2 项
Lists all available filters for a given dataset. Filters are used to narrow down the results of a Biomart query. This function returns all filters that can be applied to the specified dataset. Args: mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL") dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl") Returns: str: CSV-formatted table of all filters with their display names and descriptions. Example: list_filters("ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl") >>> "name,description chromosome_name,Chromosome/scaffold name start,Gene start (bp) end,Gene end (bp) ..."
必填参数:mart、dataset
get_data 4 个参数 需填 4 项
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 ..."
必填参数:mart、dataset、attributes、filters
get_translation 5 个参数 需填 5 项
Translates a single identifier from one attribute type to another. This function allows conversion between different identifier types, such as converting a gene symbol to an Ensembl ID. Results are cached to improve performance. Args: mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL") dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl") from_attr (str): The source attribute name (e.g., "hgnc_symbol") to_attr (str): The target attribute name (e.g., "ensembl_gene_id") target (str): The identifier value to translate (e.g., "TP53") Returns: str: The translated identifier, or an error message if not found. Example: get_translation("ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl", "hgnc_symbol", "ensembl_gene_id", "TP53") >>> "ENSG00000141510"
必填参数:mart、dataset、from_attr、to_attr、target
batch_translate 5 个参数 需填 5 项
Translates multiple identifiers in a single batch operation. This function is more efficient than multiple calls to get_translation when you need to translate many identifiers at once. Args: mart (str): The mart identifier (e.g., "ENSEMBL_MART_ENSEMBL") dataset (str): The dataset identifier (e.g., "hsapiens_gene_ensembl") from_attr (str): The source attribute name (e.g., "hgnc_symbol") to_attr (str): The target attribute name (e.g., "ensembl_gene_id") targets (list[str]): List of identifier values to translate (e.g., ["TP53", "BRCA1", "BRCA2"]) Returns: dict: A dictionary containing: - translations: Dictionary mapping input IDs to translated IDs - not_found: List of IDs that could not be translated - found_count: Number of successfully translated IDs - not_found_count: Number of IDs that could not be translated Example: batch_translate("ENSEMBL_MART_ENSEMBL", "hsapiens_gene_ensembl", "hgnc_symbol", "ensembl_gene_id", ["TP53", "BRCA1", "BRCA2"]) >>> {"translations": {"TP53": "ENSG00000141510", "BRCA1": "ENSG00000012048"}, "not_found": ["BRCA2"], "found_count": 2, "not_found_count": 1}
必填参数:mart、dataset、from_attr、to_attr、targets
服务介绍
Biomart MCP
一个用于与Biomart接口的MCP服务器
模型上下文协议 (MCP) 是一种开放协议,它标准化了应用程序如何为Anthropic开发的LLM提供上下文。这里我们使用MCP python-sdk创建了一个通过pybiomart包与Biomart接口的MCP服务器。

有一个简短的演示视频,展示了在Claude Desktop上运行的MCP服务器。
安装
克隆仓库
git clone https://github.com/jzinno/biomart-mcp.git
cd biomart-mcp
Claude Desktop
uv run --with mcp[cli] mcp install --with pybiomart biomart-mcp.py
Cursor
通过Cursor的代理模式,其他模型也可以利用MCP服务器,例如来自OpenAI或DeepSeek的模型。点击光标设置齿轮图标并导航到功能 -> MCP服务器 -> 添加新的MCP服务器。将名称设置为biomart(或者你喜欢的任何名称),并将类型设置为命令。
设置命令为:
uv run --with mcp[cli] --with pybiomart mcp run /your/path/to/biomart-mcp.py
Glama
开发
# Create a virtual environment
uv venv
# MacOS/Linux
source .venv/bin/activate
# Windows
.venv\Scripts\activate
uv sync #or uv add mcp[cli] pybiomart
# Run the server in dev mode
mcp dev biomart-mcp.py
功能
Biomart-MCP提供了几个工具来与Biomart数据库交互:
- Mart和数据集发现:列出可用的marts和数据集以探索Biomart数据库结构
- 属性和过滤器探索:查看特定数据集的常用或所有可用属性和过滤器
- 数据检索:使用特定属性和过滤器查询Biomart以获取生物数据
- ID转换:在不同的生物标识符之间进行转换(例如,基因符号到Ensembl ID)
贡献
欢迎提交拉取请求!关于开发的一些小提示:
- 我们特意只在这里使用
@mcp.tool(),这是为了最大化与支持MCP客户端的兼容性,如文档所示。 - 我们使用
@lru_cache来缓存计算成本高或调用外部API的功能的结果。 - 我们需要注意不要超出模型的上下文窗口限制,例如你会看到很多地方有
df.to_csv(index=False).replace("\r", "")。这种CSV风格的返回比像df.to_string()这样的方式更节省token,后者中的大部分token是空白字符。同时也要注意,从染色体中拉取所有基因或其他类似的大请求也会超过上下文窗口的大小。
潜在的未来功能
当然还有很多可以添加的功能,其中一些可能超出了biomart-mcp这个名字的范围。这里是一些想法:
- 使用
bs4对资源网站进行网页抓取,例如我们获取了NOTCH1的Ensembl基因ID,那么在某些情况下,可能从UCSC页面中抓取“Comments and Description Text from UniProtKB”部分的内容会很有用。 - $...$