pdb2reaction MCP server¶
pdb2reaction-mcp (alias p2r-mcp) is an MCP
server that lets any MCP-speaking agent drive every pdb2reaction CLI
subcommand via JSON-RPC over stdio — including Claude Desktop / Claude Code /
Cursor / Codeium, and any custom agent built on the official Python or
TypeScript MCP SDKs.
Install¶
pip install "pdb2reaction[mcp]"
This adds the mcp[cli] dependency and registers two console scripts:
pdb2reaction-mcp and p2r-mcp (alias).
Tools¶
18 tools, one per CLI subcommand. Each tool returns a structured dict with:
schema_version: envelope version. Live value:pdb2reaction.mcp._runner.MCP_SUBCMD_RESULT_SCHEMA_VERSION. A version bump signals a field-set / value-type change; pin against the constant rather than the literal in this doc.status:ok|failed|summary_missing|summary_parse_error|summary_run_mismatchexit_code: subprocess exit codeout_dir: managed stage directory, or null for successful helper toolssummary: parsedsummary.json; successful helpers without a managed summary return an empty objectstderr_tail/stdout_tail: last ~60 lines of process outputhint: parsed; recover: <hint>suffix from CLI error messages, if anyargv: the full argv that was executed (for reproducibility)run_id: UUID generated for this subprocess invocation. A parsed summary is returned only when it carries this exact ID; stale or mixed-generation output is reported assummary_run_mismatchwith an emptysummary.
Product CLI aliases are bound to the MCP server’s current Python interpreter
as python -m pdb2reaction, and the imported package source root is first in
the child PYTHONPATH. The child keeps the caller’s current working directory,
so relative scientific input paths retain their original meaning.
Structured error envelope¶
When a subcommand fails, the parsed summary (or sibling result.json) carries an extended error envelope so agents can pattern-match the exception class hierarchy without parsing text:
error:str(exc)of the original exceptionerror_type: exception class name (e.g."OptimizationError")error_class_chain: MRO class names (e.g.["OptimizationError", "RuntimeError", "Exception", "BaseException"])error_module: defining module of the exception classerror_label: the high-level CLI stage label
Stage runners¶
MCP tool |
CLI subcmd |
Purpose |
|---|---|---|
|
|
Optimize a single molecular geometry |
|
|
TS search (RS-P-RFO / Dimer / TRIM / RS-I-RFO) |
|
|
IRC integration from a TS geometry |
|
|
Vibrational analysis + thermochemistry |
|
|
Single-point MLIP energy + forces (+optional Hessian) |
Scans / paths / pipeline¶
MCP tool |
CLI subcmd |
Purpose |
|---|---|---|
|
|
Restraint-driven distance scans |
|
|
Two-endpoint MEP optimization |
|
|
Recursive reaction-pathway search |
|
|
End-to-end: extract → MEP → TS → IRC → freq → DFT |
|
|
Single-point DFT via gpu4pyscf |
Structure / I/O helpers¶
MCP tool |
CLI subcmd |
Purpose |
|---|---|---|
|
|
Cut a sphere around a ligand |
|
|
Repair PDB element columns |
|
|
Resolve PDB alternate locations |
|
|
Energy profile figure (PNG default; also SVG/PDF/HTML/CSV) |
|
|
Categorical energy diagram |
|
|
Bond-change diff between two PDBs |
Charge and ordered inputs¶
For tools exposing charge and ligand_charge, omit charge and supply a
per-resname ligand_charge mapping for PDB inputs when you want the total to be
derived. XYZ input without PDB residue context needs an explicit total charge.
A valid GJF charge/multiplicity header supplies both values automatically unless
you deliberately override them. If charge and ligand_charge are both
supplied, explicit charge wins.
search_paths requires input_pdb (reactant) and product_pdb; pass any
ordered intermediates as intermediate_pdbs. For staged 1D/full-pipeline scans,
put the first literal in scan_lists and later literals in
additional_scan_stages; the adapter emits one --scan-lists flag followed by
all stage values.
Opt-in IRC controls¶
run_irc (CLI: pdb2reaction irc) accepts irc_pos_def: bool — when set,
IRC convergence additionally requires a positive-definite mass-weighted
Hessian, blocking the IRC “shoulder” false-convergence where the rms-only
criterion calls success before reaching the local minimum. Defaults to
None (rms-only, legacy).
run_irc also accepts step_size and never_stop. When a branch stops after
only a few frames, reduce step_size (typically to 0.05) first. Set
never_stop=True to ignore gradient and energy endpoint criteria and trace to
the max-cycle cap; numerical/integration failures still stop. run_full_pipeline
forwards the same controls as irc_step_size / irc_never_stop and exposes
flatten plus refine_path for TS recovery.
find_transition_state (CLI: pdb2reaction tsopt) also exposes the
alternative TS optimizers via --opt-mode:
opt_mode="trim"— Helgaker (1991) trust-region image-minimization TS optopt_mode="rsprfo"— Banerjee (1985) restricted-step P-RFO TS opt
Client configuration¶
Client configuration schemas differ. The snippet below applies to clients that
accept a top-level mcpServers object; check the client’s own MCP
documentation before choosing the config file and schema.
Claude Desktop —
~/Library/Application Support/Claude/claude_desktop_config.json(macOS) /%APPDATA%\Claude\claude_desktop_config.json(Windows)Cursor —
~/.cursor/mcp.jsonOther clients — consult the client’s own MCP-server docs
{
"mcpServers": {
"pdb2reaction": {
"command": "pdb2reaction-mcp",
"args": []
}
}
}
See examples/mcp_client_config.json
for a full example with explicit env-var overrides (PATH / CUDA_VISIBLE_DEVICES).
VS Code instead uses a top-level servers object in .vscode/mcp.json
(VS Code MCP configuration reference):
{
"servers": {
"pdb2reaction": {
"command": "pdb2reaction-mcp",
"args": []
}
}
}
Custom Python MCP client¶
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
server_params = StdioServerParameters(command="pdb2reaction-mcp")
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools = await session.list_tools()
result = await session.call_tool(
"optimize_geometry",
arguments={
"input_pdb": "r.pdb",
"charge": -1,
"max_cycles": 50,
},
)
print(result.content)
Sandbox / safety notes¶
The MCP server inherits the calling environment’s PATH, conda env, and CUDA setup. Long-running tools (opt / tsopt / irc) launch the
pdb2reactionCLI in a subprocess — the agent should settimeout_secondson each tool call to bound runaway computations.Stage/pipeline output files land under the
out_dirkwarg (defaults to a uniquetempfile.mkdtemp(prefix="p2r_mcp_<subcmd>_…")so concurrent agent calls don’t collide). Helper tools use their explicit output path. Expertextra_argscan request additional non-managed behavior; it cannot override typed output paths,--out-dir, or the managed--out-json/--no-out-jsontoggle. Inspect the returnedargvwhen applying a filesystem policy.The server does not modify
~/.bashrc/ login env, install software, or authenticate model registries. All MLIP weights / PDB inputs must already exist on disk.