Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_anarci/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_anarci/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_anarci/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_ariba/app/ariba_server.py +509 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_ariba/app/ariba_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/app/arvados-python-client_server.py +298 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/app/arvados-python-client_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_augur/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/bcbio-gff_server.py +192 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/bcbio-gff_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/app/__pycache__/bioblend_server.cpython-310.pyc +0 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/app/bioblend_server.py +111 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/app/bioblend_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/requirements.txt +3 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/app/bioconductor-affy_server.py +196 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/app/bioconductor-affy_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_server.py +213 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/app/bioconductor-biovizbase_server.py +437 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/app/bioconductor-biovizbase_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-bulksignalr/Dockerfile +40 -0
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_anarci/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 anarci via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda anarci -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/anarci_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/anarci_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/anarci_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_anarci/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_anarci/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_ariba/app/ariba_server.py
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
import os
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from typing import Optional, List, Literal
|
| 6 |
+
|
| 7 |
+
# MCP decorator is not needed for the final code, as per instructions.
|
| 8 |
+
# Assuming it's provided by the MCP framework.
|
| 9 |
+
# from mcp import tool as mcp_tool
|
| 10 |
+
# For linting purposes, we can create a dummy decorator.
|
| 11 |
+
class mcp:
|
| 12 |
+
def tool(func):
|
| 13 |
+
return func
|
| 14 |
+
|
| 15 |
+
@mcp.tool
|
| 16 |
+
def pubmlstget(
|
| 17 |
+
pubmlst_db: str,
|
| 18 |
+
outdir: Path,
|
| 19 |
+
force: bool = False,
|
| 20 |
+
noverify: bool = False,
|
| 21 |
+
):
|
| 22 |
+
"""
|
| 23 |
+
Download data from a pubmlst database.
|
| 24 |
+
|
| 25 |
+
Args:
|
| 26 |
+
pubmlst_db: Name of the pubmlst database to download.
|
| 27 |
+
outdir: Output directory to save the downloaded data.
|
| 28 |
+
force: Overwrite existing files if they exist.
|
| 29 |
+
noverify: Do not verify the SSL certificate.
|
| 30 |
+
"""
|
| 31 |
+
# Input validation
|
| 32 |
+
if not pubmlst_db:
|
| 33 |
+
raise ValueError("pubmlst_db must be provided.")
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
outdir.mkdir(parents=True, exist_ok=True)
|
| 37 |
+
except Exception as e:
|
| 38 |
+
raise IOError(f"Could not create output directory {outdir}: {e}")
|
| 39 |
+
|
| 40 |
+
# Command construction
|
| 41 |
+
cmd = ["ariba", "pubmlstget"]
|
| 42 |
+
if force:
|
| 43 |
+
cmd.append("--force")
|
| 44 |
+
if noverify:
|
| 45 |
+
cmd.append("--noverify")
|
| 46 |
+
cmd.extend([pubmlst_db, str(outdir)])
|
| 47 |
+
|
| 48 |
+
# Subprocess execution
|
| 49 |
+
try:
|
| 50 |
+
result = subprocess.run(
|
| 51 |
+
cmd,
|
| 52 |
+
check=True,
|
| 53 |
+
capture_output=True,
|
| 54 |
+
text=True,
|
| 55 |
+
)
|
| 56 |
+
output_files = [str(p) for p in outdir.rglob("*") if p.is_file()]
|
| 57 |
+
return {
|
| 58 |
+
"command_executed": " ".join(cmd),
|
| 59 |
+
"stdout": result.stdout,
|
| 60 |
+
"stderr": result.stderr,
|
| 61 |
+
"output_files": output_files,
|
| 62 |
+
}
|
| 63 |
+
except FileNotFoundError:
|
| 64 |
+
raise RuntimeError("ariba command not found. Please ensure it is in your PATH.")
|
| 65 |
+
except subprocess.CalledProcessError as e:
|
| 66 |
+
return {
|
| 67 |
+
"command_executed": " ".join(cmd),
|
| 68 |
+
"stdout": e.stdout,
|
| 69 |
+
"stderr": e.stderr,
|
| 70 |
+
"error": "ARIBA pubmlstget failed",
|
| 71 |
+
"return_code": e.returncode,
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
@mcp.tool
|
| 75 |
+
def getref(
|
| 76 |
+
ref_name: Literal[
|
| 77 |
+
"argannot", "card", "megares", "plasmidfinder", "resfinder",
|
| 78 |
+
"srst2_argannot", "vfdb_core", "vfdb_full", "virfinder"
|
| 79 |
+
],
|
| 80 |
+
outdir: Path,
|
| 81 |
+
force: bool = False,
|
| 82 |
+
metadata_only: bool = False,
|
| 83 |
+
):
|
| 84 |
+
"""
|
| 85 |
+
Download reference data from NCBI/RefSeq or other sources.
|
| 86 |
+
|
| 87 |
+
Args:
|
| 88 |
+
ref_name: Name of reference data to download.
|
| 89 |
+
outdir: Output directory to save the reference data.
|
| 90 |
+
force: Overwrite existing files if they exist.
|
| 91 |
+
metadata_only: Only download metadata, not the sequences.
|
| 92 |
+
"""
|
| 93 |
+
# Input validation
|
| 94 |
+
try:
|
| 95 |
+
outdir.mkdir(parents=True, exist_ok=True)
|
| 96 |
+
except Exception as e:
|
| 97 |
+
raise IOError(f"Could not create output directory {outdir}: {e}")
|
| 98 |
+
|
| 99 |
+
# Command construction
|
| 100 |
+
cmd = ["ariba", "getref"]
|
| 101 |
+
if force:
|
| 102 |
+
cmd.append("--force")
|
| 103 |
+
if metadata_only:
|
| 104 |
+
cmd.append("--metadata_only")
|
| 105 |
+
cmd.extend([ref_name, str(outdir)])
|
| 106 |
+
|
| 107 |
+
# Subprocess execution
|
| 108 |
+
try:
|
| 109 |
+
result = subprocess.run(
|
| 110 |
+
cmd,
|
| 111 |
+
check=True,
|
| 112 |
+
capture_output=True,
|
| 113 |
+
text=True,
|
| 114 |
+
)
|
| 115 |
+
output_files = [str(p) for p in outdir.rglob("*") if p.is_file()]
|
| 116 |
+
return {
|
| 117 |
+
"command_executed": " ".join(cmd),
|
| 118 |
+
"stdout": result.stdout,
|
| 119 |
+
"stderr": result.stderr,
|
| 120 |
+
"output_files": output_files,
|
| 121 |
+
}
|
| 122 |
+
except FileNotFoundError:
|
| 123 |
+
raise RuntimeError("ariba command not found. Please ensure it is in your PATH.")
|
| 124 |
+
except subprocess.CalledProcessError as e:
|
| 125 |
+
return {
|
| 126 |
+
"command_executed": " ".join(cmd),
|
| 127 |
+
"stdout": e.stdout,
|
| 128 |
+
"stderr": e.stderr,
|
| 129 |
+
"error": "ARIBA getref failed",
|
| 130 |
+
"return_code": e.returncode,
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
@mcp.tool
|
| 134 |
+
def prepareref(
|
| 135 |
+
fasta_in: Path,
|
| 136 |
+
metadata_in: Path,
|
| 137 |
+
outdir: Path,
|
| 138 |
+
min_length: int = 1,
|
| 139 |
+
max_length: int = 10000,
|
| 140 |
+
max_n: int = 5,
|
| 141 |
+
no_cdhit: bool = False,
|
| 142 |
+
cdhit_clusters: Optional[Path] = None,
|
| 143 |
+
cdhit_threads: int = 1,
|
| 144 |
+
cdhit_mem: int = 400,
|
| 145 |
+
force: bool = False,
|
| 146 |
+
tmp_dir: Optional[Path] = None,
|
| 147 |
+
verbose: bool = False,
|
| 148 |
+
debug: bool = False,
|
| 149 |
+
):
|
| 150 |
+
"""
|
| 151 |
+
Prepare reference data for use with ARIBA.
|
| 152 |
+
|
| 153 |
+
Args:
|
| 154 |
+
fasta_in: Input FASTA file of sequences.
|
| 155 |
+
metadata_in: Input TSV file of metadata.
|
| 156 |
+
outdir: Output directory for prepared reference.
|
| 157 |
+
min_length: Minimum sequence length.
|
| 158 |
+
max_length: Maximum sequence length.
|
| 159 |
+
max_n: Maximum number of Ns allowed in a sequence.
|
| 160 |
+
no_cdhit: Do not run cd-hit.
|
| 161 |
+
cdhit_clusters: File of cd-hit clusters. Implies --no_cdhit.
|
| 162 |
+
cdhit_threads: Threads to use for cd-hit.
|
| 163 |
+
cdhit_mem: Memory for cd-hit in MB.
|
| 164 |
+
force: Overwrite existing files.
|
| 165 |
+
tmp_dir: Use this directory for temporary files.
|
| 166 |
+
verbose: Print STDOUT and STDERR from external programs.
|
| 167 |
+
debug: Print debugging messages.
|
| 168 |
+
"""
|
| 169 |
+
# Input validation
|
| 170 |
+
if not fasta_in.is_file():
|
| 171 |
+
raise FileNotFoundError(f"Input FASTA file not found: {fasta_in}")
|
| 172 |
+
if not metadata_in.is_file():
|
| 173 |
+
raise FileNotFoundError(f"Input metadata file not found: {metadata_in}")
|
| 174 |
+
if cdhit_clusters and not cdhit_clusters.is_file():
|
| 175 |
+
raise FileNotFoundError(f"cd-hit clusters file not found: {cdhit_clusters}")
|
| 176 |
+
if min_length <= 0:
|
| 177 |
+
raise ValueError("min_length must be a positive integer.")
|
| 178 |
+
if cdhit_threads <= 0:
|
| 179 |
+
raise ValueError("cdhit_threads must be a positive integer.")
|
| 180 |
+
|
| 181 |
+
try:
|
| 182 |
+
outdir.mkdir(parents=True, exist_ok=True)
|
| 183 |
+
except Exception as e:
|
| 184 |
+
raise IOError(f"Could not create output directory {outdir}: {e}")
|
| 185 |
+
|
| 186 |
+
# Command construction
|
| 187 |
+
cmd = ["ariba", "prepareref",
|
| 188 |
+
"--fasta_in", str(fasta_in),
|
| 189 |
+
"--metadata_in", str(metadata_in),
|
| 190 |
+
"--outdir", str(outdir),
|
| 191 |
+
"--min_length", str(min_length),
|
| 192 |
+
"--max_length", str(max_length),
|
| 193 |
+
"--max_N", str(max_n),
|
| 194 |
+
"--cdhit_threads", str(cdhit_threads),
|
| 195 |
+
"--cdhit_mem", str(cdhit_mem)]
|
| 196 |
+
|
| 197 |
+
if no_cdhit:
|
| 198 |
+
cmd.append("--no_cdhit")
|
| 199 |
+
if cdhit_clusters:
|
| 200 |
+
cmd.extend(["--cdhit_clusters", str(cdhit_clusters)])
|
| 201 |
+
if force:
|
| 202 |
+
cmd.append("--force")
|
| 203 |
+
if tmp_dir:
|
| 204 |
+
cmd.extend(["--tmp_dir", str(tmp_dir)])
|
| 205 |
+
if verbose:
|
| 206 |
+
cmd.append("--verbose")
|
| 207 |
+
if debug:
|
| 208 |
+
cmd.append("--debug")
|
| 209 |
+
|
| 210 |
+
# Subprocess execution
|
| 211 |
+
try:
|
| 212 |
+
result = subprocess.run(
|
| 213 |
+
cmd,
|
| 214 |
+
check=True,
|
| 215 |
+
capture_output=True,
|
| 216 |
+
text=True,
|
| 217 |
+
)
|
| 218 |
+
output_files = [str(p) for p in outdir.rglob("*") if p.is_file()]
|
| 219 |
+
return {
|
| 220 |
+
"command_executed": " ".join(cmd),
|
| 221 |
+
"stdout": result.stdout,
|
| 222 |
+
"stderr": result.stderr,
|
| 223 |
+
"output_files": output_files,
|
| 224 |
+
}
|
| 225 |
+
except FileNotFoundError:
|
| 226 |
+
raise RuntimeError("ariba command not found. Please ensure it is in your PATH.")
|
| 227 |
+
except subprocess.CalledProcessError as e:
|
| 228 |
+
return {
|
| 229 |
+
"command_executed": " ".join(cmd),
|
| 230 |
+
"stdout": e.stdout,
|
| 231 |
+
"stderr": e.stderr,
|
| 232 |
+
"error": "ARIBA prepareref failed",
|
| 233 |
+
"return_code": e.returncode,
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
@mcp.tool
|
| 237 |
+
def run(
|
| 238 |
+
ref_dir: Path,
|
| 239 |
+
reads1: Path,
|
| 240 |
+
reads2: Path,
|
| 241 |
+
outdir: Path,
|
| 242 |
+
assembly_cov: int = 10,
|
| 243 |
+
gene_cov_cutoff: float = 0.95,
|
| 244 |
+
gene_nt_extend: int = 10,
|
| 245 |
+
local_th: float = 0.9,
|
| 246 |
+
min_gene_cov: int = 1,
|
| 247 |
+
assembled_threshold: float = 0.95,
|
| 248 |
+
nucmer_min_id: int = 90,
|
| 249 |
+
nucmer_min_len: int = 50,
|
| 250 |
+
nucmer_breaklen: int = 10,
|
| 251 |
+
nucmer_max_gap: int = 20,
|
| 252 |
+
assembler: Literal["fermilite", "spades"] = "fermilite",
|
| 253 |
+
spades_options: str = "--careful",
|
| 254 |
+
threads: int = 1,
|
| 255 |
+
force: bool = False,
|
| 256 |
+
tmp_dir: Optional[Path] = None,
|
| 257 |
+
verbose: bool = False,
|
| 258 |
+
debug: bool = False,
|
| 259 |
+
noclean: bool = False,
|
| 260 |
+
unique_map_only: bool = False,
|
| 261 |
+
other_ref_fasta: Optional[Path] = None,
|
| 262 |
+
filestem: Optional[str] = None,
|
| 263 |
+
):
|
| 264 |
+
"""
|
| 265 |
+
Run the main ARIBA pipeline to identify genes from paired sequencing reads.
|
| 266 |
+
|
| 267 |
+
Args:
|
| 268 |
+
ref_dir: Reference directory, created by 'prepareref'.
|
| 269 |
+
reads1: First paired-end reads file.
|
| 270 |
+
reads2: Second paired-end reads file.
|
| 271 |
+
outdir: Output directory for results.
|
| 272 |
+
assembly_cov: Minimum coverage of internal contig flank.
|
| 273 |
+
gene_cov_cutoff: Minimum proportion of gene length covered by reads.
|
| 274 |
+
gene_nt_extend: Max nucleotides to extend assembly past gene ends.
|
| 275 |
+
local_th: Minimum proportion of bases in local assembly identical to reference.
|
| 276 |
+
min_gene_cov: Minimum read coverage depth on any base of a gene.
|
| 277 |
+
assembled_threshold: Minimum proportion of bases in a gene covered by local assembly.
|
| 278 |
+
nucmer_min_id: nucmer --minid option.
|
| 279 |
+
nucmer_min_len: nucmer --mincluster option.
|
| 280 |
+
nucmer_breaklen: nucmer --breaklen option.
|
| 281 |
+
nucmer_max_gap: nucmer --maxgap option.
|
| 282 |
+
assembler: Assembler to use.
|
| 283 |
+
spades_options: Options to pass to spades.
|
| 284 |
+
threads: Number of threads to use.
|
| 285 |
+
force: Overwrite existing output files.
|
| 286 |
+
tmp_dir: Use this directory for temporary files.
|
| 287 |
+
verbose: Print STDOUT and STDERR from external programs.
|
| 288 |
+
debug: Print debugging messages.
|
| 289 |
+
noclean: Do not clean up intermediate files.
|
| 290 |
+
unique_map_only: Only use uniquely mapping reads.
|
| 291 |
+
other_ref_fasta: FASTA file of other reference sequences (e.g., host genome).
|
| 292 |
+
filestem: Filestem to use for output files.
|
| 293 |
+
"""
|
| 294 |
+
# Input validation
|
| 295 |
+
if not ref_dir.is_dir():
|
| 296 |
+
raise FileNotFoundError(f"Reference directory not found: {ref_dir}")
|
| 297 |
+
if not reads1.is_file():
|
| 298 |
+
raise FileNotFoundError(f"Reads file 1 not found: {reads1}")
|
| 299 |
+
if not reads2.is_file():
|
| 300 |
+
raise FileNotFoundError(f"Reads file 2 not found: {reads2}")
|
| 301 |
+
if other_ref_fasta and not other_ref_fasta.is_file():
|
| 302 |
+
raise FileNotFoundError(f"Other reference FASTA not found: {other_ref_fasta}")
|
| 303 |
+
if threads <= 0:
|
| 304 |
+
raise ValueError("threads must be a positive integer.")
|
| 305 |
+
|
| 306 |
+
try:
|
| 307 |
+
outdir.mkdir(parents=True, exist_ok=True)
|
| 308 |
+
except Exception as e:
|
| 309 |
+
raise IOError(f"Could not create output directory {outdir}: {e}")
|
| 310 |
+
|
| 311 |
+
# Command construction
|
| 312 |
+
cmd = ["ariba", "run",
|
| 313 |
+
"--assembly_cov", str(assembly_cov),
|
| 314 |
+
"--gene_cov_cutoff", str(gene_cov_cutoff),
|
| 315 |
+
"--gene_nt_extend", str(gene_nt_extend),
|
| 316 |
+
"--local_th", str(local_th),
|
| 317 |
+
"--min_gene_cov", str(min_gene_cov),
|
| 318 |
+
"--assembled_threshold", str(assembled_threshold),
|
| 319 |
+
"--nucmer_min_id", str(nucmer_min_id),
|
| 320 |
+
"--nucmer_min_len", str(nucmer_min_len),
|
| 321 |
+
"--nucmer_breaklen", str(nucmer_breaklen),
|
| 322 |
+
"--nucmer_max_gap", str(nucmer_max_gap),
|
| 323 |
+
"--assembler", assembler,
|
| 324 |
+
"--spades_options", spades_options,
|
| 325 |
+
"--threads", str(threads)]
|
| 326 |
+
|
| 327 |
+
if force: cmd.append("--force")
|
| 328 |
+
if verbose: cmd.append("--verbose")
|
| 329 |
+
if debug: cmd.append("--debug")
|
| 330 |
+
if noclean: cmd.append("--noclean")
|
| 331 |
+
if unique_map_only: cmd.append("--unique_map_only")
|
| 332 |
+
if tmp_dir: cmd.extend(["--tmp_dir", str(tmp_dir)])
|
| 333 |
+
if other_ref_fasta: cmd.extend(["--other_ref_fasta", str(other_ref_fasta)])
|
| 334 |
+
if filestem: cmd.extend(["--filestem", filestem])
|
| 335 |
+
|
| 336 |
+
cmd.extend([str(ref_dir), str(reads1), str(reads2), str(outdir)])
|
| 337 |
+
|
| 338 |
+
# Subprocess execution
|
| 339 |
+
try:
|
| 340 |
+
result = subprocess.run(
|
| 341 |
+
cmd,
|
| 342 |
+
check=True,
|
| 343 |
+
capture_output=True,
|
| 344 |
+
text=True,
|
| 345 |
+
)
|
| 346 |
+
output_files = [str(p) for p in outdir.rglob("*") if p.is_file()]
|
| 347 |
+
return {
|
| 348 |
+
"command_executed": " ".join(cmd),
|
| 349 |
+
"stdout": result.stdout,
|
| 350 |
+
"stderr": result.stderr,
|
| 351 |
+
"output_files": output_files,
|
| 352 |
+
}
|
| 353 |
+
except FileNotFoundError:
|
| 354 |
+
raise RuntimeError("ariba command not found. Please ensure it is in your PATH.")
|
| 355 |
+
except subprocess.CalledProcessError as e:
|
| 356 |
+
return {
|
| 357 |
+
"command_executed": " ".join(cmd),
|
| 358 |
+
"stdout": e.stdout,
|
| 359 |
+
"stderr": e.stderr,
|
| 360 |
+
"error": "ARIBA run failed",
|
| 361 |
+
"return_code": e.returncode,
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
@mcp.tool
|
| 365 |
+
def summary(
|
| 366 |
+
out_prefix: Path,
|
| 367 |
+
in_dirs: List[Path],
|
| 368 |
+
preset: Literal["all", "assembled", "flags", "variants"] = "all",
|
| 369 |
+
cluster_cols: Optional[str] = None,
|
| 370 |
+
col_sep: str = ".",
|
| 371 |
+
row_sep: str = ".",
|
| 372 |
+
force: bool = False,
|
| 373 |
+
verbose: bool = False,
|
| 374 |
+
debug: bool = False,
|
| 375 |
+
):
|
| 376 |
+
"""
|
| 377 |
+
Summarise multiple ARIBA reports into a single file.
|
| 378 |
+
|
| 379 |
+
Args:
|
| 380 |
+
out_prefix: Output file prefix.
|
| 381 |
+
in_dirs: List of directories containing ARIBA results.
|
| 382 |
+
preset: Output preset.
|
| 383 |
+
cluster_cols: Columns to use for clustering.
|
| 384 |
+
col_sep: Separator between column names in output file.
|
| 385 |
+
row_sep: Separator between sample name and cluster name in output file.
|
| 386 |
+
force: Overwrite existing files.
|
| 387 |
+
verbose: Print STDOUT and STDERR from external programs.
|
| 388 |
+
debug: Print debugging messages.
|
| 389 |
+
"""
|
| 390 |
+
# Input validation
|
| 391 |
+
if not in_dirs:
|
| 392 |
+
raise ValueError("At least one input directory must be provided in in_dirs.")
|
| 393 |
+
for d in in_dirs:
|
| 394 |
+
if not d.is_dir():
|
| 395 |
+
raise FileNotFoundError(f"Input directory not found: {d}")
|
| 396 |
+
report_path = d / "report.tsv"
|
| 397 |
+
if not report_path.is_file():
|
| 398 |
+
raise FileNotFoundError(f"Expected report file not found in {d}: {report_path}")
|
| 399 |
+
|
| 400 |
+
try:
|
| 401 |
+
out_prefix.parent.mkdir(parents=True, exist_ok=True)
|
| 402 |
+
except Exception as e:
|
| 403 |
+
raise IOError(f"Could not create output directory {out_prefix.parent}: {e}")
|
| 404 |
+
|
| 405 |
+
# Command construction
|
| 406 |
+
cmd = ["ariba", "summary",
|
| 407 |
+
"--preset", preset,
|
| 408 |
+
"--col_sep", col_sep,
|
| 409 |
+
"--row_sep", row_sep]
|
| 410 |
+
|
| 411 |
+
if cluster_cols:
|
| 412 |
+
cmd.extend(["--cluster_cols", cluster_cols])
|
| 413 |
+
if force:
|
| 414 |
+
cmd.append("--force")
|
| 415 |
+
if verbose:
|
| 416 |
+
cmd.append("--verbose")
|
| 417 |
+
if debug:
|
| 418 |
+
cmd.append("--debug")
|
| 419 |
+
|
| 420 |
+
cmd.append(str(out_prefix))
|
| 421 |
+
cmd.extend([str(d) for d in in_dirs])
|
| 422 |
+
|
| 423 |
+
# Subprocess execution
|
| 424 |
+
try:
|
| 425 |
+
result = subprocess.run(
|
| 426 |
+
cmd,
|
| 427 |
+
check=True,
|
| 428 |
+
capture_output=True,
|
| 429 |
+
text=True,
|
| 430 |
+
)
|
| 431 |
+
output_files = [str(p) for p in out_prefix.parent.glob(f"{out_prefix.name}*")]
|
| 432 |
+
return {
|
| 433 |
+
"command_executed": " ".join(cmd),
|
| 434 |
+
"stdout": result.stdout,
|
| 435 |
+
"stderr": result.stderr,
|
| 436 |
+
"output_files": output_files,
|
| 437 |
+
}
|
| 438 |
+
except FileNotFoundError:
|
| 439 |
+
raise RuntimeError("ariba command not found. Please ensure it is in your PATH.")
|
| 440 |
+
except subprocess.CalledProcessError as e:
|
| 441 |
+
return {
|
| 442 |
+
"command_executed": " ".join(cmd),
|
| 443 |
+
"stdout": e.stdout,
|
| 444 |
+
"stderr": e.stderr,
|
| 445 |
+
"error": "ARIBA summary failed",
|
| 446 |
+
"return_code": e.returncode,
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
@mcp.tool
|
| 450 |
+
def version():
|
| 451 |
+
"""
|
| 452 |
+
Print the ARIBA version number and exit.
|
| 453 |
+
"""
|
| 454 |
+
cmd = ["ariba", "version"]
|
| 455 |
+
try:
|
| 456 |
+
result = subprocess.run(
|
| 457 |
+
cmd,
|
| 458 |
+
check=True,
|
| 459 |
+
capture_output=True,
|
| 460 |
+
text=True,
|
| 461 |
+
)
|
| 462 |
+
return {
|
| 463 |
+
"command_executed": " ".join(cmd),
|
| 464 |
+
"stdout": result.stdout,
|
| 465 |
+
"stderr": result.stderr,
|
| 466 |
+
"version": result.stdout.strip(),
|
| 467 |
+
}
|
| 468 |
+
except FileNotFoundError:
|
| 469 |
+
raise RuntimeError("ariba command not found. Please ensure it is in your PATH.")
|
| 470 |
+
except subprocess.CalledProcessError as e:
|
| 471 |
+
return {
|
| 472 |
+
"command_executed": " ".join(cmd),
|
| 473 |
+
"stdout": e.stdout,
|
| 474 |
+
"stderr": e.stderr,
|
| 475 |
+
"error": "ARIBA version command failed",
|
| 476 |
+
"return_code": e.returncode,
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
@mcp.tool
|
| 480 |
+
def test():
|
| 481 |
+
"""
|
| 482 |
+
Run the ARIBA test suite to verify installation and functionality.
|
| 483 |
+
"""
|
| 484 |
+
cmd = ["ariba", "test"]
|
| 485 |
+
try:
|
| 486 |
+
# The test command can be long-running and produce a lot of output.
|
| 487 |
+
# We capture it as usual.
|
| 488 |
+
result = subprocess.run(
|
| 489 |
+
cmd,
|
| 490 |
+
check=True,
|
| 491 |
+
capture_output=True,
|
| 492 |
+
text=True,
|
| 493 |
+
)
|
| 494 |
+
return {
|
| 495 |
+
"command_executed": " ".join(cmd),
|
| 496 |
+
"stdout": result.stdout,
|
| 497 |
+
"stderr": result.stderr,
|
| 498 |
+
"test_passed": "OK" in result.stderr,
|
| 499 |
+
}
|
| 500 |
+
except FileNotFoundError:
|
| 501 |
+
raise RuntimeError("ariba command not found. Please ensure it is in your PATH.")
|
| 502 |
+
except subprocess.CalledProcessError as e:
|
| 503 |
+
return {
|
| 504 |
+
"command_executed": " ".join(cmd),
|
| 505 |
+
"stdout": e.stdout,
|
| 506 |
+
"stderr": e.stderr,
|
| 507 |
+
"error": "ARIBA test suite failed",
|
| 508 |
+
"return_code": e.returncode,
|
| 509 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_ariba/app/ariba_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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_ariba/app/ariba_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_ariba'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/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 arvados-python-client via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda arvados-python-client -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/arvados-python-client_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/arvados-python-client_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/arvados-python-client_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/app/arvados-python-client_server.py
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import List, Optional
|
| 5 |
+
|
| 6 |
+
# MCP-standardized error handling
|
| 7 |
+
class MCPError(Exception):
|
| 8 |
+
def __init__(self, message, stderr):
|
| 9 |
+
self.message = message
|
| 10 |
+
self.stderr = stderr
|
| 11 |
+
super().__init__(self.message)
|
| 12 |
+
|
| 13 |
+
def _run_command(cmd: List[str]):
|
| 14 |
+
"""Helper function to run a command and handle exceptions."""
|
| 15 |
+
try:
|
| 16 |
+
command_str = " ".join(cmd)
|
| 17 |
+
result = subprocess.run(
|
| 18 |
+
cmd,
|
| 19 |
+
capture_output=True,
|
| 20 |
+
text=True,
|
| 21 |
+
check=True,
|
| 22 |
+
)
|
| 23 |
+
return {
|
| 24 |
+
"command_executed": command_str,
|
| 25 |
+
"stdout": result.stdout,
|
| 26 |
+
"stderr": result.stderr,
|
| 27 |
+
}
|
| 28 |
+
except FileNotFoundError:
|
| 29 |
+
raise MCPError(f"Command '{cmd[0]}' not found. Is arvados-python-client installed and in the PATH?", "")
|
| 30 |
+
except subprocess.CalledProcessError as e:
|
| 31 |
+
raise MCPError(f"Command '{' '.join(cmd)}' failed with exit code {e.returncode}", e.stderr)
|
| 32 |
+
|
| 33 |
+
@mcp.tool()
|
| 34 |
+
def arv_get(
|
| 35 |
+
object_locator: str,
|
| 36 |
+
destination_path: Optional[Path] = None,
|
| 37 |
+
filename: Optional[str] = None,
|
| 38 |
+
force: bool = False,
|
| 39 |
+
recursive: bool = False,
|
| 40 |
+
progress: bool = False,
|
| 41 |
+
) -> dict:
|
| 42 |
+
"""
|
| 43 |
+
Downloads an object from Arvados Keep to a local path or standard output.
|
| 44 |
+
|
| 45 |
+
Args:
|
| 46 |
+
object_locator: The UUID or portable data hash (PDH) of the object to download.
|
| 47 |
+
destination_path: Local path to save the object. If a directory, the original filename is used. If not provided, content is written to stdout.
|
| 48 |
+
filename: The name of the file to get from a collection.
|
| 49 |
+
force: Overwrite existing files if they exist.
|
| 50 |
+
recursive: Recursively download collections.
|
| 51 |
+
progress: Show a progress bar during download.
|
| 52 |
+
|
| 53 |
+
Returns:
|
| 54 |
+
A dictionary containing the command executed, stdout, stderr, and a list of output files.
|
| 55 |
+
"""
|
| 56 |
+
cmd = ["arv-get"]
|
| 57 |
+
|
| 58 |
+
if force:
|
| 59 |
+
cmd.append("--force")
|
| 60 |
+
if recursive:
|
| 61 |
+
cmd.append("--recursive")
|
| 62 |
+
if progress:
|
| 63 |
+
cmd.append("--progress")
|
| 64 |
+
if filename:
|
| 65 |
+
cmd.extend(["--filename", filename])
|
| 66 |
+
|
| 67 |
+
cmd.append(object_locator)
|
| 68 |
+
|
| 69 |
+
output_files = []
|
| 70 |
+
if destination_path:
|
| 71 |
+
# Ensure parent directory exists if a full path is given
|
| 72 |
+
if destination_path.parent and not destination_path.parent.is_dir():
|
| 73 |
+
destination_path.parent.mkdir(parents=True, exist_ok=True)
|
| 74 |
+
cmd.append(str(destination_path))
|
| 75 |
+
output_files.append(str(destination_path))
|
| 76 |
+
|
| 77 |
+
try:
|
| 78 |
+
result = _run_command(cmd)
|
| 79 |
+
result["output_files"] = output_files
|
| 80 |
+
return result
|
| 81 |
+
except MCPError as e:
|
| 82 |
+
return {
|
| 83 |
+
"command_executed": " ".join(cmd),
|
| 84 |
+
"stdout": "",
|
| 85 |
+
"stderr": e.stderr,
|
| 86 |
+
"error": e.message,
|
| 87 |
+
"output_files": [],
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
@mcp.tool()
|
| 91 |
+
def arv_put(
|
| 92 |
+
paths: List[Path],
|
| 93 |
+
name: Optional[str] = None,
|
| 94 |
+
owner: Optional[str] = None,
|
| 95 |
+
portable_data_hash: bool = False,
|
| 96 |
+
storage_class: Optional[str] = None,
|
| 97 |
+
num_retries: int = 5,
|
| 98 |
+
progress: bool = False,
|
| 99 |
+
) -> dict:
|
| 100 |
+
"""
|
| 101 |
+
Uploads local files or directories to Arvados Keep.
|
| 102 |
+
|
| 103 |
+
Args:
|
| 104 |
+
paths: One or more local file or directory paths to upload.
|
| 105 |
+
name: Set the name of the new collection.
|
| 106 |
+
owner: Set the owner project UUID for the new collection.
|
| 107 |
+
portable_data_hash: Use portable data hash to identify the collection.
|
| 108 |
+
storage_class: The storage class for the data (e.g., 'default', 'trash').
|
| 109 |
+
num_retries: Number of times to retry a failed API call.
|
| 110 |
+
progress: Show a progress bar during upload.
|
| 111 |
+
|
| 112 |
+
Returns:
|
| 113 |
+
A dictionary containing the command executed, stdout, and stderr.
|
| 114 |
+
"""
|
| 115 |
+
if not paths:
|
| 116 |
+
raise ValueError("At least one path must be provided for upload.")
|
| 117 |
+
|
| 118 |
+
for p in paths:
|
| 119 |
+
if not p.exists():
|
| 120 |
+
raise FileNotFoundError(f"Input path does not exist: {p}")
|
| 121 |
+
|
| 122 |
+
cmd = ["arv-put"]
|
| 123 |
+
|
| 124 |
+
if name:
|
| 125 |
+
cmd.extend(["--name", name])
|
| 126 |
+
if owner:
|
| 127 |
+
cmd.extend(["--owner", owner])
|
| 128 |
+
if portable_data_hash:
|
| 129 |
+
cmd.append("--portable-data-hash")
|
| 130 |
+
if storage_class:
|
| 131 |
+
cmd.extend(["--storage-class", storage_class])
|
| 132 |
+
if progress:
|
| 133 |
+
cmd.append("--progress")
|
| 134 |
+
|
| 135 |
+
# num_retries is a standard arvados client option
|
| 136 |
+
cmd.extend(["--num-retries", str(num_retries)])
|
| 137 |
+
|
| 138 |
+
cmd.extend([str(p) for p in paths])
|
| 139 |
+
|
| 140 |
+
try:
|
| 141 |
+
result = _run_command(cmd)
|
| 142 |
+
result["output_files"] = []
|
| 143 |
+
return result
|
| 144 |
+
except MCPError as e:
|
| 145 |
+
return {
|
| 146 |
+
"command_executed": " ".join(cmd),
|
| 147 |
+
"stdout": "",
|
| 148 |
+
"stderr": e.stderr,
|
| 149 |
+
"error": e.message,
|
| 150 |
+
"output_files": [],
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
@mcp.tool()
|
| 154 |
+
def arv_ls(
|
| 155 |
+
object_locator: str,
|
| 156 |
+
path: Optional[str] = None,
|
| 157 |
+
long_format: bool = False,
|
| 158 |
+
recursive: bool = False,
|
| 159 |
+
human_readable: bool = False,
|
| 160 |
+
) -> dict:
|
| 161 |
+
"""
|
| 162 |
+
Lists the contents of a collection in Arvados Keep.
|
| 163 |
+
|
| 164 |
+
Args:
|
| 165 |
+
object_locator: The UUID or portable data hash (PDH) of the collection to list.
|
| 166 |
+
path: A path within the collection to list.
|
| 167 |
+
long_format: Use a long listing format (similar to ls -l).
|
| 168 |
+
recursive: List subdirectories recursively.
|
| 169 |
+
human_readable: With long_format, print sizes in human-readable format (e.g., 1K, 234M, 2G).
|
| 170 |
+
|
| 171 |
+
Returns:
|
| 172 |
+
A dictionary containing the command executed, stdout (the listing), and stderr.
|
| 173 |
+
"""
|
| 174 |
+
cmd = ["arv-ls"]
|
| 175 |
+
|
| 176 |
+
if long_format:
|
| 177 |
+
cmd.append("-l")
|
| 178 |
+
if recursive:
|
| 179 |
+
cmd.append("-R")
|
| 180 |
+
if human_readable:
|
| 181 |
+
cmd.append("-h")
|
| 182 |
+
|
| 183 |
+
cmd.append(object_locator)
|
| 184 |
+
if path:
|
| 185 |
+
cmd.append(path)
|
| 186 |
+
|
| 187 |
+
try:
|
| 188 |
+
result = _run_command(cmd)
|
| 189 |
+
result["output_files"] = []
|
| 190 |
+
return result
|
| 191 |
+
except MCPError as e:
|
| 192 |
+
return {
|
| 193 |
+
"command_executed": " ".join(cmd),
|
| 194 |
+
"stdout": "",
|
| 195 |
+
"stderr": e.stderr,
|
| 196 |
+
"error": e.message,
|
| 197 |
+
"output_files": [],
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
@mcp.tool()
|
| 201 |
+
def arv_copy(
|
| 202 |
+
src_locators: List[str],
|
| 203 |
+
dest_project_uuid: str,
|
| 204 |
+
name: Optional[str] = None,
|
| 205 |
+
num_retries: int = 5,
|
| 206 |
+
) -> dict:
|
| 207 |
+
"""
|
| 208 |
+
Copies one or more objects to a destination project in Arvados.
|
| 209 |
+
|
| 210 |
+
Args:
|
| 211 |
+
src_locators: A list of source object UUIDs or portable data hashes (PDHs).
|
| 212 |
+
dest_project_uuid: The UUID of the destination project.
|
| 213 |
+
name: New name for the object(s). If copying multiple objects, this is ignored.
|
| 214 |
+
num_retries: Number of times to retry a failed API call.
|
| 215 |
+
|
| 216 |
+
Returns:
|
| 217 |
+
A dictionary containing the command executed, stdout, and stderr.
|
| 218 |
+
"""
|
| 219 |
+
if not src_locators:
|
| 220 |
+
raise ValueError("At least one source locator must be provided.")
|
| 221 |
+
if not dest_project_uuid:
|
| 222 |
+
raise ValueError("A destination project UUID must be provided.")
|
| 223 |
+
|
| 224 |
+
cmd = ["arv-copy"]
|
| 225 |
+
|
| 226 |
+
if name and len(src_locators) == 1:
|
| 227 |
+
cmd.extend(["--name", name])
|
| 228 |
+
|
| 229 |
+
cmd.extend(["--num-retries", str(num_retries)])
|
| 230 |
+
|
| 231 |
+
cmd.extend(src_locators)
|
| 232 |
+
cmd.append(dest_project_uuid)
|
| 233 |
+
|
| 234 |
+
try:
|
| 235 |
+
result = _run_command(cmd)
|
| 236 |
+
result["output_files"] = []
|
| 237 |
+
return result
|
| 238 |
+
except MCPError as e:
|
| 239 |
+
return {
|
| 240 |
+
"command_executed": " ".join(cmd),
|
| 241 |
+
"stdout": "",
|
| 242 |
+
"stderr": e.stderr,
|
| 243 |
+
"error": e.message,
|
| 244 |
+
"output_files": [],
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
@mcp.tool()
|
| 248 |
+
def arv_tag(
|
| 249 |
+
locator: str,
|
| 250 |
+
tags_to_add: Optional[List[str]] = None,
|
| 251 |
+
keys_to_remove: Optional[List[str]] = None,
|
| 252 |
+
list_tags: bool = False,
|
| 253 |
+
num_retries: int = 5,
|
| 254 |
+
) -> dict:
|
| 255 |
+
"""
|
| 256 |
+
Manipulates tags on an Arvados object. It can list, add, or remove tags.
|
| 257 |
+
|
| 258 |
+
Args:
|
| 259 |
+
locator: The UUID or portable data hash (PDH) of the object to tag.
|
| 260 |
+
tags_to_add: A list of tags to add, in 'key' or 'key=value' format.
|
| 261 |
+
keys_to_remove: A list of tag keys to remove.
|
| 262 |
+
list_tags: If True, lists the existing tags on the object.
|
| 263 |
+
num_retries: Number of times to retry a failed API call.
|
| 264 |
+
|
| 265 |
+
Returns:
|
| 266 |
+
A dictionary containing the command executed, stdout, and stderr.
|
| 267 |
+
"""
|
| 268 |
+
cmd = ["arv-tag"]
|
| 269 |
+
|
| 270 |
+
cmd.extend(["--num-retries", str(num_retries)])
|
| 271 |
+
|
| 272 |
+
if list_tags:
|
| 273 |
+
cmd.append("--list")
|
| 274 |
+
|
| 275 |
+
cmd.append(locator)
|
| 276 |
+
|
| 277 |
+
if tags_to_add:
|
| 278 |
+
for tag in tags_to_add:
|
| 279 |
+
if "=" not in tag and " " in tag:
|
| 280 |
+
raise ValueError(f"Invalid tag format: '{tag}'. Use 'key=value' or 'key'.")
|
| 281 |
+
cmd.extend(tags_to_add)
|
| 282 |
+
|
| 283 |
+
if keys_to_remove:
|
| 284 |
+
for key in keys_to_remove:
|
| 285 |
+
cmd.extend(["--remove", key])
|
| 286 |
+
|
| 287 |
+
try:
|
| 288 |
+
result = _run_command(cmd)
|
| 289 |
+
result["output_files"] = []
|
| 290 |
+
return result
|
| 291 |
+
except MCPError as e:
|
| 292 |
+
return {
|
| 293 |
+
"command_executed": " ".join(cmd),
|
| 294 |
+
"stdout": "",
|
| 295 |
+
"stderr": e.stderr,
|
| 296 |
+
"error": e.message,
|
| 297 |
+
"output_files": [],
|
| 298 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/app/arvados-python-client_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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_arvados-python-client/app/arvados-python-client_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_arvados_python_client'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-arvados-python-client:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-arvados-python-client:latest
|
| 7 |
+
container_name: mcp-arvados-python-client
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=arvados-python-client
|
| 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 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- arvados-python-client
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_arvados-python-client/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_augur/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/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 bcbio-gff via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bcbio-gff -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/bcbio-gff_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/bcbio-gff_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/bcbio-gff_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/bcbio-gff_server.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import List, Dict
|
| 5 |
+
|
| 6 |
+
# Note: The 'bcbio-gff' package is primarily a Python library. It also
|
| 7 |
+
# installs several command-line utility scripts. The documentation provided
|
| 8 |
+
# did not include the '--help' output for these scripts. The following MCP
|
| 9 |
+
# tools are based on inferred, common-sense arguments for these utilities.
|
| 10 |
+
# The actual command-line interface may differ.
|
| 11 |
+
|
| 12 |
+
@mcp.tool()
|
| 13 |
+
def gff_to_bed(
|
| 14 |
+
gff_file: Path
|
| 15 |
+
) -> Dict:
|
| 16 |
+
"""
|
| 17 |
+
Converts a GFF file to a BED file using `gff_to_bed.py`.
|
| 18 |
+
|
| 19 |
+
This tool assumes the script takes a single GFF file as input and prints
|
| 20 |
+
the resulting BED formatted data to standard output.
|
| 21 |
+
"""
|
| 22 |
+
if not gff_file.is_file():
|
| 23 |
+
raise FileNotFoundError(f"Input GFF file not found: {gff_file}")
|
| 24 |
+
|
| 25 |
+
cmd = ["gff_to_bed.py", str(gff_file)]
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
result = subprocess.run(
|
| 29 |
+
cmd,
|
| 30 |
+
capture_output=True,
|
| 31 |
+
text=True,
|
| 32 |
+
check=True
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
with tempfile.NamedTemporaryFile(
|
| 36 |
+
mode="w", delete=False, suffix=".bed", prefix="output_"
|
| 37 |
+
) as tmp_out:
|
| 38 |
+
tmp_out.write(result.stdout)
|
| 39 |
+
output_path = tmp_out.name
|
| 40 |
+
|
| 41 |
+
return {
|
| 42 |
+
"command_executed": " ".join(cmd),
|
| 43 |
+
"stdout": result.stdout,
|
| 44 |
+
"stderr": result.stderr,
|
| 45 |
+
"output_files": [output_path]
|
| 46 |
+
}
|
| 47 |
+
except FileNotFoundError:
|
| 48 |
+
raise RuntimeError("gff_to_bed.py not found. Ensure bcbio-gff scripts are in your PATH.")
|
| 49 |
+
except subprocess.CalledProcessError as e:
|
| 50 |
+
return {
|
| 51 |
+
"command_executed": " ".join(e.cmd),
|
| 52 |
+
"stdout": e.stdout,
|
| 53 |
+
"stderr": e.stderr,
|
| 54 |
+
"output_files": [],
|
| 55 |
+
"error": "Tool execution failed."
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
@mcp.tool()
|
| 59 |
+
def gff_filter_by_attribute(
|
| 60 |
+
gff_file: Path,
|
| 61 |
+
attribute_key: str,
|
| 62 |
+
attribute_value: str
|
| 63 |
+
) -> Dict:
|
| 64 |
+
"""
|
| 65 |
+
Filters a GFF file by a given attribute key-value pair using `gff_filter_by_attribute.py`.
|
| 66 |
+
|
| 67 |
+
This tool assumes the script takes an attribute key, an attribute value, and an
|
| 68 |
+
input GFF file as arguments, and prints the filtered GFF to standard output.
|
| 69 |
+
"""
|
| 70 |
+
if not gff_file.is_file():
|
| 71 |
+
raise FileNotFoundError(f"Input GFF file not found: {gff_file}")
|
| 72 |
+
|
| 73 |
+
cmd = ["gff_filter_by_attribute.py", attribute_key, attribute_value, str(gff_file)]
|
| 74 |
+
|
| 75 |
+
try:
|
| 76 |
+
result = subprocess.run(
|
| 77 |
+
cmd,
|
| 78 |
+
capture_output=True,
|
| 79 |
+
text=True,
|
| 80 |
+
check=True
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
with tempfile.NamedTemporaryFile(
|
| 84 |
+
mode="w", delete=False, suffix=".gff", prefix="filtered_"
|
| 85 |
+
) as tmp_out:
|
| 86 |
+
tmp_out.write(result.stdout)
|
| 87 |
+
output_path = tmp_out.name
|
| 88 |
+
|
| 89 |
+
return {
|
| 90 |
+
"command_executed": " ".join(cmd),
|
| 91 |
+
"stdout": result.stdout,
|
| 92 |
+
"stderr": result.stderr,
|
| 93 |
+
"output_files": [output_path]
|
| 94 |
+
}
|
| 95 |
+
except FileNotFoundError:
|
| 96 |
+
raise RuntimeError("gff_filter_by_attribute.py not found. Ensure bcbio-gff scripts are in your PATH.")
|
| 97 |
+
except subprocess.CalledProcessError as e:
|
| 98 |
+
return {
|
| 99 |
+
"command_executed": " ".join(e.cmd),
|
| 100 |
+
"stdout": e.stdout,
|
| 101 |
+
"stderr": e.stderr,
|
| 102 |
+
"output_files": [],
|
| 103 |
+
"error": "Tool execution failed."
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
@mcp.tool()
|
| 107 |
+
def gff_filter_by_type(
|
| 108 |
+
gff_file: Path,
|
| 109 |
+
feature_type: str
|
| 110 |
+
) -> Dict:
|
| 111 |
+
"""
|
| 112 |
+
Filters a GFF file by a feature type (e.g., 'gene', 'mRNA') using `gff_filter_by_type.py`.
|
| 113 |
+
|
| 114 |
+
This tool assumes the script takes an input GFF file and a feature type as
|
| 115 |
+
arguments, and prints the filtered GFF to standard output.
|
| 116 |
+
"""
|
| 117 |
+
if not gff_file.is_file():
|
| 118 |
+
raise FileNotFoundError(f"Input GFF file not found: {gff_file}")
|
| 119 |
+
|
| 120 |
+
cmd = ["gff_filter_by_type.py", str(gff_file), feature_type]
|
| 121 |
+
|
| 122 |
+
try:
|
| 123 |
+
result = subprocess.run(
|
| 124 |
+
cmd,
|
| 125 |
+
capture_output=True,
|
| 126 |
+
text=True,
|
| 127 |
+
check=True
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
with tempfile.NamedTemporaryFile(
|
| 131 |
+
mode="w", delete=False, suffix=".gff", prefix="filtered_type_"
|
| 132 |
+
) as tmp_out:
|
| 133 |
+
tmp_out.write(result.stdout)
|
| 134 |
+
output_path = tmp_out.name
|
| 135 |
+
|
| 136 |
+
return {
|
| 137 |
+
"command_executed": " ".join(cmd),
|
| 138 |
+
"stdout": result.stdout,
|
| 139 |
+
"stderr": result.stderr,
|
| 140 |
+
"output_files": [output_path]
|
| 141 |
+
}
|
| 142 |
+
except FileNotFoundError:
|
| 143 |
+
raise RuntimeError("gff_filter_by_type.py not found. Ensure bcbio-gff scripts are in your PATH.")
|
| 144 |
+
except subprocess.CalledProcessError as e:
|
| 145 |
+
return {
|
| 146 |
+
"command_executed": " ".join(e.cmd),
|
| 147 |
+
"stdout": e.stdout,
|
| 148 |
+
"stderr": e.stderr,
|
| 149 |
+
"output_files": [],
|
| 150 |
+
"error": "Tool execution failed."
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
@mcp.tool()
|
| 154 |
+
def gff_stats(
|
| 155 |
+
gff_file: Path
|
| 156 |
+
) -> Dict:
|
| 157 |
+
"""
|
| 158 |
+
Calculates statistics on features in a GFF file using `gff_stats.py`.
|
| 159 |
+
|
| 160 |
+
This tool assumes the script takes a single GFF file as input and prints
|
| 161 |
+
statistics to standard output.
|
| 162 |
+
"""
|
| 163 |
+
if not gff_file.is_file():
|
| 164 |
+
raise FileNotFoundError(f"Input GFF file not found: {gff_file}")
|
| 165 |
+
|
| 166 |
+
cmd = ["gff_stats.py", str(gff_file)]
|
| 167 |
+
|
| 168 |
+
try:
|
| 169 |
+
result = subprocess.run(
|
| 170 |
+
cmd,
|
| 171 |
+
capture_output=True,
|
| 172 |
+
text=True,
|
| 173 |
+
check=True
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
# The output is statistics text, not a structured file, so we return it directly.
|
| 177 |
+
return {
|
| 178 |
+
"command_executed": " ".join(cmd),
|
| 179 |
+
"stdout": result.stdout,
|
| 180 |
+
"stderr": result.stderr,
|
| 181 |
+
"output_files": []
|
| 182 |
+
}
|
| 183 |
+
except FileNotFoundError:
|
| 184 |
+
raise RuntimeError("gff_stats.py not found. Ensure bcbio-gff scripts are in your PATH.")
|
| 185 |
+
except subprocess.CalledProcessError as e:
|
| 186 |
+
return {
|
| 187 |
+
"command_executed": " ".join(e.cmd),
|
| 188 |
+
"stdout": e.stdout,
|
| 189 |
+
"stderr": e.stderr,
|
| 190 |
+
"output_files": [],
|
| 191 |
+
"error": "Tool execution failed."
|
| 192 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/bcbio-gff_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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_bcbio-gff/app/bcbio-gff_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bcbio_gff'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bcbio-gff:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bcbio-gff:latest
|
| 7 |
+
container_name: mcp-bcbio-gff
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bcbio-gff
|
| 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 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bcbio-gff
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bcbio-gff/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/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 bioblend via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioblend -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/bioblend_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/bioblend_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/bioblend_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/app/__pycache__/bioblend_server.cpython-310.pyc
ADDED
|
Binary file (3.52 kB). View file
|
|
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/app/bioblend_server.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import subprocess
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Dict, List, Optional
|
| 5 |
+
|
| 6 |
+
# In a real MCP environment, the 'mcp' object would be imported.
|
| 7 |
+
# For this standalone script, we define a dummy decorator.
|
| 8 |
+
class mcp:
|
| 9 |
+
@staticmethod
|
| 10 |
+
def tool(func):
|
| 11 |
+
return func
|
| 12 |
+
|
| 13 |
+
# Since bioblend is a library, we will need to ensure it is installed
|
| 14 |
+
# in the execution environment. We can simulate a check for it.
|
| 15 |
+
try:
|
| 16 |
+
from bioblend.galaxy import GalaxyInstance
|
| 17 |
+
from bioblend.galaxy.client import Client
|
| 18 |
+
from bioblend.connection import BioBlendConnectionError
|
| 19 |
+
except ImportError:
|
| 20 |
+
raise ImportError("The 'bioblend' library is required to use this tool. Please install it via 'pip install bioblend'.")
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
@mcp.tool
|
| 24 |
+
def upload_to_galaxy(
|
| 25 |
+
galaxy_url: str,
|
| 26 |
+
api_key: str,
|
| 27 |
+
history_id: str,
|
| 28 |
+
file_path: Path,
|
| 29 |
+
file_type: str = "auto",
|
| 30 |
+
dbkey: str = "?",
|
| 31 |
+
to_posix_lines: bool = True,
|
| 32 |
+
space_to_tab: bool = False,
|
| 33 |
+
) -> Dict:
|
| 34 |
+
"""
|
| 35 |
+
Uploads a dataset to a specified Galaxy history using the bioblend library.
|
| 36 |
+
|
| 37 |
+
This tool acts as a wrapper around the bioblend library's file upload
|
| 38 |
+
functionality, providing a way to programmatically add datasets to a
|
| 39 |
+
Galaxy server from the MCP framework.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
galaxy_url (str): The URL of the Galaxy instance (e.g., 'https://usegalaxy.org').
|
| 43 |
+
api_key (str): Your Galaxy API key for authentication.
|
| 44 |
+
history_id (str): The ID of the history to which the file will be uploaded.
|
| 45 |
+
file_path (Path): The local path to the file to upload.
|
| 46 |
+
file_type (str): The Galaxy datatype for the uploaded file. Defaults to 'auto'.
|
| 47 |
+
dbkey (str): The genome build (dbkey) to associate with the dataset. Defaults to '?'.
|
| 48 |
+
to_posix_lines (bool): If True, convert line endings to POSIX standard. Defaults to True.
|
| 49 |
+
space_to_tab (bool): If True, convert all spaces to tabs in the uploaded file. Defaults to False.
|
| 50 |
+
|
| 51 |
+
Returns:
|
| 52 |
+
Dict: A dictionary containing the execution details and results, including
|
| 53 |
+
the response from the Galaxy API upon successful upload.
|
| 54 |
+
"""
|
| 55 |
+
# --- Input Validation ---
|
| 56 |
+
if not galaxy_url:
|
| 57 |
+
raise ValueError("galaxy_url must be provided.")
|
| 58 |
+
if not api_key:
|
| 59 |
+
raise ValueError("api_key must be provided.")
|
| 60 |
+
if not history_id:
|
| 61 |
+
raise ValueError("history_id must be provided.")
|
| 62 |
+
|
| 63 |
+
if not file_path.is_file():
|
| 64 |
+
raise FileNotFoundError(f"Input file not found at: {file_path}")
|
| 65 |
+
|
| 66 |
+
# This tool uses the bioblend library directly, not a command-line subprocess.
|
| 67 |
+
# The 'command_executed' will represent the library call for logging purposes.
|
| 68 |
+
command_executed = (
|
| 69 |
+
f"bioblend.tools.upload_file(file_path='{file_path}', "
|
| 70 |
+
f"history_id='{history_id}', file_type='{file_type}', dbkey='{dbkey}', "
|
| 71 |
+
f"to_posix_lines={to_posix_lines}, space_to_tab={space_to_tab})"
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
stdout_str = ""
|
| 75 |
+
stderr_str = ""
|
| 76 |
+
output_data = {}
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
# --- Tool Execution ---
|
| 80 |
+
# Instantiate the Galaxy client
|
| 81 |
+
galaxy_instance = GalaxyInstance(url=galaxy_url, key=api_key)
|
| 82 |
+
|
| 83 |
+
# Execute the file upload
|
| 84 |
+
upload_result = galaxy_instance.tools.upload_file(
|
| 85 |
+
str(file_path),
|
| 86 |
+
history_id,
|
| 87 |
+
file_type=file_type,
|
| 88 |
+
dbkey=dbkey,
|
| 89 |
+
to_posix_lines=to_posix_lines,
|
| 90 |
+
space_to_tab=space_to_tab,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# Format the successful output
|
| 94 |
+
stdout_str = json.dumps(upload_result, indent=2)
|
| 95 |
+
output_data = upload_result
|
| 96 |
+
|
| 97 |
+
except BioBlendConnectionError as e:
|
| 98 |
+
stderr_str = f"Connection Error: Failed to connect to Galaxy at {galaxy_url}. Details: {e}"
|
| 99 |
+
raise RuntimeError(stderr_str) from e
|
| 100 |
+
except Exception as e:
|
| 101 |
+
# Catch other potential exceptions from the library call
|
| 102 |
+
stderr_str = f"An unexpected error occurred during the bioblend operation: {e}"
|
| 103 |
+
raise RuntimeError(stderr_str) from e
|
| 104 |
+
|
| 105 |
+
return {
|
| 106 |
+
"command_executed": command_executed,
|
| 107 |
+
"stdout": stdout_str,
|
| 108 |
+
"stderr": stderr_str,
|
| 109 |
+
"output_data": output_data,
|
| 110 |
+
"output_files": [] # Output is on the remote Galaxy server, not a local file
|
| 111 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/app/bioblend_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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_bioblend/app/bioblend_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bioblend'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
bioblend==1.9.0
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioblend:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioblend:latest
|
| 7 |
+
container_name: mcp-bioblend
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioblend
|
| 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 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioblend
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioblend/requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
bioblend==1.9.0
|
| 2 |
+
fastmcp
|
| 3 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-affy via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-affy -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/bioconductor-affy_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-affy_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-affy_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/app/bioconductor-affy_server.py
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Optional, Dict, List
|
| 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 |
+
# In a real scenario, the MCP framework would handle
|
| 11 |
+
# registration and execution.
|
| 12 |
+
return func(*args, **kwargs)
|
| 13 |
+
return wrapper
|
| 14 |
+
mcp = type("mcp", (), {"tool": tool})
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@mcp.tool
|
| 18 |
+
def run_affy_analysis(
|
| 19 |
+
cel_files_dir: Path,
|
| 20 |
+
output_expression_file: Path,
|
| 21 |
+
method: str = "rma",
|
| 22 |
+
pheno_data_file: Optional[Path] = None,
|
| 23 |
+
generate_qc_plot: bool = False,
|
| 24 |
+
qc_plot_file: Optional[Path] = None,
|
| 25 |
+
) -> Dict:
|
| 26 |
+
"""
|
| 27 |
+
Performs exploratory analysis of Affymetrix oligonucleotide arrays.
|
| 28 |
+
|
| 29 |
+
This tool reads raw Affymetrix data from .CEL files, performs background
|
| 30 |
+
correction, normalization, and probe summarization using either the RMA
|
| 31 |
+
(Robust Multi-array Average) or MAS 5.0 algorithm, and outputs a matrix
|
| 32 |
+
of expression values.
|
| 33 |
+
|
| 34 |
+
Args:
|
| 35 |
+
cel_files_dir: Path to the directory containing the input .CEL files.
|
| 36 |
+
output_expression_file: Path to write the output expression matrix (tab-separated).
|
| 37 |
+
method: The processing method to use. Must be one of 'rma' or 'mas5'.
|
| 38 |
+
Defaults to 'rma'.
|
| 39 |
+
pheno_data_file: Optional path to a phenodata file describing the samples.
|
| 40 |
+
This should be a tab-delimited file with row names matching
|
| 41 |
+
the .CEL file names.
|
| 42 |
+
generate_qc_plot: If True, generate a quality control boxplot of the raw
|
| 43 |
+
probe intensities. Defaults to False.
|
| 44 |
+
qc_plot_file: Path to save the QC plot image (e.g., plot.png).
|
| 45 |
+
Required if generate_qc_plot is True.
|
| 46 |
+
|
| 47 |
+
Returns:
|
| 48 |
+
A dictionary containing the executed command, stdout, stderr, and a
|
| 49 |
+
list of output files.
|
| 50 |
+
"""
|
| 51 |
+
# 1. Input Validation
|
| 52 |
+
if not cel_files_dir.is_dir():
|
| 53 |
+
raise ValueError(f"Input directory '{cel_files_dir}' does not exist or is not a directory.")
|
| 54 |
+
|
| 55 |
+
if pheno_data_file and not pheno_data_file.is_file():
|
| 56 |
+
raise FileNotFoundError(f"Phenodata file '{pheno_data_file}' not found.")
|
| 57 |
+
|
| 58 |
+
method_lower = method.lower()
|
| 59 |
+
if method_lower not in ["rma", "mas5"]:
|
| 60 |
+
raise ValueError(f"Invalid method '{method}'. Must be 'rma' or 'mas5'.")
|
| 61 |
+
|
| 62 |
+
if generate_qc_plot:
|
| 63 |
+
if qc_plot_file is None:
|
| 64 |
+
raise ValueError("qc_plot_file must be provided when generate_qc_plot is True.")
|
| 65 |
+
if not qc_plot_file.parent.exists():
|
| 66 |
+
qc_plot_file.parent.mkdir(parents=True, exist_ok=True)
|
| 67 |
+
elif qc_plot_file is not None:
|
| 68 |
+
print(f"Warning: qc_plot_file '{qc_plot_file}' is specified but generate_qc_plot is False. The file will not be created.")
|
| 69 |
+
|
| 70 |
+
if not output_expression_file.parent.exists():
|
| 71 |
+
output_expression_file.parent.mkdir(parents=True, exist_ok=True)
|
| 72 |
+
|
| 73 |
+
# 2. R Script Generation
|
| 74 |
+
# This script will be executed by Rscript to perform the analysis.
|
| 75 |
+
r_script_content = f"""
|
| 76 |
+
# Load necessary libraries
|
| 77 |
+
if (!requireNamespace("affy", quietly = TRUE)) {{
|
| 78 |
+
stop("The 'affy' package is not installed. Please install it from Bioconductor.")
|
| 79 |
+
}}
|
| 80 |
+
library(affy)
|
| 81 |
+
|
| 82 |
+
# Parse command-line arguments
|
| 83 |
+
args <- commandArgs(trailingOnly = TRUE)
|
| 84 |
+
if (length(args) < 3) {{
|
| 85 |
+
stop("Usage: Rscript script.R <cel_dir> <output_path> <method> [pheno_path_or_NA] [plot_path_or_NA]", call. = FALSE)
|
| 86 |
+
}}
|
| 87 |
+
|
| 88 |
+
cel_dir <- args[1]
|
| 89 |
+
output_path <- args[2]
|
| 90 |
+
method <- args[3]
|
| 91 |
+
pheno_path <- if (length(args) >= 4 && args[4] != "NA") args[4] else NULL
|
| 92 |
+
plot_path <- if (length(args) >= 5 && args[5] != "NA") args[5] else NULL
|
| 93 |
+
|
| 94 |
+
# --- Main Logic ---
|
| 95 |
+
tryCatch({{
|
| 96 |
+
# Read the data
|
| 97 |
+
cat("Reading CEL files from:", cel_dir, "\\n")
|
| 98 |
+
if (!is.null(pheno_path)) {{
|
| 99 |
+
cat("Using pheno data from:", pheno_path, "\\n")
|
| 100 |
+
# read.AnnotatedDataFrame is deprecated, using read.phenoData is more modern
|
| 101 |
+
pheno <- read.phenoData(pheno_path, header = TRUE, row.names = 1)
|
| 102 |
+
data <- ReadAffy(celfile.path = cel_dir, phenoData = pheno)
|
| 103 |
+
}} else {{
|
| 104 |
+
data <- ReadAffy(celfile.path = cel_dir)
|
| 105 |
+
}}
|
| 106 |
+
cat("Finished reading data.\\n")
|
| 107 |
+
|
| 108 |
+
# Process the data
|
| 109 |
+
cat("Processing data with method:", method, "\\n")
|
| 110 |
+
if (method == "rma") {{
|
| 111 |
+
eset <- rma(data)
|
| 112 |
+
}} else if (method == "mas5") {{
|
| 113 |
+
eset <- mas5(data)
|
| 114 |
+
}} else {{
|
| 115 |
+
stop(paste("Invalid method specified:", method))
|
| 116 |
+
}}
|
| 117 |
+
cat("Finished processing.\\n")
|
| 118 |
+
|
| 119 |
+
# Extract and write expression values
|
| 120 |
+
cat("Writing expression matrix to:", output_path, "\\n")
|
| 121 |
+
expression_matrix <- exprs(eset)
|
| 122 |
+
write.table(expression_matrix, file = output_path, sep = "\\t", quote = FALSE, col.names = NA)
|
| 123 |
+
cat("Done writing expression matrix.\\n")
|
| 124 |
+
|
| 125 |
+
# Generate QC plot if requested
|
| 126 |
+
if (!is.null(plot_path)) {{
|
| 127 |
+
cat("Generating QC plot at:", plot_path, "\\n")
|
| 128 |
+
png(filename = plot_path, width = 800, height = 600)
|
| 129 |
+
boxplot(data, main = "Raw Probe Intensities", las = 2, col="lightblue")
|
| 130 |
+
dev.off()
|
| 131 |
+
cat("Done generating plot.\\n")
|
| 132 |
+
}}
|
| 133 |
+
|
| 134 |
+
cat("Analysis complete.\\n")
|
| 135 |
+
}}, error = function(e) {{
|
| 136 |
+
cat("An error occurred:\\n")
|
| 137 |
+
cat(conditionMessage(e), "\\n")
|
| 138 |
+
quit(status = 1)
|
| 139 |
+
}})
|
| 140 |
+
"""
|
| 141 |
+
|
| 142 |
+
# 3. Subprocess Execution
|
| 143 |
+
output_files = {"expression_matrix": str(output_expression_file)}
|
| 144 |
+
cmd = ["Rscript"]
|
| 145 |
+
|
| 146 |
+
try:
|
| 147 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix=".R") as r_script_file:
|
| 148 |
+
r_script_file.write(r_script_content)
|
| 149 |
+
r_script_path = r_script_file.name
|
| 150 |
+
|
| 151 |
+
# Prepare arguments for the R script
|
| 152 |
+
pheno_path_arg = str(pheno_data_file.resolve()) if pheno_data_file else "NA"
|
| 153 |
+
plot_path_arg = str(qc_plot_file.resolve()) if generate_qc_plot and qc_plot_file else "NA"
|
| 154 |
+
|
| 155 |
+
cmd.extend([
|
| 156 |
+
r_script_path,
|
| 157 |
+
str(cel_files_dir.resolve()),
|
| 158 |
+
str(output_expression_file.resolve()),
|
| 159 |
+
method_lower,
|
| 160 |
+
pheno_path_arg,
|
| 161 |
+
plot_path_arg
|
| 162 |
+
])
|
| 163 |
+
|
| 164 |
+
# Execute the command
|
| 165 |
+
process = subprocess.run(
|
| 166 |
+
cmd,
|
| 167 |
+
check=True,
|
| 168 |
+
capture_output=True,
|
| 169 |
+
text=True
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
if generate_qc_plot and qc_plot_file:
|
| 173 |
+
output_files["qc_plot"] = str(qc_plot_file)
|
| 174 |
+
|
| 175 |
+
return {
|
| 176 |
+
"command_executed": " ".join(cmd),
|
| 177 |
+
"stdout": process.stdout,
|
| 178 |
+
"stderr": process.stderr,
|
| 179 |
+
"output_files": output_files
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
except subprocess.CalledProcessError as e:
|
| 183 |
+
return {
|
| 184 |
+
"command_executed": " ".join(cmd),
|
| 185 |
+
"stdout": e.stdout,
|
| 186 |
+
"stderr": e.stderr,
|
| 187 |
+
"error": "R script execution failed.",
|
| 188 |
+
"return_code": e.returncode,
|
| 189 |
+
"output_files": {}
|
| 190 |
+
}
|
| 191 |
+
except Exception as e:
|
| 192 |
+
raise e
|
| 193 |
+
finally:
|
| 194 |
+
# Clean up the temporary R script file
|
| 195 |
+
if 'r_script_path' in locals() and Path(r_script_path).exists():
|
| 196 |
+
Path(r_script_path).unlink()
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/app/bioconductor-affy_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/app/bioconductor-affy_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bioconductor_affy'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-affy:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-affy:latest
|
| 7 |
+
container_name: mcp-bioconductor-affy
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-affy
|
| 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 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-affy
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-affy/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-alabaster.sfe via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-alabaster.sfe -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/bioconductor-alabaster.sfe_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-alabaster.sfe_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-alabaster.sfe_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_server.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import logging
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Dict, Any, Optional
|
| 5 |
+
|
| 6 |
+
# It is assumed that the mcp decorator is available in the execution environment.
|
| 7 |
+
# from mcp import tool
|
| 8 |
+
|
| 9 |
+
# Mock decorator for local testing, not to be included in the final deliverable
|
| 10 |
+
# if 'mcp' not in globals():
|
| 11 |
+
# class mcp:
|
| 12 |
+
# @staticmethod
|
| 13 |
+
# def tool():
|
| 14 |
+
# def decorator(func):
|
| 15 |
+
# return func
|
| 16 |
+
# return decorator
|
| 17 |
+
|
| 18 |
+
logger = logging.getLogger(__name__)
|
| 19 |
+
|
| 20 |
+
@mcp.tool()
|
| 21 |
+
def stage_sfe_object(
|
| 22 |
+
input_rds: Path,
|
| 23 |
+
output_dir: Path,
|
| 24 |
+
path: str = "sfe",
|
| 25 |
+
) -> Dict[str, Any]:
|
| 26 |
+
"""
|
| 27 |
+
Stages a SpatialFeatureExperiment (SFE) object from an RDS file into the alabaster format.
|
| 28 |
+
|
| 29 |
+
This tool wraps the 'stageObject' function from the R package 'alabaster.sfe'.
|
| 30 |
+
It reads an SFE object from a specified RDS file and saves it into a structured
|
| 31 |
+
directory according to the alabaster specification. This serves as the primary
|
| 32 |
+
"save" or "serialize" function for SFE objects in the alabaster framework.
|
| 33 |
+
|
| 34 |
+
Args:
|
| 35 |
+
input_rds: Path to the input RDS file containing the SpatialFeatureExperiment object.
|
| 36 |
+
output_dir: Path to the directory where the staged object assets will be stored.
|
| 37 |
+
path: The relative path within 'output_dir' to save the object. Defaults to "sfe".
|
| 38 |
+
|
| 39 |
+
Returns:
|
| 40 |
+
A dictionary containing the execution details and the path to the main output metadata file.
|
| 41 |
+
"""
|
| 42 |
+
# 1. Input Validation
|
| 43 |
+
if not input_rds.is_file():
|
| 44 |
+
raise FileNotFoundError(f"Input RDS file not found at: {input_rds}")
|
| 45 |
+
|
| 46 |
+
if not path:
|
| 47 |
+
raise ValueError("'path' cannot be an empty string.")
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 51 |
+
except OSError as e:
|
| 52 |
+
raise OSError(f"Failed to create output directory {output_dir}: {e}")
|
| 53 |
+
|
| 54 |
+
# 2. R script construction
|
| 55 |
+
r_script_content = f"""
|
| 56 |
+
suppressPackageStartupMessages(library(alabaster.sfe))
|
| 57 |
+
suppressPackageStartupMessages(library(SpatialFeatureExperiment))
|
| 58 |
+
|
| 59 |
+
tryCatch({{
|
| 60 |
+
sfe_object <- readRDS('{input_rds.resolve()}')
|
| 61 |
+
info <- alabaster.base::stageObject(sfe_object, dir = '{output_dir.resolve()}', path = '{path}')
|
| 62 |
+
cat(file.path('{output_dir.resolve()}', info$path, "object.json"))
|
| 63 |
+
}}, error = function(e) {{
|
| 64 |
+
message("Error during R script execution: ", e$message)
|
| 65 |
+
quit(status = 1)
|
| 66 |
+
}})
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
# 3. Subprocess Execution
|
| 70 |
+
cmd = ["Rscript", "-e", r_script_content]
|
| 71 |
+
command_executed = " ".join(map(str, cmd))
|
| 72 |
+
logger.info(f"Executing command: {command_executed}")
|
| 73 |
+
|
| 74 |
+
try:
|
| 75 |
+
process = subprocess.run(
|
| 76 |
+
cmd,
|
| 77 |
+
check=True,
|
| 78 |
+
capture_output=True,
|
| 79 |
+
text=True,
|
| 80 |
+
encoding='utf-8'
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
stdout = process.stdout.strip()
|
| 84 |
+
stderr = process.stderr.strip()
|
| 85 |
+
|
| 86 |
+
main_output_file = Path(stdout)
|
| 87 |
+
if not main_output_file.is_file():
|
| 88 |
+
raise FileNotFoundError(
|
| 89 |
+
f"Expected output file not created: {main_output_file}. R stderr: {stderr}"
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
return {
|
| 93 |
+
"command_executed": command_executed,
|
| 94 |
+
"stdout": stdout,
|
| 95 |
+
"stderr": stderr,
|
| 96 |
+
"output_files": {
|
| 97 |
+
"staged_object_json": str(main_output_file)
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
except FileNotFoundError:
|
| 102 |
+
error_msg = "Error: 'Rscript' command not found. Please ensure R is installed and in your system's PATH."
|
| 103 |
+
logger.error(error_msg)
|
| 104 |
+
raise RuntimeError(error_msg) from None
|
| 105 |
+
except subprocess.CalledProcessError as e:
|
| 106 |
+
logger.error(f"Command failed with exit code {e.returncode}")
|
| 107 |
+
logger.error(f"STDOUT: {e.stdout}")
|
| 108 |
+
logger.error(f"STDERR: {e.stderr}")
|
| 109 |
+
raise RuntimeError(
|
| 110 |
+
f"R script execution failed with exit code {e.returncode}.\n"
|
| 111 |
+
f"STDOUT: {e.stdout}\n"
|
| 112 |
+
f"STDERR: {e.stderr}"
|
| 113 |
+
) from e
|
| 114 |
+
|
| 115 |
+
@mcp.tool()
|
| 116 |
+
def load_sfe_object(
|
| 117 |
+
staged_dir: Path,
|
| 118 |
+
output_rds: Path,
|
| 119 |
+
path: str = "",
|
| 120 |
+
) -> Dict[str, Any]:
|
| 121 |
+
"""
|
| 122 |
+
Loads a SpatialFeatureExperiment (SFE) object from the alabaster format into an RDS file.
|
| 123 |
+
|
| 124 |
+
This tool wraps the 'loadObject' function from the R package 'alabaster.base'.
|
| 125 |
+
It reads an SFE object from a staged directory, reconstructs it in memory, and
|
| 126 |
+
saves the complete object as a single RDS file. This is the "load" or "deserialize"
|
| 127 |
+
counterpart to the staging function.
|
| 128 |
+
|
| 129 |
+
Args:
|
| 130 |
+
staged_dir: Path to the directory containing the staged object assets.
|
| 131 |
+
output_rds: Path for the output RDS file where the loaded SFE object will be saved.
|
| 132 |
+
path: The relative path within 'staged_dir' where the object's 'object.json' is located.
|
| 133 |
+
If empty, it's assumed to be at the root of 'staged_dir'.
|
| 134 |
+
|
| 135 |
+
Returns:
|
| 136 |
+
A dictionary containing the execution details and the path to the output RDS file.
|
| 137 |
+
"""
|
| 138 |
+
# 1. Input Validation
|
| 139 |
+
if not staged_dir.is_dir():
|
| 140 |
+
raise NotADirectoryError(f"Staged asset directory not found at: {staged_dir}")
|
| 141 |
+
|
| 142 |
+
metadata_json_path = staged_dir.joinpath(path, "object.json")
|
| 143 |
+
if not metadata_json_path.is_file():
|
| 144 |
+
raise FileNotFoundError(f"Metadata file 'object.json' not found at: {metadata_json_path}")
|
| 145 |
+
|
| 146 |
+
try:
|
| 147 |
+
output_rds.parent.mkdir(parents=True, exist_ok=True)
|
| 148 |
+
except OSError as e:
|
| 149 |
+
raise OSError(f"Failed to create output directory {output_rds.parent}: {e}")
|
| 150 |
+
|
| 151 |
+
# 2. R script construction
|
| 152 |
+
r_script_content = f"""
|
| 153 |
+
suppressPackageStartupMessages(library(alabaster.sfe))
|
| 154 |
+
suppressPackageStartupMessages(library(SpatialFeatureExperiment))
|
| 155 |
+
|
| 156 |
+
tryCatch({{
|
| 157 |
+
sfe_object <- alabaster.base::loadObject(
|
| 158 |
+
'{metadata_json_path.resolve()}',
|
| 159 |
+
project = '{staged_dir.resolve()}'
|
| 160 |
+
)
|
| 161 |
+
saveRDS(sfe_object, file = '{output_rds.resolve()}')
|
| 162 |
+
cat('{output_rds.resolve()}')
|
| 163 |
+
}}, error = function(e) {{
|
| 164 |
+
message("Error during R script execution: ", e$message)
|
| 165 |
+
quit(status = 1)
|
| 166 |
+
}})
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
# 3. Subprocess Execution
|
| 170 |
+
cmd = ["Rscript", "-e", r_script_content]
|
| 171 |
+
command_executed = " ".join(map(str, cmd))
|
| 172 |
+
logger.info(f"Executing command: {command_executed}")
|
| 173 |
+
|
| 174 |
+
try:
|
| 175 |
+
process = subprocess.run(
|
| 176 |
+
cmd,
|
| 177 |
+
check=True,
|
| 178 |
+
capture_output=True,
|
| 179 |
+
text=True,
|
| 180 |
+
encoding='utf-8'
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
stdout = process.stdout.strip()
|
| 184 |
+
stderr = process.stderr.strip()
|
| 185 |
+
|
| 186 |
+
output_file = Path(stdout)
|
| 187 |
+
if not output_file.is_file() or output_file != output_rds.resolve():
|
| 188 |
+
raise FileNotFoundError(
|
| 189 |
+
f"Expected output RDS file not created at {output_rds}. R stderr: {stderr}"
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
return {
|
| 193 |
+
"command_executed": command_executed,
|
| 194 |
+
"stdout": stdout,
|
| 195 |
+
"stderr": stderr,
|
| 196 |
+
"output_files": {
|
| 197 |
+
"output_rds": str(output_file)
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
except FileNotFoundError:
|
| 202 |
+
error_msg = "Error: 'Rscript' command not found. Please ensure R is installed and in your system's PATH."
|
| 203 |
+
logger.error(error_msg)
|
| 204 |
+
raise RuntimeError(error_msg) from None
|
| 205 |
+
except subprocess.CalledProcessError as e:
|
| 206 |
+
logger.error(f"Command failed with exit code {e.returncode}")
|
| 207 |
+
logger.error(f"STDOUT: {e.stdout}")
|
| 208 |
+
logger.error(f"STDERR: {e.stderr}")
|
| 209 |
+
raise RuntimeError(
|
| 210 |
+
f"R script execution failed with exit code {e.returncode}.\n"
|
| 211 |
+
f"STDOUT: {e.stdout}\n"
|
| 212 |
+
f"STDERR: {e.stderr}"
|
| 213 |
+
) from e
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/app/bioconductor-alabaster.sfe_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bioconductor_alabaster_sfe'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-alabaster.sfe:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-alabaster.sfe:latest
|
| 7 |
+
container_name: mcp-bioconductor-alabaster.sfe
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-alabaster.sfe
|
| 12 |
+
volumes:
|
| 13 |
+
- ./workspace:/app/workspace
|
| 14 |
+
- ./output:/app/output
|
| 15 |
+
restart: unless-stopped
|
| 16 |
+
healthcheck:
|
| 17 |
+
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
|
| 18 |
+
interval: 30s
|
| 19 |
+
timeout: 10s
|
| 20 |
+
retries: 3
|
| 21 |
+
start_period: 5s
|
| 22 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-alabaster.sfe
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-alabaster.sfe/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-biovizbase via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-biovizbase -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/bioconductor-biovizbase_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-biovizbase_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-biovizbase_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/app/bioconductor-biovizbase_server.py
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List
|
| 4 |
+
import tempfile
|
| 5 |
+
import json
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
# NOTE: The @mcp.tool decorator is a placeholder for the actual MCP decorator.
|
| 9 |
+
# This code is designed to be used within an MCP environment where `mcp` is defined.
|
| 10 |
+
|
| 11 |
+
class mcp:
|
| 12 |
+
"""Placeholder for MCP decorator for standalone validation."""
|
| 13 |
+
@staticmethod
|
| 14 |
+
def tool():
|
| 15 |
+
def decorator(f):
|
| 16 |
+
return f
|
| 17 |
+
return decorator
|
| 18 |
+
|
| 19 |
+
@mcp.tool()
|
| 20 |
+
def biovizbase_get_ideogram(
|
| 21 |
+
genome: str,
|
| 22 |
+
cytoband: bool = True,
|
| 23 |
+
sub_set: Optional[str] = None,
|
| 24 |
+
output_csv: Optional[str] = None
|
| 25 |
+
) -> dict:
|
| 26 |
+
"""
|
| 27 |
+
Fetches chromosome ideogram data for a specified genome build from UCSC.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
genome: Genome build name (e.g., 'hg19', 'mm10'). Must be a valid UCSC genome.
|
| 31 |
+
cytoband: If True, includes cytoband information in the ideogram.
|
| 32 |
+
sub_set: Optional comma-separated list of chromosomes to include (e.g., 'chr1,chr2').
|
| 33 |
+
output_csv: Optional path to save the ideogram data as a CSV file. If not provided, a temporary file will be used.
|
| 34 |
+
|
| 35 |
+
Returns:
|
| 36 |
+
A dictionary containing the command executed, stdout, stderr, and a list of output files.
|
| 37 |
+
"""
|
| 38 |
+
if not genome:
|
| 39 |
+
raise ValueError("The 'genome' parameter cannot be empty.")
|
| 40 |
+
|
| 41 |
+
out_path = Path(output_csv) if output_csv else Path(tempfile.mktemp(suffix=".csv"))
|
| 42 |
+
|
| 43 |
+
subset_code = "sub_set = NULL"
|
| 44 |
+
if sub_set:
|
| 45 |
+
# Format the subset string for R: 'chr1,chr2' -> 'c("chr1", "chr2")'
|
| 46 |
+
formatted_sub_set = ','.join([f'"{s.strip()}"' for s in sub_set.split(',')])
|
| 47 |
+
subset_code = f"sub_set = c({formatted_sub_set})"
|
| 48 |
+
|
| 49 |
+
r_script = f"""
|
| 50 |
+
library(biovizBase)
|
| 51 |
+
{subset_code}
|
| 52 |
+
ideogram <- getIdeogram(genome = "{genome}", cytoband = {str(cytoband).upper()}, sub_set = sub_set)
|
| 53 |
+
write.csv(as.data.frame(ideogram), file = "{out_path}", row.names = FALSE)
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
command = ["Rscript", "-e", r_script]
|
| 57 |
+
command_executed = f"Rscript -e '{r_script.strip()}'"
|
| 58 |
+
|
| 59 |
+
try:
|
| 60 |
+
result = subprocess.run(
|
| 61 |
+
command,
|
| 62 |
+
capture_output=True,
|
| 63 |
+
text=True,
|
| 64 |
+
check=True
|
| 65 |
+
)
|
| 66 |
+
return {
|
| 67 |
+
"command_executed": command_executed,
|
| 68 |
+
"stdout": result.stdout,
|
| 69 |
+
"stderr": result.stderr,
|
| 70 |
+
"output_files": [str(out_path)] if out_path.exists() else []
|
| 71 |
+
}
|
| 72 |
+
except subprocess.CalledProcessError as e:
|
| 73 |
+
return {
|
| 74 |
+
"command_executed": command_executed,
|
| 75 |
+
"stdout": e.stdout,
|
| 76 |
+
"stderr": e.stderr,
|
| 77 |
+
"output_files": []
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
@mcp.tool()
|
| 81 |
+
def biovizbase_crunch(
|
| 82 |
+
input_file: str,
|
| 83 |
+
file_format: str,
|
| 84 |
+
which_range: Optional[str] = None,
|
| 85 |
+
output_csv: Optional[str] = None
|
| 86 |
+
) -> dict:
|
| 87 |
+
"""
|
| 88 |
+
Transforms genomic data (e.g., BAM, BED, GTF) into a format suitable for visualization by summarizing ranges.
|
| 89 |
+
|
| 90 |
+
Args:
|
| 91 |
+
input_file: Path to the input genomic data file.
|
| 92 |
+
file_format: Format of the input file (e.g., 'bam', 'bed', 'gtf', 'gff').
|
| 93 |
+
which_range: Genomic range to process, in 'chr:start-end' format (e.g., 'chr1:1000-2000').
|
| 94 |
+
output_csv: Optional path to save the crunched data as a CSV file.
|
| 95 |
+
|
| 96 |
+
Returns:
|
| 97 |
+
A dictionary containing the command executed, stdout, stderr, and a list of output files.
|
| 98 |
+
"""
|
| 99 |
+
input_path = Path(input_file)
|
| 100 |
+
if not input_path.exists():
|
| 101 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 102 |
+
|
| 103 |
+
if which_range and not re.match(r'^\w+:\d+-\d+$', which_range):
|
| 104 |
+
raise ValueError("The 'which_range' parameter must be in the format 'chr:start-end'.")
|
| 105 |
+
|
| 106 |
+
out_path = Path(output_csv) if output_csv else Path(tempfile.mktemp(suffix=".csv"))
|
| 107 |
+
|
| 108 |
+
range_code = ""
|
| 109 |
+
if which_range:
|
| 110 |
+
chrom, coords = which_range.split(':')
|
| 111 |
+
start, end = coords.split('-')
|
| 112 |
+
range_code = f', which = GRanges("{chrom}", IRanges({start}, {end}))'
|
| 113 |
+
|
| 114 |
+
r_script = f"""
|
| 115 |
+
library(biovizBase)
|
| 116 |
+
library(GenomicRanges)
|
| 117 |
+
library(rtracklayer)
|
| 118 |
+
|
| 119 |
+
if ("{file_format.lower()}" == "bam") {{
|
| 120 |
+
library(Rsamtools)
|
| 121 |
+
data <- readGAlignments("{input_path}")
|
| 122 |
+
}} else {{
|
| 123 |
+
data <- import("{input_path}", format = "{file_format.lower()}")
|
| 124 |
+
}}
|
| 125 |
+
|
| 126 |
+
res <- crunch(data{range_code})
|
| 127 |
+
write.csv(as.data.frame(res), file = "{out_path}", row.names = FALSE)
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
command = ["Rscript", "-e", r_script]
|
| 131 |
+
command_executed = f"Rscript -e '{r_script.strip()}'"
|
| 132 |
+
|
| 133 |
+
try:
|
| 134 |
+
result = subprocess.run(
|
| 135 |
+
command,
|
| 136 |
+
capture_output=True,
|
| 137 |
+
text=True,
|
| 138 |
+
check=True
|
| 139 |
+
)
|
| 140 |
+
return {
|
| 141 |
+
"command_executed": command_executed,
|
| 142 |
+
"stdout": result.stdout,
|
| 143 |
+
"stderr": result.stderr,
|
| 144 |
+
"output_files": [str(out_path)] if out_path.exists() else []
|
| 145 |
+
}
|
| 146 |
+
except subprocess.CalledProcessError as e:
|
| 147 |
+
return {
|
| 148 |
+
"command_executed": command_executed,
|
| 149 |
+
"stdout": e.stdout,
|
| 150 |
+
"stderr": e.stderr,
|
| 151 |
+
"output_files": []
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
@mcp.tool()
|
| 155 |
+
def biovizbase_get_bio_color(
|
| 156 |
+
color_type: str = "DNA"
|
| 157 |
+
) -> dict:
|
| 158 |
+
"""
|
| 159 |
+
Retrieves standard biological color schemes as a JSON object.
|
| 160 |
+
|
| 161 |
+
Args:
|
| 162 |
+
color_type: The category of color scheme. Can be 'DNA', 'RNA', 'AMINO_ACID', 'STRAND', 'CYTOBAND', or a UCSC genome build (e.g., 'hg19').
|
| 163 |
+
|
| 164 |
+
Returns:
|
| 165 |
+
A dictionary containing the command executed, stdout (with JSON color data), and stderr.
|
| 166 |
+
"""
|
| 167 |
+
if not color_type:
|
| 168 |
+
raise ValueError("The 'color_type' parameter cannot be empty.")
|
| 169 |
+
|
| 170 |
+
r_script = f"""
|
| 171 |
+
library(biovizBase)
|
| 172 |
+
library(jsonlite)
|
| 173 |
+
cols <- getBioColor(type = "{color_type}")
|
| 174 |
+
cat(jsonlite::toJSON(cols, auto_unbox = TRUE))
|
| 175 |
+
"""
|
| 176 |
+
|
| 177 |
+
command = ["Rscript", "-e", r_script]
|
| 178 |
+
command_executed = f"Rscript -e '{r_script.strip()}'"
|
| 179 |
+
|
| 180 |
+
try:
|
| 181 |
+
result = subprocess.run(
|
| 182 |
+
command,
|
| 183 |
+
capture_output=True,
|
| 184 |
+
text=True,
|
| 185 |
+
check=True
|
| 186 |
+
)
|
| 187 |
+
return {
|
| 188 |
+
"command_executed": command_executed,
|
| 189 |
+
"stdout": result.stdout,
|
| 190 |
+
"stderr": result.stderr
|
| 191 |
+
}
|
| 192 |
+
except subprocess.CalledProcessError as e:
|
| 193 |
+
return {
|
| 194 |
+
"command_executed": command_executed,
|
| 195 |
+
"stdout": e.stdout,
|
| 196 |
+
"stderr": e.stderr
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
@mcp.tool()
|
| 200 |
+
def biovizbase_calculate_islands(
|
| 201 |
+
input_file: str,
|
| 202 |
+
output_csv: Optional[str] = None
|
| 203 |
+
) -> dict:
|
| 204 |
+
"""
|
| 205 |
+
Identifies genomic 'islands' (regions of high density/coverage) in alignment or feature data.
|
| 206 |
+
|
| 207 |
+
Args:
|
| 208 |
+
input_file: Path to the input file (e.g., BAM, BED).
|
| 209 |
+
output_csv: Optional path to save the island coordinates as a CSV file.
|
| 210 |
+
|
| 211 |
+
Returns:
|
| 212 |
+
A dictionary containing the command executed, stdout, stderr, and a list of output files.
|
| 213 |
+
"""
|
| 214 |
+
input_path = Path(input_file)
|
| 215 |
+
if not input_path.exists():
|
| 216 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 217 |
+
|
| 218 |
+
out_path = Path(output_csv) if output_csv else Path(tempfile.mktemp(suffix=".csv"))
|
| 219 |
+
|
| 220 |
+
r_script = f"""
|
| 221 |
+
library(biovizBase)
|
| 222 |
+
library(GenomicRanges)
|
| 223 |
+
library(rtracklayer)
|
| 224 |
+
|
| 225 |
+
if (grepl("\\\\.bam$", "{input_path}", ignore.case = TRUE)) {{
|
| 226 |
+
library(Rsamtools)
|
| 227 |
+
data <- readGAlignments("{input_path}")
|
| 228 |
+
}} else {{
|
| 229 |
+
data <- import("{input_path}")
|
| 230 |
+
}}
|
| 231 |
+
|
| 232 |
+
res <- islands(data)
|
| 233 |
+
write.csv(as.data.frame(res), file = "{out_path}", row.names = FALSE)
|
| 234 |
+
"""
|
| 235 |
+
|
| 236 |
+
command = ["Rscript", "-e", r_script]
|
| 237 |
+
command_executed = f"Rscript -e '{r_script.strip()}'"
|
| 238 |
+
|
| 239 |
+
try:
|
| 240 |
+
result = subprocess.run(
|
| 241 |
+
command,
|
| 242 |
+
capture_output=True,
|
| 243 |
+
text=True,
|
| 244 |
+
check=True
|
| 245 |
+
)
|
| 246 |
+
return {
|
| 247 |
+
"command_executed": command_executed,
|
| 248 |
+
"stdout": result.stdout,
|
| 249 |
+
"stderr": result.stderr,
|
| 250 |
+
"output_files": [str(out_path)] if out_path.exists() else []
|
| 251 |
+
}
|
| 252 |
+
except subprocess.CalledProcessError as e:
|
| 253 |
+
return {
|
| 254 |
+
"command_executed": command_executed,
|
| 255 |
+
"stdout": e.stdout,
|
| 256 |
+
"stderr": e.stderr,
|
| 257 |
+
"output_files": []
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
@mcp.tool()
|
| 261 |
+
def biovizbase_add_stepping(
|
| 262 |
+
input_file: str,
|
| 263 |
+
group_name: Optional[str] = None,
|
| 264 |
+
extend: int = 0,
|
| 265 |
+
output_csv: Optional[str] = None
|
| 266 |
+
) -> dict:
|
| 267 |
+
"""
|
| 268 |
+
Calculates 'stepping' levels for genomic ranges to avoid overlaps in visualization.
|
| 269 |
+
|
| 270 |
+
Args:
|
| 271 |
+
input_file: Path to input BED, GFF, or other range-based file.
|
| 272 |
+
group_name: Optional column name in the data to group by for stepping calculation.
|
| 273 |
+
extend: Number of base pairs to extend ranges on each side for overlap calculation. Must be non-negative.
|
| 274 |
+
output_csv: Optional path to save the data with the new 'stepping' column.
|
| 275 |
+
|
| 276 |
+
Returns:
|
| 277 |
+
A dictionary containing the command executed, stdout, stderr, and a list of output files.
|
| 278 |
+
"""
|
| 279 |
+
input_path = Path(input_file)
|
| 280 |
+
if not input_path.exists():
|
| 281 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 282 |
+
if extend < 0:
|
| 283 |
+
raise ValueError("The 'extend' parameter must be a non-negative integer.")
|
| 284 |
+
|
| 285 |
+
out_path = Path(output_csv) if output_csv else Path(tempfile.mktemp(suffix=".csv"))
|
| 286 |
+
group_code = f', group.name = "{group_name}"' if group_name else ""
|
| 287 |
+
|
| 288 |
+
r_script = f"""
|
| 289 |
+
library(biovizBase)
|
| 290 |
+
library(rtracklayer)
|
| 291 |
+
data <- import("{input_path}")
|
| 292 |
+
res <- addStepping(data{group_code}, extend = {extend})
|
| 293 |
+
write.csv(as.data.frame(res), file = "{out_path}", row.names = FALSE)
|
| 294 |
+
"""
|
| 295 |
+
|
| 296 |
+
command = ["Rscript", "-e", r_script]
|
| 297 |
+
command_executed = f"Rscript -e '{r_script.strip()}'"
|
| 298 |
+
|
| 299 |
+
try:
|
| 300 |
+
result = subprocess.run(
|
| 301 |
+
command,
|
| 302 |
+
capture_output=True,
|
| 303 |
+
text=True,
|
| 304 |
+
check=True
|
| 305 |
+
)
|
| 306 |
+
return {
|
| 307 |
+
"command_executed": command_executed,
|
| 308 |
+
"stdout": result.stdout,
|
| 309 |
+
"stderr": result.stderr,
|
| 310 |
+
"output_files": [str(out_path)] if out_path.exists() else []
|
| 311 |
+
}
|
| 312 |
+
except subprocess.CalledProcessError as e:
|
| 313 |
+
return {
|
| 314 |
+
"command_executed": command_executed,
|
| 315 |
+
"stdout": e.stdout,
|
| 316 |
+
"stderr": e.stderr,
|
| 317 |
+
"output_files": []
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
@mcp.tool()
|
| 321 |
+
def biovizbase_rescale_ranges(
|
| 322 |
+
input_file: str,
|
| 323 |
+
to_start: int = 0,
|
| 324 |
+
to_end: int = 1000,
|
| 325 |
+
output_csv: Optional[str] = None
|
| 326 |
+
) -> dict:
|
| 327 |
+
"""
|
| 328 |
+
Rescales genomic coordinates from their original range to a new numeric range.
|
| 329 |
+
|
| 330 |
+
Args:
|
| 331 |
+
input_file: Path to input BED, GFF, or other range-based file.
|
| 332 |
+
to_start: Start of the target numeric range.
|
| 333 |
+
to_end: End of the target numeric range.
|
| 334 |
+
output_csv: Optional path to save the rescaled data.
|
| 335 |
+
|
| 336 |
+
Returns:
|
| 337 |
+
A dictionary containing the command executed, stdout, stderr, and a list of output files.
|
| 338 |
+
"""
|
| 339 |
+
input_path = Path(input_file)
|
| 340 |
+
if not input_path.exists():
|
| 341 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 342 |
+
if to_start >= to_end:
|
| 343 |
+
raise ValueError("The 'to_start' parameter must be less than 'to_end'.")
|
| 344 |
+
|
| 345 |
+
out_path = Path(output_csv) if output_csv else Path(tempfile.mktemp(suffix=".csv"))
|
| 346 |
+
|
| 347 |
+
r_script = f"""
|
| 348 |
+
library(biovizBase)
|
| 349 |
+
library(rtracklayer)
|
| 350 |
+
data <- import("{input_path}")
|
| 351 |
+
res <- rescale(data, to = c({to_start}, {to_end}))
|
| 352 |
+
write.csv(as.data.frame(res), file = "{out_path}", row.names = FALSE)
|
| 353 |
+
"""
|
| 354 |
+
|
| 355 |
+
command = ["Rscript", "-e", r_script]
|
| 356 |
+
command_executed = f"Rscript -e '{r_script.strip()}'"
|
| 357 |
+
|
| 358 |
+
try:
|
| 359 |
+
result = subprocess.run(
|
| 360 |
+
command,
|
| 361 |
+
capture_output=True,
|
| 362 |
+
text=True,
|
| 363 |
+
check=True
|
| 364 |
+
)
|
| 365 |
+
return {
|
| 366 |
+
"command_executed": command_executed,
|
| 367 |
+
"stdout": result.stdout,
|
| 368 |
+
"stderr": result.stderr,
|
| 369 |
+
"output_files": [str(out_path)] if out_path.exists() else []
|
| 370 |
+
}
|
| 371 |
+
except subprocess.CalledProcessError as e:
|
| 372 |
+
return {
|
| 373 |
+
"command_executed": command_executed,
|
| 374 |
+
"stdout": e.stdout,
|
| 375 |
+
"stderr": e.stderr,
|
| 376 |
+
"output_files": []
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
@mcp.tool()
|
| 380 |
+
def biovizbase_shrink_introns(
|
| 381 |
+
input_file: str,
|
| 382 |
+
output_csv: Optional[str] = None
|
| 383 |
+
) -> dict:
|
| 384 |
+
"""
|
| 385 |
+
Shrinks intron regions in transcript data to emphasize exons in visualization.
|
| 386 |
+
|
| 387 |
+
Args:
|
| 388 |
+
input_file: Path to input GTF/GFF file containing transcript models.
|
| 389 |
+
output_csv: Optional path to save the data with shrunk introns.
|
| 390 |
+
|
| 391 |
+
Returns:
|
| 392 |
+
A dictionary containing the command executed, stdout, stderr, and a list of output files.
|
| 393 |
+
"""
|
| 394 |
+
input_path = Path(input_file)
|
| 395 |
+
if not input_path.exists():
|
| 396 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 397 |
+
|
| 398 |
+
out_path = Path(output_csv) if output_csv else Path(tempfile.mktemp(suffix=".csv"))
|
| 399 |
+
|
| 400 |
+
r_script = f"""
|
| 401 |
+
library(biovizBase)
|
| 402 |
+
library(GenomicFeatures)
|
| 403 |
+
library(rtracklayer)
|
| 404 |
+
|
| 405 |
+
# Create a TxDb object for transcript grouping, which is required for shrink
|
| 406 |
+
txdb <- makeTxDbFromGFF("{input_path}")
|
| 407 |
+
exons <- exonsBy(txdb, by = "tx", use.names = TRUE)
|
| 408 |
+
|
| 409 |
+
res <- shrink(exons)
|
| 410 |
+
# The result is a GRangesList, we flatten it for CSV output
|
| 411 |
+
res_df <- as.data.frame(unlist(res))
|
| 412 |
+
write.csv(res_df, file = "{out_path}", row.names = FALSE)
|
| 413 |
+
"""
|
| 414 |
+
|
| 415 |
+
command = ["Rscript", "-e", r_script]
|
| 416 |
+
command_executed = f"Rscript -e '{r_script.strip()}'"
|
| 417 |
+
|
| 418 |
+
try:
|
| 419 |
+
result = subprocess.run(
|
| 420 |
+
command,
|
| 421 |
+
capture_output=True,
|
| 422 |
+
text=True,
|
| 423 |
+
check=True
|
| 424 |
+
)
|
| 425 |
+
return {
|
| 426 |
+
"command_executed": command_executed,
|
| 427 |
+
"stdout": result.stdout,
|
| 428 |
+
"stderr": result.stderr,
|
| 429 |
+
"output_files": [str(out_path)] if out_path.exists() else []
|
| 430 |
+
}
|
| 431 |
+
except subprocess.CalledProcessError as e:
|
| 432 |
+
return {
|
| 433 |
+
"command_executed": command_executed,
|
| 434 |
+
"stdout": e.stdout,
|
| 435 |
+
"stderr": e.stderr,
|
| 436 |
+
"output_files": []
|
| 437 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/app/bioconductor-biovizbase_shim_server.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import ast
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
from mcp.server.fastmcp import FastMCP
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/app/bioconductor-biovizbase_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_bioconductor_biovizbase'
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class _ShimMCP:
|
| 15 |
+
@staticmethod
|
| 16 |
+
def tool():
|
| 17 |
+
def _decorator(fn):
|
| 18 |
+
return fn
|
| 19 |
+
return _decorator
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _load_functions():
|
| 23 |
+
code = SOURCE_SERVER.read_text(encoding="utf-8")
|
| 24 |
+
tree = ast.parse(code, filename=str(SOURCE_SERVER))
|
| 25 |
+
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
|
| 26 |
+
namespace = {
|
| 27 |
+
"__name__": "__mcp_source__",
|
| 28 |
+
"mcp": _ShimMCP(),
|
| 29 |
+
}
|
| 30 |
+
exec(compile(code, str(SOURCE_SERVER), "exec"), namespace, namespace)
|
| 31 |
+
loaded = []
|
| 32 |
+
for name in function_names:
|
| 33 |
+
fn = namespace.get(name)
|
| 34 |
+
if callable(fn):
|
| 35 |
+
loaded.append(fn)
|
| 36 |
+
return loaded
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
mcp = FastMCP(SERVER_NAME)
|
| 40 |
+
for _fn in _load_functions():
|
| 41 |
+
mcp.tool()(_fn)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
mcp.run(transport="stdio")
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-bioconductor-biovizbase:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-bioconductor-biovizbase:latest
|
| 7 |
+
container_name: mcp-bioconductor-biovizbase
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=bioconductor-biovizbase
|
| 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 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- bioconductor-biovizbase
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-biovizbase/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_bioconductor-bulksignalr/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Install system dependencies
|
| 5 |
+
RUN apt-get update && apt-get install -y default-jre wget curl && apt-get clean && rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
# Install Miniconda
|
| 8 |
+
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && bash /tmp/miniconda.sh -b -p /opt/conda && rm /tmp/miniconda.sh
|
| 9 |
+
|
| 10 |
+
# Add conda to PATH
|
| 11 |
+
ENV PATH="/opt/conda/bin:$PATH"
|
| 12 |
+
|
| 13 |
+
# Install bioconductor-bulksignalr via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda bioconductor-bulksignalr -y && conda clean -a
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
RUN pip install uv
|
| 18 |
+
RUN uv pip install --system fastmcp
|
| 19 |
+
|
| 20 |
+
# Create app directory
|
| 21 |
+
WORKDIR /app
|
| 22 |
+
|
| 23 |
+
# Copy your MCP server
|
| 24 |
+
COPY app/bioconductor-bulksignalr_server.py /app/
|
| 25 |
+
|
| 26 |
+
# Create workspace and output directories
|
| 27 |
+
RUN mkdir -p /app/workspace /app/output
|
| 28 |
+
|
| 29 |
+
# Make sure the server script is executable
|
| 30 |
+
RUN chmod +x /app/bioconductor-bulksignalr_server.py
|
| 31 |
+
|
| 32 |
+
# Expose port for MCP over HTTP (optional)
|
| 33 |
+
EXPOSE 8000
|
| 34 |
+
|
| 35 |
+
# Health check
|
| 36 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD python -c "import sys; sys.exit(0)"
|
| 37 |
+
|
| 38 |
+
# Default command runs the MCP server via stdio
|
| 39 |
+
CMD ["python", "/app/bioconductor-bulksignalr_server.py"]
|
| 40 |
+
|