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_errorexit_code: subprocess exit codeout_dir: working directory the CLI wrote tosummary: parsedsummary.json(CLI output schema; see JSON Output Reference for the per-stage shape)stderr_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)
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-I-RFO / Dimer / TRIM / RS-P-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 |
Opt-in IRC convergence guard¶
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).
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¶
Every MCP client takes the same mcpServers schema. Drop the snippet below
into your client’s MCP config file:
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).
Custom Python MCP client¶
import subprocess
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.Output files land under the
out_dirkwarg (defaults to a uniquetempfile.mkdtemp(prefix="p2r_mcp_<subcmd>_…")so concurrent agent calls don’t collide).The server does not modify
~/.bashrc/ login env, install software, or write outsideout_dir. All MLIP weights / PDB inputs must already exist on disk.