BioOcto / Biomni /mcp_generated /mcp_bbmap /app /bbmap_shim_server.py
czty's picture
BioOcto code and data release (snapshot 2026-11-27, resumed) (part 27)
714afdd verified
Raw History Blame Contribute Delete
1.51 kB
#!/usr/bin/env python3
from __future__ import annotations
import ast
from pathlib import Path
from mcp.server.fastmcp import FastMCP
SOURCE_SERVER = Path('/225040511/project/BioScientist/agent_system/toolbase/mcp_batch_from_help_txt/mcp_bbmap/app/bbmap_server.py')
LOCAL_SERVER = Path(__file__).with_name(SOURCE_SERVER.name)
SERVER_NAME = 'biosci_bbmap'
class _ShimMCP:
@staticmethod
def tool(*args, **kwargs):
if args and callable(args[0]) and len(args) == 1 and not kwargs:
return args[0]
def _decorator(fn):
return fn
return _decorator
def _resolve_source_server():
if LOCAL_SERVER.exists() and LOCAL_SERVER.name != Path(__file__).name:
return LOCAL_SERVER
return SOURCE_SERVER
def _load_functions():
source_server = _resolve_source_server()
code = source_server.read_text(encoding="utf-8")
tree = ast.parse(code, filename=str(source_server))
function_names = [n.name for n in tree.body if isinstance(n, ast.FunctionDef) and not n.name.startswith("_")]
namespace = {
"__name__": "__mcp_source__",
"mcp": _ShimMCP(),
}
exec(compile(code, str(source_server), "exec"), namespace, namespace)
loaded = []
for name in function_names:
fn = namespace.get(name)
if callable(fn):
loaded.append(fn)
return loaded
mcp = FastMCP(SERVER_NAME)
for _fn in _load_functions():
mcp.tool()(_fn)
if __name__ == "__main__":
mcp.run(transport="stdio")