BioOcto code and data release (snapshot 2026-11-27, resumed) (part 30)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Biomni/mcp_generated/mcp_gatk4-spark/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_gatk4-spark/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_gatk4-spark/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_gdk-pixbuf/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_gdk-pixbuf/app/gdk-pixbuf_server.py +207 -0
- Biomni/mcp_generated/mcp_gdk-pixbuf/app/gdk-pixbuf_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_gdk-pixbuf/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_gdk-pixbuf/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_gdk-pixbuf/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_gdk-pixbuf/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_gecode/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_gecode/app/gecode_server.py +144 -0
- Biomni/mcp_generated/mcp_gecode/app/gecode_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_gecode/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_gecode/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_gecode/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_gecode/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_gemini/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_gene-trajectory-python/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_gene-trajectory-python/app/gene-trajectory-python_server.py +215 -0
- Biomni/mcp_generated/mcp_gene-trajectory-python/app/gene-trajectory-python_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_gene-trajectory-python/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_gene-trajectory-python/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_gene-trajectory-python/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_gene-trajectory-python/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_genecircuitry/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_genecircuitry/app/genecircuitry_server.py +149 -0
- Biomni/mcp_generated/mcp_genecircuitry/app/genecircuitry_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_genecircuitry/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_genecircuitry/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_genecircuitry/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_genecircuitry/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_geneimpacts/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_geneimpacts/app/geneimpacts_server.py +224 -0
- Biomni/mcp_generated/mcp_geneimpacts/app/geneimpacts_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_geneimpacts/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_geneimpacts/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_geneimpacts/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_geneimpacts/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_genenotebook/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_genoboo/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_genoboo/app/genoboo_server.py +208 -0
- Biomni/mcp_generated/mcp_genoboo/app/genoboo_shim_server.py +55 -0
- Biomni/mcp_generated/mcp_genoboo/app/requirements.txt +1 -0
- Biomni/mcp_generated/mcp_genoboo/docker-compose.yml +22 -0
- Biomni/mcp_generated/mcp_genoboo/environment.yaml +10 -0
- Biomni/mcp_generated/mcp_genoboo/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_genomad/requirements.txt +2 -0
- Biomni/mcp_generated/mcp_genomepy/Dockerfile +40 -0
- Biomni/mcp_generated/mcp_genomepy/app/genomepy_server.py +354 -0
Biomni/mcp_generated/mcp_gatk4-spark/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-gatk4-spark:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-gatk4-spark:latest
|
| 7 |
+
container_name: mcp-gatk4-spark
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=gatk4-spark
|
| 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_gatk4-spark/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- gatk4-spark
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_gatk4-spark/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_gdk-pixbuf/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 gdk-pixbuf via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda gdk-pixbuf -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/gdk-pixbuf_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/gdk-pixbuf_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/gdk-pixbuf_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_gdk-pixbuf/app/gdk-pixbuf_server.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List
|
| 4 |
+
|
| 5 |
+
from mcp.server.fastmcp import FastMCP
|
| 6 |
+
|
| 7 |
+
SERVER_NAME = 'local_gdk_pixbuf'
|
| 8 |
+
mcp = FastMCP(SERVER_NAME)
|
| 9 |
+
|
| 10 |
+
@mcp.tool()
|
| 11 |
+
def gdk_pixbuf_query_loaders(
|
| 12 |
+
update_cache: bool = False,
|
| 13 |
+
modules: Optional[str] = None
|
| 14 |
+
):
|
| 15 |
+
"""
|
| 16 |
+
Collects information about loadable modules for gdk-pixbuf and writes it to the default
|
| 17 |
+
cache file location or stdout.
|
| 18 |
+
|
| 19 |
+
Args:
|
| 20 |
+
update_cache: If True, updates the default cache file (usually requires write permissions).
|
| 21 |
+
modules: Optional space-separated list of additional modules to query.
|
| 22 |
+
"""
|
| 23 |
+
cmd = ["gdk-pixbuf-query-loaders"]
|
| 24 |
+
|
| 25 |
+
if update_cache:
|
| 26 |
+
cmd.append("--update-cache")
|
| 27 |
+
|
| 28 |
+
if modules:
|
| 29 |
+
cmd.extend(modules.split())
|
| 30 |
+
|
| 31 |
+
try:
|
| 32 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 33 |
+
return {
|
| 34 |
+
"command_executed": " ".join(cmd),
|
| 35 |
+
"stdout": result.stdout,
|
| 36 |
+
"stderr": result.stderr,
|
| 37 |
+
"status": "success"
|
| 38 |
+
}
|
| 39 |
+
except subprocess.CalledProcessError as e:
|
| 40 |
+
return {
|
| 41 |
+
"command_executed": " ".join(cmd),
|
| 42 |
+
"stdout": e.stdout,
|
| 43 |
+
"stderr": e.stderr,
|
| 44 |
+
"error": f"Process exited with code {e.returncode}"
|
| 45 |
+
}
|
| 46 |
+
except FileNotFoundError:
|
| 47 |
+
return {"error": "gdk-pixbuf-query-loaders command not found. Ensure gdk-pixbuf is installed."}
|
| 48 |
+
|
| 49 |
+
@mcp.tool()
|
| 50 |
+
def gdk_pixbuf_thumbnailer(
|
| 51 |
+
input_file: str,
|
| 52 |
+
output_file: str,
|
| 53 |
+
size: int = 128
|
| 54 |
+
):
|
| 55 |
+
"""
|
| 56 |
+
Generates a thumbnail for an image file using gdk-pixbuf.
|
| 57 |
+
|
| 58 |
+
Args:
|
| 59 |
+
input_file: Path to the source image.
|
| 60 |
+
output_file: Path where the thumbnail (PNG) will be saved.
|
| 61 |
+
size: Maximum dimension (width or height) of the thumbnail in pixels.
|
| 62 |
+
"""
|
| 63 |
+
input_path = Path(input_file)
|
| 64 |
+
output_path = Path(output_file)
|
| 65 |
+
|
| 66 |
+
if not input_path.exists():
|
| 67 |
+
return {"error": f"Input file '{input_file}' does not exist."}
|
| 68 |
+
|
| 69 |
+
if size <= 0:
|
| 70 |
+
return {"error": "Size must be a positive integer."}
|
| 71 |
+
|
| 72 |
+
# Ensure output directory exists
|
| 73 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 74 |
+
|
| 75 |
+
cmd = ["gdk-pixbuf-thumbnailer", "-s", str(size), str(input_path), str(output_path)]
|
| 76 |
+
|
| 77 |
+
try:
|
| 78 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 79 |
+
return {
|
| 80 |
+
"command_executed": " ".join(cmd),
|
| 81 |
+
"stdout": result.stdout,
|
| 82 |
+
"stderr": result.stderr,
|
| 83 |
+
"output_files": [str(output_path)]
|
| 84 |
+
}
|
| 85 |
+
except subprocess.CalledProcessError as e:
|
| 86 |
+
return {
|
| 87 |
+
"command_executed": " ".join(cmd),
|
| 88 |
+
"stdout": e.stdout,
|
| 89 |
+
"stderr": e.stderr,
|
| 90 |
+
"error": f"Thumbnail generation failed with code {e.returncode}"
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
@mcp.tool()
|
| 94 |
+
def gdk_pixbuf_csource(
|
| 95 |
+
input_file: str,
|
| 96 |
+
name: Optional[str] = None,
|
| 97 |
+
struct: bool = False,
|
| 98 |
+
extern: bool = False,
|
| 99 |
+
static: bool = False,
|
| 100 |
+
macros: bool = False,
|
| 101 |
+
raw: bool = False,
|
| 102 |
+
stream: bool = False
|
| 103 |
+
):
|
| 104 |
+
"""
|
| 105 |
+
Generates C code from images for inclusion in C programs.
|
| 106 |
+
|
| 107 |
+
Args:
|
| 108 |
+
input_file: Path to the image file.
|
| 109 |
+
name: Specifies the identifier name (variable name) for the generated data.
|
| 110 |
+
struct: Generate GdkPixdata structure (default).
|
| 111 |
+
extern: Use extern keyword in definition.
|
| 112 |
+
static: Use static keyword in definition.
|
| 113 |
+
macros: Generate image data as macros.
|
| 114 |
+
raw: Do not use run-length encoding (RLE) for pixel data.
|
| 115 |
+
stream: Generate a stream of bytes instead of a struct.
|
| 116 |
+
"""
|
| 117 |
+
input_path = Path(input_file)
|
| 118 |
+
if not input_path.exists():
|
| 119 |
+
return {"error": f"Input file '{input_file}' does not exist."}
|
| 120 |
+
|
| 121 |
+
cmd = ["gdk-pixbuf-csource"]
|
| 122 |
+
|
| 123 |
+
if name:
|
| 124 |
+
cmd.append(f"--name={name}")
|
| 125 |
+
if struct:
|
| 126 |
+
cmd.append("--struct")
|
| 127 |
+
if extern:
|
| 128 |
+
cmd.append("--extern")
|
| 129 |
+
if static:
|
| 130 |
+
cmd.append("--static")
|
| 131 |
+
if macros:
|
| 132 |
+
cmd.append("--macros")
|
| 133 |
+
if raw:
|
| 134 |
+
cmd.append("--raw")
|
| 135 |
+
if stream:
|
| 136 |
+
cmd.append("--stream")
|
| 137 |
+
|
| 138 |
+
cmd.append(str(input_path))
|
| 139 |
+
|
| 140 |
+
try:
|
| 141 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 142 |
+
return {
|
| 143 |
+
"command_executed": " ".join(cmd),
|
| 144 |
+
"stdout": result.stdout,
|
| 145 |
+
"stderr": result.stderr,
|
| 146 |
+
"description": "C source code generated to stdout"
|
| 147 |
+
}
|
| 148 |
+
except subprocess.CalledProcessError as e:
|
| 149 |
+
return {
|
| 150 |
+
"command_executed": " ".join(cmd),
|
| 151 |
+
"stdout": e.stdout,
|
| 152 |
+
"stderr": e.stderr,
|
| 153 |
+
"error": f"C-source generation failed with code {e.returncode}"
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
@mcp.tool()
|
| 157 |
+
def gdk_pixbuf_pixdata(
|
| 158 |
+
input_file: str,
|
| 159 |
+
output_file: str,
|
| 160 |
+
pre_format_struct: bool = False,
|
| 161 |
+
raw: bool = False
|
| 162 |
+
):
|
| 163 |
+
"""
|
| 164 |
+
Converts a GdkPixbuf to a GdkPixdata binary format.
|
| 165 |
+
|
| 166 |
+
Args:
|
| 167 |
+
input_file: Path to the source image.
|
| 168 |
+
output_file: Path to save the GdkPixdata file.
|
| 169 |
+
pre_format_struct: Prepare data for inclusion as a C struct.
|
| 170 |
+
raw: Do not use run-length encoding (RLE).
|
| 171 |
+
"""
|
| 172 |
+
input_path = Path(input_file)
|
| 173 |
+
output_path = Path(output_file)
|
| 174 |
+
|
| 175 |
+
if not input_path.exists():
|
| 176 |
+
return {"error": f"Input file '{input_file}' does not exist."}
|
| 177 |
+
|
| 178 |
+
# Ensure output directory exists
|
| 179 |
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 180 |
+
|
| 181 |
+
cmd = ["gdk-pixbuf-pixdata"]
|
| 182 |
+
|
| 183 |
+
if pre_format_struct:
|
| 184 |
+
cmd.append("--pre-format-struct")
|
| 185 |
+
if raw:
|
| 186 |
+
cmd.append("--raw")
|
| 187 |
+
|
| 188 |
+
cmd.extend([str(input_path), str(output_path)])
|
| 189 |
+
|
| 190 |
+
try:
|
| 191 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 192 |
+
return {
|
| 193 |
+
"command_executed": " ".join(cmd),
|
| 194 |
+
"stdout": result.stdout,
|
| 195 |
+
"stderr": result.stderr,
|
| 196 |
+
"output_files": [str(output_path)]
|
| 197 |
+
}
|
| 198 |
+
except subprocess.CalledProcessError as e:
|
| 199 |
+
return {
|
| 200 |
+
"command_executed": " ".join(cmd),
|
| 201 |
+
"stdout": e.stdout,
|
| 202 |
+
"stderr": e.stderr,
|
| 203 |
+
"error": f"Pixdata conversion failed with code {e.returncode}"
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
if __name__ == "__main__":
|
| 207 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_gdk-pixbuf/app/gdk-pixbuf_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_gdk-pixbuf/app/gdk-pixbuf_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_gdk_pixbuf'
|
| 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_gdk-pixbuf/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_gdk-pixbuf/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-gdk-pixbuf:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-gdk-pixbuf:latest
|
| 7 |
+
container_name: mcp-gdk-pixbuf
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=gdk-pixbuf
|
| 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_gdk-pixbuf/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- gdk-pixbuf
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_gdk-pixbuf/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_gecode/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 gecode via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda gecode -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/gecode_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/gecode_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/gecode_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_gecode/app/gecode_server.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List, Dict, Any
|
| 4 |
+
|
| 5 |
+
from mcp.server.fastmcp import FastMCP
|
| 6 |
+
|
| 7 |
+
SERVER_NAME = 'local_gecode'
|
| 8 |
+
mcp = FastMCP(SERVER_NAME)
|
| 9 |
+
|
| 10 |
+
@mcp.tool()
|
| 11 |
+
def fzn_gecode(
|
| 12 |
+
fzn_file: str,
|
| 13 |
+
all_solutions: bool = False,
|
| 14 |
+
num_solutions: int = 1,
|
| 15 |
+
parallel: int = 1,
|
| 16 |
+
time_limit: int = 0,
|
| 17 |
+
statistics: bool = False,
|
| 18 |
+
free_search: bool = False,
|
| 19 |
+
seed: int = 0,
|
| 20 |
+
output_file: Optional[str] = None,
|
| 21 |
+
) -> Dict[str, Any]:
|
| 22 |
+
"""
|
| 23 |
+
Execute the Gecode FlatZinc interpreter to solve constraint problems.
|
| 24 |
+
|
| 25 |
+
Args:
|
| 26 |
+
fzn_file: Path to the FlatZinc (.fzn) input file.
|
| 27 |
+
all_solutions: Search for all solutions (overrides num_solutions).
|
| 28 |
+
num_solutions: Number of solutions to search for (default 1, use 0 for all).
|
| 29 |
+
parallel: Number of threads to use for parallel search (default 1).
|
| 30 |
+
time_limit: Time limit in milliseconds (0 for no limit).
|
| 31 |
+
statistics: Print solver statistics after execution.
|
| 32 |
+
free_search: Use free search (ignore search annotations in the FZN file).
|
| 33 |
+
seed: Random seed for the solver.
|
| 34 |
+
output_file: Redirect solver output to a specific file.
|
| 35 |
+
"""
|
| 36 |
+
# Input validation
|
| 37 |
+
fzn_path = Path(fzn_file)
|
| 38 |
+
if not fzn_path.exists():
|
| 39 |
+
return {
|
| 40 |
+
"error": f"Input FlatZinc file not found: {fzn_file}",
|
| 41 |
+
"command_executed": ""
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
if not fzn_path.suffix == ".fzn":
|
| 45 |
+
# Warning: Gecode expects .fzn files, but we proceed as the user might have renamed it
|
| 46 |
+
pass
|
| 47 |
+
|
| 48 |
+
# Construct command
|
| 49 |
+
cmd = ["fzn-gecode"]
|
| 50 |
+
|
| 51 |
+
# Handle solution count
|
| 52 |
+
if all_solutions:
|
| 53 |
+
cmd.append("-a")
|
| 54 |
+
elif num_solutions != 1:
|
| 55 |
+
if num_solutions < 0:
|
| 56 |
+
return {"error": "num_solutions must be non-negative", "command_executed": ""}
|
| 57 |
+
cmd.extend(["-n", str(num_solutions)])
|
| 58 |
+
|
| 59 |
+
# Parallelism
|
| 60 |
+
if parallel < 1:
|
| 61 |
+
return {"error": "parallel threads must be at least 1", "command_executed": ""}
|
| 62 |
+
cmd.extend(["-p", str(parallel)])
|
| 63 |
+
|
| 64 |
+
# Time limit
|
| 65 |
+
if time_limit > 0:
|
| 66 |
+
cmd.extend(["-t", str(time_limit)])
|
| 67 |
+
elif time_limit < 0:
|
| 68 |
+
return {"error": "time_limit must be non-negative", "command_executed": ""}
|
| 69 |
+
|
| 70 |
+
# Boolean flags
|
| 71 |
+
if statistics:
|
| 72 |
+
cmd.append("-s")
|
| 73 |
+
if free_search:
|
| 74 |
+
cmd.append("-f")
|
| 75 |
+
|
| 76 |
+
# Seed
|
| 77 |
+
if seed != 0:
|
| 78 |
+
cmd.extend(["-r", str(seed)])
|
| 79 |
+
|
| 80 |
+
# Output file
|
| 81 |
+
if output_file:
|
| 82 |
+
cmd.extend(["-o", output_file])
|
| 83 |
+
|
| 84 |
+
# Positional argument
|
| 85 |
+
cmd.append(str(fzn_path))
|
| 86 |
+
|
| 87 |
+
try:
|
| 88 |
+
# Execute the solver
|
| 89 |
+
process = subprocess.run(
|
| 90 |
+
cmd,
|
| 91 |
+
capture_output=True,
|
| 92 |
+
text=True,
|
| 93 |
+
check=True
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
return {
|
| 97 |
+
"command_executed": " ".join(cmd),
|
| 98 |
+
"stdout": process.stdout,
|
| 99 |
+
"stderr": process.stderr,
|
| 100 |
+
"output_files": [output_file] if output_file else []
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
except subprocess.CalledProcessError as e:
|
| 104 |
+
return {
|
| 105 |
+
"error": f"Gecode execution failed with exit code {e.returncode}",
|
| 106 |
+
"command_executed": " ".join(cmd),
|
| 107 |
+
"stdout": e.stdout,
|
| 108 |
+
"stderr": e.stderr
|
| 109 |
+
}
|
| 110 |
+
except FileNotFoundError:
|
| 111 |
+
return {
|
| 112 |
+
"error": "fzn-gecode binary not found. Ensure Gecode is installed and in your PATH.",
|
| 113 |
+
"command_executed": " ".join(cmd)
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
@mcp.tool()
|
| 117 |
+
def gecode_version() -> Dict[str, Any]:
|
| 118 |
+
"""
|
| 119 |
+
Check the installed version of Gecode via fzn-gecode.
|
| 120 |
+
"""
|
| 121 |
+
cmd = ["fzn-gecode", "--help"] # fzn-gecode usually prints version in help or doesn't have a --version flag
|
| 122 |
+
|
| 123 |
+
try:
|
| 124 |
+
process = subprocess.run(
|
| 125 |
+
cmd,
|
| 126 |
+
capture_output=True,
|
| 127 |
+
text=True,
|
| 128 |
+
check=False # Help might return non-zero in some versions
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
# Extract version if possible, otherwise return full help text
|
| 132 |
+
return {
|
| 133 |
+
"command_executed": " ".join(cmd),
|
| 134 |
+
"stdout": process.stdout,
|
| 135 |
+
"stderr": process.stderr
|
| 136 |
+
}
|
| 137 |
+
except Exception as e:
|
| 138 |
+
return {
|
| 139 |
+
"error": str(e),
|
| 140 |
+
"command_executed": " ".join(cmd)
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
if __name__ == "__main__":
|
| 144 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_gecode/app/gecode_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_gecode/app/gecode_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_gecode'
|
| 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_gecode/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_gecode/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-gecode:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-gecode:latest
|
| 7 |
+
container_name: mcp-gecode
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=gecode
|
| 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_gecode/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- gecode
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_gecode/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_gemini/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_gene-trajectory-python/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 gene-trajectory-python via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda gene-trajectory-python -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/gene-trajectory-python_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/gene-trajectory-python_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/gene-trajectory-python_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_gene-trajectory-python/app/gene-trajectory-python_server.py
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from typing import Optional, Dict, List
|
| 6 |
+
|
| 7 |
+
# MCP-related imports are intentionally omitted as per the instructions.
|
| 8 |
+
# from mcp import tool
|
| 9 |
+
|
| 10 |
+
from mcp.server.fastmcp import FastMCP
|
| 11 |
+
|
| 12 |
+
SERVER_NAME = 'local_gene_trajectory_python'
|
| 13 |
+
mcp = FastMCP(SERVER_NAME)
|
| 14 |
+
|
| 15 |
+
@mcp.tool()
|
| 16 |
+
def run_gene_trajectory(
|
| 17 |
+
adata_path: Path,
|
| 18 |
+
output_adata_path: Path,
|
| 19 |
+
obsm_key: str = 'X_pca',
|
| 20 |
+
n_variable_genes: int = 2000,
|
| 21 |
+
layer: Optional[str] = None,
|
| 22 |
+
n_components: int = 50,
|
| 23 |
+
n_neighbors: int = 15,
|
| 24 |
+
use_highly_variable: bool = True,
|
| 25 |
+
resolution: float = 1.0,
|
| 26 |
+
n_clusters: Optional[int] = None,
|
| 27 |
+
n_groups: int = 100,
|
| 28 |
+
n_pcs: int = 50,
|
| 29 |
+
n_diff_maps: int = 15,
|
| 30 |
+
t: int = 1,
|
| 31 |
+
random_state: int = 0,
|
| 32 |
+
output_trajectory_plot: Optional[Path] = None,
|
| 33 |
+
trajectory_plot_basis: str = 'X_diffmap_eval',
|
| 34 |
+
output_heatmap_plot: Optional[Path] = None,
|
| 35 |
+
heatmap_plot_n_genes: int = 10,
|
| 36 |
+
output_feature_plot: Optional[Path] = None,
|
| 37 |
+
feature_plot_basis: str = 'X_umap',
|
| 38 |
+
) -> Dict:
|
| 39 |
+
"""
|
| 40 |
+
Runs the full GeneTrajectory pipeline on a single-cell dataset.
|
| 41 |
+
|
| 42 |
+
This tool identifies trajectories of genes rather than cells by calculating
|
| 43 |
+
optimal transport distances between gene distributions across the cell-cell graph.
|
| 44 |
+
It takes an AnnData object as input, performs the analysis, and saves the
|
| 45 |
+
updated AnnData object with trajectory information. Optional plots can also be generated.
|
| 46 |
+
|
| 47 |
+
Args:
|
| 48 |
+
adata_path: Path to the input AnnData file (`.h5ad`).
|
| 49 |
+
output_adata_path: Path to save the output AnnData file (`.h5ad`) with results.
|
| 50 |
+
obsm_key: Key in `adata.obsm` for the PCA representation.
|
| 51 |
+
n_variable_genes: Number of highly variable genes to use.
|
| 52 |
+
layer: The layer in `adata` to use for computation. If None, `adata.X` is used.
|
| 53 |
+
n_components: Number of principal components to compute if `obsm_key` is not present.
|
| 54 |
+
n_neighbors: Number of neighbors for the cell-cell graph.
|
| 55 |
+
use_highly_variable: Whether to use highly variable genes.
|
| 56 |
+
resolution: Resolution for Leiden clustering.
|
| 57 |
+
n_clusters: Number of clusters for K-means in coarse-graining. If None, it's determined automatically.
|
| 58 |
+
n_groups: Number of groups for coarse-graining.
|
| 59 |
+
n_pcs: Number of principal components for the diffusion map.
|
| 60 |
+
n_diff_maps: Number of diffusion maps to compute.
|
| 61 |
+
t: Time step for the diffusion map.
|
| 62 |
+
random_state: Random state for reproducibility.
|
| 63 |
+
output_trajectory_plot: Optional path to save the gene trajectory plot as a PNG file.
|
| 64 |
+
trajectory_plot_basis: Basis to use for the trajectory plot (e.g., 'X_diffmap_eval').
|
| 65 |
+
output_heatmap_plot: Optional path to save the gene program heatmap as a PNG file.
|
| 66 |
+
heatmap_plot_n_genes: Number of genes to display in the heatmap for each program.
|
| 67 |
+
output_feature_plot: Optional path to save the gene program feature plot as a PNG file.
|
| 68 |
+
feature_plot_basis: Basis to use for the feature plot (e.g., 'X_umap').
|
| 69 |
+
|
| 70 |
+
Returns:
|
| 71 |
+
A dictionary containing the executed command, stdout, stderr, and a
|
| 72 |
+
dictionary of output file paths.
|
| 73 |
+
"""
|
| 74 |
+
# 1. Input validation
|
| 75 |
+
if not adata_path.is_file():
|
| 76 |
+
raise FileNotFoundError(f"Input AnnData file not found: {adata_path}")
|
| 77 |
+
if n_variable_genes <= 0:
|
| 78 |
+
raise ValueError("n_variable_genes must be a positive integer.")
|
| 79 |
+
if n_components <= 0:
|
| 80 |
+
raise ValueError("n_components must be a positive integer.")
|
| 81 |
+
if n_neighbors <= 0:
|
| 82 |
+
raise ValueError("n_neighbors must be a positive integer.")
|
| 83 |
+
if resolution <= 0:
|
| 84 |
+
raise ValueError("resolution must be a positive float.")
|
| 85 |
+
if n_groups <= 0:
|
| 86 |
+
raise ValueError("n_groups must be a positive integer.")
|
| 87 |
+
if n_pcs <= 0:
|
| 88 |
+
raise ValueError("n_pcs must be a positive integer.")
|
| 89 |
+
if n_diff_maps <= 0:
|
| 90 |
+
raise ValueError("n_diff_maps must be a positive integer.")
|
| 91 |
+
if t <= 0:
|
| 92 |
+
raise ValueError("t must be a positive integer.")
|
| 93 |
+
|
| 94 |
+
with tempfile.TemporaryDirectory() as temp_dir_str:
|
| 95 |
+
temp_dir = Path(temp_dir_str)
|
| 96 |
+
script_path = temp_dir / "run_gene_trajectory_script.py"
|
| 97 |
+
|
| 98 |
+
# 2. Generate the Python script to execute the library's functions
|
| 99 |
+
# This approach isolates the execution and dependencies from the MCP server.
|
| 100 |
+
script_content = f"""
|
| 101 |
+
import sys
|
| 102 |
+
import warnings
|
| 103 |
+
import anndata as ad
|
| 104 |
+
import gene_trajectory as gt
|
| 105 |
+
import matplotlib.pyplot as plt
|
| 106 |
+
|
| 107 |
+
# Suppress common warnings from underlying libraries for cleaner output
|
| 108 |
+
warnings.filterwarnings("ignore", category=UserWarning, module='scanpy')
|
| 109 |
+
warnings.filterwarnings("ignore", category=FutureWarning)
|
| 110 |
+
|
| 111 |
+
try:
|
| 112 |
+
# Load input data
|
| 113 |
+
adata = ad.read_h5ad(r'{adata_path.resolve()}')
|
| 114 |
+
|
| 115 |
+
# Instantiate the GeneTrajectory model
|
| 116 |
+
model = gt.GeneTrajectory()
|
| 117 |
+
|
| 118 |
+
# Run the full pipeline
|
| 119 |
+
adata_result = model.run(
|
| 120 |
+
adata,
|
| 121 |
+
obsm_key='{obsm_key}',
|
| 122 |
+
n_variable_genes={n_variable_genes},
|
| 123 |
+
layer={repr(layer)},
|
| 124 |
+
n_components={n_components},
|
| 125 |
+
n_neighbors={n_neighbors},
|
| 126 |
+
use_highly_variable={use_highly_variable},
|
| 127 |
+
resolution={resolution},
|
| 128 |
+
n_clusters={repr(n_clusters)},
|
| 129 |
+
n_groups={n_groups},
|
| 130 |
+
n_pcs={n_pcs},
|
| 131 |
+
n_diff_maps={n_diff_maps},
|
| 132 |
+
t={t},
|
| 133 |
+
random_state={random_state},
|
| 134 |
+
copy=True
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
# Save the resulting AnnData object
|
| 138 |
+
adata_result.write_h5ad(r'{output_adata_path.resolve()}')
|
| 139 |
+
|
| 140 |
+
# Generate and save optional plots
|
| 141 |
+
if {output_trajectory_plot is not None}:
|
| 142 |
+
output_traj_plot_path = r'{str(output_trajectory_plot.resolve()) if output_trajectory_plot else ""}'
|
| 143 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
| 144 |
+
model.plot_trajectory(basis='{trajectory_plot_basis}', ax=ax)
|
| 145 |
+
fig.savefig(output_traj_plot_path, bbox_inches='tight', dpi=300)
|
| 146 |
+
plt.close(fig)
|
| 147 |
+
|
| 148 |
+
if {output_heatmap_plot is not None}:
|
| 149 |
+
output_heatmap_plot_path = r'{str(output_heatmap_plot.resolve()) if output_heatmap_plot else ""}'
|
| 150 |
+
# plot_program_heatmap returns a seaborn ClusterGrid object
|
| 151 |
+
grid = model.plot_program_heatmap(n_genes={heatmap_plot_n_genes})
|
| 152 |
+
grid.savefig(output_heatmap_plot_path, bbox_inches='tight', dpi=300)
|
| 153 |
+
plt.close()
|
| 154 |
+
|
| 155 |
+
if {output_feature_plot is not None}:
|
| 156 |
+
output_feature_plot_path = r'{str(output_feature_plot.resolve()) if output_feature_plot else ""}'
|
| 157 |
+
# Check if the required basis exists in the AnnData object
|
| 158 |
+
if '{feature_plot_basis}' not in adata_result.obsm:
|
| 159 |
+
print(
|
| 160 |
+
f"Warning: Basis '{feature_plot_basis}' not found in adata.obsm. Skipping feature plot.",
|
| 161 |
+
file=sys.stderr
|
| 162 |
+
)
|
| 163 |
+
else:
|
| 164 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
| 165 |
+
model.plot_program_feature(basis='{feature_plot_basis}', ax=ax)
|
| 166 |
+
fig.savefig(output_feature_plot_path, bbox_inches='tight', dpi=300)
|
| 167 |
+
plt.close(fig)
|
| 168 |
+
|
| 169 |
+
except Exception as e:
|
| 170 |
+
print(f"An error occurred during GeneTrajectory execution: {{e}}", file=sys.stderr)
|
| 171 |
+
sys.exit(1)
|
| 172 |
+
|
| 173 |
+
print("GeneTrajectory analysis completed successfully.")
|
| 174 |
+
"""
|
| 175 |
+
script_path.write_text(script_content)
|
| 176 |
+
|
| 177 |
+
# 3. Execute the script in a subprocess
|
| 178 |
+
command = [sys.executable, str(script_path)]
|
| 179 |
+
command_str = " ".join(command)
|
| 180 |
+
|
| 181 |
+
try:
|
| 182 |
+
result = subprocess.run(
|
| 183 |
+
command,
|
| 184 |
+
capture_output=True,
|
| 185 |
+
text=True,
|
| 186 |
+
check=True,
|
| 187 |
+
cwd=temp_dir,
|
| 188 |
+
)
|
| 189 |
+
except subprocess.CalledProcessError as e:
|
| 190 |
+
print(f"Error executing GeneTrajectory script.")
|
| 191 |
+
print(f"Return Code: {e.returncode}")
|
| 192 |
+
print(f"Stdout: {e.stdout}")
|
| 193 |
+
print(f"Stderr: {e.stderr}")
|
| 194 |
+
raise
|
| 195 |
+
|
| 196 |
+
# 4. Collect output file paths for the structured result
|
| 197 |
+
output_files = {"processed_adata": str(output_adata_path)}
|
| 198 |
+
if output_trajectory_plot:
|
| 199 |
+
output_files["trajectory_plot"] = str(output_trajectory_plot)
|
| 200 |
+
if output_heatmap_plot:
|
| 201 |
+
output_files["heatmap_plot"] = str(output_heatmap_plot)
|
| 202 |
+
if output_feature_plot:
|
| 203 |
+
# Only report the file if it was actually created
|
| 204 |
+
if output_feature_plot.exists():
|
| 205 |
+
output_files["feature_plot"] = str(output_feature_plot)
|
| 206 |
+
|
| 207 |
+
return {
|
| 208 |
+
"command_executed": command_str,
|
| 209 |
+
"stdout": result.stdout,
|
| 210 |
+
"stderr": result.stderr,
|
| 211 |
+
"output_files": output_files,
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
if __name__ == "__main__":
|
| 215 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_gene-trajectory-python/app/gene-trajectory-python_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_gene-trajectory-python/app/gene-trajectory-python_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_gene_trajectory_python'
|
| 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_gene-trajectory-python/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_gene-trajectory-python/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-gene-trajectory-python:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-gene-trajectory-python:latest
|
| 7 |
+
container_name: mcp-gene-trajectory-python
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=gene-trajectory-python
|
| 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_gene-trajectory-python/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- gene-trajectory-python
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_gene-trajectory-python/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_genecircuitry/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 genecircuitry via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda genecircuitry -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/genecircuitry_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/genecircuitry_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/genecircuitry_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_genecircuitry/app/genecircuitry_server.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import List, Optional
|
| 5 |
+
|
| 6 |
+
# This is a placeholder for the MCP decorator.
|
| 7 |
+
# In a real MCP environment, this would be provided by the MCP framework.
|
| 8 |
+
def tool(func):
|
| 9 |
+
def wrapper(*args, **kwargs):
|
| 10 |
+
return func(*args, **kwargs)
|
| 11 |
+
return wrapper
|
| 12 |
+
|
| 13 |
+
mcp = type("mcp", (), {"tool": tool})
|
| 14 |
+
|
| 15 |
+
@mcp.tool
|
| 16 |
+
def run_pipeline(
|
| 17 |
+
input_file: Path,
|
| 18 |
+
output_dir: Path,
|
| 19 |
+
steps: Optional[List[str]] = None,
|
| 20 |
+
skip_celloracle: bool = False,
|
| 21 |
+
skip_hotspot: bool = False,
|
| 22 |
+
seed: Optional[int] = None,
|
| 23 |
+
n_jobs: int = 1,
|
| 24 |
+
min_genes: Optional[int] = None,
|
| 25 |
+
cluster_key_stratification: Optional[str] = None,
|
| 26 |
+
parallel: bool = False,
|
| 27 |
+
):
|
| 28 |
+
"""
|
| 29 |
+
Runs the complete genecircuitry analysis pipeline for TRN analysis from single-cell data.
|
| 30 |
+
|
| 31 |
+
This tool integrates Scanpy for preprocessing, CellOracle for GRN inference,
|
| 32 |
+
and Hotspot for identifying embedding-aware gene modules.
|
| 33 |
+
"""
|
| 34 |
+
# --- Input Validation ---
|
| 35 |
+
if not input_file.is_file():
|
| 36 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 37 |
+
|
| 38 |
+
if n_jobs <= 0:
|
| 39 |
+
raise ValueError("n_jobs must be a positive integer.")
|
| 40 |
+
|
| 41 |
+
allowed_steps = [
|
| 42 |
+
"load", "preprocessing", "stratification", "clustering",
|
| 43 |
+
"celloracle", "hotspot", "grn_analysis", "summary"
|
| 44 |
+
]
|
| 45 |
+
if steps:
|
| 46 |
+
for step in steps:
|
| 47 |
+
if step not in allowed_steps:
|
| 48 |
+
raise ValueError(
|
| 49 |
+
f"Invalid step '{step}'. Allowed steps are: {', '.join(allowed_steps)}"
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
if parallel and not cluster_key_stratification:
|
| 53 |
+
raise ValueError(
|
| 54 |
+
"When --parallel is enabled, --cluster-key-stratification must be provided."
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# --- File Path Handling ---
|
| 58 |
+
try:
|
| 59 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 60 |
+
except OSError as e:
|
| 61 |
+
raise OSError(f"Failed to create output directory {output_dir}: {e}")
|
| 62 |
+
|
| 63 |
+
# --- Command Construction ---
|
| 64 |
+
# The documentation suggests the main entry point is a script, but a `genecircuitry`
|
| 65 |
+
# CLI is also mentioned. We will assume the installed package provides this entry point.
|
| 66 |
+
cmd = [
|
| 67 |
+
"genecircuitry",
|
| 68 |
+
"--input", str(input_file),
|
| 69 |
+
"--output", str(output_dir),
|
| 70 |
+
]
|
| 71 |
+
|
| 72 |
+
if steps:
|
| 73 |
+
cmd.append("--steps")
|
| 74 |
+
cmd.extend(steps)
|
| 75 |
+
|
| 76 |
+
if skip_celloracle:
|
| 77 |
+
cmd.append("--skip-celloracle")
|
| 78 |
+
|
| 79 |
+
if skip_hotspot:
|
| 80 |
+
cmd.append("--skip-hotspot")
|
| 81 |
+
|
| 82 |
+
if seed is not None:
|
| 83 |
+
cmd.extend(["--seed", str(seed)])
|
| 84 |
+
|
| 85 |
+
cmd.extend(["--n-jobs", str(n_jobs)])
|
| 86 |
+
|
| 87 |
+
if min_genes is not None:
|
| 88 |
+
cmd.extend(["--min-genes", str(min_genes)])
|
| 89 |
+
|
| 90 |
+
if cluster_key_stratification:
|
| 91 |
+
cmd.extend(["--cluster-key-stratification", cluster_key_stratification])
|
| 92 |
+
|
| 93 |
+
if parallel:
|
| 94 |
+
cmd.append("--parallel")
|
| 95 |
+
|
| 96 |
+
command_executed = " ".join(cmd)
|
| 97 |
+
|
| 98 |
+
# --- Subprocess Execution ---
|
| 99 |
+
try:
|
| 100 |
+
result = subprocess.run(
|
| 101 |
+
cmd,
|
| 102 |
+
capture_output=True,
|
| 103 |
+
text=True,
|
| 104 |
+
check=True,
|
| 105 |
+
cwd=output_dir, # Run from the output directory to keep logs/temp files contained
|
| 106 |
+
)
|
| 107 |
+
except FileNotFoundError:
|
| 108 |
+
return {
|
| 109 |
+
"error": "genecircuitry command not found. Please ensure the tool is installed and in the system's PATH.",
|
| 110 |
+
"command_executed": command_executed,
|
| 111 |
+
"stdout": "",
|
| 112 |
+
"stderr": "Executable not found.",
|
| 113 |
+
}
|
| 114 |
+
except subprocess.CalledProcessError as e:
|
| 115 |
+
return {
|
| 116 |
+
"error": "GeneCircuitry pipeline failed.",
|
| 117 |
+
"command_executed": command_executed,
|
| 118 |
+
"stdout": e.stdout,
|
| 119 |
+
"stderr": e.stderr,
|
| 120 |
+
"return_code": e.returncode,
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
# --- Structured Result Return ---
|
| 124 |
+
# Based on the documentation, these are the expected primary output files.
|
| 125 |
+
# The exact files generated may depend on the steps run.
|
| 126 |
+
output_files = {
|
| 127 |
+
"preprocessed_data": str(output_dir / "preprocessed_adata.h5ad"),
|
| 128 |
+
"analysis_summary": str(output_dir / "analysis_summary.txt"),
|
| 129 |
+
"celloracle_object": str(output_dir / "celloracle" / "oracle_object.celloracle.oracle"),
|
| 130 |
+
"celloracle_links": str(output_dir / "celloracle" / "grn_links.celloracle.links"),
|
| 131 |
+
"hotspot_autocorrelation": str(output_dir / "hotspot" / "autocorrelation_results.csv"),
|
| 132 |
+
"hotspot_significant_genes": str(output_dir / "hotspot" / "significant_genes.csv"),
|
| 133 |
+
"hotspot_gene_modules": str(output_dir / "hotspot" / "gene_modules.csv"),
|
| 134 |
+
"qc_figures_dir": str(output_dir / "figures" / "qc"),
|
| 135 |
+
"grn_analysis_figures_dir": str(output_dir / "figures" / "grn_analysis"),
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
# Filter out files that might not have been created
|
| 139 |
+
final_output_files = {
|
| 140 |
+
key: path for key, path in output_files.items() if Path(path).exists() or Path(path).is_dir()
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
return {
|
| 145 |
+
"command_executed": command_executed,
|
| 146 |
+
"stdout": result.stdout,
|
| 147 |
+
"stderr": result.stderr,
|
| 148 |
+
"output_files": final_output_files,
|
| 149 |
+
}
|
Biomni/mcp_generated/mcp_genecircuitry/app/genecircuitry_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_genecircuitry/app/genecircuitry_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_genecircuitry'
|
| 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_genecircuitry/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_genecircuitry/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-genecircuitry:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-genecircuitry:latest
|
| 7 |
+
container_name: mcp-genecircuitry
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=genecircuitry
|
| 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_genecircuitry/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- genecircuitry
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_genecircuitry/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_geneimpacts/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 geneimpacts via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda geneimpacts -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/geneimpacts_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/geneimpacts_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/geneimpacts_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_geneimpacts/app/geneimpacts_server.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Optional, Dict, List, Any
|
| 5 |
+
|
| 6 |
+
# This is a placeholder for the actual mcp decorator.
|
| 7 |
+
# Per the instructions, there is "NO NEED to import mcp".
|
| 8 |
+
def tool(*args, **kwargs):
|
| 9 |
+
def decorator(f):
|
| 10 |
+
return f
|
| 11 |
+
return decorator
|
| 12 |
+
|
| 13 |
+
mcp = type("mcp", (), {"tool": tool})
|
| 14 |
+
|
| 15 |
+
# The Python script that will be executed by the MCP tool.
|
| 16 |
+
# This script uses the geneimpacts library to perform the core logic.
|
| 17 |
+
VCF_PROCESSING_SCRIPT = """
|
| 18 |
+
import sys
|
| 19 |
+
import argparse
|
| 20 |
+
import re
|
| 21 |
+
from geneimpacts import Vep, SnpEff, BCFtools
|
| 22 |
+
|
| 23 |
+
def get_parser_and_header(ann_type, ann_field, vcf_header_lines):
|
| 24 |
+
\"\"\"Find the INFO header and return the parser class and format string.\"\"\"
|
| 25 |
+
parser_class = None
|
| 26 |
+
if ann_type == 'vep':
|
| 27 |
+
parser_class = Vep
|
| 28 |
+
elif ann_type == 'snpeff':
|
| 29 |
+
parser_class = SnpEff
|
| 30 |
+
elif ann_type == 'bcftools':
|
| 31 |
+
parser_class = BCFtools
|
| 32 |
+
else:
|
| 33 |
+
# This case should be caught by argparse choices, but is here for safety.
|
| 34 |
+
raise ValueError(f"Unknown annotation type: {ann_type}")
|
| 35 |
+
|
| 36 |
+
# Regex to find the format string within the VCF INFO header description
|
| 37 |
+
header_pattern = re.compile(f'##INFO=<ID={ann_field},.*Description=".*Format: (.*?)">')
|
| 38 |
+
format_string = None
|
| 39 |
+
for line in vcf_header_lines:
|
| 40 |
+
match = header_pattern.search(line)
|
| 41 |
+
if match:
|
| 42 |
+
format_string = match.group(1).strip()
|
| 43 |
+
break
|
| 44 |
+
|
| 45 |
+
if format_string is None:
|
| 46 |
+
raise ValueError(f"Could not find format string for INFO field '{ann_field}' in VCF header. "
|
| 47 |
+
f"Expected a ##INFO line with 'Format: ...' in the description.")
|
| 48 |
+
|
| 49 |
+
return parser_class, format_string
|
| 50 |
+
|
| 51 |
+
def get_top_impact_string(effects):
|
| 52 |
+
\"\"\"Get a string representation of the top impact(s).\"\"\"
|
| 53 |
+
if not effects:
|
| 54 |
+
return "."
|
| 55 |
+
|
| 56 |
+
# Effect.top_severity can return a single object or a list if there's a tie
|
| 57 |
+
top_effects = effects[0].top_severity(effects)
|
| 58 |
+
if not isinstance(top_effects, list):
|
| 59 |
+
top_effects = [top_effects]
|
| 60 |
+
|
| 61 |
+
# Create a unique, sorted list of strings for deterministic output
|
| 62 |
+
impact_strings = {f"{e.gene}|{e.impact_severity}|{e.impact}" for e in top_effects}
|
| 63 |
+
return ",".join(sorted(list(impact_strings)))
|
| 64 |
+
|
| 65 |
+
def main():
|
| 66 |
+
parser = argparse.ArgumentParser(description="Prioritize variant impacts in a VCF file using geneimpacts.")
|
| 67 |
+
parser.add_argument('input_vcf', help="Input VCF file.")
|
| 68 |
+
parser.add_argument('output_vcf', help="Output VCF file.")
|
| 69 |
+
parser.add_argument('--ann_type', required=True, choices=['vep', 'snpeff', 'bcftools'], help="Annotation type.")
|
| 70 |
+
parser.add_argument('--ann_field', required=True, help="INFO field containing the annotations (e.g., CSQ, ANN).")
|
| 71 |
+
parser.add_argument('--new_field', required=True, help="Name for the new INFO field with the top impact.")
|
| 72 |
+
args = parser.parse_args()
|
| 73 |
+
|
| 74 |
+
header_lines = []
|
| 75 |
+
variant_lines = []
|
| 76 |
+
with open(args.input_vcf, 'r') as infile:
|
| 77 |
+
for line in infile:
|
| 78 |
+
if line.startswith('#'):
|
| 79 |
+
header_lines.append(line)
|
| 80 |
+
else:
|
| 81 |
+
variant_lines.append(line)
|
| 82 |
+
|
| 83 |
+
try:
|
| 84 |
+
EffectParser, format_header = get_parser_and_header(args.ann_type, args.ann_field, header_lines)
|
| 85 |
+
except ValueError as e:
|
| 86 |
+
sys.stderr.write(str(e) + '\\n')
|
| 87 |
+
sys.exit(1)
|
| 88 |
+
|
| 89 |
+
with open(args.output_vcf, 'w') as outfile:
|
| 90 |
+
# Write original header, inserting our new INFO field definition
|
| 91 |
+
for line in header_lines:
|
| 92 |
+
if line.startswith('#CHROM'):
|
| 93 |
+
new_header_line = f'##INFO=<ID={args.new_field},Number=.,Type=String,Description="Most severe functional impact from {args.ann_field} field, predicted by geneimpacts. Format: Gene|Severity|Impact">'
|
| 94 |
+
outfile.write(new_header_line + '\\n')
|
| 95 |
+
outfile.write(line)
|
| 96 |
+
|
| 97 |
+
# Process and write variant lines
|
| 98 |
+
for line in variant_lines:
|
| 99 |
+
fields = line.strip().split('\\t')
|
| 100 |
+
info_col = fields[7]
|
| 101 |
+
|
| 102 |
+
info_dict = {item.split('=', 1)[0]: item.split('=', 1)[1] if '=' in item else True for item in info_col.split(';')}
|
| 103 |
+
|
| 104 |
+
top_impact_str = "."
|
| 105 |
+
if args.ann_field in info_dict and info_dict[args.ann_field] is not True:
|
| 106 |
+
ann_string = info_dict[args.ann_field]
|
| 107 |
+
try:
|
| 108 |
+
parser_instance = EffectParser(ann_string, header=format_header)
|
| 109 |
+
effects = list(parser_instance)
|
| 110 |
+
top_impact_str = get_top_impact_string(effects)
|
| 111 |
+
except Exception as e:
|
| 112 |
+
sys.stderr.write(f"Warning: Could not process variant {fields[0]}:{fields[1]}. Error: {e}\\n")
|
| 113 |
+
top_impact_str = "ERROR_PARSING"
|
| 114 |
+
|
| 115 |
+
new_info_entry = f"{args.new_field}={top_impact_str}"
|
| 116 |
+
|
| 117 |
+
if info_col == ".":
|
| 118 |
+
fields[7] = new_info_entry
|
| 119 |
+
else:
|
| 120 |
+
fields[7] = f"{info_col};{new_info_entry}"
|
| 121 |
+
|
| 122 |
+
outfile.write('\\t'.join(fields) + '\\n')
|
| 123 |
+
|
| 124 |
+
if __name__ == "__main__":
|
| 125 |
+
main()
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
from mcp.server.fastmcp import FastMCP
|
| 129 |
+
|
| 130 |
+
SERVER_NAME = 'local_geneimpacts'
|
| 131 |
+
mcp = FastMCP(SERVER_NAME)
|
| 132 |
+
|
| 133 |
+
@mcp.tool()
|
| 134 |
+
def prioritize(
|
| 135 |
+
vcf_file: Path,
|
| 136 |
+
annotation_type: str,
|
| 137 |
+
annotation_field: str,
|
| 138 |
+
output_vcf: Optional[Path] = None,
|
| 139 |
+
new_info_field: str = "GI_TOP"
|
| 140 |
+
) -> Dict[str, Any]:
|
| 141 |
+
"""
|
| 142 |
+
Prioritizes variant effects from VEP, SnpEff, or BCFtools annotations in a VCF file.
|
| 143 |
+
|
| 144 |
+
This tool reads a VCF file, parses the specified annotation field, uses the
|
| 145 |
+
geneimpacts library to determine the most severe impact for each variant, and
|
| 146 |
+
writes a new VCF file with this information added to a new INFO field.
|
| 147 |
+
|
| 148 |
+
Args:
|
| 149 |
+
vcf_file: Path to the input VCF file.
|
| 150 |
+
annotation_type: The type of annotation to parse. Must be one of 'vep', 'snpeff', or 'bcftools'.
|
| 151 |
+
annotation_field: The INFO field tag containing the annotations (e.g., 'CSQ' for VEP, 'ANN' for SnpEff).
|
| 152 |
+
output_vcf: Optional path for the output annotated VCF file. If not provided, a temporary file will be created.
|
| 153 |
+
new_info_field: The name for the new INFO field that will store the top impact. Defaults to 'GI_TOP'.
|
| 154 |
+
|
| 155 |
+
Returns:
|
| 156 |
+
A dictionary containing the command executed, stdout, stderr, and a dictionary of output files.
|
| 157 |
+
"""
|
| 158 |
+
# 1. Input validation
|
| 159 |
+
if not vcf_file.is_file():
|
| 160 |
+
raise FileNotFoundError(f"Input VCF file not found: {vcf_file}")
|
| 161 |
+
|
| 162 |
+
valid_ann_types = ['vep', 'snpeff', 'bcftools']
|
| 163 |
+
if annotation_type not in valid_ann_types:
|
| 164 |
+
raise ValueError(f"Invalid annotation_type '{annotation_type}'. Must be one of {valid_ann_types}")
|
| 165 |
+
|
| 166 |
+
if not new_info_field.isalnum() or new_info_field[0].isdigit():
|
| 167 |
+
raise ValueError(f"new_info_field '{new_info_field}' must be alphanumeric and not start with a digit.")
|
| 168 |
+
|
| 169 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 170 |
+
temp_dir_path = Path(temp_dir)
|
| 171 |
+
|
| 172 |
+
# 2. File path handling
|
| 173 |
+
if output_vcf:
|
| 174 |
+
output_path = output_vcf
|
| 175 |
+
if not output_path.parent.exists():
|
| 176 |
+
raise FileNotFoundError(f"Parent directory for output file does not exist: {output_path.parent}")
|
| 177 |
+
else:
|
| 178 |
+
output_path = temp_dir_path / f"{vcf_file.stem}.geneimpacts.vcf"
|
| 179 |
+
|
| 180 |
+
script_path = temp_dir_path / "vcf_processor.py"
|
| 181 |
+
script_path.write_text(VCF_PROCESSING_SCRIPT)
|
| 182 |
+
|
| 183 |
+
# 3. Subprocess execution
|
| 184 |
+
cmd = [
|
| 185 |
+
"python", str(script_path),
|
| 186 |
+
str(vcf_file),
|
| 187 |
+
str(output_path),
|
| 188 |
+
"--ann_type", annotation_type,
|
| 189 |
+
"--ann_field", annotation_field,
|
| 190 |
+
"--new_field", new_info_field
|
| 191 |
+
]
|
| 192 |
+
|
| 193 |
+
command_executed = " ".join(cmd)
|
| 194 |
+
|
| 195 |
+
try:
|
| 196 |
+
result = subprocess.run(
|
| 197 |
+
cmd,
|
| 198 |
+
capture_output=True,
|
| 199 |
+
text=True,
|
| 200 |
+
check=True,
|
| 201 |
+
cwd=temp_dir
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
# 4. Structured result return
|
| 205 |
+
return {
|
| 206 |
+
"command_executed": command_executed,
|
| 207 |
+
"stdout": result.stdout,
|
| 208 |
+
"stderr": result.stderr,
|
| 209 |
+
"output_files": {
|
| 210 |
+
"annotated_vcf": str(output_path)
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
except subprocess.CalledProcessError as e:
|
| 214 |
+
# 5. Error handling
|
| 215 |
+
return {
|
| 216 |
+
"command_executed": command_executed,
|
| 217 |
+
"stdout": e.stdout,
|
| 218 |
+
"stderr": e.stderr,
|
| 219 |
+
"error": f"geneimpacts wrapper script failed with exit code {e.returncode}",
|
| 220 |
+
"output_files": {}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
if __name__ == "__main__":
|
| 224 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_geneimpacts/app/geneimpacts_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_geneimpacts/app/geneimpacts_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_geneimpacts'
|
| 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_geneimpacts/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_geneimpacts/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-geneimpacts:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-geneimpacts:latest
|
| 7 |
+
container_name: mcp-geneimpacts
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=geneimpacts
|
| 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_geneimpacts/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- geneimpacts
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_geneimpacts/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_genenotebook/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_genoboo/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 genoboo via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda genoboo -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/genoboo_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/genoboo_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/genoboo_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_genoboo/app/genoboo_server.py
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional
|
| 4 |
+
|
| 5 |
+
# Note: The @mcp.tool decorator is used for MCP integration and is assumed to be available in the execution environment.
|
| 6 |
+
# No import is included here as per the instructions.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
from mcp.server.fastmcp import FastMCP
|
| 10 |
+
|
| 11 |
+
SERVER_NAME = 'local_genoboo'
|
| 12 |
+
mcp = FastMCP(SERVER_NAME)
|
| 13 |
+
|
| 14 |
+
@mcp.tool()
|
| 15 |
+
def run_genenotebook(port: int = 3000, timeout: int = 60):
|
| 16 |
+
"""
|
| 17 |
+
Starts the GeneNoteBook server.
|
| 18 |
+
|
| 19 |
+
This command initiates the server process, which does not terminate on its own.
|
| 20 |
+
A timeout is used to capture the initial startup logs and then terminate the process.
|
| 21 |
+
Managing the long-running server process is outside the scope of this tool.
|
| 22 |
+
The default admin account is username: 'admin', password: 'admin'.
|
| 23 |
+
"""
|
| 24 |
+
# Input validation
|
| 25 |
+
if not (1 <= port <= 65535):
|
| 26 |
+
raise ValueError("Port must be an integer between 1 and 65535.")
|
| 27 |
+
if timeout <= 0:
|
| 28 |
+
raise ValueError("Timeout must be a positive integer.")
|
| 29 |
+
|
| 30 |
+
cmd = ["genenotebook", "run", "--port", str(port)]
|
| 31 |
+
command_executed = " ".join(cmd)
|
| 32 |
+
stdout_str = ""
|
| 33 |
+
stderr_str = ""
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
# Run the command with a timeout, as it's a server process.
|
| 37 |
+
# We don't use check=True because a timeout is the expected outcome.
|
| 38 |
+
process = subprocess.run(
|
| 39 |
+
cmd, capture_output=True, text=True, timeout=timeout
|
| 40 |
+
)
|
| 41 |
+
stdout_str = process.stdout
|
| 42 |
+
stderr_str = process.stderr
|
| 43 |
+
# If it exits before timeout, it might be an error
|
| 44 |
+
if process.returncode != 0:
|
| 45 |
+
stderr_str += (
|
| 46 |
+
f"\nProcess exited unexpectedly with code {process.returncode}."
|
| 47 |
+
)
|
| 48 |
+
except subprocess.TimeoutExpired as e:
|
| 49 |
+
# This is the expected outcome for a server process.
|
| 50 |
+
stdout_str = e.stdout if e.stdout else ""
|
| 51 |
+
stderr_str = e.stderr if e.stderr else ""
|
| 52 |
+
stderr_str += f"\nProcess timed out after {timeout} seconds, as expected for a server startup."
|
| 53 |
+
except FileNotFoundError:
|
| 54 |
+
return {
|
| 55 |
+
"command_executed": command_executed,
|
| 56 |
+
"stdout": "",
|
| 57 |
+
"stderr": "Error: 'genenotebook' command not found. Please ensure it is installed and in your PATH.",
|
| 58 |
+
"output_files": [],
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
return {
|
| 62 |
+
"command_executed": command_executed,
|
| 63 |
+
"stdout": stdout_str,
|
| 64 |
+
"stderr": stderr_str,
|
| 65 |
+
"output_files": [],
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
@mcp.tool()
|
| 70 |
+
def add_genome(
|
| 71 |
+
genome_fasta: Path,
|
| 72 |
+
name: str,
|
| 73 |
+
username: str,
|
| 74 |
+
password: str,
|
| 75 |
+
port: int = 3000,
|
| 76 |
+
):
|
| 77 |
+
"""
|
| 78 |
+
Adds a genome from a FASTA file to a running GeneNoteBook instance.
|
| 79 |
+
|
| 80 |
+
This tool requires a GeneNoteBook server to be running and accessible at the specified port.
|
| 81 |
+
"""
|
| 82 |
+
# Input validation
|
| 83 |
+
if not genome_fasta.is_file():
|
| 84 |
+
raise FileNotFoundError(f"Input genome FASTA file not found: {genome_fasta}")
|
| 85 |
+
if not name:
|
| 86 |
+
raise ValueError("A name for the genome (-n) must be provided.")
|
| 87 |
+
if not username:
|
| 88 |
+
raise ValueError("A username (-u) must be provided.")
|
| 89 |
+
if not password:
|
| 90 |
+
raise ValueError("A password (-p) must be provided.")
|
| 91 |
+
if not (1 <= port <= 65535):
|
| 92 |
+
raise ValueError("Port must be an integer between 1 and 65535.")
|
| 93 |
+
|
| 94 |
+
cmd = [
|
| 95 |
+
"genenotebook",
|
| 96 |
+
"add",
|
| 97 |
+
"genome",
|
| 98 |
+
"-u",
|
| 99 |
+
username,
|
| 100 |
+
"-p",
|
| 101 |
+
password,
|
| 102 |
+
"--port",
|
| 103 |
+
str(port),
|
| 104 |
+
"-n",
|
| 105 |
+
name,
|
| 106 |
+
str(genome_fasta),
|
| 107 |
+
]
|
| 108 |
+
command_executed = " ".join(cmd)
|
| 109 |
+
|
| 110 |
+
try:
|
| 111 |
+
process = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 112 |
+
stdout = process.stdout
|
| 113 |
+
stderr = process.stderr
|
| 114 |
+
except subprocess.CalledProcessError as e:
|
| 115 |
+
return {
|
| 116 |
+
"command_executed": command_executed,
|
| 117 |
+
"stdout": e.stdout,
|
| 118 |
+
"stderr": e.stderr,
|
| 119 |
+
"output_files": [],
|
| 120 |
+
}
|
| 121 |
+
except FileNotFoundError:
|
| 122 |
+
return {
|
| 123 |
+
"command_executed": command_executed,
|
| 124 |
+
"stdout": "",
|
| 125 |
+
"stderr": "Error: 'genenotebook' command not found. Please ensure it is installed and in your PATH.",
|
| 126 |
+
"output_files": [],
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
return {
|
| 130 |
+
"command_executed": command_executed,
|
| 131 |
+
"stdout": stdout,
|
| 132 |
+
"stderr": stderr,
|
| 133 |
+
"output_files": [],
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
@mcp.tool()
|
| 138 |
+
def add_annotation(
|
| 139 |
+
annotation_gff3: Path,
|
| 140 |
+
name: str,
|
| 141 |
+
username: str,
|
| 142 |
+
password: str,
|
| 143 |
+
port: int = 3000,
|
| 144 |
+
):
|
| 145 |
+
"""
|
| 146 |
+
Adds an annotation file (GFF3) to a genome in a running GeneNoteBook instance.
|
| 147 |
+
|
| 148 |
+
This tool requires a GeneNoteBook server to be running and accessible at the specified port.
|
| 149 |
+
The 'name' parameter should match the name of an existing genome in the database.
|
| 150 |
+
"""
|
| 151 |
+
# Input validation
|
| 152 |
+
if not annotation_gff3.is_file():
|
| 153 |
+
raise FileNotFoundError(
|
| 154 |
+
f"Input annotation GFF3 file not found: {annotation_gff3}"
|
| 155 |
+
)
|
| 156 |
+
if not name:
|
| 157 |
+
raise ValueError("A name for the target genome (-n) must be provided.")
|
| 158 |
+
if not username:
|
| 159 |
+
raise ValueError("A username (-u) must be provided.")
|
| 160 |
+
if not password:
|
| 161 |
+
raise ValueError("A password (-p) must be provided.")
|
| 162 |
+
if not (1 <= port <= 65535):
|
| 163 |
+
raise ValueError("Port must be an integer between 1 and 65535.")
|
| 164 |
+
|
| 165 |
+
cmd = [
|
| 166 |
+
"genenotebook",
|
| 167 |
+
"add",
|
| 168 |
+
"annotation",
|
| 169 |
+
"-u",
|
| 170 |
+
username,
|
| 171 |
+
"-p",
|
| 172 |
+
password,
|
| 173 |
+
"--port",
|
| 174 |
+
str(port),
|
| 175 |
+
"-n",
|
| 176 |
+
name,
|
| 177 |
+
str(annotation_gff3),
|
| 178 |
+
]
|
| 179 |
+
command_executed = " ".join(cmd)
|
| 180 |
+
|
| 181 |
+
try:
|
| 182 |
+
process = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 183 |
+
stdout = process.stdout
|
| 184 |
+
stderr = process.stderr
|
| 185 |
+
except subprocess.CalledProcessError as e:
|
| 186 |
+
return {
|
| 187 |
+
"command_executed": command_executed,
|
| 188 |
+
"stdout": e.stdout,
|
| 189 |
+
"stderr": e.stderr,
|
| 190 |
+
"output_files": [],
|
| 191 |
+
}
|
| 192 |
+
except FileNotFoundError:
|
| 193 |
+
return {
|
| 194 |
+
"command_executed": command_executed,
|
| 195 |
+
"stdout": "",
|
| 196 |
+
"stderr": "Error: 'genenotebook' command not found. Please ensure it is installed and in your PATH.",
|
| 197 |
+
"output_files": [],
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
return {
|
| 201 |
+
"command_executed": command_executed,
|
| 202 |
+
"stdout": stdout,
|
| 203 |
+
"stderr": stderr,
|
| 204 |
+
"output_files": [],
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
if __name__ == "__main__":
|
| 208 |
+
mcp.run(transport="stdio")
|
Biomni/mcp_generated/mcp_genoboo/app/genoboo_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_genoboo/app/genoboo_server.py')
|
| 11 |
+
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
|
| 12 |
+
SERVER_NAME = 'biosci_genoboo'
|
| 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_genoboo/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
Biomni/mcp_generated/mcp_genoboo/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-genoboo:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-genoboo:latest
|
| 7 |
+
container_name: mcp-genoboo
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=genoboo
|
| 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_genoboo/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- genoboo
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
Biomni/mcp_generated/mcp_genoboo/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_genomad/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
Biomni/mcp_generated/mcp_genomepy/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 genomepy via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda genomepy -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/genomepy_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/genomepy_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/genomepy_server.py"]
|
| 40 |
+
|
Biomni/mcp_generated/mcp_genomepy/app/genomepy_server.py
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List, Literal, Dict, Any
|
| 4 |
+
|
| 5 |
+
# Define common types for reusability and clarity
|
| 6 |
+
GenomeMaskType = Literal["hard", "soft", "none"]
|
| 7 |
+
ProviderType = Literal["GENCODE", "Ensembl", "UCSC", "NCBI", "Local", "URL"]
|
| 8 |
+
UCSCAnnotationType = Literal["ncbiRefSeq", "refGene", "ensGene", "knownGene"]
|
| 9 |
+
PluginName = Literal["blacklist", "bowtie2", "bwa", "gmap", "hisat2", "minimap2", "star"]
|
| 10 |
+
|
| 11 |
+
def _run_genomepy_command(
|
| 12 |
+
command_args: List[str],
|
| 13 |
+
expected_output_paths: Optional[List[Path]] = None
|
| 14 |
+
) -> Dict[str, Any]:
|
| 15 |
+
"""
|
| 16 |
+
Helper function to run genomepy commands and handle output/errors.
|
| 17 |
+
"""
|
| 18 |
+
cmd = ["genomepy"] + command_args
|
| 19 |
+
command_executed = " ".join(map(str, cmd))
|
| 20 |
+
stdout = ""
|
| 21 |
+
stderr = ""
|
| 22 |
+
output_files_found: List[str] = []
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
result = subprocess.run(
|
| 26 |
+
cmd,
|
| 27 |
+
capture_output=True,
|
| 28 |
+
text=True,
|
| 29 |
+
check=True
|
| 30 |
+
)
|
| 31 |
+
stdout = result.stdout
|
| 32 |
+
stderr = result.stderr
|
| 33 |
+
|
| 34 |
+
if expected_output_paths:
|
| 35 |
+
for p in expected_output_paths:
|
| 36 |
+
if p.exists():
|
| 37 |
+
output_files_found.append(str(p.resolve()))
|
| 38 |
+
|
| 39 |
+
except subprocess.CalledProcessError as e:
|
| 40 |
+
return {
|
| 41 |
+
"command_executed": command_executed,
|
| 42 |
+
"stdout": e.stdout,
|
| 43 |
+
"stderr": e.stderr,
|
| 44 |
+
"error": f"Command failed with exit code {e.returncode}",
|
| 45 |
+
"output_files": output_files_found,
|
| 46 |
+
}
|
| 47 |
+
except FileNotFoundError:
|
| 48 |
+
return {
|
| 49 |
+
"command_executed": command_executed,
|
| 50 |
+
"stdout": "",
|
| 51 |
+
"stderr": "genomepy command not found. Please ensure it is installed and in your PATH.",
|
| 52 |
+
"error": "genomepy executable not found",
|
| 53 |
+
"output_files": output_files_found,
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
return {
|
| 57 |
+
"command_executed": command_executed,
|
| 58 |
+
"stdout": stdout,
|
| 59 |
+
"stderr": stderr,
|
| 60 |
+
"output_files": output_files_found,
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
from mcp.server.fastmcp import FastMCP
|
| 64 |
+
|
| 65 |
+
SERVER_NAME = 'local_genomepy'
|
| 66 |
+
mcp = FastMCP(SERVER_NAME)
|
| 67 |
+
|
| 68 |
+
@mcp.tool()
|
| 69 |
+
def get_version() -> Dict[str, Any]:
|
| 70 |
+
"""
|
| 71 |
+
Show the genomepy version.
|
| 72 |
+
"""
|
| 73 |
+
return _run_genomepy_command(["--version"])
|
| 74 |
+
|
| 75 |
+
@mcp.tool()
|
| 76 |
+
def search(
|
| 77 |
+
term: str,
|
| 78 |
+
provider: Optional[ProviderType] = None,
|
| 79 |
+
size: bool = False,
|
| 80 |
+
) -> Dict[str, Any]:
|
| 81 |
+
"""
|
| 82 |
+
Search for genomes and gene annotations by name, taxonomy ID, or assembly accession ID.
|
| 83 |
+
|
| 84 |
+
Args:
|
| 85 |
+
term: The search term (e.g., genome name, taxonomy ID, assembly accession ID).
|
| 86 |
+
provider: Limit the search result to a specific provider (e.g., "UCSC", "Ensembl").
|
| 87 |
+
size: If True, get the absolute size of each genome (this option slows down the search).
|
| 88 |
+
|
| 89 |
+
Returns:
|
| 90 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 91 |
+
"""
|
| 92 |
+
if not term:
|
| 93 |
+
raise ValueError("Search term cannot be empty.")
|
| 94 |
+
|
| 95 |
+
cmd_args = ["search", term]
|
| 96 |
+
if provider:
|
| 97 |
+
cmd_args.extend(["--provider", provider])
|
| 98 |
+
if size:
|
| 99 |
+
cmd_args.append("--size")
|
| 100 |
+
|
| 101 |
+
return _run_genomepy_command(cmd_args)
|
| 102 |
+
|
| 103 |
+
@mcp.tool()
|
| 104 |
+
def install(
|
| 105 |
+
name_or_path_or_url: str,
|
| 106 |
+
annotation: bool = False,
|
| 107 |
+
provider: Optional[ProviderType] = None,
|
| 108 |
+
genomes_dir: Optional[Path] = None,
|
| 109 |
+
regex: Optional[str] = None,
|
| 110 |
+
no_match: bool = False,
|
| 111 |
+
mask: GenomeMaskType = "soft",
|
| 112 |
+
bgzip: bool = False,
|
| 113 |
+
localname: Optional[str] = None,
|
| 114 |
+
url_to_annotation: Optional[str] = None,
|
| 115 |
+
local_path_to_annotation: Optional[Path] = None,
|
| 116 |
+
force: bool = False,
|
| 117 |
+
threads: int = 8,
|
| 118 |
+
ucsc_annotation: Optional[UCSCAnnotationType] = None,
|
| 119 |
+
) -> Dict[str, Any]:
|
| 120 |
+
"""
|
| 121 |
+
Install a genome and optionally run active plugins.
|
| 122 |
+
Supports downloading from providers (Ensembl, UCSC, NCBI, GENCODE), URLs, or local files.
|
| 123 |
+
|
| 124 |
+
Args:
|
| 125 |
+
name_or_path_or_url: The genome name, URL, or local file path to install.
|
| 126 |
+
annotation: If True, download gene annotation files along with the genome.
|
| 127 |
+
provider: Specify the provider by name (e.g., "UCSC", "Ensembl"). Required for URL/Local.
|
| 128 |
+
genomes_dir: Directory where genomes will be saved. Defaults to ~/.local/share/genomes/.
|
| 129 |
+
regex: A regular expression to filter for matching sequences (e.g., 'chr[0-9XY]+$').
|
| 130 |
+
no_match: Use with --regex to filter for non-matching sequences.
|
| 131 |
+
mask: Masking type for genome sequences. Choices: "hard" (ACNNN), "soft" (ACgtN), "none" (ACGTN).
|
| 132 |
+
bgzip: If True, compress the downloaded data using bgzip.
|
| 133 |
+
localname: Local name for the genome (used when provider is URL or Local).
|
| 134 |
+
url_to_annotation: URL to an annotation file (used with --provider URL).
|
| 135 |
+
local_path_to_annotation: Filepath to a local annotation file (used with --provider Local).
|
| 136 |
+
force: If True, overwrite local files if they exist.
|
| 137 |
+
threads: Number of threads to use for aligner index creation (if plugins are active).
|
| 138 |
+
ucsc_annotation: Specific UCSC annotation type to download (e.g., "refGene", "ncbiRefSeq").
|
| 139 |
+
Only applicable when --provider UCSC.
|
| 140 |
+
|
| 141 |
+
Returns:
|
| 142 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 143 |
+
"""
|
| 144 |
+
if not name_or_path_or_url:
|
| 145 |
+
raise ValueError("Genome name, path, or URL cannot be empty.")
|
| 146 |
+
if threads < 1:
|
| 147 |
+
raise ValueError("Number of threads must be a positive integer.")
|
| 148 |
+
if no_match and not regex:
|
| 149 |
+
raise ValueError("--no-match requires --regex to be set.")
|
| 150 |
+
if url_to_annotation and provider != "URL":
|
| 151 |
+
raise ValueError("--URL-to-annotation can only be used with --provider URL.")
|
| 152 |
+
if local_path_to_annotation and provider != "Local":
|
| 153 |
+
raise ValueError("--Local-path-to-annotation can only be used with --provider Local.")
|
| 154 |
+
if ucsc_annotation and provider != "UCSC":
|
| 155 |
+
raise ValueError("--UCSC-annotation can only be used with --provider UCSC.")
|
| 156 |
+
if local_path_to_annotation and not Path(local_path_to_annotation).is_file():
|
| 157 |
+
raise FileNotFoundError(f"Local annotation file not found: {local_path_to_annotation}")
|
| 158 |
+
|
| 159 |
+
cmd_args = ["install", name_or_path_or_url]
|
| 160 |
+
|
| 161 |
+
if annotation:
|
| 162 |
+
cmd_args.append("--annotation")
|
| 163 |
+
if provider:
|
| 164 |
+
cmd_args.extend(["--provider", provider])
|
| 165 |
+
|
| 166 |
+
final_genomes_dir = genomes_dir if genomes_dir else Path.home() / ".local" / "share" / "genomes"
|
| 167 |
+
final_genomes_dir.mkdir(parents=True, exist_ok=True)
|
| 168 |
+
cmd_args.extend(["--genomes_dir", str(final_genomes_dir)])
|
| 169 |
+
|
| 170 |
+
if regex:
|
| 171 |
+
cmd_args.extend(["--regex", regex])
|
| 172 |
+
if no_match:
|
| 173 |
+
cmd_args.append("--no-match")
|
| 174 |
+
if mask != "soft":
|
| 175 |
+
cmd_args.extend(["--mask", mask])
|
| 176 |
+
if bgzip:
|
| 177 |
+
cmd_args.append("--bgzip")
|
| 178 |
+
if localname:
|
| 179 |
+
cmd_args.extend(["--localname", localname])
|
| 180 |
+
if url_to_annotation:
|
| 181 |
+
cmd_args.extend(["--URL-to-annotation", url_to_annotation])
|
| 182 |
+
if local_path_to_annotation:
|
| 183 |
+
cmd_args.extend(["--Local-path-to-annotation", str(local_path_to_annotation)])
|
| 184 |
+
if force:
|
| 185 |
+
cmd_args.append("--force")
|
| 186 |
+
if threads != 8:
|
| 187 |
+
cmd_args.extend(["--threads", str(threads)])
|
| 188 |
+
if ucsc_annotation:
|
| 189 |
+
cmd_args.extend(["--UCSC-annotation", ucsc_annotation])
|
| 190 |
+
|
| 191 |
+
# Determine the local name for the genome, which forms the subfolder name
|
| 192 |
+
genome_local_name: str
|
| 193 |
+
if localname:
|
| 194 |
+
genome_local_name = localname
|
| 195 |
+
elif provider in ["Local", "URL"]:
|
| 196 |
+
base_name = Path(name_or_path_or_url).name
|
| 197 |
+
# Remove common genome file extensions to get the base name genomepy uses for folders
|
| 198 |
+
suffixes_to_remove = [".fa.gz", ".fasta.gz", ".fa", ".fasta", ".tar.gz", ".tar"]
|
| 199 |
+
for suffix in suffixes_to_remove:
|
| 200 |
+
if base_name.endswith(suffix):
|
| 201 |
+
base_name = base_name[:-len(suffix)]
|
| 202 |
+
break
|
| 203 |
+
genome_local_name = base_name
|
| 204 |
+
else:
|
| 205 |
+
genome_local_name = name_or_path_or_url
|
| 206 |
+
|
| 207 |
+
# Predict potential output files
|
| 208 |
+
expected_output_paths: List[Path] = []
|
| 209 |
+
genome_output_folder = final_genomes_dir / genome_local_name
|
| 210 |
+
|
| 211 |
+
fasta_filename = f"{genome_local_name}.fa.gz" if bgzip else f"{genome_local_name}.fa"
|
| 212 |
+
expected_output_paths.append(genome_output_folder / fasta_filename)
|
| 213 |
+
expected_output_paths.append(genome_output_folder / f"{fasta_filename}.fai") # pyfaidx index
|
| 214 |
+
expected_output_paths.append(genome_output_folder / "README.txt") # Reproducibility file
|
| 215 |
+
|
| 216 |
+
if annotation:
|
| 217 |
+
expected_output_paths.append(genome_output_folder / f"{genome_local_name}.annotation.gtf")
|
| 218 |
+
expected_output_paths.append(genome_output_folder / f"{genome_local_name}.annotation.bed")
|
| 219 |
+
|
| 220 |
+
return _run_genomepy_command(cmd_args, expected_output_paths=expected_output_paths)
|
| 221 |
+
|
| 222 |
+
@mcp.tool()
|
| 223 |
+
def annotation(
|
| 224 |
+
genome_name: str,
|
| 225 |
+
provider: Optional[ProviderType] = None,
|
| 226 |
+
genomes_dir: Optional[Path] = None,
|
| 227 |
+
) -> Dict[str, Any]:
|
| 228 |
+
"""
|
| 229 |
+
Show the first lines of each available gene annotation for a specified genome.
|
| 230 |
+
|
| 231 |
+
Args:
|
| 232 |
+
genome_name: The name of the genome for which to inspect annotations.
|
| 233 |
+
provider: Limit to a specific provider.
|
| 234 |
+
genomes_dir: Directory where genomes are stored. Defaults to ~/.local/share/genomes/.
|
| 235 |
+
|
| 236 |
+
Returns:
|
| 237 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 238 |
+
"""
|
| 239 |
+
if not genome_name:
|
| 240 |
+
raise ValueError("Genome name cannot be empty.")
|
| 241 |
+
|
| 242 |
+
cmd_args = ["annotation", genome_name]
|
| 243 |
+
if provider:
|
| 244 |
+
cmd_args.extend(["--provider", provider])
|
| 245 |
+
if genomes_dir:
|
| 246 |
+
if not genomes_dir.is_dir():
|
| 247 |
+
raise FileNotFoundError(f"Genomes directory not found: {genomes_dir}")
|
| 248 |
+
cmd_args.extend(["--genomes_dir", str(genomes_dir)])
|
| 249 |
+
|
| 250 |
+
return _run_genomepy_command(cmd_args)
|
| 251 |
+
|
| 252 |
+
@mcp.tool()
|
| 253 |
+
def clean() -> Dict[str, Any]:
|
| 254 |
+
"""
|
| 255 |
+
Remove local provider data and cached genome lists.
|
| 256 |
+
|
| 257 |
+
Returns:
|
| 258 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 259 |
+
"""
|
| 260 |
+
return _run_genomepy_command(["clean"])
|
| 261 |
+
|
| 262 |
+
@mcp.tool()
|
| 263 |
+
def config_generate() -> Dict[str, Any]:
|
| 264 |
+
"""
|
| 265 |
+
Generate a default genomepy configuration file (~/.config/genomepy/genomepy.yaml).
|
| 266 |
+
|
| 267 |
+
Returns:
|
| 268 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 269 |
+
"""
|
| 270 |
+
config_file = Path.home() / ".config" / "genomepy" / "genomepy.yaml"
|
| 271 |
+
return _run_genomepy_command(["config", "generate"], expected_output_paths=[config_file])
|
| 272 |
+
|
| 273 |
+
@mcp.tool()
|
| 274 |
+
def genomes(
|
| 275 |
+
provider: Optional[ProviderType] = None,
|
| 276 |
+
size: bool = False,
|
| 277 |
+
) -> Dict[str, Any]:
|
| 278 |
+
"""
|
| 279 |
+
List available genomes, optionally filtered by provider and including genome sizes.
|
| 280 |
+
|
| 281 |
+
Args:
|
| 282 |
+
provider: Limit the genome list to a specific provider.
|
| 283 |
+
size: If True, get the absolute size of each genome (this option slows down the search).
|
| 284 |
+
|
| 285 |
+
Returns:
|
| 286 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 287 |
+
"""
|
| 288 |
+
cmd_args = ["genomes"]
|
| 289 |
+
if provider:
|
| 290 |
+
cmd_args.extend(["--provider", provider])
|
| 291 |
+
if size:
|
| 292 |
+
cmd_args.append("--size")
|
| 293 |
+
|
| 294 |
+
return _run_genomepy_command(cmd_args)
|
| 295 |
+
|
| 296 |
+
@mcp.tool()
|
| 297 |
+
def plugin_list() -> Dict[str, Any]:
|
| 298 |
+
"""
|
| 299 |
+
List currently enabled genomepy plugins.
|
| 300 |
+
|
| 301 |
+
Returns:
|
| 302 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 303 |
+
"""
|
| 304 |
+
return _run_genomepy_command(["plugin", "list"])
|
| 305 |
+
|
| 306 |
+
@mcp.tool()
|
| 307 |
+
def plugin_enable(
|
| 308 |
+
plugin_name: PluginName,
|
| 309 |
+
) -> Dict[str, Any]:
|
| 310 |
+
"""
|
| 311 |
+
Enable a genomepy plugin.
|
| 312 |
+
Plugins are optional steps executed after installing an assembly (e.g., blacklist, aligner indexes).
|
| 313 |
+
|
| 314 |
+
Args:
|
| 315 |
+
plugin_name: The name of the plugin to enable (e.g., "blacklist", "bwa", "star").
|
| 316 |
+
|
| 317 |
+
Returns:
|
| 318 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 319 |
+
"""
|
| 320 |
+
if not plugin_name:
|
| 321 |
+
raise ValueError("Plugin name cannot be empty.")
|
| 322 |
+
|
| 323 |
+
return _run_genomepy_command(["plugin", "enable", plugin_name])
|
| 324 |
+
|
| 325 |
+
@mcp.tool()
|
| 326 |
+
def plugin_disable(
|
| 327 |
+
plugin_name: PluginName,
|
| 328 |
+
) -> Dict[str, Any]:
|
| 329 |
+
"""
|
| 330 |
+
Disable a genomepy plugin.
|
| 331 |
+
|
| 332 |
+
Args:
|
| 333 |
+
plugin_name: The name of the plugin to disable.
|
| 334 |
+
|
| 335 |
+
Returns:
|
| 336 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 337 |
+
"""
|
| 338 |
+
if not plugin_name:
|
| 339 |
+
raise ValueError("Plugin name cannot be empty.")
|
| 340 |
+
|
| 341 |
+
return _run_genomepy_command(["plugin", "disable", plugin_name])
|
| 342 |
+
|
| 343 |
+
@mcp.tool()
|
| 344 |
+
def providers() -> Dict[str, Any]:
|
| 345 |
+
"""
|
| 346 |
+
List all available genome providers.
|
| 347 |
+
|
| 348 |
+
Returns:
|
| 349 |
+
A dictionary containing the command executed, stdout, stderr, and any output files.
|
| 350 |
+
"""
|
| 351 |
+
return _run_genomepy_command(["providers"])
|
| 352 |
+
|
| 353 |
+
if __name__ == "__main__":
|
| 354 |
+
mcp.run(transport="stdio")
|