BioOcto code and data release (snapshot 2026-11-27, resumed) (part 28)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Biomni/mcp_generated/mcp_bioconductor-affyio copy/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_server.py +221 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/app/bioconductor-alabaster.spatial_server.py +297 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/app/bioconductor-alabaster.spatial_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster/app/bioconductor-alabaster_server.py +66 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster/app/bioconductor-alabaster_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_bioconductor-alabaster/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_bioconductor-ancombc/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_bioconductor-ancombc/app/bioconductor-ancombc_server.py +251 -0
- Biomni/mcp_generated/mcp_bioconductor-ancombc/app/bioconductor-ancombc_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_bioconductor-ancombc/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_bioconductor-ancombc/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_bioconductor-ancombc/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_bioconductor-ancombc/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_bioconductor-annotate/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_bioconductor-annotate/app/bioconductor-annotate_server.py +141 -0
- Biomni/mcp_generated/mcp_bioconductor-annotate/app/bioconductor-annotate_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_bioconductor-annotate/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_bioconductor-annotate/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_bioconductor-annotate/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationdbi/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationdbi/app/bioconductor-annotationdbi_server.py +464 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationdbi/app/bioconductor-annotationdbi_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationdbi/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationdbi/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationdbi/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationfilter/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationfilter/app/bioconductor-annotationfilter_server.py +293 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationfilter/app/bioconductor-annotationfilter_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationfilter/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationfilter/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationfilter/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationfilter/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_bioconductor-annotationhub/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_bioconductor-apeglm/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_bioconductor-apeglm/app/bioconductor-apeglm_server.py +133 -0
Biomni/mcp_generated/mcp_bioconductor-affyio copy/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-alabaster.sfe via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-alabaster.sfe -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/bioconductor-alabaster.sfe_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-alabaster.sfe_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-alabaster.sfe_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_server.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import logging
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Dict, Any, Optional
|
| 5 |
+
|
| 6 |
+
# It is assumed that the mcp decorator is available in the execution environment.
|
| 7 |
+
# from mcp import tool
|
| 8 |
+
|
| 9 |
+
# Mock decorator for local testing, not to be included in the final deliverable
|
| 10 |
+
# if 'mcp' not in globals():
|
| 11 |
+
# class mcp:
|
| 12 |
+
# @staticmethod
|
| 13 |
+
# def tool():
|
| 14 |
+
# def decorator(func):
|
| 15 |
+
# return func
|
| 16 |
+
# return decorator
|
| 17 |
+
|
| 18 |
+
logger = logging.getLogger(__name__)
|
| 19 |
+
|
| 20 |
+
from mcp.server.fastmcp import FastMCP
|
| 21 |
+
|
| 22 |
+
SERVER_NAME = 'local_bioconductor_alabaster_sfe'
|
| 23 |
+
mcp = FastMCP(SERVER_NAME)
|
| 24 |
+
|
| 25 |
+
@mcp.tool()
|
| 26 |
+
def stage_sfe_object(
|
| 27 |
+
input_rds: Path,
|
| 28 |
+
output_dir: Path,
|
| 29 |
+
path: str = "sfe",
|
| 30 |
+
) -> Dict[str, Any]:
|
| 31 |
+
"""
|
| 32 |
+
Stages a SpatialFeatureExperiment (SFE) object from an RDS file into the alabaster format.
|
| 33 |
+
|
| 34 |
+
This tool wraps the 'stageObject' function from the R package 'alabaster.sfe'.
|
| 35 |
+
It reads an SFE object from a specified RDS file and saves it into a structured
|
| 36 |
+
directory according to the alabaster specification. This serves as the primary
|
| 37 |
+
"save" or "serialize" function for SFE objects in the alabaster framework.
|
| 38 |
+
|
| 39 |
+
Args:
|
| 40 |
+
input_rds: Path to the input RDS file containing the SpatialFeatureExperiment object.
|
| 41 |
+
output_dir: Path to the directory where the staged object assets will be stored.
|
| 42 |
+
path: The relative path within 'output_dir' to save the object. Defaults to "sfe".
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
A dictionary containing the execution details and the path to the main output metadata file.
|
| 46 |
+
"""
|
| 47 |
+
# 1. Input Validation
|
| 48 |
+
if not input_rds.is_file():
|
| 49 |
+
raise FileNotFoundError(f"Input RDS file not found at: {input_rds}")
|
| 50 |
+
|
| 51 |
+
if not path:
|
| 52 |
+
raise ValueError("'path' cannot be an empty string.")
|
| 53 |
+
|
| 54 |
+
try:
|
| 55 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 56 |
+
except OSError as e:
|
| 57 |
+
raise OSError(f"Failed to create output directory {output_dir}: {e}")
|
| 58 |
+
|
| 59 |
+
# 2. R script construction
|
| 60 |
+
r_script_content = f"""
|
| 61 |
+
suppressPackageStartupMessages(library(alabaster.sfe))
|
| 62 |
+
suppressPackageStartupMessages(library(SpatialFeatureExperiment))
|
| 63 |
+
|
| 64 |
+
tryCatch({{
|
| 65 |
+
sfe_object <- readRDS('{input_rds.resolve()}')
|
| 66 |
+
info <- alabaster.base::stageObject(sfe_object, dir = '{output_dir.resolve()}', path = '{path}')
|
| 67 |
+
cat(file.path('{output_dir.resolve()}', info$path, "object.json"))
|
| 68 |
+
}}, error = function(e) {{
|
| 69 |
+
message("Error during R script execution: ", e$message)
|
| 70 |
+
quit(status = 1)
|
| 71 |
+
}})
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
# 3. Subprocess Execution
|
| 75 |
+
cmd = ["Rscript", "-e", r_script_content]
|
| 76 |
+
command_executed = " ".join(map(str, cmd))
|
| 77 |
+
logger.info(f"Executing command: {command_executed}")
|
| 78 |
+
|
| 79 |
+
try:
|
| 80 |
+
process = subprocess.run(
|
| 81 |
+
cmd,
|
| 82 |
+
check=True,
|
| 83 |
+
capture_output=True,
|
| 84 |
+
text=True,
|
| 85 |
+
encoding='utf-8'
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
stdout = process.stdout.strip()
|
| 89 |
+
stderr = process.stderr.strip()
|
| 90 |
+
|
| 91 |
+
main_output_file = Path(stdout)
|
| 92 |
+
if not main_output_file.is_file():
|
| 93 |
+
raise FileNotFoundError(
|
| 94 |
+
f"Expected output file not created: {main_output_file}. R stderr: {stderr}"
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
return {
|
| 98 |
+
"command_executed": command_executed,
|
| 99 |
+
"stdout": stdout,
|
| 100 |
+
"stderr": stderr,
|
| 101 |
+
"output_files": {
|
| 102 |
+
"staged_object_json": str(main_output_file)
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
except FileNotFoundError:
|
| 107 |
+
error_msg = "Error: 'Rscript' command not found. Please ensure R is installed and in your system's PATH."
|
| 108 |
+
logger.error(error_msg)
|
| 109 |
+
raise RuntimeError(error_msg) from None
|
| 110 |
+
except subprocess.CalledProcessError as e:
|
| 111 |
+
logger.error(f"Command failed with exit code {e.returncode}")
|
| 112 |
+
logger.error(f"STDOUT: {e.stdout}")
|
| 113 |
+
logger.error(f"STDERR: {e.stderr}")
|
| 114 |
+
raise RuntimeError(
|
| 115 |
+
f"R script execution failed with exit code {e.returncode}.\n"
|
| 116 |
+
f"STDOUT: {e.stdout}\n"
|
| 117 |
+
f"STDERR: {e.stderr}"
|
| 118 |
+
) from e
|
| 119 |
+
|
| 120 |
+
@mcp.tool()
|
| 121 |
+
def load_sfe_object(
|
| 122 |
+
staged_dir: Path,
|
| 123 |
+
output_rds: Path,
|
| 124 |
+
path: str = "",
|
| 125 |
+
) -> Dict[str, Any]:
|
| 126 |
+
"""
|
| 127 |
+
Loads a SpatialFeatureExperiment (SFE) object from the alabaster format into an RDS file.
|
| 128 |
+
|
| 129 |
+
This tool wraps the 'loadObject' function from the R package 'alabaster.base'.
|
| 130 |
+
It reads an SFE object from a staged directory, reconstructs it in memory, and
|
| 131 |
+
saves the complete object as a single RDS file. This is the "load" or "deserialize"
|
| 132 |
+
counterpart to the staging function.
|
| 133 |
+
|
| 134 |
+
Args:
|
| 135 |
+
staged_dir: Path to the directory containing the staged object assets.
|
| 136 |
+
output_rds: Path for the output RDS file where the loaded SFE object will be saved.
|
| 137 |
+
path: The relative path within 'staged_dir' where the object's 'object.json' is located.
|
| 138 |
+
If empty, it's assumed to be at the root of 'staged_dir'.
|
| 139 |
+
|
| 140 |
+
Returns:
|
| 141 |
+
A dictionary containing the execution details and the path to the output RDS file.
|
| 142 |
+
"""
|
| 143 |
+
# 1. Input Validation
|
| 144 |
+
if not staged_dir.is_dir():
|
| 145 |
+
raise NotADirectoryError(f"Staged asset directory not found at: {staged_dir}")
|
| 146 |
+
|
| 147 |
+
metadata_json_path = staged_dir.joinpath(path, "object.json")
|
| 148 |
+
if not metadata_json_path.is_file():
|
| 149 |
+
raise FileNotFoundError(f"Metadata file 'object.json' not found at: {metadata_json_path}")
|
| 150 |
+
|
| 151 |
+
try:
|
| 152 |
+
output_rds.parent.mkdir(parents=True, exist_ok=True)
|
| 153 |
+
except OSError as e:
|
| 154 |
+
raise OSError(f"Failed to create output directory {output_rds.parent}: {e}")
|
| 155 |
+
|
| 156 |
+
# 2. R script construction
|
| 157 |
+
r_script_content = f"""
|
| 158 |
+
suppressPackageStartupMessages(library(alabaster.sfe))
|
| 159 |
+
suppressPackageStartupMessages(library(SpatialFeatureExperiment))
|
| 160 |
+
|
| 161 |
+
tryCatch({{
|
| 162 |
+
sfe_object <- alabaster.base::loadObject(
|
| 163 |
+
'{metadata_json_path.resolve()}',
|
| 164 |
+
project = '{staged_dir.resolve()}'
|
| 165 |
+
)
|
| 166 |
+
saveRDS(sfe_object, file = '{output_rds.resolve()}')
|
| 167 |
+
cat('{output_rds.resolve()}')
|
| 168 |
+
}}, error = function(e) {{
|
| 169 |
+
message("Error during R script execution: ", e$message)
|
| 170 |
+
quit(status = 1)
|
| 171 |
+
}})
|
| 172 |
+
"""
|
| 173 |
+
|
| 174 |
+
# 3. Subprocess Execution
|
| 175 |
+
cmd = ["Rscript", "-e", r_script_content]
|
| 176 |
+
command_executed = " ".join(map(str, cmd))
|
| 177 |
+
logger.info(f"Executing command: {command_executed}")
|
| 178 |
+
|
| 179 |
+
try:
|
| 180 |
+
process = subprocess.run(
|
| 181 |
+
cmd,
|
| 182 |
+
check=True,
|
| 183 |
+
capture_output=True,
|
| 184 |
+
text=True,
|
| 185 |
+
encoding='utf-8'
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
stdout = process.stdout.strip()
|
| 189 |
+
stderr = process.stderr.strip()
|
| 190 |
+
|
| 191 |
+
output_file = Path(stdout)
|
| 192 |
+
if not output_file.is_file() or output_file != output_rds.resolve():
|
| 193 |
+
raise FileNotFoundError(
|
| 194 |
+
f"Expected output RDS file not created at {output_rds}. R stderr: {stderr}"
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
return {
|
| 198 |
+
"command_executed": command_executed,
|
| 199 |
+
"stdout": stdout,
|
| 200 |
+
"stderr": stderr,
|
| 201 |
+
"output_files": {
|
| 202 |
+
"output_rds": str(output_file)
|
| 203 |
+
}
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
except FileNotFoundError:
|
| 207 |
+
error_msg = "Error: 'Rscript' command not found. Please ensure R is installed and in your system's PATH."
|
| 208 |
+
logger.error(error_msg)
|
| 209 |
+
raise RuntimeError(error_msg) from None
|
| 210 |
+
except subprocess.CalledProcessError as e:
|
| 211 |
+
logger.error(f"Command failed with exit code {e.returncode}")
|
| 212 |
+
logger.error(f"STDOUT: {e.stdout}")
|
| 213 |
+
logger.error(f"STDERR: {e.stderr}")
|
| 214 |
+
raise RuntimeError(
|
| 215 |
+
f"R script execution failed with exit code {e.returncode}.\n"
|
| 216 |
+
f"STDOUT: {e.stdout}\n"
|
| 217 |
+
f"STDERR: {e.stderr}"
|
| 218 |
+
) from e
|
| 219 |
+
|
| 220 |
+
if __name__ == "__main__":
|
| 221 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_shim_server.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_bioconductor_alabaster_sfe'
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class _ShimMCP:
|
| 16 |
+
@staticmethod
|
| 17 |
+
def tool(*args, **kwargs):
|
| 18 |
+
if args and callable(args[0]) and len(args) == 1 and not kwargs:
|
| 19 |
+
return args[0]
|
| 20 |
+
def _decorator(fn):
|
| 21 |
+
return fn
|
| 22 |
+
return _decorator
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _resolve_source_server():
|
| 26 |
+
if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
|
| 27 |
+
return LOCAL_SERVER
|
| 28 |
+
return SOURCE_SERVER
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _load_functions():
|
| 32 |
+
source_server = _resolve_source_server()
|
| 33 |
+
code = source_server.read_text(encoding="utf-8")
|
| 34 |
+
tree = ast.parse(code, filename=str(source_server))
|
| 35 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 36 |
+
namespace = {
|
| 37 |
+
"__name__": "__mcp_source__",
|
| 38 |
+
"mcp": _ShimMCP(),
|
| 39 |
+
}
|
| 40 |
+
exec(compile(code, str(source_server), "exec"), namespace, namespace)
|
| 41 |
+
loaded = []
|
| 42 |
+
for name in function_names:
|
| 43 |
+
fn = namespace.get(name)
|
| 44 |
+
if callable(fn):
|
| 45 |
+
loaded.append(fn)
|
| 46 |
+
return loaded
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
mcp = FastMCP(SERVER_NAME)
|
| 50 |
+
for _fn in _load_functions():
|
| 51 |
+
mcp.tool()(_fn)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-alabaster.sfe:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-alabaster.sfe:latest
|
| 7 |
+
container_name: mcp-bioconductor-alabaster.sfe
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-alabaster.sfe
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-alabaster.sfe
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.sfe/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-alabaster.spatial via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-alabaster.spatial -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/bioconductor-alabaster.spatial_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-alabaster.spatial_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-alabaster.spatial_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/app/bioconductor-alabaster.spatial_server.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
import os
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from typing import Optional, List, Dict, Any
|
| 6 |
+
|
| 7 |
+
# No need to import mcp as per instructions.
|
| 8 |
+
|
| 9 |
+
def _run_r_script(script_content: str, cwd: Path) -> Dict[str, Any]:
|
| 10 |
+
"""
|
| 11 |
+
Executes an R script and captures its output.
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
script_content: The R script as a string.
|
| 15 |
+
cwd: The current working directory for the R script execution.
|
| 16 |
+
|
| 17 |
+
Returns:
|
| 18 |
+
A dictionary containing execution details, including command, stdout, stderr,
|
| 19 |
+
and an error message if the script fails.
|
| 20 |
+
"""
|
| 21 |
+
with tempfile.NamedTemporaryFile(mode="w", suffix=".R", delete=False) as r_script_file:
|
| 22 |
+
r_script_file.write(script_content)
|
| 23 |
+
r_script_path = Path(r_script_file.name)
|
| 24 |
+
|
| 25 |
+
command = ["Rscript", str(r_script_path)]
|
| 26 |
+
|
| 27 |
+
stdout = ""
|
| 28 |
+
stderr = ""
|
| 29 |
+
try:
|
| 30 |
+
process = subprocess.run(
|
| 31 |
+
command,
|
| 32 |
+
capture_output=True,
|
| 33 |
+
text=True,
|
| 34 |
+
check=True,
|
| 35 |
+
cwd=cwd # Run R script in the specified working directory
|
| 36 |
+
)
|
| 37 |
+
stdout = process.stdout
|
| 38 |
+
stderr = process.stderr
|
| 39 |
+
except subprocess.CalledProcessError as e:
|
| 40 |
+
return {
|
| 41 |
+
"command_executed": " ".join(command),
|
| 42 |
+
"stdout": e.stdout,
|
| 43 |
+
"stderr": e.stderr,
|
| 44 |
+
"error": f"R script execution failed with exit code {e.returncode}",
|
| 45 |
+
"output_files": [],
|
| 46 |
+
}
|
| 47 |
+
finally:
|
| 48 |
+
os.remove(r_script_path)
|
| 49 |
+
|
| 50 |
+
return {
|
| 51 |
+
"command_executed": " ".join(command),
|
| 52 |
+
"stdout": stdout,
|
| 53 |
+
"stderr": stderr,
|
| 54 |
+
"output_files": [], # This will be populated by the calling function
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
from mcp.server.fastmcp import FastMCP
|
| 58 |
+
|
| 59 |
+
SERVER_NAME = 'local_bioconductor_alabaster_spatial'
|
| 60 |
+
mcp = FastMCP(SERVER_NAME)
|
| 61 |
+
|
| 62 |
+
@mcp.tool()
|
| 63 |
+
def save_spatial_experiment(
|
| 64 |
+
input_spatial_experiment_rds: Path,
|
| 65 |
+
output_directory: Path,
|
| 66 |
+
precomputed: bool = True,
|
| 67 |
+
deferred: bool = False,
|
| 68 |
+
compression_level: Optional[int] = None,
|
| 69 |
+
compression_filter: Optional[str] = None,
|
| 70 |
+
) -> Dict[str, Any]:
|
| 71 |
+
"""
|
| 72 |
+
Saves a SpatialExperiment object and its images into file artifacts.
|
| 73 |
+
|
| 74 |
+
This function serializes an R SpatialExperiment object (provided as an RDS file)
|
| 75 |
+
into a directory structure of file artifacts, offering a portable alternative
|
| 76 |
+
to direct RDS serialization. The `alabaster.spatial` package handles the
|
| 77 |
+
conversion and storage of the object and its associated images.
|
| 78 |
+
|
| 79 |
+
Args:
|
| 80 |
+
input_spatial_experiment_rds: Path to an RDS file containing the SpatialExperiment object.
|
| 81 |
+
This file must exist.
|
| 82 |
+
output_directory: Path to the directory where the file artifacts will be saved.
|
| 83 |
+
This directory will be created if it does not exist.
|
| 84 |
+
precomputed: Logical, whether to save precomputed results. Defaults to TRUE.
|
| 85 |
+
deferred: Logical, whether to defer saving of certain components. Defaults to FALSE.
|
| 86 |
+
compression_level: Integer, compression level for HDF5 files (0-9).
|
| 87 |
+
If None, R's default (typically 6) will be used.
|
| 88 |
+
compression_filter: String, compression filter for HDF5 files (e.g., "gzip", "lzf").
|
| 89 |
+
If None, no specific filter is applied.
|
| 90 |
+
|
| 91 |
+
Returns:
|
| 92 |
+
A dictionary containing execution details, including the command executed,
|
| 93 |
+
stdout, stderr, and a list of generated output files/directories.
|
| 94 |
+
Returns an error if input file is not found, output path is invalid,
|
| 95 |
+
compression_level is out of range, or R script execution fails.
|
| 96 |
+
"""
|
| 97 |
+
# Input validation
|
| 98 |
+
if not input_spatial_experiment_rds.is_file():
|
| 99 |
+
return {
|
| 100 |
+
"command_executed": "",
|
| 101 |
+
"stdout": "",
|
| 102 |
+
"stderr": f"Error: Input RDS file not found at '{input_spatial_experiment_rds}'",
|
| 103 |
+
"output_files": [],
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
if output_directory.exists() and not output_directory.is_dir():
|
| 107 |
+
return {
|
| 108 |
+
"command_executed": "",
|
| 109 |
+
"stdout": "",
|
| 110 |
+
"stderr": f"Error: Output path '{output_directory}' exists but is not a directory.",
|
| 111 |
+
"output_files": [],
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
try:
|
| 115 |
+
output_directory.mkdir(parents=True, exist_ok=True)
|
| 116 |
+
except OSError as e:
|
| 117 |
+
return {
|
| 118 |
+
"command_executed": "",
|
| 119 |
+
"stdout": "",
|
| 120 |
+
"stderr": f"Error: Could not create output directory '{output_directory}': {e}",
|
| 121 |
+
"output_files": [],
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
if compression_level is not None and not (0 <= compression_level <= 9):
|
| 125 |
+
return {
|
| 126 |
+
"command_executed": "",
|
| 127 |
+
"stdout": "",
|
| 128 |
+
"stderr": f"Error: 'compression_level' must be an integer between 0 and 9, got {compression_level}",
|
| 129 |
+
"output_files": [],
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
# Construct R script
|
| 133 |
+
r_script_template = """
|
| 134 |
+
suppressPackageStartupMessages({{
|
| 135 |
+
library(alabaster.spatial)
|
| 136 |
+
library(SpatialExperiment)
|
| 137 |
+
library(S4Vectors)
|
| 138 |
+
library(alabaster.base)
|
| 139 |
+
library(rhdf5) # Explicitly load for HDF5 operations
|
| 140 |
+
}})
|
| 141 |
+
|
| 142 |
+
input_rds_path <- "{input_rds_path}"
|
| 143 |
+
output_dir_path <- "{output_dir_path}"
|
| 144 |
+
|
| 145 |
+
# Load the SpatialExperiment object
|
| 146 |
+
if (!file.exists(input_rds_path)) {{
|
| 147 |
+
stop(paste0("Input RDS file not found: ", input_rds_path))
|
| 148 |
+
}}
|
| 149 |
+
se_object <- readRDS(input_rds_path)
|
| 150 |
+
|
| 151 |
+
# Ensure it's a SpatialExperiment object
|
| 152 |
+
if (!is(se_object, "SpatialExperiment")) {{
|
| 153 |
+
stop("Loaded object is not a SpatialExperiment object.")
|
| 154 |
+
}}
|
| 155 |
+
|
| 156 |
+
# Prepare additional arguments for saveObject
|
| 157 |
+
save_args <- list(
|
| 158 |
+
x = se_object,
|
| 159 |
+
path = output_dir_path,
|
| 160 |
+
precomputed = {precomputed_r},
|
| 161 |
+
deferred = {deferred_r}
|
| 162 |
+
)
|
| 163 |
+
{compression_level_r}
|
| 164 |
+
{compression_filter_r}
|
| 165 |
+
|
| 166 |
+
# Call saveObject
|
| 167 |
+
do.call(alabaster.spatial::saveObject, save_args)
|
| 168 |
+
|
| 169 |
+
message(paste0("SpatialExperiment object saved to: ", output_dir_path))
|
| 170 |
+
"""
|
| 171 |
+
|
| 172 |
+
compression_level_r = f"save_args$compression_level <- {compression_level}" if compression_level is not None else ""
|
| 173 |
+
compression_filter_r = f"save_args$compression_filter <- '{compression_filter}'" if compression_filter is not None else ""
|
| 174 |
+
|
| 175 |
+
r_script_content = r_script_template.format(
|
| 176 |
+
input_rds_path=input_spatial_experiment_rds.resolve(),
|
| 177 |
+
output_dir_path=output_directory.resolve(),
|
| 178 |
+
precomputed_r=str(precomputed).upper(),
|
| 179 |
+
deferred_r=str(deferred).upper(),
|
| 180 |
+
compression_level_r=compression_level_r,
|
| 181 |
+
compression_filter_r=compression_filter_r,
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
# Execute R script
|
| 185 |
+
result = _run_r_script(r_script_content, output_directory.parent) # Run in parent dir to allow output_directory creation
|
| 186 |
+
if "error" in result:
|
| 187 |
+
return result
|
| 188 |
+
|
| 189 |
+
result["output_files"] = [str(output_directory.resolve())]
|
| 190 |
+
return result
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
@mcp.tool()
|
| 194 |
+
def read_spatial_experiment(
|
| 195 |
+
input_directory: Path,
|
| 196 |
+
output_spatial_experiment_rds: Path,
|
| 197 |
+
metadata_only: bool = False,
|
| 198 |
+
image_format: Optional[str] = None,
|
| 199 |
+
) -> Dict[str, Any]:
|
| 200 |
+
"""
|
| 201 |
+
Loads a SpatialExperiment object and its images from file artifacts.
|
| 202 |
+
|
| 203 |
+
This function reconstructs an R SpatialExperiment object from a directory
|
| 204 |
+
of file artifacts previously saved by `save_spatial_experiment`.
|
| 205 |
+
|
| 206 |
+
Args:
|
| 207 |
+
input_directory: Path to the directory containing the file artifacts.
|
| 208 |
+
This directory must exist and be valid.
|
| 209 |
+
output_spatial_experiment_rds: Path to the output RDS file where the
|
| 210 |
+
reconstructed SpatialExperiment object will be saved.
|
| 211 |
+
The parent directory will be created if it does not exist.
|
| 212 |
+
metadata_only: Logical, whether to only load metadata and not the full data.
|
| 213 |
+
Defaults to FALSE.
|
| 214 |
+
image_format: String, desired image format for loading (e.g., "png", "jpeg", "tiff").
|
| 215 |
+
If None, images are loaded in their original format.
|
| 216 |
+
|
| 217 |
+
Returns:
|
| 218 |
+
A dictionary containing execution details, including the command executed,
|
| 219 |
+
stdout, stderr, and a list of generated output files.
|
| 220 |
+
Returns an error if input directory is not found, output path is invalid,
|
| 221 |
+
or R script execution fails.
|
| 222 |
+
"""
|
| 223 |
+
# Input validation
|
| 224 |
+
if not input_directory.is_dir():
|
| 225 |
+
return {
|
| 226 |
+
"command_executed": "",
|
| 227 |
+
"stdout": "",
|
| 228 |
+
"stderr": f"Error: Input directory not found at '{input_directory}'",
|
| 229 |
+
"output_files": [],
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
if output_spatial_experiment_rds.exists() and not output_spatial_experiment_rds.is_file():
|
| 233 |
+
return {
|
| 234 |
+
"command_executed": "",
|
| 235 |
+
"stdout": "",
|
| 236 |
+
"stderr": f"Error: Output path '{output_spatial_experiment_rds}' exists but is not a file.",
|
| 237 |
+
"output_files": [],
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
try:
|
| 241 |
+
output_spatial_experiment_rds.parent.mkdir(parents=True, exist_ok=True)
|
| 242 |
+
except OSError as e:
|
| 243 |
+
return {
|
| 244 |
+
"command_executed": "",
|
| 245 |
+
"stdout": "",
|
| 246 |
+
"stderr": f"Error: Could not create parent directory for output RDS file '{output_spatial_experiment_rds}': {e}",
|
| 247 |
+
"output_files": [],
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
# Construct R script
|
| 251 |
+
r_script_template = """
|
| 252 |
+
suppressPackageStartupMessages({{
|
| 253 |
+
library(alabaster.spatial)
|
| 254 |
+
library(SpatialExperiment)
|
| 255 |
+
library(S4Vectors)
|
| 256 |
+
library(alabaster.base)
|
| 257 |
+
library(rhdf5) # Explicitly load for HDF5 operations
|
| 258 |
+
}})
|
| 259 |
+
|
| 260 |
+
input_dir_path <- "{input_dir_path}"
|
| 261 |
+
output_rds_path <- "{output_rds_path}"
|
| 262 |
+
|
| 263 |
+
# Prepare additional arguments for readObject
|
| 264 |
+
read_args <- list(
|
| 265 |
+
path = input_dir_path,
|
| 266 |
+
metadata.only = {metadata_only_r}
|
| 267 |
+
)
|
| 268 |
+
{image_format_r}
|
| 269 |
+
|
| 270 |
+
# Call readObject
|
| 271 |
+
se_object <- do.call(alabaster.spatial::readObject, read_args)
|
| 272 |
+
|
| 273 |
+
# Save the SpatialExperiment object to RDS
|
| 274 |
+
saveRDS(se_object, file = output_rds_path)
|
| 275 |
+
|
| 276 |
+
message(paste0("SpatialExperiment object loaded from: ", input_dir_path, " and saved to: ", output_rds_path))
|
| 277 |
+
"""
|
| 278 |
+
|
| 279 |
+
image_format_r = f"read_args$image.format <- '{image_format}'" if image_format is not None else ""
|
| 280 |
+
|
| 281 |
+
r_script_content = r_script_template.format(
|
| 282 |
+
input_dir_path=input_directory.resolve(),
|
| 283 |
+
output_rds_path=output_spatial_experiment_rds.resolve(),
|
| 284 |
+
metadata_only_r=str(metadata_only).upper(),
|
| 285 |
+
image_format_r=image_format_r,
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
# Execute R script
|
| 289 |
+
result = _run_r_script(r_script_content, output_spatial_experiment_rds.parent)
|
| 290 |
+
if "error" in result:
|
| 291 |
+
return result
|
| 292 |
+
|
| 293 |
+
result["output_files"] = [str(output_spatial_experiment_rds.resolve())]
|
| 294 |
+
return result
|
| 295 |
+
|
| 296 |
+
if __name__ == "__main__":
|
| 297 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/app/bioconductor-alabaster.spatial_shim_server.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.spatial/app/bioconductor-alabaster.spatial_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_bioconductor_alabaster_spatial'
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class _ShimMCP:
|
| 16 |
+
@staticmethod
|
| 17 |
+
def tool(*args, **kwargs):
|
| 18 |
+
if args and callable(args[0]) and len(args) == 1 and not kwargs:
|
| 19 |
+
return args[0]
|
| 20 |
+
def _decorator(fn):
|
| 21 |
+
return fn
|
| 22 |
+
return _decorator
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _resolve_source_server():
|
| 26 |
+
if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
|
| 27 |
+
return LOCAL_SERVER
|
| 28 |
+
return SOURCE_SERVER
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _load_functions():
|
| 32 |
+
source_server = _resolve_source_server()
|
| 33 |
+
code = source_server.read_text(encoding="utf-8")
|
| 34 |
+
tree = ast.parse(code, filename=str(source_server))
|
| 35 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 36 |
+
namespace = {
|
| 37 |
+
"__name__": "__mcp_source__",
|
| 38 |
+
"mcp": _ShimMCP(),
|
| 39 |
+
}
|
| 40 |
+
exec(compile(code, str(source_server), "exec"), namespace, namespace)
|
| 41 |
+
loaded = []
|
| 42 |
+
for name in function_names:
|
| 43 |
+
fn = namespace.get(name)
|
| 44 |
+
if callable(fn):
|
| 45 |
+
loaded.append(fn)
|
| 46 |
+
return loaded
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
mcp = FastMCP(SERVER_NAME)
|
| 50 |
+
for _fn in _load_functions():
|
| 51 |
+
mcp.tool()(_fn)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-alabaster.spatial:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-alabaster.spatial:latest
|
| 7 |
+
container_name: mcp-bioconductor-alabaster.spatial
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-alabaster.spatial
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-alabaster.spatial
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster.spatial/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_bioconductor-alabaster/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-alabaster via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-alabaster -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/bioconductor-alabaster_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-alabaster_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-alabaster_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster/app/bioconductor-alabaster_server.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Optional, List
|
| 5 |
+
import tempfile
|
| 6 |
+
import logging
|
| 7 |
+
|
| 8 |
+
# Configure logging
|
| 9 |
+
logging.basicConfig(level=logging.INFO)
|
| 10 |
+
|
| 11 |
+
# Mock mcp.tool decorator for standalone execution
|
| 12 |
+
class mcp:
|
| 13 |
+
def tool(func):
|
| 14 |
+
def wrapper(*args, **kwargs):
|
| 15 |
+
return func(*args, **kwargs)
|
| 16 |
+
return wrapper
|
| 17 |
+
|
| 18 |
+
@mcp.tool
|
| 19 |
+
def alabaster_check():
|
| 20 |
+
"""
|
| 21 |
+
Verifies the installation of the bioconductor-alabaster umbrella package.
|
| 22 |
+
|
| 23 |
+
This tool does not perform any data analysis. Instead, it attempts to load
|
| 24 |
+
the 'alabaster' library within an R session to confirm that the Alabaster
|
| 25 |
+
framework and all its components are correctly installed and accessible.
|
| 26 |
+
A successful execution indicates the environment is ready for tools that
|
| 27 |
+
depend on the Alabaster suite.
|
| 28 |
+
"""
|
| 29 |
+
command = ["Rscript", "-e", "library(alabaster)"]
|
| 30 |
+
command_str = " ".join(command)
|
| 31 |
+
logging.info(f"Executing command: {command_str}")
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
process = subprocess.run(
|
| 35 |
+
command,
|
| 36 |
+
check=True,
|
| 37 |
+
capture_output=True,
|
| 38 |
+
text=True,
|
| 39 |
+
)
|
| 40 |
+
stdout = process.stdout
|
| 41 |
+
stderr = process.stderr
|
| 42 |
+
logging.info("bioconductor-alabaster package loaded successfully.")
|
| 43 |
+
|
| 44 |
+
except FileNotFoundError:
|
| 45 |
+
logging.error("Rscript not found. Please ensure R is installed and in your PATH.")
|
| 46 |
+
# Re-raise with a more informative message for the MCP context
|
| 47 |
+
raise RuntimeError("Rscript executable not found. R installation is required.") from None
|
| 48 |
+
|
| 49 |
+
except subprocess.CalledProcessError as e:
|
| 50 |
+
logging.error(f"Error loading bioconductor-alabaster package.")
|
| 51 |
+
logging.error(f"Stderr: {e.stderr}")
|
| 52 |
+
logging.error(f"Stdout: {e.stdout}")
|
| 53 |
+
return {
|
| 54 |
+
"command_executed": command_str,
|
| 55 |
+
"stdout": e.stdout,
|
| 56 |
+
"stderr": e.stderr,
|
| 57 |
+
"error": "Failed to load the 'alabaster' R library. It may not be installed correctly.",
|
| 58 |
+
"return_code": e.returncode,
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
return {
|
| 62 |
+
"command_executed": command_str,
|
| 63 |
+
"stdout": stdout,
|
| 64 |
+
"stderr": stderr,
|
| 65 |
+
"status": "success"
|
| 66 |
+
}
|
Biomni/mcp_generated/mcp_bioconductor-alabaster/app/bioconductor-alabaster_shim_server.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster/app/bioconductor-alabaster_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_bioconductor_alabaster'
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class _ShimMCP:
|
| 16 |
+
@staticmethod
|
| 17 |
+
def tool(*args, **kwargs):
|
| 18 |
+
if args and callable(args[0]) and len(args) == 1 and not kwargs:
|
| 19 |
+
return args[0]
|
| 20 |
+
def _decorator(fn):
|
| 21 |
+
return fn
|
| 22 |
+
return _decorator
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _resolve_source_server():
|
| 26 |
+
if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
|
| 27 |
+
return LOCAL_SERVER
|
| 28 |
+
return SOURCE_SERVER
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _load_functions():
|
| 32 |
+
source_server = _resolve_source_server()
|
| 33 |
+
code = source_server.read_text(encoding="utf-8")
|
| 34 |
+
tree = ast.parse(code, filename=str(source_server))
|
| 35 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 36 |
+
namespace = {
|
| 37 |
+
"__name__": "__mcp_source__",
|
| 38 |
+
"mcp": _ShimMCP(),
|
| 39 |
+
}
|
| 40 |
+
exec(compile(code, str(source_server), "exec"), namespace, namespace)
|
| 41 |
+
loaded = []
|
| 42 |
+
for name in function_names:
|
| 43 |
+
fn = namespace.get(name)
|
| 44 |
+
if callable(fn):
|
| 45 |
+
loaded.append(fn)
|
| 46 |
+
return loaded
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
mcp = FastMCP(SERVER_NAME)
|
| 50 |
+
for _fn in _load_functions():
|
| 51 |
+
mcp.tool()(_fn)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-alabaster/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-alabaster:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-alabaster:latest
|
| 7 |
+
container_name: mcp-bioconductor-alabaster
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-alabaster
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-alabaster
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_bioconductor-alabaster/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_bioconductor-ancombc/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-ancombc via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-ancombc -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/bioconductor-ancombc_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-ancombc_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-ancombc_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_bioconductor-ancombc/app/bioconductor-ancombc_server.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
import textwrap
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from typing import Dict, List, Optional
|
| 6 |
+
|
| 7 |
+
# @mcp.tool() is a placeholder for the actual decorator.
|
| 8 |
+
# The function is written to be compatible with the MCP server environment.
|
| 9 |
+
def mcp_tool_placeholder(*args, **kwargs):
|
| 10 |
+
def decorator(func):
|
| 11 |
+
return func
|
| 12 |
+
return decorator
|
| 13 |
+
|
| 14 |
+
@mcp_tool_placeholder()
|
| 15 |
+
def ancombc2(
|
| 16 |
+
otu_table: Path,
|
| 17 |
+
sample_metadata: Path,
|
| 18 |
+
formula: str,
|
| 19 |
+
output_dir: Path,
|
| 20 |
+
taxonomy_table: Optional[Path] = None,
|
| 21 |
+
p_adj_method: str = "holm",
|
| 22 |
+
zero_cut: float = 0.9,
|
| 23 |
+
lib_cut: int = 1000,
|
| 24 |
+
struc_zero: bool = False,
|
| 25 |
+
neg_lb: bool = False,
|
| 26 |
+
tol: float = 1e-05,
|
| 27 |
+
max_iter: int = 100,
|
| 28 |
+
conserve: bool = False,
|
| 29 |
+
alpha: float = 0.05,
|
| 30 |
+
global_test: bool = False,
|
| 31 |
+
group: Optional[str] = None,
|
| 32 |
+
mdfdr_dist: str = "normal",
|
| 33 |
+
n_cl: int = 1,
|
| 34 |
+
verbose: bool = False,
|
| 35 |
+
output_prefix: str = "ancombc2_results",
|
| 36 |
+
) -> Dict:
|
| 37 |
+
"""
|
| 38 |
+
Performs differential abundance analysis on microbiome data using ANCOM-BC2.
|
| 39 |
+
|
| 40 |
+
ANCOM-BC2 (Analysis of Compositions of Microbiomes with Bias Correction 2) is a
|
| 41 |
+
method for identifying differentially abundant taxa between groups while correcting
|
| 42 |
+
for sample-specific and taxon-specific biases.
|
| 43 |
+
|
| 44 |
+
Args:
|
| 45 |
+
otu_table: Path to the feature/OTU count table (CSV format). Rows should be taxa
|
| 46 |
+
and columns should be samples. The first column should be taxon IDs.
|
| 47 |
+
sample_metadata: Path to the sample metadata file (CSV format). Rows should be
|
| 48 |
+
samples and columns should be metadata variables. The first
|
| 49 |
+
column should be sample IDs.
|
| 50 |
+
formula: An R-style formula string specifying the model, e.g., "age + sex + diagnosis".
|
| 51 |
+
Variables must correspond to columns in the sample_metadata file.
|
| 52 |
+
output_dir: Path to the directory where output files will be saved.
|
| 53 |
+
taxonomy_table: Optional path to the taxonomy table (CSV format). Rows should be
|
| 54 |
+
taxa, columns should be taxonomic ranks. The first column must
|
| 55 |
+
be taxon IDs matching the OTU table.
|
| 56 |
+
p_adj_method: Method for p-value adjustment.
|
| 57 |
+
Options: "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none".
|
| 58 |
+
zero_cut: A numerical value between 0 and 1. Taxa with a proportion of zeros greater
|
| 59 |
+
than this value will be excluded from the analysis.
|
| 60 |
+
lib_cut: A numerical value. Samples with library sizes less than this value will be
|
| 61 |
+
excluded from the analysis.
|
| 62 |
+
struc_zero: Whether to detect structural zeros.
|
| 63 |
+
neg_lb: Whether to use the negative binomial distribution for modeling sampling fractions.
|
| 64 |
+
If FALSE, a log-linear model is used.
|
| 65 |
+
tol: Convergence tolerance for the optimization algorithm.
|
| 66 |
+
max_iter: Maximum number of iterations for the optimization algorithm.
|
| 67 |
+
conserve: Whether to use a conservative variance estimate for the test statistic.
|
| 68 |
+
alpha: Significance level for identifying differentially abundant taxa.
|
| 69 |
+
global_test: Whether to perform a global test for the specified group variable.
|
| 70 |
+
group: The name of the group variable for the global test. Required if `global_test` is True.
|
| 71 |
+
Must be a column name in the sample_metadata file.
|
| 72 |
+
mdfdr_dist: The assumed distribution of the E-values in m-DFDR.
|
| 73 |
+
Options: "normal", "t".
|
| 74 |
+
n_cl: Number of CPU cores to use for parallel computation.
|
| 75 |
+
verbose: Whether to display progress messages during execution.
|
| 76 |
+
output_prefix: Prefix for the output result files.
|
| 77 |
+
|
| 78 |
+
Returns:
|
| 79 |
+
A dictionary containing the executed command, stdout, stderr, and a list of
|
| 80 |
+
paths to the generated output files.
|
| 81 |
+
"""
|
| 82 |
+
# --- 1. Input Validation ---
|
| 83 |
+
if not otu_table.is_file():
|
| 84 |
+
raise FileNotFoundError(f"OTU table not found at: {otu_table}")
|
| 85 |
+
if not sample_metadata.is_file():
|
| 86 |
+
raise FileNotFoundError(f"Sample metadata not found at: {sample_metadata}")
|
| 87 |
+
if taxonomy_table and not taxonomy_table.is_file():
|
| 88 |
+
raise FileNotFoundError(f"Taxonomy table not found at: {taxonomy_table}")
|
| 89 |
+
|
| 90 |
+
p_adj_methods = ["holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"]
|
| 91 |
+
if p_adj_method not in p_adj_methods:
|
| 92 |
+
raise ValueError(f"Invalid p_adj_method '{p_adj_method}'. Must be one of {p_adj_methods}")
|
| 93 |
+
|
| 94 |
+
mdfdr_dists = ["normal", "t"]
|
| 95 |
+
if mdfdr_dist not in mdfdr_dists:
|
| 96 |
+
raise ValueError(f"Invalid mdfdr_dist '{mdfdr_dist}'. Must be one of {mdfdr_dists}")
|
| 97 |
+
|
| 98 |
+
if not 0 <= zero_cut <= 1:
|
| 99 |
+
raise ValueError("zero_cut must be between 0 and 1.")
|
| 100 |
+
if not 0 < alpha < 1:
|
| 101 |
+
raise ValueError("alpha must be between 0 and 1.")
|
| 102 |
+
if lib_cut < 0:
|
| 103 |
+
raise ValueError("lib_cut must be a non-negative integer.")
|
| 104 |
+
if max_iter <= 0:
|
| 105 |
+
raise ValueError("max_iter must be a positive integer.")
|
| 106 |
+
if n_cl <= 0:
|
| 107 |
+
raise ValueError("n_cl must be a positive integer.")
|
| 108 |
+
if tol <= 0:
|
| 109 |
+
raise ValueError("tol must be a positive float.")
|
| 110 |
+
|
| 111 |
+
if global_test and not group:
|
| 112 |
+
raise ValueError("The 'group' parameter is required when 'global_test' is True.")
|
| 113 |
+
|
| 114 |
+
# --- 2. Prepare for Execution ---
|
| 115 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 116 |
+
|
| 117 |
+
output_res_path = output_dir / f"{output_prefix}_DA.csv"
|
| 118 |
+
output_files = [str(output_res_path)]
|
| 119 |
+
|
| 120 |
+
output_global_res_path = output_dir / f"{output_prefix}_global.csv"
|
| 121 |
+
if global_test:
|
| 122 |
+
output_files.append(str(output_global_res_path))
|
| 123 |
+
|
| 124 |
+
# Convert Python types to R-compatible strings
|
| 125 |
+
r_tax_file = f"'{taxonomy_table.resolve()}'" if taxonomy_table else "NULL"
|
| 126 |
+
r_group = f"'{group}'" if group else "NULL"
|
| 127 |
+
r_struc_zero = "TRUE" if struc_zero else "FALSE"
|
| 128 |
+
r_neg_lb = "TRUE" if neg_lb else "FALSE"
|
| 129 |
+
r_conserve = "TRUE" if conserve else "FALSE"
|
| 130 |
+
r_global_test = "TRUE" if global_test else "FALSE"
|
| 131 |
+
r_verbose = "TRUE" if verbose else "FALSE"
|
| 132 |
+
|
| 133 |
+
# --- 3. Generate R Script ---
|
| 134 |
+
r_script_content = textwrap.dedent(f"""
|
| 135 |
+
# Load required libraries
|
| 136 |
+
library(ANCOMBC)
|
| 137 |
+
library(phyloseq)
|
| 138 |
+
|
| 139 |
+
# --- Parameters ---
|
| 140 |
+
otu_file <- '{otu_table.resolve()}'
|
| 141 |
+
meta_file <- '{sample_metadata.resolve()}'
|
| 142 |
+
tax_file <- {r_tax_file}
|
| 143 |
+
output_res_path <- '{output_res_path.resolve()}'
|
| 144 |
+
output_global_res_path <- '{output_global_res_path.resolve()}'
|
| 145 |
+
|
| 146 |
+
# --- Load and prepare data ---
|
| 147 |
+
# read.csv with row.names = 1 assumes first column is the index
|
| 148 |
+
otu_mat <- as.matrix(read.csv(otu_file, row.names = 1, check.names = FALSE))
|
| 149 |
+
meta_data <- read.csv(meta_file, row.names = 1, check.names = FALSE)
|
| 150 |
+
|
| 151 |
+
# Ensure sample names match and are in the same order
|
| 152 |
+
samples_in_common <- intersect(rownames(meta_data), colnames(otu_mat))
|
| 153 |
+
if (length(samples_in_common) == 0) {{
|
| 154 |
+
stop("No common sample IDs found between OTU table and metadata.")
|
| 155 |
+
}}
|
| 156 |
+
otu_mat <- otu_mat[, samples_in_common, drop = FALSE]
|
| 157 |
+
meta_data <- meta_data[samples_in_common, , drop = FALSE]
|
| 158 |
+
|
| 159 |
+
OTU <- otu_table(otu_mat, taxa_are_rows = TRUE)
|
| 160 |
+
META <- sample_data(meta_data)
|
| 161 |
+
|
| 162 |
+
# Load taxonomy if provided
|
| 163 |
+
if (!is.null(tax_file)) {{
|
| 164 |
+
tax_mat <- as.matrix(read.csv(tax_file, row.names = 1, check.names = FALSE))
|
| 165 |
+
# Ensure taxon names match
|
| 166 |
+
taxa_in_common <- intersect(rownames(tax_mat), rownames(otu_mat))
|
| 167 |
+
if (length(taxa_in_common) == 0) {{
|
| 168 |
+
warning("No common taxon IDs found between OTU table and taxonomy table. Proceeding without taxonomy.")
|
| 169 |
+
pseq <- phyloseq(OTU, META)
|
| 170 |
+
}} else {{
|
| 171 |
+
tax_mat_filtered <- tax_mat[taxa_in_common, , drop = FALSE]
|
| 172 |
+
TAX <- tax_table(tax_mat_filtered)
|
| 173 |
+
pseq <- phyloseq(OTU, META, TAX)
|
| 174 |
+
}}
|
| 175 |
+
}} else {{
|
| 176 |
+
pseq <- phyloseq(OTU, META)
|
| 177 |
+
}}
|
| 178 |
+
|
| 179 |
+
# --- Run ANCOM-BC2 ---
|
| 180 |
+
output <- ancombc2(
|
| 181 |
+
data = pseq,
|
| 182 |
+
formula = "{formula}",
|
| 183 |
+
p_adj_method = "{p_adj_method}",
|
| 184 |
+
zero_cut = {zero_cut},
|
| 185 |
+
lib_cut = {lib_cut},
|
| 186 |
+
struc_zero = {r_struc_zero},
|
| 187 |
+
neg_lb = {r_neg_lb},
|
| 188 |
+
tol = {tol},
|
| 189 |
+
max_iter = {max_iter},
|
| 190 |
+
conserve = {r_conserve},
|
| 191 |
+
alpha = {alpha},
|
| 192 |
+
global = {r_global_test},
|
| 193 |
+
group = {r_group},
|
| 194 |
+
mdfdr_dist = "{mdfdr_dist}",
|
| 195 |
+
n_cl = {n_cl},
|
| 196 |
+
verbose = {r_verbose}
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
# --- Save results ---
|
| 200 |
+
# Save differential abundance results
|
| 201 |
+
res_df <- data.frame(output$res)
|
| 202 |
+
write.csv(res_df, file = output_res_path, row.names = TRUE)
|
| 203 |
+
|
| 204 |
+
# Save global test results if applicable
|
| 205 |
+
if ({r_global_test} && !is.null(output$res_global)) {{
|
| 206 |
+
res_global_df <- data.frame(output$res_global)
|
| 207 |
+
write.csv(res_global_df, file = output_global_res_path, row.names = TRUE)
|
| 208 |
+
}}
|
| 209 |
+
|
| 210 |
+
print("ANCOM-BC2 analysis completed successfully.")
|
| 211 |
+
""")
|
| 212 |
+
|
| 213 |
+
# --- 4. Execute ---
|
| 214 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix=".R") as r_script_file:
|
| 215 |
+
r_script_file.write(r_script_content)
|
| 216 |
+
r_script_path = r_script_file.name
|
| 217 |
+
|
| 218 |
+
command = ["Rscript", r_script_path]
|
| 219 |
+
command_executed = " ".join(command)
|
| 220 |
+
|
| 221 |
+
try:
|
| 222 |
+
result = subprocess.run(
|
| 223 |
+
command,
|
| 224 |
+
capture_output=True,
|
| 225 |
+
text=True,
|
| 226 |
+
check=True,
|
| 227 |
+
)
|
| 228 |
+
stdout = result.stdout
|
| 229 |
+
stderr = result.stderr
|
| 230 |
+
except subprocess.CalledProcessError as e:
|
| 231 |
+
# Clean up the temporary script file on error
|
| 232 |
+
Path(r_script_path).unlink()
|
| 233 |
+
return {
|
| 234 |
+
"command_executed": command_executed,
|
| 235 |
+
"stdout": e.stdout,
|
| 236 |
+
"stderr": e.stderr,
|
| 237 |
+
"return_code": e.returncode,
|
| 238 |
+
"output_files": []
|
| 239 |
+
}
|
| 240 |
+
finally:
|
| 241 |
+
# Ensure temporary script is always cleaned up
|
| 242 |
+
if Path(r_script_path).exists():
|
| 243 |
+
Path(r_script_path).unlink()
|
| 244 |
+
|
| 245 |
+
# --- 5. Return results ---
|
| 246 |
+
return {
|
| 247 |
+
"command_executed": command_executed,
|
| 248 |
+
"stdout": stdout,
|
| 249 |
+
"stderr": stderr,
|
| 250 |
+
"output_files": output_files
|
| 251 |
+
}
|
Biomni/mcp_generated/mcp_bioconductor-ancombc/app/bioconductor-ancombc_shim_server.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-ancombc/app/bioconductor-ancombc_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_bioconductor_ancombc'
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class _ShimMCP:
|
| 16 |
+
@staticmethod
|
| 17 |
+
def tool(*args, **kwargs):
|
| 18 |
+
if args and callable(args[0]) and len(args) == 1 and not kwargs:
|
| 19 |
+
return args[0]
|
| 20 |
+
def _decorator(fn):
|
| 21 |
+
return fn
|
| 22 |
+
return _decorator
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _resolve_source_server():
|
| 26 |
+
if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
|
| 27 |
+
return LOCAL_SERVER
|
| 28 |
+
return SOURCE_SERVER
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _load_functions():
|
| 32 |
+
source_server = _resolve_source_server()
|
| 33 |
+
code = source_server.read_text(encoding="utf-8")
|
| 34 |
+
tree = ast.parse(code, filename=str(source_server))
|
| 35 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 36 |
+
namespace = {
|
| 37 |
+
"__name__": "__mcp_source__",
|
| 38 |
+
"mcp": _ShimMCP(),
|
| 39 |
+
}
|
| 40 |
+
exec(compile(code, str(source_server), "exec"), namespace, namespace)
|
| 41 |
+
loaded = []
|
| 42 |
+
for name in function_names:
|
| 43 |
+
fn = namespace.get(name)
|
| 44 |
+
if callable(fn):
|
| 45 |
+
loaded.append(fn)
|
| 46 |
+
return loaded
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
mcp = FastMCP(SERVER_NAME)
|
| 50 |
+
for _fn in _load_functions():
|
| 51 |
+
mcp.tool()(_fn)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-ancombc/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_bioconductor-ancombc/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-ancombc:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-ancombc:latest
|
| 7 |
+
container_name: mcp-bioconductor-ancombc
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-ancombc
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
Biomni/mcp_generated/mcp_bioconductor-ancombc/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-ancombc
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_bioconductor-ancombc/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_bioconductor-annotate/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-annotate via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-annotate -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY bioconductor-annotate_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-annotate_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-annotate_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotate/app/bioconductor-annotate_server.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import logging
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Optional, List, Dict, Any
|
| 5 |
+
|
| 6 |
+
# The mcp.tool decorator is supplied by the MCP framework.
|
| 7 |
+
# It is aliased here for clarity and to allow for standalone code analysis.
|
| 8 |
+
class mcp:
|
| 9 |
+
"""A dummy class to represent the MCP decorator for static analysis."""
|
| 10 |
+
@staticmethod
|
| 11 |
+
def tool(func):
|
| 12 |
+
"""A dummy decorator that returns the function unchanged."""
|
| 13 |
+
return func
|
| 14 |
+
|
| 15 |
+
@mcp.tool
|
| 16 |
+
def rscript(
|
| 17 |
+
script_file: Optional[Path] = None,
|
| 18 |
+
expressions: Optional[List[str]] = None,
|
| 19 |
+
script_args: Optional[List[str]] = None,
|
| 20 |
+
verbose: bool = False,
|
| 21 |
+
default_packages: Optional[str] = None,
|
| 22 |
+
vanilla: bool = False,
|
| 23 |
+
save: bool = False,
|
| 24 |
+
no_environ: bool = False,
|
| 25 |
+
no_site_file: bool = False,
|
| 26 |
+
no_init_file: bool = False,
|
| 27 |
+
restore: bool = False,
|
| 28 |
+
) -> Dict[str, Any]:
|
| 29 |
+
"""
|
| 30 |
+
Executes an R script or R expressions using the Rscript command-line tool.
|
| 31 |
+
|
| 32 |
+
This tool serves as a wrapper for the Rscript interpreter, which is commonly
|
| 33 |
+
used to run bioinformatics scripts that rely on R packages from repositories
|
| 34 |
+
like CRAN or Bioconductor (e.g., for using bioconductor-annotate).
|
| 35 |
+
You must provide either a path to an R script file or a list of R expressions
|
| 36 |
+
to execute.
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
script_file: Path to the R script file to be executed.
|
| 40 |
+
expressions: A list of R expressions to execute directly. Use this instead of script_file.
|
| 41 |
+
script_args: A list of arguments to be passed to the R script itself.
|
| 42 |
+
verbose: If True, enables verbose output, printing information on progress.
|
| 43 |
+
default_packages: A comma-separated string of package names to be loaded by default.
|
| 44 |
+
vanilla: If True, combines --no-save, --no-restore, --no-site-file,
|
| 45 |
+
--no-init-file, and --no-environ. This provides a clean session.
|
| 46 |
+
If True, the individual flags (save, restore, etc.) are ignored.
|
| 47 |
+
save: If True, the workspace will be saved at the end of the session. Ignored if vanilla is True.
|
| 48 |
+
no_environ: If True, site and user environment files will not be read. Ignored if vanilla is True.
|
| 49 |
+
no_site_file: If True, the site-wide Rprofile will not be read. Ignored if vanilla is True.
|
| 50 |
+
no_init_file: If True, the user's R profile will not be read. Ignored if vanilla is True.
|
| 51 |
+
restore: If True, previously saved objects will be restored at startup. Ignored if vanilla is True.
|
| 52 |
+
|
| 53 |
+
Returns:
|
| 54 |
+
A dictionary containing the executed command, stdout, stderr, and a list of output files.
|
| 55 |
+
"""
|
| 56 |
+
# 1. Input Validation
|
| 57 |
+
if not script_file and not expressions:
|
| 58 |
+
raise ValueError("Either 'script_file' or 'expressions' must be provided.")
|
| 59 |
+
if script_file and expressions:
|
| 60 |
+
raise ValueError("Cannot provide both 'script_file' and 'expressions' simultaneously.")
|
| 61 |
+
|
| 62 |
+
if script_file:
|
| 63 |
+
if not script_file.is_file():
|
| 64 |
+
raise FileNotFoundError(f"The specified script file does not exist: {script_file}")
|
| 65 |
+
|
| 66 |
+
# 2. Command Construction
|
| 67 |
+
cmd = ["Rscript"]
|
| 68 |
+
|
| 69 |
+
if verbose:
|
| 70 |
+
cmd.append("--verbose")
|
| 71 |
+
|
| 72 |
+
if default_packages:
|
| 73 |
+
cmd.append(f"--default-packages={default_packages}")
|
| 74 |
+
|
| 75 |
+
if vanilla:
|
| 76 |
+
cmd.append("--vanilla")
|
| 77 |
+
else:
|
| 78 |
+
# These options are processed only if --vanilla is not used
|
| 79 |
+
if save:
|
| 80 |
+
cmd.append("--save")
|
| 81 |
+
if no_environ:
|
| 82 |
+
cmd.append("--no-environ")
|
| 83 |
+
if no_site_file:
|
| 84 |
+
cmd.append("--no-site-file")
|
| 85 |
+
if no_init_file:
|
| 86 |
+
cmd.append("--no-init-file")
|
| 87 |
+
if restore:
|
| 88 |
+
cmd.append("--restore")
|
| 89 |
+
|
| 90 |
+
# Add script file or expressions to execute
|
| 91 |
+
if script_file:
|
| 92 |
+
cmd.append(str(script_file))
|
| 93 |
+
elif expressions:
|
| 94 |
+
for expr in expressions:
|
| 95 |
+
cmd.extend(["-e", expr])
|
| 96 |
+
|
| 97 |
+
# Add trailing arguments for the R script
|
| 98 |
+
if script_args:
|
| 99 |
+
cmd.extend(script_args)
|
| 100 |
+
|
| 101 |
+
command_executed = " ".join(cmd)
|
| 102 |
+
logging.info(f"Executing command: {command_executed}")
|
| 103 |
+
|
| 104 |
+
# 3. Subprocess Execution and Error Handling
|
| 105 |
+
try:
|
| 106 |
+
result = subprocess.run(
|
| 107 |
+
cmd,
|
| 108 |
+
capture_output=True,
|
| 109 |
+
text=True,
|
| 110 |
+
check=True,
|
| 111 |
+
)
|
| 112 |
+
except FileNotFoundError:
|
| 113 |
+
# This error occurs if 'Rscript' is not in the system's PATH
|
| 114 |
+
logging.error("Rscript executable not found.")
|
| 115 |
+
return {
|
| 116 |
+
"error": "Rscript not found. Please ensure R is installed and in your PATH.",
|
| 117 |
+
"command_executed": command_executed,
|
| 118 |
+
"stdout": "",
|
| 119 |
+
"stderr": "Rscript executable not found.",
|
| 120 |
+
"output_files": []
|
| 121 |
+
}
|
| 122 |
+
except subprocess.CalledProcessError as e:
|
| 123 |
+
# This error occurs if the R script exits with a non-zero status code
|
| 124 |
+
logging.error(f"Rscript execution failed with exit code {e.returncode}")
|
| 125 |
+
return {
|
| 126 |
+
"error": f"Rscript execution failed with exit code {e.returncode}.",
|
| 127 |
+
"command_executed": command_executed,
|
| 128 |
+
"stdout": e.stdout,
|
| 129 |
+
"stderr": e.stderr,
|
| 130 |
+
"output_files": []
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
# 4. Structured Result Return
|
| 134 |
+
# This wrapper cannot reliably determine output files generated by the user's script.
|
| 135 |
+
# The user is responsible for knowing and handling the script's output.
|
| 136 |
+
return {
|
| 137 |
+
"command_executed": command_executed,
|
| 138 |
+
"stdout": result.stdout,
|
| 139 |
+
"stderr": result.stderr,
|
| 140 |
+
"output_files": []
|
| 141 |
+
}
|
Biomni/mcp_generated/mcp_bioconductor-annotate/app/bioconductor-annotate_shim_server.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_help_txt/mcp_bioconductor-annotate/app/bioconductor-annotate_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_bioconductor_annotate'
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class _ShimMCP:
|
| 16 |
+
@staticmethod
|
| 17 |
+
def tool(*args, **kwargs):
|
| 18 |
+
if args and callable(args[0]) and len(args) == 1 and not kwargs:
|
| 19 |
+
return args[0]
|
| 20 |
+
def _decorator(fn):
|
| 21 |
+
return fn
|
| 22 |
+
return _decorator
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _resolve_source_server():
|
| 26 |
+
if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
|
| 27 |
+
return LOCAL_SERVER
|
| 28 |
+
return SOURCE_SERVER
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _load_functions():
|
| 32 |
+
source_server = _resolve_source_server()
|
| 33 |
+
code = source_server.read_text(encoding="utf-8")
|
| 34 |
+
tree = ast.parse(code, filename=str(source_server))
|
| 35 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 36 |
+
namespace = {
|
| 37 |
+
"__name__": "__mcp_source__",
|
| 38 |
+
"mcp": _ShimMCP(),
|
| 39 |
+
}
|
| 40 |
+
exec(compile(code, str(source_server), "exec"), namespace, namespace)
|
| 41 |
+
loaded = []
|
| 42 |
+
for name in function_names:
|
| 43 |
+
fn = namespace.get(name)
|
| 44 |
+
if callable(fn):
|
| 45 |
+
loaded.append(fn)
|
| 46 |
+
return loaded
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
mcp = FastMCP(SERVER_NAME)
|
| 50 |
+
for _fn in _load_functions():
|
| 51 |
+
mcp.tool()(_fn)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-annotate/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-annotate:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-annotate:latest
|
| 7 |
+
container_name: mcp-bioconductor-annotate
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-annotate
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotate/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-annotate
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotate/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_bioconductor-annotationdbi/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-annotationdbi via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-annotationdbi -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY bioconductor-annotationdbi_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-annotationdbi_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-annotationdbi_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotationdbi/app/bioconductor-annotationdbi_server.py
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Optional, List
|
| 5 |
+
|
| 6 |
+
# MCP decorator is assumed to be defined in the execution environment.
|
| 7 |
+
# No import is needed as per the instructions.
|
| 8 |
+
|
| 9 |
+
from mcp.server.fastmcp import FastMCP
|
| 10 |
+
|
| 11 |
+
SERVER_NAME = 'local_bioconductor_annotationdbi'
|
| 12 |
+
mcp = FastMCP(SERVER_NAME)
|
| 13 |
+
|
| 14 |
+
@mcp.tool()
|
| 15 |
+
def annotationdbi_columns(db_package: str) -> dict:
|
| 16 |
+
"""
|
| 17 |
+
Lists all available columns for a given Bioconductor annotation package.
|
| 18 |
+
|
| 19 |
+
This tool requires R, Rscript, and the Bioconductor packages 'AnnotationDbi'
|
| 20 |
+
and the specified 'db_package' to be installed in the R environment.
|
| 21 |
+
|
| 22 |
+
Args:
|
| 23 |
+
db_package: The name of the Bioconductor annotation package (e.g., "org.Hs.eg.db").
|
| 24 |
+
|
| 25 |
+
Returns:
|
| 26 |
+
A dictionary containing the command executed and the standard output with the column names.
|
| 27 |
+
"""
|
| 28 |
+
if not db_package:
|
| 29 |
+
raise ValueError("db_package must be a non-empty string.")
|
| 30 |
+
|
| 31 |
+
r_script_content = f"""
|
| 32 |
+
suppressPackageStartupMessages(library(AnnotationDbi))
|
| 33 |
+
|
| 34 |
+
db_package_name <- "{db_package}"
|
| 35 |
+
|
| 36 |
+
if (!requireNamespace(db_package_name, quietly = TRUE)) {{
|
| 37 |
+
stop(paste("Annotation package '", db_package_name, "' is not installed. Please install it from Bioconductor."), call. = FALSE)
|
| 38 |
+
}}
|
| 39 |
+
db <- get(db_package_name)
|
| 40 |
+
|
| 41 |
+
tryCatch({{
|
| 42 |
+
result_data <- AnnotationDbi::columns(db)
|
| 43 |
+
cat(result_data, sep = "\\n")
|
| 44 |
+
}}, error = function(e) {{
|
| 45 |
+
stop(paste("AnnotationDbi::columns failed:", e$message), call. = FALSE)
|
| 46 |
+
}})
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix=".R", delete=False, encoding='utf-8') as tmp_script:
|
| 50 |
+
tmp_script.write(r_script_content)
|
| 51 |
+
script_path = tmp_script.name
|
| 52 |
+
|
| 53 |
+
cmd = ["Rscript", script_path]
|
| 54 |
+
command_executed = f"Rscript {script_path}"
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
result = subprocess.run(
|
| 58 |
+
cmd,
|
| 59 |
+
capture_output=True,
|
| 60 |
+
text=True,
|
| 61 |
+
check=True,
|
| 62 |
+
encoding='utf-8'
|
| 63 |
+
)
|
| 64 |
+
return {
|
| 65 |
+
"command_executed": command_executed,
|
| 66 |
+
"stdout": result.stdout,
|
| 67 |
+
"stderr": result.stderr,
|
| 68 |
+
}
|
| 69 |
+
except subprocess.CalledProcessError as e:
|
| 70 |
+
return {
|
| 71 |
+
"command_executed": command_executed,
|
| 72 |
+
"stdout": e.stdout,
|
| 73 |
+
"stderr": e.stderr,
|
| 74 |
+
"error": f"R script execution failed with exit code {e.returncode}"
|
| 75 |
+
}
|
| 76 |
+
except FileNotFoundError:
|
| 77 |
+
return {
|
| 78 |
+
"command_executed": command_executed,
|
| 79 |
+
"stdout": "",
|
| 80 |
+
"stderr": "Error: 'Rscript' command not found. Please ensure R is installed and 'Rscript' is in your system's PATH.",
|
| 81 |
+
"error": "Dependency not found"
|
| 82 |
+
}
|
| 83 |
+
finally:
|
| 84 |
+
Path(script_path).unlink()
|
| 85 |
+
|
| 86 |
+
@mcp.tool()
|
| 87 |
+
def annotationdbi_keytypes(db_package: str) -> dict:
|
| 88 |
+
"""
|
| 89 |
+
Lists all available keytypes for a given Bioconductor annotation package.
|
| 90 |
+
|
| 91 |
+
This tool requires R, Rscript, and the Bioconductor packages 'AnnotationDbi'
|
| 92 |
+
and the specified 'db_package' to be installed in the R environment.
|
| 93 |
+
|
| 94 |
+
Args:
|
| 95 |
+
db_package: The name of the Bioconductor annotation package (e.g., "org.Hs.eg.db").
|
| 96 |
+
|
| 97 |
+
Returns:
|
| 98 |
+
A dictionary containing the command executed and the standard output with the keytype names.
|
| 99 |
+
"""
|
| 100 |
+
if not db_package:
|
| 101 |
+
raise ValueError("db_package must be a non-empty string.")
|
| 102 |
+
|
| 103 |
+
r_script_content = f"""
|
| 104 |
+
suppressPackageStartupMessages(library(AnnotationDbi))
|
| 105 |
+
|
| 106 |
+
db_package_name <- "{db_package}"
|
| 107 |
+
|
| 108 |
+
if (!requireNamespace(db_package_name, quietly = TRUE)) {{
|
| 109 |
+
stop(paste("Annotation package '", db_package_name, "' is not installed. Please install it from Bioconductor."), call. = FALSE)
|
| 110 |
+
}}
|
| 111 |
+
db <- get(db_package_name)
|
| 112 |
+
|
| 113 |
+
tryCatch({{
|
| 114 |
+
result_data <- AnnotationDbi::keytypes(db)
|
| 115 |
+
cat(result_data, sep = "\\n")
|
| 116 |
+
}}, error = function(e) {{
|
| 117 |
+
stop(paste("AnnotationDbi::keytypes failed:", e$message), call. = FALSE)
|
| 118 |
+
}})
|
| 119 |
+
"""
|
| 120 |
+
|
| 121 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix=".R", delete=False, encoding='utf-8') as tmp_script:
|
| 122 |
+
tmp_script.write(r_script_content)
|
| 123 |
+
script_path = tmp_script.name
|
| 124 |
+
|
| 125 |
+
cmd = ["Rscript", script_path]
|
| 126 |
+
command_executed = f"Rscript {script_path}"
|
| 127 |
+
|
| 128 |
+
try:
|
| 129 |
+
result = subprocess.run(
|
| 130 |
+
cmd,
|
| 131 |
+
capture_output=True,
|
| 132 |
+
text=True,
|
| 133 |
+
check=True,
|
| 134 |
+
encoding='utf-8'
|
| 135 |
+
)
|
| 136 |
+
return {
|
| 137 |
+
"command_executed": command_executed,
|
| 138 |
+
"stdout": result.stdout,
|
| 139 |
+
"stderr": result.stderr,
|
| 140 |
+
}
|
| 141 |
+
except subprocess.CalledProcessError as e:
|
| 142 |
+
return {
|
| 143 |
+
"command_executed": command_executed,
|
| 144 |
+
"stdout": e.stdout,
|
| 145 |
+
"stderr": e.stderr,
|
| 146 |
+
"error": f"R script execution failed with exit code {e.returncode}"
|
| 147 |
+
}
|
| 148 |
+
except FileNotFoundError:
|
| 149 |
+
return {
|
| 150 |
+
"command_executed": command_executed,
|
| 151 |
+
"stdout": "",
|
| 152 |
+
"stderr": "Error: 'Rscript' command not found. Please ensure R is installed and 'Rscript' is in your system's PATH.",
|
| 153 |
+
"error": "Dependency not found"
|
| 154 |
+
}
|
| 155 |
+
finally:
|
| 156 |
+
Path(script_path).unlink()
|
| 157 |
+
|
| 158 |
+
@mcp.tool()
|
| 159 |
+
def annotationdbi_keys(db_package: str, keytype: str) -> dict:
|
| 160 |
+
"""
|
| 161 |
+
Lists all available keys for a given keytype in a Bioconductor annotation package.
|
| 162 |
+
|
| 163 |
+
This tool requires R, Rscript, and the Bioconductor packages 'AnnotationDbi'
|
| 164 |
+
and the specified 'db_package' to be installed in the R environment.
|
| 165 |
+
|
| 166 |
+
Args:
|
| 167 |
+
db_package: The name of the Bioconductor annotation package (e.g., "org.Hs.eg.db").
|
| 168 |
+
keytype: The keytype for which to retrieve all available keys (e.g., "ENTREZID").
|
| 169 |
+
|
| 170 |
+
Returns:
|
| 171 |
+
A dictionary containing the command executed and the standard output with the keys.
|
| 172 |
+
"""
|
| 173 |
+
if not db_package:
|
| 174 |
+
raise ValueError("db_package must be a non-empty string.")
|
| 175 |
+
if not keytype:
|
| 176 |
+
raise ValueError("keytype must be a non-empty string.")
|
| 177 |
+
|
| 178 |
+
r_script_content = f"""
|
| 179 |
+
suppressPackageStartupMessages(library(AnnotationDbi))
|
| 180 |
+
|
| 181 |
+
db_package_name <- "{db_package}"
|
| 182 |
+
keytype_str <- "{keytype}"
|
| 183 |
+
|
| 184 |
+
if (!requireNamespace(db_package_name, quietly = TRUE)) {{
|
| 185 |
+
stop(paste("Annotation package '", db_package_name, "' is not installed. Please install it from Bioconductor."), call. = FALSE)
|
| 186 |
+
}}
|
| 187 |
+
db <- get(db_package_name)
|
| 188 |
+
|
| 189 |
+
tryCatch({{
|
| 190 |
+
result_data <- AnnotationDbi::keys(db, keytype = keytype_str)
|
| 191 |
+
cat(result_data, sep = "\\n")
|
| 192 |
+
}}, error = function(e) {{
|
| 193 |
+
stop(paste("AnnotationDbi::keys failed:", e$message), call. = FALSE)
|
| 194 |
+
}})
|
| 195 |
+
"""
|
| 196 |
+
|
| 197 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix=".R", delete=False, encoding='utf-8') as tmp_script:
|
| 198 |
+
tmp_script.write(r_script_content)
|
| 199 |
+
script_path = tmp_script.name
|
| 200 |
+
|
| 201 |
+
cmd = ["Rscript", script_path]
|
| 202 |
+
command_executed = f"Rscript {script_path}"
|
| 203 |
+
|
| 204 |
+
try:
|
| 205 |
+
result = subprocess.run(
|
| 206 |
+
cmd,
|
| 207 |
+
capture_output=True,
|
| 208 |
+
text=True,
|
| 209 |
+
check=True,
|
| 210 |
+
encoding='utf-8'
|
| 211 |
+
)
|
| 212 |
+
return {
|
| 213 |
+
"command_executed": command_executed,
|
| 214 |
+
"stdout": result.stdout,
|
| 215 |
+
"stderr": result.stderr,
|
| 216 |
+
}
|
| 217 |
+
except subprocess.CalledProcessError as e:
|
| 218 |
+
return {
|
| 219 |
+
"command_executed": command_executed,
|
| 220 |
+
"stdout": e.stdout,
|
| 221 |
+
"stderr": e.stderr,
|
| 222 |
+
"error": f"R script execution failed with exit code {e.returncode}"
|
| 223 |
+
}
|
| 224 |
+
except FileNotFoundError:
|
| 225 |
+
return {
|
| 226 |
+
"command_executed": command_executed,
|
| 227 |
+
"stdout": "",
|
| 228 |
+
"stderr": "Error: 'Rscript' command not found. Please ensure R is installed and 'Rscript' is in your system's PATH.",
|
| 229 |
+
"error": "Dependency not found"
|
| 230 |
+
}
|
| 231 |
+
finally:
|
| 232 |
+
Path(script_path).unlink()
|
| 233 |
+
|
| 234 |
+
@mcp.tool()
|
| 235 |
+
def annotationdbi_select(
|
| 236 |
+
db_package: str,
|
| 237 |
+
keys: str,
|
| 238 |
+
columns: str,
|
| 239 |
+
keytype: str,
|
| 240 |
+
output_file: Path,
|
| 241 |
+
) -> dict:
|
| 242 |
+
"""
|
| 243 |
+
Retrieves data from a Bioconductor annotation package using AnnotationDbi::select.
|
| 244 |
+
|
| 245 |
+
This tool requires R, Rscript, and the Bioconductor packages 'AnnotationDbi'
|
| 246 |
+
and the specified 'db_package' to be installed in the R environment.
|
| 247 |
+
|
| 248 |
+
Args:
|
| 249 |
+
db_package: The name of the Bioconductor annotation package (e.g., "org.Hs.eg.db").
|
| 250 |
+
keys: A comma-separated string of keys to query (e.g., "BRCA1,TP53").
|
| 251 |
+
columns: A comma-separated string of columns to retrieve (e.g., "SYMBOL,GENENAME,ENTREZID").
|
| 252 |
+
keytype: The type of the provided keys (e.g., "SYMBOL").
|
| 253 |
+
output_file: The path to save the results as a TSV file.
|
| 254 |
+
|
| 255 |
+
Returns:
|
| 256 |
+
A dictionary containing the command executed, logs, and the path to the output file.
|
| 257 |
+
"""
|
| 258 |
+
if not db_package:
|
| 259 |
+
raise ValueError("db_package must be a non-empty string.")
|
| 260 |
+
if not keys:
|
| 261 |
+
raise ValueError("keys must be a non-empty, comma-separated string.")
|
| 262 |
+
if not columns:
|
| 263 |
+
raise ValueError("columns must be a non-empty, comma-separated string.")
|
| 264 |
+
if not keytype:
|
| 265 |
+
raise ValueError("keytype must be a non-empty string.")
|
| 266 |
+
|
| 267 |
+
output_file.parent.mkdir(parents=True, exist_ok=True)
|
| 268 |
+
|
| 269 |
+
r_script_content = f"""
|
| 270 |
+
suppressPackageStartupMessages(library(AnnotationDbi))
|
| 271 |
+
|
| 272 |
+
db_package_name <- "{db_package}"
|
| 273 |
+
keys_vec <- unlist(strsplit("{keys}", ","))
|
| 274 |
+
columns_vec <- unlist(strsplit("{columns}", ","))
|
| 275 |
+
keytype_str <- "{keytype}"
|
| 276 |
+
output_file_path <- "{output_file.resolve()}"
|
| 277 |
+
|
| 278 |
+
if (!requireNamespace(db_package_name, quietly = TRUE)) {{
|
| 279 |
+
stop(paste("Annotation package '", db_package_name, "' is not installed. Please install it from Bioconductor."), call. = FALSE)
|
| 280 |
+
}}
|
| 281 |
+
db <- get(db_package_name)
|
| 282 |
+
|
| 283 |
+
tryCatch({{
|
| 284 |
+
results <- AnnotationDbi::select(db,
|
| 285 |
+
keys = keys_vec,
|
| 286 |
+
columns = columns_vec,
|
| 287 |
+
keytype = keytype_str)
|
| 288 |
+
|
| 289 |
+
write.table(results,
|
| 290 |
+
file = output_file_path,
|
| 291 |
+
sep = "\\t",
|
| 292 |
+
row.names = FALSE,
|
| 293 |
+
col.names = TRUE,
|
| 294 |
+
quote = FALSE)
|
| 295 |
+
|
| 296 |
+
cat(paste("Successfully wrote", nrow(results), "rows to", basename(output_file_path), "\\n"))
|
| 297 |
+
|
| 298 |
+
}}, error = function(e) {{
|
| 299 |
+
stop(paste("AnnotationDbi::select failed:", e$message), call. = FALSE)
|
| 300 |
+
}})
|
| 301 |
+
"""
|
| 302 |
+
|
| 303 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix=".R", delete=False, encoding='utf-8') as tmp_script:
|
| 304 |
+
tmp_script.write(r_script_content)
|
| 305 |
+
script_path = tmp_script.name
|
| 306 |
+
|
| 307 |
+
cmd = ["Rscript", script_path]
|
| 308 |
+
command_executed = f"Rscript {script_path}"
|
| 309 |
+
|
| 310 |
+
try:
|
| 311 |
+
result = subprocess.run(
|
| 312 |
+
cmd,
|
| 313 |
+
capture_output=True,
|
| 314 |
+
text=True,
|
| 315 |
+
check=True,
|
| 316 |
+
encoding='utf-8'
|
| 317 |
+
)
|
| 318 |
+
return {
|
| 319 |
+
"command_executed": command_executed,
|
| 320 |
+
"stdout": result.stdout,
|
| 321 |
+
"stderr": result.stderr,
|
| 322 |
+
"output_files": [str(output_file.resolve())]
|
| 323 |
+
}
|
| 324 |
+
except subprocess.CalledProcessError as e:
|
| 325 |
+
return {
|
| 326 |
+
"command_executed": command_executed,
|
| 327 |
+
"stdout": e.stdout,
|
| 328 |
+
"stderr": e.stderr,
|
| 329 |
+
"error": f"R script execution failed with exit code {e.returncode}",
|
| 330 |
+
"output_files": []
|
| 331 |
+
}
|
| 332 |
+
except FileNotFoundError:
|
| 333 |
+
return {
|
| 334 |
+
"command_executed": command_executed,
|
| 335 |
+
"stdout": "",
|
| 336 |
+
"stderr": "Error: 'Rscript' command not found. Please ensure R is installed and 'Rscript' is in your system's PATH.",
|
| 337 |
+
"error": "Dependency not found",
|
| 338 |
+
"output_files": []
|
| 339 |
+
}
|
| 340 |
+
finally:
|
| 341 |
+
Path(script_path).unlink()
|
| 342 |
+
|
| 343 |
+
@mcp.tool()
|
| 344 |
+
def annotationdbi_mapids(
|
| 345 |
+
db_package: str,
|
| 346 |
+
keys: str,
|
| 347 |
+
column: str,
|
| 348 |
+
keytype: str,
|
| 349 |
+
output_file: Path,
|
| 350 |
+
multi_vals: str = "first",
|
| 351 |
+
) -> dict:
|
| 352 |
+
"""
|
| 353 |
+
Maps identifiers from one type to another using AnnotationDbi::mapIds.
|
| 354 |
+
|
| 355 |
+
This tool requires R, Rscript, and the Bioconductor packages 'AnnotationDbi'
|
| 356 |
+
and the specified 'db_package' to be installed in the R environment.
|
| 357 |
+
|
| 358 |
+
Args:
|
| 359 |
+
db_package: The name of the Bioconductor annotation package (e.g., "org.Hs.eg.db").
|
| 360 |
+
keys: A comma-separated string of keys to query (e.g., "BRCA1,TP53").
|
| 361 |
+
column: The single column (identifier type) to map to (e.g., "ENTREZID").
|
| 362 |
+
keytype: The type of the provided keys (e.g., "SYMBOL").
|
| 363 |
+
output_file: The path to save the mapping results as a TSV file.
|
| 364 |
+
multi_vals: How to handle multiple matches. One of "first", "list", "filter", "asNA".
|
| 365 |
+
|
| 366 |
+
Returns:
|
| 367 |
+
A dictionary containing the command executed, logs, and the path to the output file.
|
| 368 |
+
"""
|
| 369 |
+
if not db_package:
|
| 370 |
+
raise ValueError("db_package must be a non-empty string.")
|
| 371 |
+
if not keys:
|
| 372 |
+
raise ValueError("keys must be a non-empty, comma-separated string.")
|
| 373 |
+
if not column:
|
| 374 |
+
raise ValueError("column must be a non-empty string.")
|
| 375 |
+
if not keytype:
|
| 376 |
+
raise ValueError("keytype must be a non-empty string.")
|
| 377 |
+
|
| 378 |
+
valid_multi_vals = ["first", "list", "filter", "asNA", "character"]
|
| 379 |
+
if multi_vals not in valid_multi_vals:
|
| 380 |
+
raise ValueError(f"multi_vals must be one of {valid_multi_vals}")
|
| 381 |
+
|
| 382 |
+
output_file.parent.mkdir(parents=True, exist_ok=True)
|
| 383 |
+
|
| 384 |
+
r_script_content = f"""
|
| 385 |
+
suppressPackageStartupMessages(library(AnnotationDbi))
|
| 386 |
+
|
| 387 |
+
db_package_name <- "{db_package}"
|
| 388 |
+
keys_vec <- unlist(strsplit("{keys}", ","))
|
| 389 |
+
column_str <- "{column}"
|
| 390 |
+
keytype_str <- "{keytype}"
|
| 391 |
+
multi_vals_str <- "{multi_vals}"
|
| 392 |
+
output_file_path <- "{output_file.resolve()}"
|
| 393 |
+
|
| 394 |
+
if (!requireNamespace(db_package_name, quietly = TRUE)) {{
|
| 395 |
+
stop(paste("Annotation package '", db_package_name, "' is not installed. Please install it from Bioconductor."), call. = FALSE)
|
| 396 |
+
}}
|
| 397 |
+
db <- get(db_package_name)
|
| 398 |
+
|
| 399 |
+
tryCatch({{
|
| 400 |
+
results_vec <- AnnotationDbi::mapIds(db,
|
| 401 |
+
keys = keys_vec,
|
| 402 |
+
column = column_str,
|
| 403 |
+
keytype = keytype_str,
|
| 404 |
+
multiVals = multi_vals_str)
|
| 405 |
+
|
| 406 |
+
# Convert named vector to a data frame for saving
|
| 407 |
+
results_df <- data.frame(FROM = names(results_vec), TO = I(results_vec), stringsAsFactors = FALSE)
|
| 408 |
+
|
| 409 |
+
write.table(results_df,
|
| 410 |
+
file = output_file_path,
|
| 411 |
+
sep = "\\t",
|
| 412 |
+
row.names = FALSE,
|
| 413 |
+
col.names = TRUE,
|
| 414 |
+
quote = FALSE)
|
| 415 |
+
|
| 416 |
+
cat(paste("Successfully wrote", nrow(results_df), "rows to", basename(output_file_path), "\\n"))
|
| 417 |
+
|
| 418 |
+
}}, error = function(e) {{
|
| 419 |
+
stop(paste("AnnotationDbi::mapIds failed:", e$message), call. = FALSE)
|
| 420 |
+
}})
|
| 421 |
+
"""
|
| 422 |
+
|
| 423 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix=".R", delete=False, encoding='utf-8') as tmp_script:
|
| 424 |
+
tmp_script.write(r_script_content)
|
| 425 |
+
script_path = tmp_script.name
|
| 426 |
+
|
| 427 |
+
cmd = ["Rscript", script_path]
|
| 428 |
+
command_executed = f"Rscript {script_path}"
|
| 429 |
+
|
| 430 |
+
try:
|
| 431 |
+
result = subprocess.run(
|
| 432 |
+
cmd,
|
| 433 |
+
capture_output=True,
|
| 434 |
+
text=True,
|
| 435 |
+
check=True,
|
| 436 |
+
encoding='utf-8'
|
| 437 |
+
)
|
| 438 |
+
return {
|
| 439 |
+
"command_executed": command_executed,
|
| 440 |
+
"stdout": result.stdout,
|
| 441 |
+
"stderr": result.stderr,
|
| 442 |
+
"output_files": [str(output_file.resolve())]
|
| 443 |
+
}
|
| 444 |
+
except subprocess.CalledProcessError as e:
|
| 445 |
+
return {
|
| 446 |
+
"command_executed": command_executed,
|
| 447 |
+
"stdout": e.stdout,
|
| 448 |
+
"stderr": e.stderr,
|
| 449 |
+
"error": f"R script execution failed with exit code {e.returncode}",
|
| 450 |
+
"output_files": []
|
| 451 |
+
}
|
| 452 |
+
except FileNotFoundError:
|
| 453 |
+
return {
|
| 454 |
+
"command_executed": command_executed,
|
| 455 |
+
"stdout": "",
|
| 456 |
+
"stderr": "Error: 'Rscript' command not found. Please ensure R is installed and 'Rscript' is in your system's PATH.",
|
| 457 |
+
"error": "Dependency not found",
|
| 458 |
+
"output_files": []
|
| 459 |
+
}
|
| 460 |
+
finally:
|
| 461 |
+
Path(script_path).unlink()
|
| 462 |
+
|
| 463 |
+
if __name__ == "__main__":
|
| 464 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-annotationdbi/app/bioconductor-annotationdbi_shim_server.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_help_txt/mcp_bioconductor-annotationdbi/app/bioconductor-annotationdbi_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_bioconductor_annotationdbi'
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class _ShimMCP:
|
| 16 |
+
@staticmethod
|
| 17 |
+
def tool(*args, **kwargs):
|
| 18 |
+
if args and callable(args[0]) and len(args) == 1 and not kwargs:
|
| 19 |
+
return args[0]
|
| 20 |
+
def _decorator(fn):
|
| 21 |
+
return fn
|
| 22 |
+
return _decorator
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _resolve_source_server():
|
| 26 |
+
if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
|
| 27 |
+
return LOCAL_SERVER
|
| 28 |
+
return SOURCE_SERVER
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _load_functions():
|
| 32 |
+
source_server = _resolve_source_server()
|
| 33 |
+
code = source_server.read_text(encoding="utf-8")
|
| 34 |
+
tree = ast.parse(code, filename=str(source_server))
|
| 35 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 36 |
+
namespace = {
|
| 37 |
+
"__name__": "__mcp_source__",
|
| 38 |
+
"mcp": _ShimMCP(),
|
| 39 |
+
}
|
| 40 |
+
exec(compile(code, str(source_server), "exec"), namespace, namespace)
|
| 41 |
+
loaded = []
|
| 42 |
+
for name in function_names:
|
| 43 |
+
fn = namespace.get(name)
|
| 44 |
+
if callable(fn):
|
| 45 |
+
loaded.append(fn)
|
| 46 |
+
return loaded
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
mcp = FastMCP(SERVER_NAME)
|
| 50 |
+
for _fn in _load_functions():
|
| 51 |
+
mcp.tool()(_fn)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-annotationdbi/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-annotationdbi:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-annotationdbi:latest
|
| 7 |
+
container_name: mcp-bioconductor-annotationdbi
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-annotationdbi
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotationdbi/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-annotationdbi
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotationdbi/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_bioconductor-annotationfilter/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-annotationfilter via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-annotationfilter -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/bioconductor-annotationfilter_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-annotationfilter_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-annotationfilter_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotationfilter/app/bioconductor-annotationfilter_server.py
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import json
|
| 3 |
+
from typing import List, Optional, Union
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
from mcp.server.fastmcp import FastMCP
|
| 7 |
+
|
| 8 |
+
SERVER_NAME = 'local_bioconductor_annotationfilter'
|
| 9 |
+
mcp = FastMCP(SERVER_NAME)
|
| 10 |
+
|
| 11 |
+
@mcp.tool()
|
| 12 |
+
def create_individual_filter(
|
| 13 |
+
filter_class: str,
|
| 14 |
+
value: Union[str, List[str]],
|
| 15 |
+
condition: str = "==",
|
| 16 |
+
) -> dict:
|
| 17 |
+
"""
|
| 18 |
+
Create an individual AnnotationFilter object (e.g., GeneIdFilter, SymbolFilter).
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
filter_class: The class of the filter (e.g., 'GeneIdFilter', 'SymbolFilter', 'EntrezFilter',
|
| 22 |
+
'GenenameFilter', 'TxIdFilter', 'ExonIdFilter', 'ProteinIdFilter', 'UniprotFilter',
|
| 23 |
+
'SeqNameFilter', 'SeqStrandFilter', 'SeqStartFilter', 'SeqEndFilter',
|
| 24 |
+
'GeneBiotypeFilter', 'TxBiotypeFilter').
|
| 25 |
+
value: The value(s) to filter by. Can be a single string or a list of strings.
|
| 26 |
+
condition: The filter condition. Supported: '==', '!=', 'startsWith', 'endsWith', 'contains', '>', '<', '>=', '<='.
|
| 27 |
+
"""
|
| 28 |
+
# Validation of filter classes
|
| 29 |
+
valid_classes = [
|
| 30 |
+
"CdsEndFilter", "CdsStartFilter", "EntrezFilter", "ExonIdFilter", "ExonRankFilter",
|
| 31 |
+
"ExonEndFilter", "ExonStartFilter", "GeneIdFilter", "GeneBiotypeFilter", "GenenameFilter",
|
| 32 |
+
"GeneStartFilter", "GeneEndFilter", "ProteinIdFilter", "SeqNameFilter", "SeqStrandFilter",
|
| 33 |
+
"SymbolFilter", "TxIdFilter", "TxBiotypeFilter", "TxStartFilter", "TxEndFilter", "UniprotFilter"
|
| 34 |
+
]
|
| 35 |
+
if filter_class not in valid_classes:
|
| 36 |
+
return {"error": f"Invalid filter_class. Must be one of: {', '.join(valid_classes)}"}
|
| 37 |
+
|
| 38 |
+
# Validation of conditions
|
| 39 |
+
valid_conditions = ["==", "!=", "startsWith", "endsWith", "contains", ">", "<", ">=", "<="]
|
| 40 |
+
if condition not in valid_conditions:
|
| 41 |
+
return {"error": f"Invalid condition. Must be one of: {', '.join(valid_conditions)}"}
|
| 42 |
+
|
| 43 |
+
# Format value for R
|
| 44 |
+
if isinstance(value, list):
|
| 45 |
+
r_value = 'c(' + ', '.join([f'"{v}"' for v in value]) + ')'
|
| 46 |
+
else:
|
| 47 |
+
r_value = f'"{value}"'
|
| 48 |
+
|
| 49 |
+
r_script = f"""
|
| 50 |
+
suppressPackageStartupMessages(library(AnnotationFilter))
|
| 51 |
+
f <- {filter_class}({r_value}, condition = "{condition}")
|
| 52 |
+
cat(as.character(f), "\\n")
|
| 53 |
+
print(f)
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
result = subprocess.run(
|
| 58 |
+
["Rscript", "-e", r_script],
|
| 59 |
+
capture_output=True,
|
| 60 |
+
text=True,
|
| 61 |
+
check=True
|
| 62 |
+
)
|
| 63 |
+
return {
|
| 64 |
+
"command_executed": f"Rscript -e '{r_script.strip()}'",
|
| 65 |
+
"stdout": result.stdout,
|
| 66 |
+
"stderr": result.stderr,
|
| 67 |
+
"filter_string": result.stdout.splitlines()[0] if result.stdout else ""
|
| 68 |
+
}
|
| 69 |
+
except subprocess.CalledProcessError as e:
|
| 70 |
+
return {
|
| 71 |
+
"error": "R execution failed",
|
| 72 |
+
"stdout": e.stdout,
|
| 73 |
+
"stderr": e.stderr
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
@mcp.tool()
|
| 77 |
+
def parse_filter_formula(
|
| 78 |
+
formula: str,
|
| 79 |
+
) -> dict:
|
| 80 |
+
"""
|
| 81 |
+
Create an AnnotationFilter object using the R formula syntax.
|
| 82 |
+
|
| 83 |
+
Args:
|
| 84 |
+
formula: An R formula string representing the filter, e.g., '~ symbol == "ADA"' or '~ gene_id %in% c("1", "2")'.
|
| 85 |
+
"""
|
| 86 |
+
if not formula.startswith("~"):
|
| 87 |
+
formula = "~ " + formula
|
| 88 |
+
|
| 89 |
+
r_script = f"""
|
| 90 |
+
suppressPackageStartupMessages(library(AnnotationFilter))
|
| 91 |
+
f <- AnnotationFilter({formula})
|
| 92 |
+
print(f)
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
try:
|
| 96 |
+
result = subprocess.run(
|
| 97 |
+
["Rscript", "-e", r_script],
|
| 98 |
+
capture_output=True,
|
| 99 |
+
text=True,
|
| 100 |
+
check=True
|
| 101 |
+
)
|
| 102 |
+
return {
|
| 103 |
+
"command_executed": f"Rscript -e '{r_script.strip()}'",
|
| 104 |
+
"stdout": result.stdout,
|
| 105 |
+
"stderr": result.stderr
|
| 106 |
+
}
|
| 107 |
+
except subprocess.CalledProcessError as e:
|
| 108 |
+
return {
|
| 109 |
+
"error": "Failed to parse formula. Ensure syntax is correct (e.g., '~ symbol == \"ADA\"')",
|
| 110 |
+
"stdout": e.stdout,
|
| 111 |
+
"stderr": e.stderr
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
@mcp.tool()
|
| 115 |
+
def create_filter_list(
|
| 116 |
+
filters: List[str],
|
| 117 |
+
logic_op: str = "&",
|
| 118 |
+
) -> dict:
|
| 119 |
+
"""
|
| 120 |
+
Combine multiple AnnotationFilter objects into an AnnotationFilterList.
|
| 121 |
+
|
| 122 |
+
Args:
|
| 123 |
+
filters: A list of R filter construction strings, e.g., ['GeneIdFilter("123")', 'SymbolFilter("ADA")'].
|
| 124 |
+
logic_op: The logical operator to combine filters. Use '&' for AND, '|' for OR.
|
| 125 |
+
"""
|
| 126 |
+
if logic_op not in ["&", "|"]:
|
| 127 |
+
return {"error": "logic_op must be '&' or '|'"}
|
| 128 |
+
|
| 129 |
+
# Construct the R list
|
| 130 |
+
filter_list_str = ", ".join(filters)
|
| 131 |
+
|
| 132 |
+
r_script = f"""
|
| 133 |
+
suppressPackageStartupMessages(library(AnnotationFilter))
|
| 134 |
+
fl <- AnnotationFilterList({filter_list_str}, logicOp = "{logic_op}")
|
| 135 |
+
print(fl)
|
| 136 |
+
"""
|
| 137 |
+
|
| 138 |
+
try:
|
| 139 |
+
result = subprocess.run(
|
| 140 |
+
["Rscript", "-e", r_script],
|
| 141 |
+
capture_output=True,
|
| 142 |
+
text=True,
|
| 143 |
+
check=True
|
| 144 |
+
)
|
| 145 |
+
return {
|
| 146 |
+
"command_executed": f"Rscript -e '{r_script.strip()}'",
|
| 147 |
+
"stdout": result.stdout,
|
| 148 |
+
"stderr": result.stderr
|
| 149 |
+
}
|
| 150 |
+
except subprocess.CalledProcessError as e:
|
| 151 |
+
return {
|
| 152 |
+
"error": "Failed to create filter list. Ensure individual filter strings are valid R code.",
|
| 153 |
+
"stdout": e.stdout,
|
| 154 |
+
"stderr": e.stderr
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
@mcp.tool()
|
| 158 |
+
def get_filter_properties(
|
| 159 |
+
filter_expression: str,
|
| 160 |
+
) -> dict:
|
| 161 |
+
"""
|
| 162 |
+
Extract properties (field, value, condition) from an AnnotationFilter object.
|
| 163 |
+
|
| 164 |
+
Args:
|
| 165 |
+
filter_expression: An R string that creates a filter, e.g., 'GeneIdFilter("ENSG0001")'.
|
| 166 |
+
"""
|
| 167 |
+
r_script = f"""
|
| 168 |
+
suppressPackageStartupMessages(library(AnnotationFilter))
|
| 169 |
+
f <- {filter_expression}
|
| 170 |
+
cat("field:", field(f), "\\n")
|
| 171 |
+
cat("condition:", condition(f), "\\n")
|
| 172 |
+
cat("value:", paste(value(f), collapse=", "), "\\n")
|
| 173 |
+
"""
|
| 174 |
+
|
| 175 |
+
try:
|
| 176 |
+
result = subprocess.run(
|
| 177 |
+
["Rscript", "-e", r_script],
|
| 178 |
+
capture_output=True,
|
| 179 |
+
text=True,
|
| 180 |
+
check=True
|
| 181 |
+
)
|
| 182 |
+
return {
|
| 183 |
+
"command_executed": f"Rscript -e '{r_script.strip()}'",
|
| 184 |
+
"stdout": result.stdout,
|
| 185 |
+
"stderr": result.stderr
|
| 186 |
+
}
|
| 187 |
+
except subprocess.CalledProcessError as e:
|
| 188 |
+
return {
|
| 189 |
+
"error": "Failed to extract properties. Ensure the filter expression is valid.",
|
| 190 |
+
"stdout": e.stdout,
|
| 191 |
+
"stderr": e.stderr
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
@mcp.tool()
|
| 195 |
+
def list_supported_filters() -> dict:
|
| 196 |
+
"""
|
| 197 |
+
List all supported filter classes and conditions in the AnnotationFilter package.
|
| 198 |
+
"""
|
| 199 |
+
r_script = """
|
| 200 |
+
suppressPackageStartupMessages(library(AnnotationFilter))
|
| 201 |
+
# Get all classes that inherit from AnnotationFilter
|
| 202 |
+
# This is a simplified list based on package documentation
|
| 203 |
+
filters <- c(
|
| 204 |
+
"CdsEndFilter", "CdsStartFilter", "EntrezFilter", "ExonIdFilter", "ExonRankFilter",
|
| 205 |
+
"ExonEndFilter", "ExonStartFilter", "GeneIdFilter", "GeneBiotypeFilter", "GenenameFilter",
|
| 206 |
+
"GeneStartFilter", "GeneEndFilter", "ProteinIdFilter", "SeqNameFilter", "SeqStrandFilter",
|
| 207 |
+
"SymbolFilter", "TxIdFilter", "TxBiotypeFilter", "TxStartFilter", "TxEndFilter", "UniprotFilter"
|
| 208 |
+
)
|
| 209 |
+
conditions <- c("==", "!=", "startsWith", "endsWith", "contains", ">", "<", ">=", "<=")
|
| 210 |
+
|
| 211 |
+
cat("Supported Filters:\\n")
|
| 212 |
+
cat(paste("-", filters, collapse="\\n"), "\\n\\n")
|
| 213 |
+
cat("Supported Conditions:\\n")
|
| 214 |
+
cat(paste("-", conditions, collapse="\\n"), "\\n")
|
| 215 |
+
"""
|
| 216 |
+
|
| 217 |
+
try:
|
| 218 |
+
result = subprocess.run(
|
| 219 |
+
["Rscript", "-e", r_script],
|
| 220 |
+
capture_output=True,
|
| 221 |
+
text=True,
|
| 222 |
+
check=True
|
| 223 |
+
)
|
| 224 |
+
return {
|
| 225 |
+
"command_executed": "Rscript -e '...'",
|
| 226 |
+
"stdout": result.stdout,
|
| 227 |
+
"stderr": result.stderr
|
| 228 |
+
}
|
| 229 |
+
except subprocess.CalledProcessError as e:
|
| 230 |
+
return {
|
| 231 |
+
"error": "Failed to list filters",
|
| 232 |
+
"stdout": e.stdout,
|
| 233 |
+
"stderr": e.stderr
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
@mcp.tool()
|
| 237 |
+
def translate_to_sql_where(
|
| 238 |
+
filter_expression: str,
|
| 239 |
+
) -> dict:
|
| 240 |
+
"""
|
| 241 |
+
Translate an AnnotationFilter object into a SQL WHERE clause fragment.
|
| 242 |
+
Note: This is a conceptual translation as used by packages like ensembldb.
|
| 243 |
+
|
| 244 |
+
Args:
|
| 245 |
+
filter_expression: An R string that creates a filter, e.g., 'GeneIdFilter("ENSG0001")'.
|
| 246 |
+
"""
|
| 247 |
+
# In AnnotationFilter, the translation is often handled by the consuming package (like ensembldb)
|
| 248 |
+
# but we can simulate the logic here for the user.
|
| 249 |
+
r_script = f"""
|
| 250 |
+
suppressPackageStartupMessages(library(AnnotationFilter))
|
| 251 |
+
f <- {filter_expression}
|
| 252 |
+
|
| 253 |
+
# Simple translation logic
|
| 254 |
+
cond <- condition(f)
|
| 255 |
+
val <- value(f)
|
| 256 |
+
fld <- field(f)
|
| 257 |
+
|
| 258 |
+
if (length(val) > 1) {{
|
| 259 |
+
sql_val <- paste0("('", paste(val, collapse="', '"), "')")
|
| 260 |
+
sql_cond <- if (cond == "==") "IN" else "NOT IN"
|
| 261 |
+
}} else {{
|
| 262 |
+
sql_val <- paste0("'", val, "'")
|
| 263 |
+
sql_cond <- cond
|
| 264 |
+
if (cond == "startsWith") {{ sql_cond <- "LIKE"; sql_val <- paste0("'", val, "%'") }}
|
| 265 |
+
if (cond == "endsWith") {{ sql_cond <- "LIKE"; sql_val <- paste0("'% ", val, "'") }}
|
| 266 |
+
if (cond == "contains") {{ sql_cond <- "LIKE"; sql_val <- paste0("'%", val, "%'") }}
|
| 267 |
+
}}
|
| 268 |
+
|
| 269 |
+
cat(paste(fld, sql_cond, sql_val))
|
| 270 |
+
"""
|
| 271 |
+
|
| 272 |
+
try:
|
| 273 |
+
result = subprocess.run(
|
| 274 |
+
["Rscript", "-e", r_script],
|
| 275 |
+
capture_output=True,
|
| 276 |
+
text=True,
|
| 277 |
+
check=True
|
| 278 |
+
)
|
| 279 |
+
return {
|
| 280 |
+
"command_executed": f"Rscript -e '{r_script.strip()}'",
|
| 281 |
+
"sql_fragment": result.stdout.strip(),
|
| 282 |
+
"stdout": result.stdout,
|
| 283 |
+
"stderr": result.stderr
|
| 284 |
+
}
|
| 285 |
+
except subprocess.CalledProcessError as e:
|
| 286 |
+
return {
|
| 287 |
+
"error": "Failed to translate filter",
|
| 288 |
+
"stdout": e.stdout,
|
| 289 |
+
"stderr": e.stderr
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
if __name__ == "__main__":
|
| 293 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-annotationfilter/app/bioconductor-annotationfilter_shim_server.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-annotationfilter/app/bioconductor-annotationfilter_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_bioconductor_annotationfilter'
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class _ShimMCP:
|
| 16 |
+
@staticmethod
|
| 17 |
+
def tool(*args, **kwargs):
|
| 18 |
+
if args and callable(args[0]) and len(args) == 1 and not kwargs:
|
| 19 |
+
return args[0]
|
| 20 |
+
def _decorator(fn):
|
| 21 |
+
return fn
|
| 22 |
+
return _decorator
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _resolve_source_server():
|
| 26 |
+
if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
|
| 27 |
+
return LOCAL_SERVER
|
| 28 |
+
return SOURCE_SERVER
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _load_functions():
|
| 32 |
+
source_server = _resolve_source_server()
|
| 33 |
+
code = source_server.read_text(encoding="utf-8")
|
| 34 |
+
tree = ast.parse(code, filename=str(source_server))
|
| 35 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 36 |
+
namespace = {
|
| 37 |
+
"__name__": "__mcp_source__",
|
| 38 |
+
"mcp": _ShimMCP(),
|
| 39 |
+
}
|
| 40 |
+
exec(compile(code, str(source_server), "exec"), namespace, namespace)
|
| 41 |
+
loaded = []
|
| 42 |
+
for name in function_names:
|
| 43 |
+
fn = namespace.get(name)
|
| 44 |
+
if callable(fn):
|
| 45 |
+
loaded.append(fn)
|
| 46 |
+
return loaded
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
mcp = FastMCP(SERVER_NAME)
|
| 50 |
+
for _fn in _load_functions():
|
| 51 |
+
mcp.tool()(_fn)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_bioconductor-annotationfilter/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotationfilter/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-annotationfilter:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-annotationfilter:latest
|
| 7 |
+
container_name: mcp-bioconductor-annotationfilter
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-annotationfilter
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotationfilter/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-annotationfilter
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_bioconductor-annotationfilter/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_bioconductor-annotationhub/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_bioconductor-apeglm/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-apeglm via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-apeglm -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY bioconductor-apeglm_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-apeglm_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-apeglm_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_bioconductor-apeglm/app/bioconductor-apeglm_server.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import List, Optional, Dict, Any
|
| 4 |
+
|
| 5 |
+
from mcp.server.fastmcp import FastMCP
|
| 6 |
+
|
| 7 |
+
SERVER_NAME = 'local_bioconductor_apeglm'
|
| 8 |
+
mcp = FastMCP(SERVER_NAME)
|
| 9 |
+
|
| 10 |
+
@mcp.tool()
|
| 11 |
+
def run_r_script(
|
| 12 |
+
r_script_file: Optional[Path] = None,
|
| 13 |
+
r_expressions: Optional[List[str]] = None,
|
| 14 |
+
script_args: Optional[List[str]] = None,
|
| 15 |
+
verbose: bool = False,
|
| 16 |
+
default_packages: Optional[str] = None,
|
| 17 |
+
save_workspace: bool = False,
|
| 18 |
+
no_environ: bool = False,
|
| 19 |
+
no_site_file: bool = False,
|
| 20 |
+
no_init_file: bool = False,
|
| 21 |
+
restore_workspace: bool = False,
|
| 22 |
+
vanilla: bool = False,
|
| 23 |
+
) -> Dict[str, Any]:
|
| 24 |
+
"""
|
| 25 |
+
Executes an R script file or R expressions using the Rscript command.
|
| 26 |
+
|
| 27 |
+
This tool provides a wrapper for the Rscript command, allowing users to run
|
| 28 |
+
R code with various configuration options. It supports executing a specified
|
| 29 |
+
R script file or a list of R expressions directly. It also allows passing
|
| 30 |
+
arguments to the R script itself and configuring R's startup behavior.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
r_script_file: Path to an R script file to execute. Mutually exclusive with `r_expressions`.
|
| 34 |
+
r_expressions: A list of R expressions (strings) to execute. Mutually exclusive with `r_script_file`.
|
| 35 |
+
script_args: A list of arguments to be passed to the R script or expressions.
|
| 36 |
+
verbose: If True, print information on progress (corresponds to Rscript's --verbose).
|
| 37 |
+
default_packages: A comma-separated list of package names, or 'NULL',
|
| 38 |
+
to set the default packages loaded (corresponds to --default-packages).
|
| 39 |
+
save_workspace: If True, save the workspace at the end of the session (corresponds to R's --save).
|
| 40 |
+
Ignored if `vanilla` is True.
|
| 41 |
+
no_environ: If True, don't read the site and user environment files (corresponds to R's --no-environ).
|
| 42 |
+
Ignored if `vanilla` is True.
|
| 43 |
+
no_site_file: If True, don't read the site-wide Rprofile (corresponds to R's --no-site-file).
|
| 44 |
+
Ignored if `vanilla` is True.
|
| 45 |
+
no_init_file: If True, don't read the user R profile (corresponds to R's --no-init-file).
|
| 46 |
+
Ignored if `vanilla` is True.
|
| 47 |
+
restore_workspace: If True, restore previously saved objects at startup (corresponds to R's --restore).
|
| 48 |
+
Ignored if `vanilla` is True.
|
| 49 |
+
vanilla: If True, combine --no-save, --no-restore, --no-site-file, --no-init-file, and --no-environ.
|
| 50 |
+
This option overrides individual settings for these flags.
|
| 51 |
+
|
| 52 |
+
Returns:
|
| 53 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 54 |
+
In case of an error, it includes error details and the return code.
|
| 55 |
+
|
| 56 |
+
Raises:
|
| 57 |
+
ValueError: If neither `r_script_file` nor `r_expressions` is provided, or if both are provided.
|
| 58 |
+
FileNotFoundError: If `r_script_file` is provided but does not exist.
|
| 59 |
+
"""
|
| 60 |
+
command: List[str] = ["Rscript"]
|
| 61 |
+
output_files: List[Path] = []
|
| 62 |
+
|
| 63 |
+
# Input validation for script source
|
| 64 |
+
if r_script_file is None and r_expressions is None:
|
| 65 |
+
raise ValueError("Either 'r_script_file' or 'r_expressions' must be provided.")
|
| 66 |
+
if r_script_file is not None and r_expressions is not None:
|
| 67 |
+
raise ValueError("Cannot provide both 'r_script_file' and 'r_expressions'. Choose one.")
|
| 68 |
+
|
| 69 |
+
if r_script_file:
|
| 70 |
+
if not r_script_file.is_file():
|
| 71 |
+
raise FileNotFoundError(f"R script file not found: {r_script_file}")
|
| 72 |
+
|
| 73 |
+
# Add Rscript specific options
|
| 74 |
+
if verbose:
|
| 75 |
+
command.append("--verbose")
|
| 76 |
+
if default_packages is not None:
|
| 77 |
+
command.append(f"--default-packages={default_packages}")
|
| 78 |
+
|
| 79 |
+
# Add R options (passed to R, in addition to --no-echo --no-restore by Rscript)
|
| 80 |
+
if vanilla:
|
| 81 |
+
command.append("--vanilla")
|
| 82 |
+
else:
|
| 83 |
+
# Only add these if --vanilla is not set, as --vanilla implies them
|
| 84 |
+
if save_workspace:
|
| 85 |
+
command.append("--save")
|
| 86 |
+
if no_environ:
|
| 87 |
+
command.append("--no-environ")
|
| 88 |
+
if no_site_file:
|
| 89 |
+
command.append("--no-site-file")
|
| 90 |
+
if no_init_file:
|
| 91 |
+
command.append("--no-init-file")
|
| 92 |
+
if restore_workspace:
|
| 93 |
+
command.append("--restore")
|
| 94 |
+
|
| 95 |
+
# Add the script source (file or expressions)
|
| 96 |
+
if r_script_file:
|
| 97 |
+
command.append(str(r_script_file))
|
| 98 |
+
elif r_expressions:
|
| 99 |
+
for expr in r_expressions:
|
| 100 |
+
command.extend(["-e", expr])
|
| 101 |
+
|
| 102 |
+
# Add arguments to the R script
|
| 103 |
+
if script_args:
|
| 104 |
+
command.extend(script_args)
|
| 105 |
+
|
| 106 |
+
try:
|
| 107 |
+
process = subprocess.run(
|
| 108 |
+
command,
|
| 109 |
+
capture_output=True,
|
| 110 |
+
text=True,
|
| 111 |
+
check=True
|
| 112 |
+
)
|
| 113 |
+
stdout = process.stdout
|
| 114 |
+
stderr = process.stderr
|
| 115 |
+
except subprocess.CalledProcessError as e:
|
| 116 |
+
return {
|
| 117 |
+
"command_executed": " ".join(command),
|
| 118 |
+
"stdout": e.stdout,
|
| 119 |
+
"stderr": e.stderr,
|
| 120 |
+
"error": str(e),
|
| 121 |
+
"returncode": e.returncode,
|
| 122 |
+
"output_files": output_files,
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
return {
|
| 126 |
+
"command_executed": " ".join(command),
|
| 127 |
+
"stdout": stdout,
|
| 128 |
+
"stderr": stderr,
|
| 129 |
+
"output_files": output_files,
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
if __name__ == "__main__":
|
| 133 |
+
mcp.run(transport="stdio")
|