BioOcto code and data release (snapshot 2026-11-27) (part 11)
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_perl-http-cookies/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-cookies/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/app/perl-http-daemon_server.py +184 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/app/perl-http-daemon_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/app/perl-http-date_server.py +289 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/app/perl-http-date_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/app/perl-http-message_server.py +292 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/app/perl-http-message_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/app/perl-http-negotiate_server.py +186 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/app/perl-http-negotiate_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/app/perl-image-info_server.py +160 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/app/perl-image-info_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/app/perl-image-size_server.py +114 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/app/perl-image-size_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/environment.yaml +10 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/requirements.txt +2 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/Dockerfile +40 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/app/perl-importer_server.py +237 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/app/perl-importer_shim_server.py +45 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/app/requirements.txt +1 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/docker-compose.yml +22 -0
- BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/environment.yaml +10 -0
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-cookies/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- perl-http-cookies
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-cookies/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/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 perl-http-daemon via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda perl-http-daemon -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/perl-http-daemon_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/perl-http-daemon_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/perl-http-daemon_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/app/perl-http-daemon_server.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import List, Optional, Union
|
| 4 |
+
|
| 5 |
+
@mcp.tool()
|
| 6 |
+
def run_perl_interpreter(
|
| 7 |
+
program_file: Optional[Path] = None,
|
| 8 |
+
program_arguments: Optional[List[str]] = None,
|
| 9 |
+
record_separator_octal: Optional[str] = None,
|
| 10 |
+
autosplit: bool = False,
|
| 11 |
+
unicode_features: Optional[str] = None,
|
| 12 |
+
check_syntax_only: bool = False,
|
| 13 |
+
debugger: Optional[str] = None,
|
| 14 |
+
debug_flags: Optional[str] = None,
|
| 15 |
+
program_string: Optional[List[str]] = None,
|
| 16 |
+
program_string_extended: Optional[List[str]] = None,
|
| 17 |
+
no_sitecustomize: bool = False,
|
| 18 |
+
split_pattern: Optional[str] = None,
|
| 19 |
+
edit_in_place_extension: Optional[str] = None,
|
| 20 |
+
include_directories: Optional[List[Path]] = None,
|
| 21 |
+
line_ending_processing_terminator: Optional[str] = None,
|
| 22 |
+
use_modules: Optional[List[str]] = None,
|
| 23 |
+
no_modules: Optional[List[str]] = None,
|
| 24 |
+
loop_around_program: bool = False,
|
| 25 |
+
loop_and_print: bool = False,
|
| 26 |
+
rudimentary_switch_parsing: bool = False,
|
| 27 |
+
look_for_programfile_in_path: bool = False,
|
| 28 |
+
tainting_warnings: bool = False,
|
| 29 |
+
tainting_checks: bool = False,
|
| 30 |
+
dump_core_after_parsing: bool = False,
|
| 31 |
+
allow_unsafe_operations: bool = False,
|
| 32 |
+
print_version: bool = False,
|
| 33 |
+
print_config_summary_variable: Optional[str] = None,
|
| 34 |
+
enable_warnings: bool = False,
|
| 35 |
+
enable_all_warnings: bool = False,
|
| 36 |
+
ignore_text_before_shebang_directory: Optional[Path] = None,
|
| 37 |
+
disable_all_warnings: bool = False,
|
| 38 |
+
) -> dict:
|
| 39 |
+
"""
|
| 40 |
+
Executes a Perl script or one-liner using the Perl interpreter.
|
| 41 |
+
|
| 42 |
+
This tool wraps the generic 'perl' interpreter command, providing access to its
|
| 43 |
+
various command-line switches. While the request was for 'perl-http-daemon',
|
| 44 |
+
'HTTP::Daemon' is a Perl module, not a standalone executable. The provided
|
| 45 |
+
CLI help is for the 'perl' interpreter itself. This function allows running
|
| 46 |
+
any Perl script, including those that might utilize the 'HTTP::Daemon' module,
|
| 47 |
+
with full control over interpreter options.
|
| 48 |
+
"""
|
| 49 |
+
command = ["perl"]
|
| 50 |
+
output_files = []
|
| 51 |
+
|
| 52 |
+
# --- Input validation ---
|
| 53 |
+
if program_file:
|
| 54 |
+
if not program_file.is_file():
|
| 55 |
+
raise FileNotFoundError(f"Program file not found: {program_file}")
|
| 56 |
+
if program_string or program_string_extended:
|
| 57 |
+
raise ValueError("Cannot specify both a program file and program string(s) (-e/-E).")
|
| 58 |
+
|
| 59 |
+
if program_string and program_string_extended:
|
| 60 |
+
raise ValueError("Cannot specify both -e and -E program strings simultaneously.")
|
| 61 |
+
|
| 62 |
+
if loop_around_program and loop_and_print:
|
| 63 |
+
raise ValueError("Cannot specify both -n and -p simultaneously.")
|
| 64 |
+
|
| 65 |
+
warning_flags_set = sum([enable_warnings, enable_all_warnings, disable_all_warnings])
|
| 66 |
+
if warning_flags_set > 1:
|
| 67 |
+
raise ValueError("Cannot specify more than one of -w, -W, or -X simultaneously.")
|
| 68 |
+
|
| 69 |
+
if include_directories:
|
| 70 |
+
for d in include_directories:
|
| 71 |
+
if not d.is_dir():
|
| 72 |
+
raise NotADirectoryError(f"Include directory not found or is not a directory: {d}")
|
| 73 |
+
|
| 74 |
+
if ignore_text_before_shebang_directory:
|
| 75 |
+
if not ignore_text_before_shebang_directory.is_dir():
|
| 76 |
+
raise NotADirectoryError(f"Directory for -x not found or is not a directory: {ignore_text_before_shebang_directory}")
|
| 77 |
+
|
| 78 |
+
# --- Build command ---
|
| 79 |
+
if record_separator_octal is not None:
|
| 80 |
+
command.append(f"-0{record_separator_octal}")
|
| 81 |
+
if autosplit:
|
| 82 |
+
command.append("-a")
|
| 83 |
+
if unicode_features is not None:
|
| 84 |
+
command.append(f"-C{unicode_features}")
|
| 85 |
+
if check_syntax_only:
|
| 86 |
+
command.append("-c")
|
| 87 |
+
if debugger is not None:
|
| 88 |
+
command.append(f"-d:{debugger}" if debugger else "-d")
|
| 89 |
+
if debug_flags is not None:
|
| 90 |
+
command.append(f"-D{debug_flags}")
|
| 91 |
+
if program_string:
|
| 92 |
+
for p_str in program_string:
|
| 93 |
+
command.extend(["-e", p_str])
|
| 94 |
+
if program_string_extended:
|
| 95 |
+
for p_str in program_string_extended:
|
| 96 |
+
command.extend(["-E", p_str])
|
| 97 |
+
if no_sitecustomize:
|
| 98 |
+
command.append("-f")
|
| 99 |
+
if split_pattern is not None:
|
| 100 |
+
command.append(f"-F{split_pattern}")
|
| 101 |
+
if edit_in_place_extension is not None:
|
| 102 |
+
command.append(f"-i{edit_in_place_extension}")
|
| 103 |
+
if include_directories:
|
| 104 |
+
for d in include_directories:
|
| 105 |
+
command.extend(["-I", str(d)])
|
| 106 |
+
if line_ending_processing_terminator is not None:
|
| 107 |
+
command.append(f"-l{line_ending_processing_terminator}")
|
| 108 |
+
if use_modules:
|
| 109 |
+
for module in use_modules:
|
| 110 |
+
command.extend(["-M", module])
|
| 111 |
+
if no_modules:
|
| 112 |
+
for module in no_modules:
|
| 113 |
+
command.extend(["-m-", module])
|
| 114 |
+
if loop_around_program:
|
| 115 |
+
command.append("-n")
|
| 116 |
+
if loop_and_print:
|
| 117 |
+
command.append("-p")
|
| 118 |
+
if rudimentary_switch_parsing:
|
| 119 |
+
command.append("-s")
|
| 120 |
+
if look_for_programfile_in_path:
|
| 121 |
+
command.append("-S")
|
| 122 |
+
if tainting_warnings:
|
| 123 |
+
command.append("-t")
|
| 124 |
+
if tainting_checks:
|
| 125 |
+
command.append("-T")
|
| 126 |
+
if dump_core_after_parsing:
|
| 127 |
+
command.append("-u")
|
| 128 |
+
if allow_unsafe_operations:
|
| 129 |
+
command.append("-U")
|
| 130 |
+
if print_version:
|
| 131 |
+
command.append("-v")
|
| 132 |
+
if print_config_summary_variable is not None:
|
| 133 |
+
command.append(f"-V:{print_config_summary_variable}" if print_config_summary_variable else "-V")
|
| 134 |
+
if enable_warnings:
|
| 135 |
+
command.append("-w")
|
| 136 |
+
if enable_all_warnings:
|
| 137 |
+
command.append("-W")
|
| 138 |
+
if ignore_text_before_shebang_directory is not None:
|
| 139 |
+
command.append(f"-x{ignore_text_before_shebang_directory}")
|
| 140 |
+
if disable_all_warnings:
|
| 141 |
+
command.append("-X")
|
| 142 |
+
|
| 143 |
+
# Add program file and its arguments (positional)
|
| 144 |
+
if program_file:
|
| 145 |
+
command.append(str(program_file))
|
| 146 |
+
|
| 147 |
+
if program_arguments:
|
| 148 |
+
command.extend(program_arguments)
|
| 149 |
+
|
| 150 |
+
# --- Execute command ---
|
| 151 |
+
try:
|
| 152 |
+
process = subprocess.run(
|
| 153 |
+
command,
|
| 154 |
+
capture_output=True,
|
| 155 |
+
text=True,
|
| 156 |
+
check=True
|
| 157 |
+
)
|
| 158 |
+
stdout = process.stdout
|
| 159 |
+
stderr = process.stderr
|
| 160 |
+
except subprocess.CalledProcessError as e:
|
| 161 |
+
return {
|
| 162 |
+
"command_executed": " ".join(e.cmd),
|
| 163 |
+
"stdout": e.stdout,
|
| 164 |
+
"stderr": e.stderr,
|
| 165 |
+
"output_files": [],
|
| 166 |
+
"error": f"Perl command failed with exit code {e.returncode}.",
|
| 167 |
+
"returncode": e.returncode,
|
| 168 |
+
}
|
| 169 |
+
except FileNotFoundError:
|
| 170 |
+
return {
|
| 171 |
+
"command_executed": " ".join(command),
|
| 172 |
+
"stdout": "",
|
| 173 |
+
"stderr": "Error: 'perl' command not found. Please ensure Perl is installed and accessible in your PATH.",
|
| 174 |
+
"output_files": [],
|
| 175 |
+
"error": "Perl executable not found.",
|
| 176 |
+
"returncode": 127,
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
return {
|
| 180 |
+
"command_executed": " ".join(command),
|
| 181 |
+
"stdout": stdout,
|
| 182 |
+
"stderr": stderr,
|
| 183 |
+
"output_files": output_files,
|
| 184 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/app/perl-http-daemon_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_perl-http-daemon/app/perl-http-daemon_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_perl_http_daemon'
|
| 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_perl-http-daemon/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-perl-http-daemon:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-perl-http-daemon:latest
|
| 7 |
+
container_name: mcp-perl-http-daemon
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=perl-http-daemon
|
| 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_perl-http-daemon/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- perl-http-daemon
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-daemon/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/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 perl-http-date via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda perl-http-date -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/perl-http-date_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/perl-http-date_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/perl-http-date_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/app/perl-http-date_server.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Optional, List, Dict, Any
|
| 5 |
+
|
| 6 |
+
# Mock decorator for standalone execution
|
| 7 |
+
class mcp:
|
| 8 |
+
@staticmethod
|
| 9 |
+
def tool(func):
|
| 10 |
+
return func
|
| 11 |
+
|
| 12 |
+
@mcp.tool
|
| 13 |
+
def time2str(time: Optional[int] = None) -> Dict[str, Any]:
|
| 14 |
+
"""
|
| 15 |
+
Converts a machine time (seconds since epoch) to an HTTP-formatted string.
|
| 16 |
+
|
| 17 |
+
This function wraps the `time2str()` function from the Perl HTTP::Date module.
|
| 18 |
+
The string returned is in the format preferred for the HTTP protocol (RFC 1123),
|
| 19 |
+
represented in Universal Time (GMT). Example: Sun, 06 Nov 1994 08:49:37 GMT.
|
| 20 |
+
|
| 21 |
+
Args:
|
| 22 |
+
time: The time in seconds since the epoch. If not provided or None,
|
| 23 |
+
the current time will be used.
|
| 24 |
+
|
| 25 |
+
Returns:
|
| 26 |
+
A dictionary containing the command executed, stdout (the formatted date string),
|
| 27 |
+
stderr, and a list of output files (which is always empty).
|
| 28 |
+
"""
|
| 29 |
+
command = ["perl", "-MHTTP::Date", "-e"]
|
| 30 |
+
if time is not None:
|
| 31 |
+
if not isinstance(time, int):
|
| 32 |
+
raise TypeError("The 'time' parameter must be an integer.")
|
| 33 |
+
script = f'print HTTP::Date::time2str({time})'
|
| 34 |
+
else:
|
| 35 |
+
script = 'print HTTP::Date::time2str()'
|
| 36 |
+
|
| 37 |
+
command.append(script)
|
| 38 |
+
|
| 39 |
+
command_str = " ".join(command)
|
| 40 |
+
|
| 41 |
+
try:
|
| 42 |
+
result = subprocess.run(
|
| 43 |
+
command,
|
| 44 |
+
capture_output=True,
|
| 45 |
+
text=True,
|
| 46 |
+
check=True,
|
| 47 |
+
)
|
| 48 |
+
return {
|
| 49 |
+
"command_executed": command_str,
|
| 50 |
+
"stdout": result.stdout.strip(),
|
| 51 |
+
"stderr": result.stderr.strip(),
|
| 52 |
+
"output_files": []
|
| 53 |
+
}
|
| 54 |
+
except FileNotFoundError:
|
| 55 |
+
return {
|
| 56 |
+
"command_executed": command_str,
|
| 57 |
+
"stdout": "",
|
| 58 |
+
"stderr": "Error: 'perl' executable not found. Please ensure Perl is installed and in your PATH.",
|
| 59 |
+
"output_files": []
|
| 60 |
+
}
|
| 61 |
+
except subprocess.CalledProcessError as e:
|
| 62 |
+
return {
|
| 63 |
+
"command_executed": command_str,
|
| 64 |
+
"stdout": e.stdout.strip(),
|
| 65 |
+
"stderr": e.stderr.strip(),
|
| 66 |
+
"output_files": []
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
@mcp.tool
|
| 70 |
+
def str2time(date_string: str, zone: Optional[str] = None) -> Dict[str, Any]:
|
| 71 |
+
"""
|
| 72 |
+
Converts a date string to machine time (seconds since epoch).
|
| 73 |
+
|
| 74 |
+
This function wraps the `str2time()` function from the Perl HTTP::Date module.
|
| 75 |
+
It returns the machine time if the format is recognized, otherwise it may return an empty string.
|
| 76 |
+
Note: If the zone is not 'GMT' or numerical (e.g., '-0800'), the Time::Zone Perl module
|
| 77 |
+
must be installed for the date to be recognized.
|
| 78 |
+
|
| 79 |
+
Args:
|
| 80 |
+
date_string: The date string to convert.
|
| 81 |
+
zone: The default time zone to use if the date string does not contain one.
|
| 82 |
+
|
| 83 |
+
Returns:
|
| 84 |
+
A dictionary containing the command executed, stdout (the machine time),
|
| 85 |
+
stderr, and a list of output files (which is always empty).
|
| 86 |
+
"""
|
| 87 |
+
if not date_string:
|
| 88 |
+
raise ValueError("The 'date_string' parameter cannot be empty.")
|
| 89 |
+
|
| 90 |
+
command = ["perl", "-MHTTP::Date", "-e"]
|
| 91 |
+
|
| 92 |
+
if zone:
|
| 93 |
+
script = 'print HTTP::Date::str2time(shift, shift)'
|
| 94 |
+
command.extend([script, date_string, zone])
|
| 95 |
+
else:
|
| 96 |
+
script = 'print HTTP::Date::str2time(shift)'
|
| 97 |
+
command.extend([script, date_string])
|
| 98 |
+
|
| 99 |
+
command_str = " ".join(f"'{arg}'" if " " in arg else arg for arg in command)
|
| 100 |
+
|
| 101 |
+
try:
|
| 102 |
+
result = subprocess.run(
|
| 103 |
+
command,
|
| 104 |
+
capture_output=True,
|
| 105 |
+
text=True,
|
| 106 |
+
check=True,
|
| 107 |
+
)
|
| 108 |
+
return {
|
| 109 |
+
"command_executed": command_str,
|
| 110 |
+
"stdout": result.stdout.strip(),
|
| 111 |
+
"stderr": result.stderr.strip(),
|
| 112 |
+
"output_files": []
|
| 113 |
+
}
|
| 114 |
+
except FileNotFoundError:
|
| 115 |
+
return {
|
| 116 |
+
"command_executed": command_str,
|
| 117 |
+
"stdout": "",
|
| 118 |
+
"stderr": "Error: 'perl' executable not found. Please ensure Perl is installed and in your PATH.",
|
| 119 |
+
"output_files": []
|
| 120 |
+
}
|
| 121 |
+
except subprocess.CalledProcessError as e:
|
| 122 |
+
return {
|
| 123 |
+
"command_executed": command_str,
|
| 124 |
+
"stdout": e.stdout.strip(),
|
| 125 |
+
"stderr": e.stderr.strip(),
|
| 126 |
+
"output_files": []
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
@mcp.tool
|
| 130 |
+
def parse_date(date_string: str) -> Dict[str, Any]:
|
| 131 |
+
"""
|
| 132 |
+
Parses a date string and returns its components.
|
| 133 |
+
|
| 134 |
+
This function wraps the `parse_date()` function from the Perl HTTP::Date module.
|
| 135 |
+
It returns a comma-separated string of numerical values:
|
| 136 |
+
year,month,day,hour,min,sec,timezone. The year will be the full 4-digit year,
|
| 137 |
+
and month numbers start with 1 for January.
|
| 138 |
+
|
| 139 |
+
Args:
|
| 140 |
+
date_string: The date string to parse.
|
| 141 |
+
|
| 142 |
+
Returns:
|
| 143 |
+
A dictionary containing the command executed, stdout (the parsed date components),
|
| 144 |
+
stderr, and a list of output files (which is always empty).
|
| 145 |
+
"""
|
| 146 |
+
if not date_string:
|
| 147 |
+
raise ValueError("The 'date_string' parameter cannot be empty.")
|
| 148 |
+
|
| 149 |
+
script = 'my @parts = HTTP::Date::parse_date(shift); print join(",", @parts);'
|
| 150 |
+
command = ["perl", "-MHTTP::Date", "-e", script, date_string]
|
| 151 |
+
command_str = " ".join(f"'{arg}'" if " " in arg else arg for arg in command)
|
| 152 |
+
|
| 153 |
+
try:
|
| 154 |
+
result = subprocess.run(
|
| 155 |
+
command,
|
| 156 |
+
capture_output=True,
|
| 157 |
+
text=True,
|
| 158 |
+
check=True,
|
| 159 |
+
)
|
| 160 |
+
return {
|
| 161 |
+
"command_executed": command_str,
|
| 162 |
+
"stdout": result.stdout.strip(),
|
| 163 |
+
"stderr": result.stderr.strip(),
|
| 164 |
+
"output_files": []
|
| 165 |
+
}
|
| 166 |
+
except FileNotFoundError:
|
| 167 |
+
return {
|
| 168 |
+
"command_executed": command_str,
|
| 169 |
+
"stdout": "",
|
| 170 |
+
"stderr": "Error: 'perl' executable not found. Please ensure Perl is installed and in your PATH.",
|
| 171 |
+
"output_files": []
|
| 172 |
+
}
|
| 173 |
+
except subprocess.CalledProcessError as e:
|
| 174 |
+
return {
|
| 175 |
+
"command_executed": command_str,
|
| 176 |
+
"stdout": e.stdout.strip(),
|
| 177 |
+
"stderr": e.stderr.strip(),
|
| 178 |
+
"output_files": []
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
@mcp.tool
|
| 182 |
+
def time2iso(time: Optional[int] = None) -> Dict[str, Any]:
|
| 183 |
+
"""
|
| 184 |
+
Converts machine time to a 'YYYY-MM-DD hh:mm:ss' formatted string in the local time zone.
|
| 185 |
+
|
| 186 |
+
This function wraps the `time2iso()` function from the Perl HTTP::Date module.
|
| 187 |
+
|
| 188 |
+
Args:
|
| 189 |
+
time: The time in seconds since the epoch. If not provided or None,
|
| 190 |
+
the current time will be used.
|
| 191 |
+
|
| 192 |
+
Returns:
|
| 193 |
+
A dictionary containing the command executed, stdout (the formatted date string),
|
| 194 |
+
stderr, and a list of output files (which is always empty).
|
| 195 |
+
"""
|
| 196 |
+
command = ["perl", "-MHTTP::Date", "-e"]
|
| 197 |
+
if time is not None:
|
| 198 |
+
if not isinstance(time, int):
|
| 199 |
+
raise TypeError("The 'time' parameter must be an integer.")
|
| 200 |
+
script = f'print HTTP::Date::time2iso({time})'
|
| 201 |
+
else:
|
| 202 |
+
script = 'print HTTP::Date::time2iso()'
|
| 203 |
+
|
| 204 |
+
command.append(script)
|
| 205 |
+
|
| 206 |
+
command_str = " ".join(command)
|
| 207 |
+
|
| 208 |
+
try:
|
| 209 |
+
result = subprocess.run(
|
| 210 |
+
command,
|
| 211 |
+
capture_output=True,
|
| 212 |
+
text=True,
|
| 213 |
+
check=True,
|
| 214 |
+
)
|
| 215 |
+
return {
|
| 216 |
+
"command_executed": command_str,
|
| 217 |
+
"stdout": result.stdout.strip(),
|
| 218 |
+
"stderr": result.stderr.strip(),
|
| 219 |
+
"output_files": []
|
| 220 |
+
}
|
| 221 |
+
except FileNotFoundError:
|
| 222 |
+
return {
|
| 223 |
+
"command_executed": command_str,
|
| 224 |
+
"stdout": "",
|
| 225 |
+
"stderr": "Error: 'perl' executable not found. Please ensure Perl is installed and in your PATH.",
|
| 226 |
+
"output_files": []
|
| 227 |
+
}
|
| 228 |
+
except subprocess.CalledProcessError as e:
|
| 229 |
+
return {
|
| 230 |
+
"command_executed": command_str,
|
| 231 |
+
"stdout": e.stdout.strip(),
|
| 232 |
+
"stderr": e.stderr.strip(),
|
| 233 |
+
"output_files": []
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
@mcp.tool
|
| 237 |
+
def time2isoz(time: Optional[int] = None) -> Dict[str, Any]:
|
| 238 |
+
"""
|
| 239 |
+
Converts machine time to a 'YYYY-MM-DD hh:mm:ssZ' formatted string in Universal Time.
|
| 240 |
+
|
| 241 |
+
This function wraps the `time2isoz()` function from the Perl HTTP::Date module.
|
| 242 |
+
|
| 243 |
+
Args:
|
| 244 |
+
time: The time in seconds since the epoch. If not provided or None,
|
| 245 |
+
the current time will be used.
|
| 246 |
+
|
| 247 |
+
Returns:
|
| 248 |
+
A dictionary containing the command executed, stdout (the formatted date string),
|
| 249 |
+
stderr, and a list of output files (which is always empty).
|
| 250 |
+
"""
|
| 251 |
+
command = ["perl", "-MHTTP::Date", "-e"]
|
| 252 |
+
if time is not None:
|
| 253 |
+
if not isinstance(time, int):
|
| 254 |
+
raise TypeError("The 'time' parameter must be an integer.")
|
| 255 |
+
script = f'print HTTP::Date::time2isoz({time})'
|
| 256 |
+
else:
|
| 257 |
+
script = 'print HTTP::Date::time2isoz()'
|
| 258 |
+
|
| 259 |
+
command.append(script)
|
| 260 |
+
|
| 261 |
+
command_str = " ".join(command)
|
| 262 |
+
|
| 263 |
+
try:
|
| 264 |
+
result = subprocess.run(
|
| 265 |
+
command,
|
| 266 |
+
capture_output=True,
|
| 267 |
+
text=True,
|
| 268 |
+
check=True,
|
| 269 |
+
)
|
| 270 |
+
return {
|
| 271 |
+
"command_executed": command_str,
|
| 272 |
+
"stdout": result.stdout.strip(),
|
| 273 |
+
"stderr": result.stderr.strip(),
|
| 274 |
+
"output_files": []
|
| 275 |
+
}
|
| 276 |
+
except FileNotFoundError:
|
| 277 |
+
return {
|
| 278 |
+
"command_executed": command_str,
|
| 279 |
+
"stdout": "",
|
| 280 |
+
"stderr": "Error: 'perl' executable not found. Please ensure Perl is installed and in your PATH.",
|
| 281 |
+
"output_files": []
|
| 282 |
+
}
|
| 283 |
+
except subprocess.CalledProcessError as e:
|
| 284 |
+
return {
|
| 285 |
+
"command_executed": command_str,
|
| 286 |
+
"stdout": e.stdout.strip(),
|
| 287 |
+
"stderr": e.stderr.strip(),
|
| 288 |
+
"output_files": []
|
| 289 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/app/perl-http-date_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_perl-http-date/app/perl-http-date_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_perl_http_date'
|
| 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_perl-http-date/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-perl-http-date:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-perl-http-date:latest
|
| 7 |
+
container_name: mcp-perl-http-date
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=perl-http-date
|
| 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_perl-http-date/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- perl-http-date
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-date/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/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 perl-http-message via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda perl-http-message -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/perl-http-message_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/perl-http-message_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/perl-http-message_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/app/perl-http-message_server.py
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from typing import Optional, List
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
@mcp.tool()
|
| 6 |
+
def http_message_as_string(
|
| 7 |
+
raw_message: str,
|
| 8 |
+
eol: Optional[str] = None,
|
| 9 |
+
):
|
| 10 |
+
"""
|
| 11 |
+
Parses a raw HTTP message string and returns it formatted as a single string.
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
raw_message: The raw HTTP message string to parse.
|
| 15 |
+
eol: Optional line ending sequence to use (default is "\\n").
|
| 16 |
+
"""
|
| 17 |
+
# Construct Perl one-liner
|
| 18 |
+
# We use base64 or escaping to pass the raw message safely,
|
| 19 |
+
# but for simplicity in this environment, we'll use a temporary file or stdin.
|
| 20 |
+
|
| 21 |
+
perl_code = 'use HTTP::Message; my $m = HTTP::Message->parse($ARGV[0]);'
|
| 22 |
+
if eol:
|
| 23 |
+
perl_code += 'print $m->as_string($ARGV[1]);'
|
| 24 |
+
args = [raw_message, eol]
|
| 25 |
+
else:
|
| 26 |
+
perl_code += 'print $m->as_string;'
|
| 27 |
+
args = [raw_message]
|
| 28 |
+
|
| 29 |
+
try:
|
| 30 |
+
result = subprocess.run(
|
| 31 |
+
["perl", "-MHTTP::Message", "-e", perl_code, "--"] + args,
|
| 32 |
+
capture_output=True,
|
| 33 |
+
text=True,
|
| 34 |
+
check=True
|
| 35 |
+
)
|
| 36 |
+
return {
|
| 37 |
+
"command_executed": f"perl -MHTTP::Message -e '{perl_code}'",
|
| 38 |
+
"stdout": result.stdout,
|
| 39 |
+
"stderr": result.stderr,
|
| 40 |
+
"output": result.stdout
|
| 41 |
+
}
|
| 42 |
+
except subprocess.CalledProcessError as e:
|
| 43 |
+
return {
|
| 44 |
+
"error": str(e),
|
| 45 |
+
"stdout": e.stdout,
|
| 46 |
+
"stderr": e.stderr
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
@mcp.tool()
|
| 50 |
+
def http_message_dump(
|
| 51 |
+
raw_message: str,
|
| 52 |
+
maxlength: int = 512,
|
| 53 |
+
no_content: str = "(no content)",
|
| 54 |
+
prefix: str = ""
|
| 55 |
+
):
|
| 56 |
+
"""
|
| 57 |
+
Returns a detailed dump of the HTTP message, escaping non-printable bytes.
|
| 58 |
+
Useful for debugging raw HTTP traffic.
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
raw_message: The raw HTTP message string.
|
| 62 |
+
maxlength: How much of the content to show. Set to 0 for unlimited.
|
| 63 |
+
no_content: String to display if there is no content.
|
| 64 |
+
prefix: String to prefix to each line of the dump.
|
| 65 |
+
"""
|
| 66 |
+
perl_code = (
|
| 67 |
+
'use HTTP::Message; '
|
| 68 |
+
'my $m = HTTP::Message->parse($ARGV[0]); '
|
| 69 |
+
'print $m->dump(maxlength => $ARGV[1], no_content => $ARGV[2], prefix => $ARGV[3]);'
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
result = subprocess.run(
|
| 74 |
+
["perl", "-MHTTP::Message", "-e", perl_code, "--", raw_message, str(maxlength), no_content, prefix],
|
| 75 |
+
capture_output=True,
|
| 76 |
+
text=True,
|
| 77 |
+
check=True
|
| 78 |
+
)
|
| 79 |
+
return {
|
| 80 |
+
"command_executed": "HTTP::Message->dump",
|
| 81 |
+
"stdout": result.stdout,
|
| 82 |
+
"stderr": result.stderr,
|
| 83 |
+
"dump": result.stdout
|
| 84 |
+
}
|
| 85 |
+
except subprocess.CalledProcessError as e:
|
| 86 |
+
return {
|
| 87 |
+
"error": str(e),
|
| 88 |
+
"stdout": e.stdout,
|
| 89 |
+
"stderr": e.stderr
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
@mcp.tool()
|
| 93 |
+
def http_message_decoded_content(
|
| 94 |
+
raw_message: str,
|
| 95 |
+
charset: Optional[str] = None,
|
| 96 |
+
default_charset: str = "ISO-8859-1",
|
| 97 |
+
alt_charset: Optional[str] = None,
|
| 98 |
+
charset_strict: bool = False,
|
| 99 |
+
raise_error: bool = False
|
| 100 |
+
):
|
| 101 |
+
"""
|
| 102 |
+
Returns the content of the message with Content-Encoding undone and character sets decoded.
|
| 103 |
+
|
| 104 |
+
Args:
|
| 105 |
+
raw_message: The raw HTTP message string.
|
| 106 |
+
charset: Overrides the charset parameter for text content.
|
| 107 |
+
default_charset: Overrides the default guessed charset.
|
| 108 |
+
alt_charset: Fallback charset if the primary one fails.
|
| 109 |
+
charset_strict: If True, abort decoding on malformed characters.
|
| 110 |
+
raise_error: If True, raise an exception on failure.
|
| 111 |
+
"""
|
| 112 |
+
# Build options hash for Perl
|
| 113 |
+
options = []
|
| 114 |
+
if charset: options.append(f'charset => "{charset}"')
|
| 115 |
+
options.append(f'default_charset => "{default_charset}"')
|
| 116 |
+
if alt_charset: options.append(f'alt_charset => "{alt_charset}"')
|
| 117 |
+
options.append(f'charset_strict => {"1" if charset_strict else "0"}')
|
| 118 |
+
options.append(f'raise_error => {"1" if raise_error else "0"}')
|
| 119 |
+
|
| 120 |
+
opt_str = ", ".join(options)
|
| 121 |
+
perl_code = (
|
| 122 |
+
'use HTTP::Message; '
|
| 123 |
+
'my $m = HTTP::Message->parse($ARGV[0]); '
|
| 124 |
+
f'my $c = $m->decoded_content({opt_str}); '
|
| 125 |
+
'print $c if defined $c;'
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
try:
|
| 129 |
+
result = subprocess.run(
|
| 130 |
+
["perl", "-MHTTP::Message", "-e", perl_code, "--", raw_message],
|
| 131 |
+
capture_output=True,
|
| 132 |
+
text=True,
|
| 133 |
+
check=True
|
| 134 |
+
)
|
| 135 |
+
return {
|
| 136 |
+
"command_executed": "HTTP::Message->decoded_content",
|
| 137 |
+
"stdout": result.stdout,
|
| 138 |
+
"stderr": result.stderr,
|
| 139 |
+
"decoded_content": result.stdout
|
| 140 |
+
}
|
| 141 |
+
except subprocess.CalledProcessError as e:
|
| 142 |
+
return {
|
| 143 |
+
"error": str(e),
|
| 144 |
+
"stdout": e.stdout,
|
| 145 |
+
"stderr": e.stderr
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
@mcp.tool()
|
| 149 |
+
def http_message_encode(
|
| 150 |
+
raw_message: str,
|
| 151 |
+
encoding: str = "gzip"
|
| 152 |
+
):
|
| 153 |
+
"""
|
| 154 |
+
Applies a specific encoding (e.g., gzip, deflate, base64) to the message content.
|
| 155 |
+
Returns the full message with the new encoding and updated headers.
|
| 156 |
+
|
| 157 |
+
Args:
|
| 158 |
+
raw_message: The raw HTTP message string.
|
| 159 |
+
encoding: The encoding to apply (gzip, deflate, x-bzip2, base64, or br).
|
| 160 |
+
"""
|
| 161 |
+
valid_encodings = ["gzip", "deflate", "x-bzip2", "base64", "br", "identity"]
|
| 162 |
+
if encoding not in valid_encodings:
|
| 163 |
+
return {"error": f"Invalid encoding. Must be one of: {', '.join(valid_encodings)}"}
|
| 164 |
+
|
| 165 |
+
perl_code = (
|
| 166 |
+
'use HTTP::Message; '
|
| 167 |
+
'my $m = HTTP::Message->parse($ARGV[0]); '
|
| 168 |
+
'if ($m->encode($ARGV[1])) { print $m->as_string; } '
|
| 169 |
+
'else { die "Encoding failed"; }'
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
try:
|
| 173 |
+
result = subprocess.run(
|
| 174 |
+
["perl", "-MHTTP::Message", "-e", perl_code, "--", raw_message, encoding],
|
| 175 |
+
capture_output=True,
|
| 176 |
+
text=True,
|
| 177 |
+
check=True
|
| 178 |
+
)
|
| 179 |
+
return {
|
| 180 |
+
"command_executed": f"HTTP::Message->encode('{encoding}')",
|
| 181 |
+
"stdout": result.stdout,
|
| 182 |
+
"stderr": result.stderr,
|
| 183 |
+
"encoded_message": result.stdout
|
| 184 |
+
}
|
| 185 |
+
except subprocess.CalledProcessError as e:
|
| 186 |
+
return {
|
| 187 |
+
"error": "Encoding failed. Note: multipart/* or message/* cannot be encoded.",
|
| 188 |
+
"stdout": e.stdout,
|
| 189 |
+
"stderr": e.stderr
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
@mcp.tool()
|
| 193 |
+
def http_message_get_parts(
|
| 194 |
+
raw_message: str
|
| 195 |
+
):
|
| 196 |
+
"""
|
| 197 |
+
For composite messages (multipart/* or message/*), extracts and returns each part as a separate string.
|
| 198 |
+
|
| 199 |
+
Args:
|
| 200 |
+
raw_message: The raw HTTP message string.
|
| 201 |
+
"""
|
| 202 |
+
perl_code = (
|
| 203 |
+
'use HTTP::Message; '
|
| 204 |
+
'my $m = HTTP::Message->parse($ARGV[0]); '
|
| 205 |
+
'my @parts = $m->parts; '
|
| 206 |
+
'foreach my $p (@parts) { print "---PART_BOUNDARY---\\n"; print $p->as_string; }'
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
try:
|
| 210 |
+
result = subprocess.run(
|
| 211 |
+
["perl", "-MHTTP::Message", "-e", perl_code, "--", raw_message],
|
| 212 |
+
capture_output=True,
|
| 213 |
+
text=True,
|
| 214 |
+
check=True
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
parts = []
|
| 218 |
+
if result.stdout:
|
| 219 |
+
# Split by boundary and filter out empty strings
|
| 220 |
+
parts = [p.strip() for p in result.stdout.split("---PART_BOUNDARY---\n") if p.strip()]
|
| 221 |
+
|
| 222 |
+
return {
|
| 223 |
+
"command_executed": "HTTP::Message->parts",
|
| 224 |
+
"stdout": result.stdout,
|
| 225 |
+
"stderr": result.stderr,
|
| 226 |
+
"parts_count": len(parts),
|
| 227 |
+
"parts": parts
|
| 228 |
+
}
|
| 229 |
+
except subprocess.CalledProcessError as e:
|
| 230 |
+
return {
|
| 231 |
+
"error": str(e),
|
| 232 |
+
"stdout": e.stdout,
|
| 233 |
+
"stderr": e.stderr
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
@mcp.tool()
|
| 237 |
+
def http_message_header_operations(
|
| 238 |
+
raw_message: str,
|
| 239 |
+
operation: str,
|
| 240 |
+
header_field: str,
|
| 241 |
+
header_value: Optional[str] = None
|
| 242 |
+
):
|
| 243 |
+
"""
|
| 244 |
+
Performs header manipulations on an HTTP message.
|
| 245 |
+
|
| 246 |
+
Args:
|
| 247 |
+
raw_message: The raw HTTP message string.
|
| 248 |
+
operation: The operation to perform: 'get', 'set', 'push', 'remove'.
|
| 249 |
+
header_field: The name of the header field (e.g., 'Content-Type').
|
| 250 |
+
header_value: The value to set or push (required for 'set' and 'push').
|
| 251 |
+
"""
|
| 252 |
+
if operation not in ["get", "set", "push", "remove"]:
|
| 253 |
+
return {"error": "Invalid operation. Use 'get', 'set', 'push', or 'remove'."}
|
| 254 |
+
|
| 255 |
+
if operation in ["set", "push"] and header_value is None:
|
| 256 |
+
return {"error": f"header_value is required for operation '{operation}'"}
|
| 257 |
+
|
| 258 |
+
perl_logic = ""
|
| 259 |
+
if operation == "get":
|
| 260 |
+
perl_logic = 'print $m->header($ARGV[1]);'
|
| 261 |
+
elif operation == "set":
|
| 262 |
+
perl_logic = '$m->header($ARGV[1] => $ARGV[2]); print $m->as_string;'
|
| 263 |
+
elif operation == "push":
|
| 264 |
+
perl_logic = '$m->push_header($ARGV[1] => $ARGV[2]); print $m->as_string;'
|
| 265 |
+
elif operation == "remove":
|
| 266 |
+
perl_logic = '$m->remove_header($ARGV[1]); print $m->as_string;'
|
| 267 |
+
|
| 268 |
+
perl_code = f'use HTTP::Message; my $m = HTTP::Message->parse($ARGV[0]); {perl_logic}'
|
| 269 |
+
|
| 270 |
+
args = [raw_message, header_field]
|
| 271 |
+
if header_value:
|
| 272 |
+
args.append(header_value)
|
| 273 |
+
|
| 274 |
+
try:
|
| 275 |
+
result = subprocess.run(
|
| 276 |
+
["perl", "-MHTTP::Message", "-e", perl_code, "--"] + args,
|
| 277 |
+
capture_output=True,
|
| 278 |
+
text=True,
|
| 279 |
+
check=True
|
| 280 |
+
)
|
| 281 |
+
return {
|
| 282 |
+
"command_executed": f"HTTP::Message header {operation}",
|
| 283 |
+
"stdout": result.stdout,
|
| 284 |
+
"stderr": result.stderr,
|
| 285 |
+
"result": result.stdout
|
| 286 |
+
}
|
| 287 |
+
except subprocess.CalledProcessError as e:
|
| 288 |
+
return {
|
| 289 |
+
"error": str(e),
|
| 290 |
+
"stdout": e.stdout,
|
| 291 |
+
"stderr": e.stderr
|
| 292 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/app/perl-http-message_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_perl-http-message/app/perl-http-message_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_perl_http_message'
|
| 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_perl-http-message/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-perl-http-message:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-perl-http-message:latest
|
| 7 |
+
container_name: mcp-perl-http-message
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=perl-http-message
|
| 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_perl-http-message/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- perl-http-message
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-message/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/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 perl-http-negotiate via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda perl-http-negotiate -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/perl-http-negotiate_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/perl-http-negotiate_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/perl-http-negotiate_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/app/perl-http-negotiate_server.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import shlex
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Optional, List
|
| 5 |
+
|
| 6 |
+
# This is a placeholder for the MCP decorator.
|
| 7 |
+
# In a real MCP environment, this would be imported.
|
| 8 |
+
def mcp_tool_placeholder():
|
| 9 |
+
def decorator(func):
|
| 10 |
+
return func
|
| 11 |
+
return decorator
|
| 12 |
+
|
| 13 |
+
mcp = type('MCP', (), {'tool': mcp_tool_placeholder})
|
| 14 |
+
|
| 15 |
+
@mcp.tool()
|
| 16 |
+
def run_perl(
|
| 17 |
+
programfile: Optional[Path] = None,
|
| 18 |
+
arguments: Optional[List[str]] = None,
|
| 19 |
+
execute_program: Optional[List[str]] = None,
|
| 20 |
+
execute_program_with_features: Optional[List[str]] = None,
|
| 21 |
+
check_syntax_only: bool = False,
|
| 22 |
+
print_version: bool = False,
|
| 23 |
+
print_config: Optional[str] = None,
|
| 24 |
+
record_separator: Optional[str] = None,
|
| 25 |
+
autosplit: bool = False,
|
| 26 |
+
split_pattern: Optional[str] = None,
|
| 27 |
+
loop_around_program: bool = False,
|
| 28 |
+
loop_and_print: bool = False,
|
| 29 |
+
in_place_edit: Optional[str] = None,
|
| 30 |
+
line_ending_processing: Optional[str] = None,
|
| 31 |
+
include_directory: Optional[List[Path]] = None,
|
| 32 |
+
use_module: Optional[List[str]] = None,
|
| 33 |
+
no_module: Optional[List[str]] = None,
|
| 34 |
+
use_module_m: Optional[List[str]] = None,
|
| 35 |
+
no_module_m: Optional[List[str]] = None,
|
| 36 |
+
enable_warnings: bool = False,
|
| 37 |
+
enable_all_warnings: bool = False,
|
| 38 |
+
disable_all_warnings: bool = False,
|
| 39 |
+
tainting_warnings: bool = False,
|
| 40 |
+
tainting_checks: bool = False,
|
| 41 |
+
unicode_features: Optional[str] = None,
|
| 42 |
+
run_under_debugger: Optional[str] = None,
|
| 43 |
+
debugging_flags: Optional[str] = None,
|
| 44 |
+
no_sitecustomize: bool = False,
|
| 45 |
+
parse_switches: bool = False,
|
| 46 |
+
search_path: bool = False,
|
| 47 |
+
dump_core: bool = False,
|
| 48 |
+
unsafe_operations: bool = False,
|
| 49 |
+
ignore_pre_hashbang_text: Optional[str] = None,
|
| 50 |
+
):
|
| 51 |
+
"""
|
| 52 |
+
Executes a script or command using the Perl interpreter.
|
| 53 |
+
|
| 54 |
+
This tool is a wrapper for the generic 'perl' executable. The provided
|
| 55 |
+
documentation for 'perl-http-negotiate' indicates it is a library, not a
|
| 56 |
+
standalone command-line tool. This function therefore exposes the underlying
|
| 57 |
+
'perl' interpreter, within an environment where 'perl-http-negotiate' is
|
| 58 |
+
available for use in scripts (e.g., 'use HTTP::Negotiate;').
|
| 59 |
+
|
| 60 |
+
Args:
|
| 61 |
+
programfile: Path to the Perl program file to execute.
|
| 62 |
+
arguments: A list of arguments to be passed to the program file.
|
| 63 |
+
execute_program: One or more lines of a program to be executed. Omit programfile.
|
| 64 |
+
execute_program_with_features: Like execute_program, but enables all optional features.
|
| 65 |
+
check_syntax_only: Check syntax only (runs BEGIN and CHECK blocks). Corresponds to -c.
|
| 66 |
+
print_version: Print version, patchlevel, and license. Corresponds to -v.
|
| 67 |
+
print_config: Print configuration summary. Provide a variable name to see a single value. Corresponds to -V[:variable].
|
| 68 |
+
record_separator: Specify record separator (e.g., an octal number). Corresponds to -0[octal].
|
| 69 |
+
autosplit: Enable autosplit mode with -n or -p (splits $_ into @F). Corresponds to -a.
|
| 70 |
+
split_pattern: The pattern to use for splitting in autosplit mode. Corresponds to -F/pattern/.
|
| 71 |
+
loop_around_program: Assume "while (<>) { ... }" loop around the program. Corresponds to -n.
|
| 72 |
+
loop_and_print: Assume a loop like -n but also print the line, similar to sed. Corresponds to -p.
|
| 73 |
+
in_place_edit: Edit <> files in place. Provide an extension to make a backup. Corresponds to -i[extension].
|
| 74 |
+
line_ending_processing: Enable line ending processing and specify the line terminator. Corresponds to -l[octal].
|
| 75 |
+
include_directory: Specify @INC/#include directories. Multiple paths can be provided. Corresponds to -I.
|
| 76 |
+
use_module: Execute "use module..." before the program. Corresponds to -Mmodule.
|
| 77 |
+
no_module: Execute "no module..." before the program. Corresponds to -M-module.
|
| 78 |
+
use_module_m: Execute "use module..." before the program. Corresponds to -mmodule.
|
| 79 |
+
no_module_m: Execute "no module..." before the program. Corresponds to -m-module.
|
| 80 |
+
enable_warnings: Enable many useful warnings. Corresponds to -w.
|
| 81 |
+
enable_all_warnings: Enable all warnings. Corresponds to -W.
|
| 82 |
+
disable_all_warnings: Disable all warnings. Corresponds to -X.
|
| 83 |
+
tainting_warnings: Enable tainting warnings. Corresponds to -t.
|
| 84 |
+
tainting_checks: Enable tainting checks. Corresponds to -T.
|
| 85 |
+
unicode_features: Enable the listed Unicode features. Corresponds to -C[number/list].
|
| 86 |
+
run_under_debugger: Run the program under the debugger. Provide a debugger name if needed. Corresponds to -d[:debugger].
|
| 87 |
+
debugging_flags: Set debugging flags (argument is a bit mask or alphabets). Corresponds to -D[number/list].
|
| 88 |
+
no_sitecustomize: Don't do $sitelib/sitecustomize.pl at startup. Corresponds to -f.
|
| 89 |
+
parse_switches: Enable rudimentary parsing for switches after the programfile. Corresponds to -s.
|
| 90 |
+
search_path: Look for the programfile using the PATH environment variable. Corresponds to -S.
|
| 91 |
+
dump_core: Dump core after parsing the program. Corresponds to -u.
|
| 92 |
+
unsafe_operations: Allow unsafe operations. Corresponds to -U.
|
| 93 |
+
ignore_pre_hashbang_text: Ignore text before #!perl line. Optionally provide a directory to cd into. Corresponds to -x[directory].
|
| 94 |
+
"""
|
| 95 |
+
# --- Input Validation ---
|
| 96 |
+
execution_target_count = sum([
|
| 97 |
+
programfile is not None,
|
| 98 |
+
execute_program is not None,
|
| 99 |
+
execute_program_with_features is not None,
|
| 100 |
+
print_version,
|
| 101 |
+
print_config is not None
|
| 102 |
+
])
|
| 103 |
+
if execution_target_count == 0:
|
| 104 |
+
raise ValueError("An execution target is required. Please provide one of 'programfile', 'execute_program', 'execute_program_with_features', 'print_version', or 'print_config'.")
|
| 105 |
+
if execution_target_count > 1 and not (print_version and programfile): # perl -v script.pl is valid
|
| 106 |
+
if not (print_version and (execute_program or execute_program_with_features)):
|
| 107 |
+
raise ValueError("Only one primary execution target ('programfile', 'execute_program', 'execute_program_with_features', 'print_config') can be specified at a time.")
|
| 108 |
+
|
| 109 |
+
if programfile and not programfile.exists():
|
| 110 |
+
raise FileNotFoundError(f"The specified program file does not exist: {programfile}")
|
| 111 |
+
|
| 112 |
+
# --- Command Construction ---
|
| 113 |
+
cmd = ["perl"]
|
| 114 |
+
|
| 115 |
+
if record_separator is not None: cmd.append(f"-0{record_separator}")
|
| 116 |
+
if autosplit: cmd.append("-a")
|
| 117 |
+
if unicode_features is not None: cmd.append(f"-C{unicode_features}")
|
| 118 |
+
if check_syntax_only: cmd.append("-c")
|
| 119 |
+
if run_under_debugger is not None: cmd.append(f"-d{':' if run_under_debugger else ''}{run_under_debugger}")
|
| 120 |
+
if debugging_flags is not None: cmd.append(f"-D{debugging_flags}")
|
| 121 |
+
if execute_program:
|
| 122 |
+
for prog_line in execute_program: cmd.extend(["-e", prog_line])
|
| 123 |
+
if execute_program_with_features:
|
| 124 |
+
for prog_line in execute_program_with_features: cmd.extend(["-E", prog_line])
|
| 125 |
+
if no_sitecustomize: cmd.append("-f")
|
| 126 |
+
if split_pattern is not None: cmd.append(f"-F{split_pattern}")
|
| 127 |
+
if in_place_edit is not None: cmd.append(f"-i{in_place_edit}")
|
| 128 |
+
if include_directory:
|
| 129 |
+
for directory in include_directory: cmd.extend(["-I", str(directory)])
|
| 130 |
+
if line_ending_processing is not None: cmd.append(f"-l{line_ending_processing}")
|
| 131 |
+
if use_module:
|
| 132 |
+
for module in use_module: cmd.extend(["-M", module])
|
| 133 |
+
if no_module:
|
| 134 |
+
for module in no_module: cmd.extend(["-M-", module])
|
| 135 |
+
if use_module_m:
|
| 136 |
+
for module in use_module_m: cmd.extend(["-m", module])
|
| 137 |
+
if no_module_m:
|
| 138 |
+
for module in no_module_m: cmd.extend(["-m-", module])
|
| 139 |
+
if loop_around_program: cmd.append("-n")
|
| 140 |
+
if loop_and_print: cmd.append("-p")
|
| 141 |
+
if parse_switches: cmd.append("-s")
|
| 142 |
+
if search_path: cmd.append("-S")
|
| 143 |
+
if tainting_warnings: cmd.append("-t")
|
| 144 |
+
if tainting_checks: cmd.append("-T")
|
| 145 |
+
if dump_core: cmd.append("-u")
|
| 146 |
+
if unsafe_operations: cmd.append("-U")
|
| 147 |
+
if print_version: cmd.append("-v")
|
| 148 |
+
if print_config is not None: cmd.append(f"-V{':' if print_config else ''}{print_config}")
|
| 149 |
+
if enable_warnings: cmd.append("-w")
|
| 150 |
+
if enable_all_warnings: cmd.append("-W")
|
| 151 |
+
if ignore_pre_hashbang_text is not None: cmd.append(f"-x{ignore_pre_hashbang_text}")
|
| 152 |
+
if disable_all_warnings: cmd.append("-X")
|
| 153 |
+
|
| 154 |
+
if programfile:
|
| 155 |
+
cmd.append(str(programfile))
|
| 156 |
+
|
| 157 |
+
if arguments:
|
| 158 |
+
cmd.extend(arguments)
|
| 159 |
+
|
| 160 |
+
# --- Subprocess Execution ---
|
| 161 |
+
command_executed = shlex.join(cmd)
|
| 162 |
+
try:
|
| 163 |
+
result = subprocess.run(
|
| 164 |
+
cmd,
|
| 165 |
+
capture_output=True,
|
| 166 |
+
text=True,
|
| 167 |
+
check=True
|
| 168 |
+
)
|
| 169 |
+
return {
|
| 170 |
+
"command_executed": command_executed,
|
| 171 |
+
"stdout": result.stdout,
|
| 172 |
+
"stderr": result.stderr,
|
| 173 |
+
"output_files": []
|
| 174 |
+
}
|
| 175 |
+
except FileNotFoundError:
|
| 176 |
+
raise RuntimeError("The 'perl' executable was not found. Please ensure it is installed and in your system's PATH.")
|
| 177 |
+
except subprocess.CalledProcessError as e:
|
| 178 |
+
# Non-zero exit code is not necessarily an error for tools like this,
|
| 179 |
+
# but we return it structured for the user to decide.
|
| 180 |
+
return {
|
| 181 |
+
"command_executed": command_executed,
|
| 182 |
+
"stdout": e.stdout,
|
| 183 |
+
"stderr": e.stderr,
|
| 184 |
+
"error": f"Perl execution failed with return code {e.returncode}.",
|
| 185 |
+
"output_files": []
|
| 186 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/app/perl-http-negotiate_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_perl-http-negotiate/app/perl-http-negotiate_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_perl_http_negotiate'
|
| 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_perl-http-negotiate/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-perl-http-negotiate:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-perl-http-negotiate:latest
|
| 7 |
+
container_name: mcp-perl-http-negotiate
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=perl-http-negotiate
|
| 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_perl-http-negotiate/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- perl-http-negotiate
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-http-negotiate/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/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 perl-image-info via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda perl-image-info -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/perl-image-info_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/perl-image-info_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/perl-image-info_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/app/perl-image-info_server.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from typing import Dict, Any, List
|
| 6 |
+
|
| 7 |
+
# Note: The execution of these tools requires a Perl environment with the
|
| 8 |
+
# Image::Info and JSON modules installed. The conda package `perl-image-info`
|
| 9 |
+
# provides Image::Info, and `perl-json` is a standard module usually
|
| 10 |
+
# available in modern Perl installations.
|
| 11 |
+
|
| 12 |
+
@mcp.tool()
|
| 13 |
+
def get_image_info(
|
| 14 |
+
image_file: Path,
|
| 15 |
+
) -> Dict[str, Any]:
|
| 16 |
+
"""
|
| 17 |
+
Extracts detailed meta information from an image file using Perl's Image::Info module.
|
| 18 |
+
|
| 19 |
+
This function wraps the `image_info` subroutine, returning a dictionary of metadata
|
| 20 |
+
including dimensions, color type, resolution, and format-specific information
|
| 21 |
+
(e.g., EXIF data for JPEGs).
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
image_file: The path to the input image file. Supported formats include
|
| 25 |
+
AVIF, BMP, GIF, ICO, JPEG, PNG, PBM/PGM/PPM, SVG, TIFF,
|
| 26 |
+
WBMP, WEBP, XBM, and XPM.
|
| 27 |
+
|
| 28 |
+
Returns:
|
| 29 |
+
A dictionary containing the command execution details and the extracted image metadata.
|
| 30 |
+
"""
|
| 31 |
+
if not image_file.is_file():
|
| 32 |
+
raise FileNotFoundError(f"Input file not found: {image_file}")
|
| 33 |
+
|
| 34 |
+
perl_script_content = f"""
|
| 35 |
+
use strict;
|
| 36 |
+
use warnings;
|
| 37 |
+
use Image::Info qw(image_info);
|
| 38 |
+
use JSON;
|
| 39 |
+
|
| 40 |
+
my $file = shift @ARGV;
|
| 41 |
+
die "Usage: $0 <image_file>\\n" unless defined $file;
|
| 42 |
+
|
| 43 |
+
my $info = image_info($file);
|
| 44 |
+
|
| 45 |
+
# Encode the resulting Perl hash reference to JSON for easy parsing in Python.
|
| 46 |
+
print encode_json($info);
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix=".pl", delete=True) as tmp_script:
|
| 50 |
+
tmp_script.write(perl_script_content)
|
| 51 |
+
tmp_script.flush()
|
| 52 |
+
|
| 53 |
+
cmd = ["perl", tmp_script.name, str(image_file)]
|
| 54 |
+
command_executed = " ".join(cmd)
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
process = subprocess.run(
|
| 58 |
+
cmd,
|
| 59 |
+
check=True,
|
| 60 |
+
capture_output=True,
|
| 61 |
+
text=True,
|
| 62 |
+
encoding='utf-8'
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
try:
|
| 66 |
+
metadata = json.loads(process.stdout)
|
| 67 |
+
except json.JSONDecodeError:
|
| 68 |
+
# This case handles if the script runs but outputs non-JSON text
|
| 69 |
+
raise ValueError(f"Failed to parse JSON output from Perl script. stdout: {process.stdout}")
|
| 70 |
+
|
| 71 |
+
return {
|
| 72 |
+
"command_executed": command_executed,
|
| 73 |
+
"stdout": process.stdout,
|
| 74 |
+
"stderr": process.stderr,
|
| 75 |
+
"output_files": [],
|
| 76 |
+
"image_metadata": metadata
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
except subprocess.CalledProcessError as e:
|
| 80 |
+
# This case handles if the perl script itself fails (e.g., file not found, module missing)
|
| 81 |
+
return {
|
| 82 |
+
"command_executed": command_executed,
|
| 83 |
+
"stdout": e.stdout,
|
| 84 |
+
"stderr": e.stderr,
|
| 85 |
+
"output_files": [],
|
| 86 |
+
"error": f"Perl script execution failed with return code {e.returncode}."
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
@mcp.tool()
|
| 90 |
+
def get_image_type(
|
| 91 |
+
image_file: Path,
|
| 92 |
+
) -> Dict[str, Any]:
|
| 93 |
+
"""
|
| 94 |
+
Quickly determines the type of an image file using Perl's Image::Info module.
|
| 95 |
+
|
| 96 |
+
This function wraps the `image_type` subroutine, which is a faster alternative
|
| 97 |
+
to get_image_info. It only identifies the file type (e.g., 'GIF', 'JPEG', 'PNG')
|
| 98 |
+
without parsing the full image structure.
|
| 99 |
+
|
| 100 |
+
Args:
|
| 101 |
+
image_file: The path to the input image file.
|
| 102 |
+
|
| 103 |
+
Returns:
|
| 104 |
+
A dictionary containing the command execution details and the determined image type.
|
| 105 |
+
"""
|
| 106 |
+
if not image_file.is_file():
|
| 107 |
+
raise FileNotFoundError(f"Input file not found: {image_file}")
|
| 108 |
+
|
| 109 |
+
perl_script_content = f"""
|
| 110 |
+
use strict;
|
| 111 |
+
use warnings;
|
| 112 |
+
use Image::Info qw(image_type);
|
| 113 |
+
use JSON;
|
| 114 |
+
|
| 115 |
+
my $file = shift @ARGV;
|
| 116 |
+
die "Usage: $0 <image_file>\\n" unless defined $file;
|
| 117 |
+
|
| 118 |
+
my $type_info = image_type($file);
|
| 119 |
+
|
| 120 |
+
# Encode the resulting Perl hash reference to JSON for easy parsing in Python.
|
| 121 |
+
print encode_json($type_info);
|
| 122 |
+
"""
|
| 123 |
+
|
| 124 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix=".pl", delete=True) as tmp_script:
|
| 125 |
+
tmp_script.write(perl_script_content)
|
| 126 |
+
tmp_script.flush()
|
| 127 |
+
|
| 128 |
+
cmd = ["perl", tmp_script.name, str(image_file)]
|
| 129 |
+
command_executed = " ".join(cmd)
|
| 130 |
+
|
| 131 |
+
try:
|
| 132 |
+
process = subprocess.run(
|
| 133 |
+
cmd,
|
| 134 |
+
check=True,
|
| 135 |
+
capture_output=True,
|
| 136 |
+
text=True,
|
| 137 |
+
encoding='utf-8'
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
try:
|
| 141 |
+
type_info = json.loads(process.stdout)
|
| 142 |
+
except json.JSONDecodeError:
|
| 143 |
+
raise ValueError(f"Failed to parse JSON output from Perl script. stdout: {process.stdout}")
|
| 144 |
+
|
| 145 |
+
return {
|
| 146 |
+
"command_executed": command_executed,
|
| 147 |
+
"stdout": process.stdout,
|
| 148 |
+
"stderr": process.stderr,
|
| 149 |
+
"output_files": [],
|
| 150 |
+
"image_type_info": type_info
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
except subprocess.CalledProcessError as e:
|
| 154 |
+
return {
|
| 155 |
+
"command_executed": command_executed,
|
| 156 |
+
"stdout": e.stdout,
|
| 157 |
+
"stderr": e.stderr,
|
| 158 |
+
"output_files": [],
|
| 159 |
+
"error": f"Perl script execution failed with return code {e.returncode}."
|
| 160 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/app/perl-image-info_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_perl-image-info/app/perl-image-info_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_perl_image_info'
|
| 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_perl-image-info/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-perl-image-info:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-perl-image-info:latest
|
| 7 |
+
container_name: mcp-perl-image-info
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=perl-image-info
|
| 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_perl-image-info/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- perl-image-info
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-info/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/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 perl-image-size via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda perl-image-size -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/perl-image-size_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/perl-image-size_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/perl-image-size_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/app/perl-image-size_server.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import tempfile
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from typing import Dict, Any, Optional
|
| 5 |
+
|
| 6 |
+
# from mcp import mcp
|
| 7 |
+
|
| 8 |
+
@mcp.tool()
|
| 9 |
+
def image_size(
|
| 10 |
+
image_file: Path
|
| 11 |
+
) -> Dict[str, Any]:
|
| 12 |
+
"""
|
| 13 |
+
Determines the width and height of an image file using the Perl Image::Size library.
|
| 14 |
+
|
| 15 |
+
This tool acts as a wrapper around the Perl 'Image::Size' module, which does not
|
| 16 |
+
provide a direct command-line executable. It dynamically creates and executes a
|
| 17 |
+
Perl script to extract the dimensions from the specified image file.
|
| 18 |
+
|
| 19 |
+
Args:
|
| 20 |
+
image_file: The path to the input image file (e.g., JPG, PNG, GIF, etc.).
|
| 21 |
+
|
| 22 |
+
Returns:
|
| 23 |
+
A dictionary containing the command executed, stdout, stderr, and the
|
| 24 |
+
parsed width and height of the image.
|
| 25 |
+
"""
|
| 26 |
+
# 1. Input validation
|
| 27 |
+
if not image_file.is_file():
|
| 28 |
+
raise FileNotFoundError(f"Input file not found: {image_file}")
|
| 29 |
+
|
| 30 |
+
# 2. Perl script content
|
| 31 |
+
# This script uses the Image::Size module to get dimensions and prints them
|
| 32 |
+
# to stdout in a "width,height" format for easy parsing.
|
| 33 |
+
perl_script_content = r"""
|
| 34 |
+
use strict;
|
| 35 |
+
use warnings;
|
| 36 |
+
use Image::Size;
|
| 37 |
+
|
| 38 |
+
# Get the image file path from the command line arguments
|
| 39 |
+
my $file = shift @ARGV;
|
| 40 |
+
|
| 41 |
+
# Basic validation within the script
|
| 42 |
+
die "Usage: $0 <image_file>\n" unless defined $file;
|
| 43 |
+
die "File not found or is not a regular file: $file\n" unless -f $file;
|
| 44 |
+
|
| 45 |
+
# Get the image size
|
| 46 |
+
my ($width, $height) = imgsize($file);
|
| 47 |
+
|
| 48 |
+
# Print the result in a machine-readable format if successful
|
| 49 |
+
if (defined $width && defined $height) {
|
| 50 |
+
print "$width,$height\n";
|
| 51 |
+
} else {
|
| 52 |
+
# Print a descriptive error message to stderr if size could not be determined
|
| 53 |
+
my $error_msg = Image::Size::errormsg();
|
| 54 |
+
print STDERR "Could not determine size for '$file': $error_msg\n";
|
| 55 |
+
exit 1;
|
| 56 |
+
}
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
command_to_run = []
|
| 60 |
+
try:
|
| 61 |
+
# 3. Create a temporary file for the Perl script
|
| 62 |
+
with tempfile.NamedTemporaryFile(mode='w', delete=True, suffix=".pl", encoding='utf-8') as tmp_script:
|
| 63 |
+
tmp_script.write(perl_script_content)
|
| 64 |
+
tmp_script.flush() # Ensure all content is written to disk
|
| 65 |
+
|
| 66 |
+
command_to_run = ['perl', tmp_script.name, str(image_file)]
|
| 67 |
+
|
| 68 |
+
# 4. Subprocess execution
|
| 69 |
+
process = subprocess.run(
|
| 70 |
+
command_to_run,
|
| 71 |
+
capture_output=True,
|
| 72 |
+
text=True,
|
| 73 |
+
check=True
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# 5. Parse the output
|
| 77 |
+
stdout_clean = process.stdout.strip()
|
| 78 |
+
if not stdout_clean:
|
| 79 |
+
raise ValueError("Perl script produced no output to stdout.")
|
| 80 |
+
|
| 81 |
+
width_str, height_str = stdout_clean.split(',')
|
| 82 |
+
width = int(width_str)
|
| 83 |
+
height = int(height_str)
|
| 84 |
+
|
| 85 |
+
# 6. Return structured result
|
| 86 |
+
return {
|
| 87 |
+
"command_executed": " ".join(command_to_run),
|
| 88 |
+
"stdout": process.stdout,
|
| 89 |
+
"stderr": process.stderr,
|
| 90 |
+
"width": width,
|
| 91 |
+
"height": height,
|
| 92 |
+
"output_files": []
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
except FileNotFoundError:
|
| 96 |
+
raise RuntimeError("The 'perl' command was not found. Is Perl installed and in your system's PATH?")
|
| 97 |
+
except subprocess.CalledProcessError as e:
|
| 98 |
+
# This catches errors when the Perl script returns a non-zero exit code
|
| 99 |
+
return {
|
| 100 |
+
"command_executed": " ".join(command_to_run),
|
| 101 |
+
"stdout": e.stdout,
|
| 102 |
+
"stderr": e.stderr,
|
| 103 |
+
"error": "Perl script execution failed with a non-zero exit code.",
|
| 104 |
+
"output_files": []
|
| 105 |
+
}
|
| 106 |
+
except (ValueError, IndexError) as e:
|
| 107 |
+
# This catches errors if the stdout format is not "width,height"
|
| 108 |
+
return {
|
| 109 |
+
"command_executed": " ".join(command_to_run),
|
| 110 |
+
"stdout": process.stdout if 'process' in locals() else "",
|
| 111 |
+
"stderr": process.stderr if 'process' in locals() else "",
|
| 112 |
+
"error": f"Failed to parse Perl script output. Expected 'width,height', got '{stdout_clean}'. Details: {e}",
|
| 113 |
+
"output_files": []
|
| 114 |
+
}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/app/perl-image-size_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_perl-image-size/app/perl-image-size_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_perl_image_size'
|
| 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_perl-image-size/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-perl-image-size:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-perl-image-size:latest
|
| 7 |
+
container_name: mcp-perl-image-size
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=perl-image-size
|
| 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_perl-image-size/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- perl-image-size
|
| 9 |
+
- python=3.10
|
| 10 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-image-size/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastmcp
|
| 2 |
+
mcp
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/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 perl-importer via conda (e.g., from bioconda)
|
| 14 |
+
RUN conda install -c bioconda perl-importer -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/perl-importer_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/perl-importer_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/perl-importer_server.py"]
|
| 40 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/app/perl-importer_server.py
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from typing import Optional, List, Dict, Any
|
| 4 |
+
|
| 5 |
+
@mcp.tool()
|
| 6 |
+
def install_perl_module(
|
| 7 |
+
module_name: str,
|
| 8 |
+
notest: bool = True,
|
| 9 |
+
force: bool = False,
|
| 10 |
+
local_lib: Optional[str] = None,
|
| 11 |
+
sudo: bool = False,
|
| 12 |
+
):
|
| 13 |
+
"""
|
| 14 |
+
Installs Perl modules using cpanm (App::cpanminus), a common requirement for
|
| 15 |
+
bioinformatics pipelines (e.g., BioPerl, VCFtools).
|
| 16 |
+
"""
|
| 17 |
+
# Input validation
|
| 18 |
+
if not module_name:
|
| 19 |
+
return {"error": "Module name must be provided"}
|
| 20 |
+
|
| 21 |
+
command = []
|
| 22 |
+
if sudo:
|
| 23 |
+
command.append("sudo")
|
| 24 |
+
|
| 25 |
+
command.extend(["cpanm", module_name])
|
| 26 |
+
|
| 27 |
+
if notest:
|
| 28 |
+
command.append("--notest")
|
| 29 |
+
if force:
|
| 30 |
+
command.append("--force")
|
| 31 |
+
if local_lib:
|
| 32 |
+
lib_path = Path(local_lib)
|
| 33 |
+
command.extend(["-l", str(lib_path.absolute())])
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
result = subprocess.run(
|
| 37 |
+
command,
|
| 38 |
+
capture_output=True,
|
| 39 |
+
text=True,
|
| 40 |
+
check=True
|
| 41 |
+
)
|
| 42 |
+
return {
|
| 43 |
+
"command_executed": " ".join(command),
|
| 44 |
+
"stdout": result.stdout,
|
| 45 |
+
"stderr": result.stderr,
|
| 46 |
+
"status": "success"
|
| 47 |
+
}
|
| 48 |
+
except subprocess.CalledProcessError as e:
|
| 49 |
+
return {
|
| 50 |
+
"command_executed": " ".join(command),
|
| 51 |
+
"stdout": e.stdout,
|
| 52 |
+
"stderr": e.stderr,
|
| 53 |
+
"error": f"Installation failed with exit code {e.returncode}"
|
| 54 |
+
}
|
| 55 |
+
except FileNotFoundError:
|
| 56 |
+
return {"error": "cpanm is not installed on the system. Please install App::cpanminus."}
|
| 57 |
+
|
| 58 |
+
@mcp.tool()
|
| 59 |
+
def execute_perl_script(
|
| 60 |
+
script_path: str,
|
| 61 |
+
args: Optional[List[str]] = None,
|
| 62 |
+
perl5lib: Optional[str] = None,
|
| 63 |
+
include_path: Optional[str] = None,
|
| 64 |
+
warnings: bool = True,
|
| 65 |
+
):
|
| 66 |
+
"""
|
| 67 |
+
Executes a Perl script with specified arguments and environment variables.
|
| 68 |
+
Commonly used for running BioPerl scripts or custom bioinformatics parsers.
|
| 69 |
+
"""
|
| 70 |
+
script = Path(script_path)
|
| 71 |
+
if not script.exists():
|
| 72 |
+
return {"error": f"Script not found at {script_path}"}
|
| 73 |
+
|
| 74 |
+
command = ["perl"]
|
| 75 |
+
if warnings:
|
| 76 |
+
command.append("-w")
|
| 77 |
+
if include_path:
|
| 78 |
+
command.extend(["-I", include_path])
|
| 79 |
+
|
| 80 |
+
command.append(str(script.absolute()))
|
| 81 |
+
|
| 82 |
+
if args:
|
| 83 |
+
command.extend(args)
|
| 84 |
+
|
| 85 |
+
env = {}
|
| 86 |
+
if perl5lib:
|
| 87 |
+
env["PERL5LIB"] = perl5lib
|
| 88 |
+
|
| 89 |
+
try:
|
| 90 |
+
result = subprocess.run(
|
| 91 |
+
command,
|
| 92 |
+
capture_output=True,
|
| 93 |
+
text=True,
|
| 94 |
+
check=True,
|
| 95 |
+
env=env if env else None
|
| 96 |
+
)
|
| 97 |
+
return {
|
| 98 |
+
"command_executed": " ".join(command),
|
| 99 |
+
"stdout": result.stdout,
|
| 100 |
+
"stderr": result.stderr,
|
| 101 |
+
"output_files": [] # Perl scripts often output to stdout unless redirected
|
| 102 |
+
}
|
| 103 |
+
except subprocess.CalledProcessError as e:
|
| 104 |
+
return {
|
| 105 |
+
"command_executed": " ".join(command),
|
| 106 |
+
"stdout": e.stdout,
|
| 107 |
+
"stderr": e.stderr,
|
| 108 |
+
"error": f"Script execution failed with exit code {e.returncode}"
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
@mcp.tool()
|
| 112 |
+
def check_perl_syntax(
|
| 113 |
+
script_path: str,
|
| 114 |
+
include_path: Optional[str] = None,
|
| 115 |
+
):
|
| 116 |
+
"""
|
| 117 |
+
Performs a syntax check on a Perl script (perl -c).
|
| 118 |
+
Useful for validating bioinformatics scripts before long-running pipeline execution.
|
| 119 |
+
"""
|
| 120 |
+
script = Path(script_path)
|
| 121 |
+
if not script.exists():
|
| 122 |
+
return {"error": f"Script not found at {script_path}"}
|
| 123 |
+
|
| 124 |
+
command = ["perl", "-c"]
|
| 125 |
+
if include_path:
|
| 126 |
+
command.extend(["-I", include_path])
|
| 127 |
+
command.append(str(script.absolute()))
|
| 128 |
+
|
| 129 |
+
try:
|
| 130 |
+
result = subprocess.run(
|
| 131 |
+
command,
|
| 132 |
+
capture_output=True,
|
| 133 |
+
text=True,
|
| 134 |
+
check=True
|
| 135 |
+
)
|
| 136 |
+
return {
|
| 137 |
+
"command_executed": " ".join(command),
|
| 138 |
+
"stdout": result.stdout,
|
| 139 |
+
"stderr": result.stderr,
|
| 140 |
+
"valid": True
|
| 141 |
+
}
|
| 142 |
+
except subprocess.CalledProcessError as e:
|
| 143 |
+
return {
|
| 144 |
+
"command_executed": " ".join(command),
|
| 145 |
+
"stdout": e.stdout,
|
| 146 |
+
"stderr": e.stderr,
|
| 147 |
+
"valid": False,
|
| 148 |
+
"error": "Syntax check failed"
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
@mcp.tool()
|
| 152 |
+
def list_installed_perl_modules(
|
| 153 |
+
search_term: Optional[str] = None,
|
| 154 |
+
):
|
| 155 |
+
"""
|
| 156 |
+
Lists installed Perl modules or searches for a specific module.
|
| 157 |
+
Helps verify if bioinformatics dependencies like Bio::Seq or Bio::DB::Fasta are available.
|
| 158 |
+
"""
|
| 159 |
+
# Using perldoc -l is a reliable way to find module paths
|
| 160 |
+
if search_term:
|
| 161 |
+
command = ["perldoc", "-l", search_term]
|
| 162 |
+
else:
|
| 163 |
+
# Fallback to listing all modules via instmodsh (part of ExtUtils::Installed)
|
| 164 |
+
# This is a bit complex in shell, so we use a perl one-liner
|
| 165 |
+
command = ["perl", "-MExtUtils::Installed", "-e", "print join('\\n', ExtUtils::Installed->new()->modules())"]
|
| 166 |
+
|
| 167 |
+
try:
|
| 168 |
+
result = subprocess.run(
|
| 169 |
+
command,
|
| 170 |
+
capture_output=True,
|
| 171 |
+
text=True,
|
| 172 |
+
check=True
|
| 173 |
+
)
|
| 174 |
+
return {
|
| 175 |
+
"command_executed": " ".join(command),
|
| 176 |
+
"installed_modules": result.stdout.splitlines(),
|
| 177 |
+
"stdout": result.stdout
|
| 178 |
+
}
|
| 179 |
+
except subprocess.CalledProcessError as e:
|
| 180 |
+
return {
|
| 181 |
+
"command_executed": " ".join(command),
|
| 182 |
+
"stderr": e.stderr,
|
| 183 |
+
"error": "Could not retrieve module list. Ensure ExtUtils::Installed is available."
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
@mcp.tool()
|
| 187 |
+
def bioperl_load_gff(
|
| 188 |
+
gff_file: str,
|
| 189 |
+
database_name: str,
|
| 190 |
+
db_type: str = "sqlite",
|
| 191 |
+
create: bool = True,
|
| 192 |
+
user: Optional[str] = None,
|
| 193 |
+
password: Optional[str] = None,
|
| 194 |
+
):
|
| 195 |
+
"""
|
| 196 |
+
Specialized importer tool for BioPerl's bp_seqfeature_load.pl.
|
| 197 |
+
Imports GFF3/GTF files into a SeqFeature database (SQLite, MySQL, or PostgreSQL).
|
| 198 |
+
"""
|
| 199 |
+
gff_path = Path(gff_file)
|
| 200 |
+
if not gff_path.exists():
|
| 201 |
+
return {"error": f"GFF file not found: {gff_file}"}
|
| 202 |
+
|
| 203 |
+
# Constructing the bp_seqfeature_load.pl command
|
| 204 |
+
command = ["bp_seqfeature_load.pl", "-d", database_name, "-f", db_type]
|
| 205 |
+
|
| 206 |
+
if create:
|
| 207 |
+
command.append("-c")
|
| 208 |
+
if user:
|
| 209 |
+
command.extend(["-u", user])
|
| 210 |
+
if password:
|
| 211 |
+
command.extend(["-p", password])
|
| 212 |
+
|
| 213 |
+
command.append(str(gff_path.absolute()))
|
| 214 |
+
|
| 215 |
+
try:
|
| 216 |
+
result = subprocess.run(
|
| 217 |
+
command,
|
| 218 |
+
capture_output=True,
|
| 219 |
+
text=True,
|
| 220 |
+
check=True
|
| 221 |
+
)
|
| 222 |
+
return {
|
| 223 |
+
"command_executed": " ".join(command),
|
| 224 |
+
"stdout": result.stdout,
|
| 225 |
+
"stderr": result.stderr,
|
| 226 |
+
"database": database_name,
|
| 227 |
+
"status": "Import completed"
|
| 228 |
+
}
|
| 229 |
+
except subprocess.CalledProcessError as e:
|
| 230 |
+
return {
|
| 231 |
+
"command_executed": " ".join(command),
|
| 232 |
+
"stdout": e.stdout,
|
| 233 |
+
"stderr": e.stderr,
|
| 234 |
+
"error": f"BioPerl GFF import failed: {e.stderr}"
|
| 235 |
+
}
|
| 236 |
+
except FileNotFoundError:
|
| 237 |
+
return {"error": "bp_seqfeature_load.pl not found. Is BioPerl installed?"}
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/app/perl-importer_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_perl-importer/app/perl-importer_server.py')
|
| 11 |
+
SERVER_NAME = 'biosci_perl_importer'
|
| 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_perl-importer/app/requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
BioScientist/agent_system/toolbase/mcp_batch_from_manual_txt/mcp_perl-importer/docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
mcp-perl-importer:
|
| 5 |
+
build: .
|
| 6 |
+
image: mcp-perl-importer:latest
|
| 7 |
+
container_name: mcp-perl-importer
|
| 8 |
+
ports:
|
| 9 |
+
- "8000:8000"
|
| 10 |
+
environment:
|
| 11 |
+
- MCP_SERVER_NAME=perl-importer
|
| 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_perl-importer/environment.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
name: mcp-tool
|
| 3 |
+
channels:
|
| 4 |
+
- bioconda
|
| 5 |
+
- conda-forge
|
| 6 |
+
- defaults
|
| 7 |
+
dependencies:
|
| 8 |
+
- perl-importer
|
| 9 |
+
- python=3.10
|
| 10 |
+
|