Skip to content

Plugin MCP Server

Hiromichi Yokoyama edited this page Nov 26, 2026 · 21 revisions

Plugin: MCP Server

MCP Server exposes MoleditPy as a live Model Context Protocol (MCP) server, enabling AI coding assistants and LLM agents (such as Claude Desktop, Claude Code, Google Antigravity, Cursor, Windsurf, VS Code Copilot) to inspect, query, and manipulate molecular structures in real time.

Repository moleditpy-mcp_server
Author HiroYokoyama
Supported OS Windows, macOS, Linux, WSL
Supported Python >=3.9, <3.15
Supported MoleditPy >=5.0.0, <6.0.0
First-party plugin license LGPL-3.0-or-later
Menu location Plugins ▸ MCP Server ▸ Start Server / ▸ Stop Server / ▸ Status & Settings...
Extra dependencies None (standard-library HTTP JSON-RPC server)

See Official Plugins for the full catalogue.


1. Overview and architecture

The Model Context Protocol (MCP) provides an open standard for connecting AI models to local software environments. With MCP Server active:

  • Runs as a lightweight local HTTP server (MCP Streamable HTTP, JSON-RPC over POST) at http://127.0.0.1:7891/mcp, speaking both the initialize-handshake protocol and the stateless MCP 2026-07-28 protocol.
  • Any MCP-compatible AI assistant can connect to MoleditPy without requiring custom client plugins.
  • Listens on localhost only, and refuses requests made from a web page (a non-local Origin, or a DNS-rebinding Host), so a site open in your browser cannot drive MoleditPy.

2. Capabilities and AI tools exposed

AI assistants connecting to the server gain access to 61 structured tools:

Molecular inspection

  • get_current_molecule: SMILES, molecular formula, molecular weight, atom and bond counts, and whether 3D coordinates exist. A structure loaded with distance-based bonds only still reports its formula and weight (without SMILES).
  • get_molecule_xyz, get_atom_properties, get_bond_info: Geometry as an XYZ block, per-atom properties, and the full bond table.
  • get_selected_atoms: Indices and elements of the atoms the user has selected in the 2D editor.
  • get_mapped_smiles, substructure_search, get_molecule_descriptors, compute_partial_charges: Atom-mapped SMILES for targeting, SMARTS matches, RDKit's standard descriptor set, and Gasteiger charges.
  • get_molecule_image: Render the 2D canvas or the 3D viewer and return it as a real image the assistant can look at, not text. atom_labels=true overlays the atom indices for that one capture; background sets a color or transparent for that capture.
  • measure_geometry: Distances, angles and dihedrals by atom index, several in one call.
  • compare_structures: RMSD against another structure with the same atom order (pasted XYZ or a file, any frame of a trajectory), Kabsch-aligned, optionally over heavy atoms only. overlay=true switches the viewer to the stick style and draws both structures, told apart by carbon color while every other element keeps its CPK color; clear_overlay restores the style and colors.

Molecular manipulation

  • load_molecule_by_name: Query PubChem online (e.g. "Load ibuprofen") and render the structure directly onto the canvas.
  • load_molecule_from_smiles, load_from_mol_block, show_xyz_in_viewer: Load structures from SMILES, a MOL/SDF block, or an XYZ block.
  • load_molecule_by_name, load_molecule_from_smiles and load_from_mol_block replace what is on the canvas (2.2.2): they clear the canvas and the current molecule first, with an undo checkpoint, as clear_canvas does. The canvas is cleared only after the input parses or the PubChem lookup succeeds, so a failed load changes nothing. clear=false adds the molecule to the drawing instead.
  • load_xyz_file: Load an .xyz file from the base folder without pasting coordinates. Multi-frame files (optimization trajectories) are supported: frame picks one (default: the last).
  • XYZ loading never stops on MoleditPy's charge dialog: pass charge for an ion, or skip_chemistry=true for distance-based bonds only. Without either, a structure whose bonds cannot be assigned at charge 0 loads with distance-based bonds and the result says so. The camera is re-fitted to each new structure unless keep_camera=true (for stepping through frames).
  • An XYZ with transition metals, lanthanides or actinides, whose bond orders RDKit cannot assign, loads with distance-based bonds; MoleditPy 5.3.1's confirmation for this is answered for you (2.2.2). The result names those elements and says that a given charge was not applied to them.
  • Loading XYZ replaces the current document. If it has unsaved changes (MCP edits such as edit_bonds count), show_xyz_in_viewer and load_xyz_file return an error and load nothing, instead of stopping on MoleditPy's "Unsaved Changes" dialog. Save first, or pass discard_unsaved=true to discard the changes and load. Any other dialog that opens during an MCP call is reported as an error naming it, rather than a time-out.
  • apply_reaction_smarts, add_hydrogens, remove_hydrogens, set_atom_charge, delete_atoms: Edit the current molecule directly; each re-sanitizes and rejects a result that is not a valid structure.
  • edit_bonds: Add or remove bonds by atom index pairs, the way the Bond Editor plugin does: the 3D coordinates are kept and one undo step is recorded. Useful for long or partial contacts that distance-based bonding leaves out; an edit above normal valence is kept and reported rather than refused.
  • trigger_3d_conversion: Generate 3D coordinates (ETKDG embedding + force-field optimization). Waits until the conversion has finished (or reports why it failed); pass wait: false to return immediately.
  • optimize_geometry: Refine the existing 3D conformer with MMFF94 or UFF.
  • run_python: Execute Python / RDKit code on MoleditPy's main thread with full access to the plugin context (ctx). It is not a sandbox: the code runs with your full access to the computer. Since 2.2.0, Status & Settings ▸ run_python tool decides whether a client may use it: Allowed (default) runs without asking, Ask each time shows the code in a MoleditPy dialog and runs it only on Yes, and Off refuses it and leaves it out of the tool list. The file-access limits below bind a client only while this is set to Ask each time or Off.
  • clear_canvas, check_chemistry, refresh_ui: Clear the editor, run the valence check, and resync the UI after direct edits.

3D visualization and camera

  • set_cpk_color_override / set_bond_color_override: Color-code specific atoms or bonds in the 3D viewer; the override survives redraws, and reset_cpk_color_override clears it.
  • reset_3d_camera, fit_2d_view, refresh_3d_view, enter_3d_mode / exit_3d_mode: Frame the molecule and switch between the 2D editor and the 3D viewer.
  • set_3d_camera / get_3d_camera: Point the camera exactly (a position, or the side to look from, plus the screen-up direction and zoom) and read it back, so a view can be reproduced. The view can also be set from atoms: along an atom-atom axis (direction_atoms), straight at the best plane of a ring (plane_atoms), centered on a group (focal_atoms); parallel_projection switches to an orthographic view.
  • set_3d_style: Switch the 3D style (ball and stick, CPK, wireframe, stick); color overrides are kept.
  • save_molecule_image: Write the 2D or 3D view as a PNG into the base folder, for reports and notes, on the viewer's background, white, or transparent.

Files and input generation

  • write_file_with_xyz_block: The preferred way to write a quantum-chemistry input file (ORCA, Gaussian, GAMESS, xTB, ...): the coordinate block comes straight from the live molecule between your header and footer, so coordinates are never retyped.
  • write_text_file, read_text_file, list_directory, delete_file: Plain file access.
  • get_file_io_config / set_file_io_config: The base folder and extension allowlist every file tool is confined to. With no base folder set, the file tools are disabled. A change requested by an AI is applied only after you press Yes in a MoleditPy dialog.
  • request_read_folder: Ask for read-only access to another folder; MoleditPy shows a Yes/No dialog (default No). Read-only folders can also be added or cleared in Status & Settings.... Inside them the reading tools accept absolute paths; writing and deleting stay in the base folder.
  • find_files, grep_files: Search by file name or by content in that base folder, the installed MoleditPy source, or the user's plugin folder.

Plugin authoring and discovery

  • get_plugin_dev_manual, list_app_source_tree, get_app_source: Read the plugin development manual and the installed MoleditPy source.
  • get_plugin_dir, reload_plugins: Write a plugin into the plugin folder and load it without restarting; the plugin menus are rebuilt so they call the reloaded code.
  • list_available_plugins, open_plugin_installer: Search the official plugin registry and open the Plugin Installer for the user.
  • get_app_info: MoleditPy and MCP Server versions.

Safety and Undo integration

  • The molecule-editing tools push an entry to MoleditPy's native Undo stack, so the user can revert an AI edit with Ctrl+Z; push_undo_checkpoint records one on demand (for example after run_python).
  • File tools never leave the configured base folder (reads: or a read-only folder you approved), an AI cannot widen file access without your Yes in the app, refuse to overwrite without overwrite=true, and delete_file requires confirm=true.

3. Connecting AI clients

Copy configuration from Status & Settings ▸ Client configuration first. Replace YOUR_TOKEN below with your own server token. Include the authentication header in your client configuration.

For Claude Code, one command registers the server for all your projects:

claude mcp add --transport http -s user moleditpy http://127.0.0.1:7891/mcp --header "Authorization: Bearer YOUR_TOKEN"

Use -s project instead to write a .mcp.json into the current project only (Claude Code asks you to approve it on the next start). claude mcp get moleditpy shows whether it is connected.

For other clients, add the following to the MCP configuration file (e.g. claude_desktop_config.json):

{
  "mcpServers": {
    "moleditpy": {
      "type": "streamable-http",
      "url": "http://127.0.0.1:7891/mcp",
      "headers": {"Authorization": "Bearer YOUR_TOKEN"}
    }
  }
}

Start the server from Plugins ▸ MCP Server ▸ Start Server, or enable auto-start on launch via Plugins ▸ MCP Server ▸ Status & Settings..., which also shows ready-to-copy snippets for Claude Code, Cursor, Windsurf, Zed, VS Code, Codex CLI and Antigravity.

If another MoleditPy instance is already serving the configured port, starting the server (manually or on launch) is skipped and the Status dialog shows that it is running in another instance.

Reloading plugins stops the running server and starts it again with the reloaded code, so the port is never left held by the old copy.


Usage notes

MCP requests use Authorization: Bearer <token>. Copy client configuration from Status & Settings and keep its token private.

A connected assistant acts on text it reads, such as a structure file, a compound record or the plugin registry. Choose Ask each time or Off for run_python unless you need unattended code execution and trust everything the assistant will read. Since 2.2.0, UNC and device paths (for example \\server\share) are refused by request_read_folder, set_file_io_config and absolute reads, and the write and delete tools refuse the plugin's own settings.json.

From version 2.1.0, all MCP settings are saved in mcp_server/settings.json inside the installed plugin folder: the port, auto-start, protocol mode, authentication token, base folder, allowed extensions and read-only folders. The Plugin Installer keeps this file when updating, and release packages do not contain it. The first launch after upgrading imports the existing values from MoleditPy's shared settings, so configured clients keep working; the old keys are left in place but no longer read. Deleting the file runs the import again, and a malformed file is reported and left untouched. The file holds the token, so keep it private and out of source control and shared plugin folders.

The dialog contains Server, File access and Client configuration sections. Select a folder row to view or copy its path. Add…, Remove selected and Clear all… manage read-only permissions. The read/write folder takes priority when a path belongs to both permission lists.


4. See also

Atom indices and formal charges must be integers. Fractional values, booleans and non-finite numbers are rejected before editing the molecule. Reaction anchors must name an existing atom; XYZ structure comparisons require finite coordinates.

Reaction anchors must also belong to a reaction match; an unmatched anchor cannot silently select another site. JSON flags such as confirm and overwrite accept only true or false. XYZ exports validate ordering, precision, comments and finite coordinates; image saves use atomic/exclusive writes. File searches and source trees skip symbolic links and Windows reparse points. Stopping the server cancels queued edits before the GUI bridge is retired, and a hidden Status dialog pauses its polling timer.


This page documents MCP Server v2.2.2, and was last updated on 2026-11-26. See REGISTRY/plugins.json for the current version.

Clone this wiki locally