Metadata-Version: 2.5
Name: pythonparts-mcp
Version: 0.3.0.post1
Summary: MCP server exposing the ALLPLAN Python runtime to AI coding assistants
Requires-Python: >=3.11
Requires-Dist: fastmcp>=3.0
Requires-Dist: pyright>=1.1
Requires-Dist: pywin32>=306; sys_platform == 'win32'
Description-Content-Type: text/markdown

# PythonParts Local MCP Server

An MCP server that exposes the local ALLPLAN Python runtime to AI coding assistants.
It is started once per ALLPLAN version and gives any MCP-compatible agent accurate,
live information about the interpreter, import paths, installed packages, and type
correctness — without guessing or hallucinating.

Transport: **stdio** (spawned as a subprocess by the MCP client).  
Protocol: [Model Context Protocol](https://modelcontextprotocol.io/) via `FastMCP`.  
Release history: see the changelog in `CHANGELOG.md`, which also appears at the end of the PyPI page.

---

## Prerequisites

- [**uv**](https://docs.astral.sh/uv/getting-started/installation/) — Python package manager used to run the server without a manual install step.

  ```powershell
  winget install astral-sh.uv
  ```

---

## Attaching to your AI agent

Add the following entry to your MCP configuration:

```json
"pythonparts-local-mcp": {
  "type": "stdio",
  "command": "uvx",
  "args": [
    "pythonparts-mcp",
    "--allplan-version", "2027"
  ]
}
```

**Arguments:**

| Argument | Required | Description | Example |
|---|---|---|---|
| `--allplan-version` | yes | Installed ALLPLAN version | `2027` |
| `--std-path` | no | Path to ALLPLAN's `Std` directory | `C:\Data\Allplan\Allplan 2027\Std` |
| `--usr-path` | no | Path to ALLPLAN's user directory. Located under `Usr\<username>` or `Usr\Local` depending on your ALLPLAN configuration. | `C:\Users\Jane\Documents\Nemetschek\Allplan\2027\Usr\Local` |
| `--product-name` | no | Product name under which ALLPLAN is registered in the Windows registry. Default: `Allplan`. | `Allplan` |

The `prg` and `etc` paths are resolved automatically from the Windows registry, so
ALLPLAN must be installed. The server starts without the Std and Usr paths.

### Std and Usr paths

Each of the two paths is resolved on its own, in this order:

1. The `--std-path` / `--usr-path` argument.
2. `std_path` / `usr_path` in `PLUGIN_DATA\config.json`, where `PLUGIN_DATA` is the
   environment variable the plugin host sets for the server. If `PLUGIN_DATA` is not set,
   `COPILOT_PLUGIN_DATA` and then `CLAUDE_PLUGIN_DATA` are used instead; Claude Code sets
   only the latter.
3. Otherwise the path is not set.

An empty value, a value starting with `REPLACE-WITH-`, a `${...}` variable the host did
not expand, or an unreadable `config.json` counts as not set. With a path not set, the
server still works: its `sys.path` entries are left out, and the tools add a `note` saying so.

To set the paths, call `set_allplan_paths`. It applies them at once and writes them to
`PLUGIN_DATA\config.json`, which plugin updates leave alone:

```json
{"std_path": "C:\\Data\\Allplan\\Allplan 2027\\Std", "usr_path": "C:\\Users\\Jane\\Documents\\Nemetschek\\Allplan\\2027\\Usr\\Local"}
```

Arguments win over `config.json`. Leave them out unless the host does not provide
`PLUGIN_DATA`.

---

## Available Tools

### `get_allplan_info()`

Returns the installed ALLPLAN version string and the four resolved file-system paths (`prg`, `etc`, `std`, `usr`). No input required. An unset `std` or `usr` is reported as `"Not set. Use set_allplan_paths()"`. If a set path does not exist, `data.warnings` says so.

```json
{
  "ok": true,
  "data": {
    "version": "2027.0.0",
    "paths": {
      "prg": "C:\\Program Files\\Allplan\\Allplan 2027\\Prg",
      "etc": "C:\\ProgramData\\Nemetschek\\Allplan\\2027\\etc",
      "std": "X:\\Path\\To\\Allplan\\Std",
      "usr": "Not set. Use set_allplan_paths()"
    }
  }
}
```

### `set_allplan_paths(std_path: str = None, usr_path: str = None)`

Sets the ALLPLAN Std and/or Usr directory. Each value must be an absolute path to an existing directory; if any value is rejected, nothing changes. A path you leave out keeps its value. The new paths apply immediately to every tool, including type checks, without a restart.

With `PLUGIN_DATA` set, the paths are saved to `PLUGIN_DATA\config.json` and loaded on every start. Without it, they apply to the current session only and `data.persisted` is `false`. `data.warnings` appears when a `--std-path`/`--usr-path` argument will override the saved value after a restart.

```json
{
  "ok": true,
  "data": {
    "std": "C:\\Data\\Allplan\\Allplan 2027\\Std",
    "usr": "C:\\Users\\Jane\\Documents\\Nemetschek\\Allplan\\2027\\Usr\\Local",
    "persisted": true,
    "config_file": "C:\\Users\\Jane\\.copilot\\installed-plugins\\...\\data\\config.json"
  },
  "note": "Paths are active now and saved to C:\\Users\\Jane\\.copilot\\...\\config.json."
}
```

### Note on unset paths

`get_python_env_info`, `list_site_packages`, `typecheck_file`, `inspect_symbol` and `run_snippet_in_sandbox` work with the Std or Usr path unset. Their result then has a top-level `note` naming the missing path, for example:

```json
{"ok": true, "data": [], "note": "The ALLPLAN Std and Usr paths are not set, so the matching sys.path entries are omitted and modules from there cannot be resolved. Use set_allplan_paths() to set them."}
```

### `get_python_env_info()`

Returns the path to the ALLPLAN-embedded Python interpreter, its version, and the ordered `sys.path` ALLPLAN uses when executing PythonParts scripts. No input required.

```json
{
  "ok": true,
  "data": {
    "interpreter_path": "C:\\...\\Prg\\Python\\python.exe",
    "python_version": "3.11.9",
    "sys_path": ["C:\\...\\Prg\\Python", "..."]
  }
}
```

### `list_site_packages()`

Lists all Python packages installed in the ALLPLAN-embedded Python environment, deduplicated and sorted alphabetically. No input required.

```json
{
  "ok": true,
  "data": [
    {"name": "requests", "version": "2.31.0"},
    {"name": "shapely", "version": null}
  ]
}
```

### `typecheck_file(file_path: str)`

Type-checks a `.py` file against the ALLPLAN runtime using Pyright. Input: absolute path to the file.

```json
{
  "ok": true,
  "data": {
    "error_count": 2,
    "warning_count": 0,
    "diagnostics": [
      {
        "severity": "error",
        "message": "...",
        "file": "C:\\...\\main.py",
        "line": 12,
        "column": 5,
        "rule": "reportMissingImports"
      }
    ]
  }
}
```

### `inspect_symbol(symbol: str)`

Inspects a Python symbol in the live ALLPLAN runtime — returns its category, signature, docstring, and public members. Use this to verify a symbol exists and discover its API before writing code against it.

Input: dotted Python path to the symbol.

For native ALLPLAN modules the result is enriched from the matching `.pyi` stub, named in `stub_file`, so `members` and `magic_methods` carry full signatures. `docstring` is a list of lines. `overloads` lists `{signature, docstring}` per overload and is empty for symbols without overloads.

```json
{
  "ok": true,
  "data": {
    "symbol": "NemAll_Python_Geometry.Point3D",
    "category": "class",
    "module": "NemAll_Python_Geometry",
    "docstring": ["Representation class for 3D point"],
    "signature": null,
    "overloads": [],
    "members": ["GetCoords(self) -> tuple[float, float, float]", "GetDistance(self, point: Point3D) -> float", "..."],
    "magic_methods": ["__add__(self, vec: Vector3D) -> Point3D", "__eq__(self, point: Point3D) -> bool", "..."],
    "stub_file": "C:\\ProgramData\\Nemetschek\\Allplan\\2027\\etc\\PythonPartsFramework\\InterfaceStubs\\NemAll_Python_Geometry.pyi"
  }
}
```

### `run_snippet_in_sandbox(code: str)`

Runs a Python snippet against the ALLPLAN libraries in a **separate process, outside ALLPLAN**, and returns its `print()` output. ALLPLAN does not need to be running, and the snippet cannot touch the open drawing or project data. This is the tool to reach for when verifying geometry math or API behaviour.

The ALLPLAN interface modules are pre-imported as globals (`AllplanGeometry`, `AllplanBasisElements`, …). There is no document and no coordinate input, so `document` and `coord_input` are **not** available — anything that needs the open drawing, the project or user settings will fail or return a meaningless value.

Globals do not persist between calls, so each snippet must be self-contained. The first call spends a second or two loading the ALLPLAN DLLs; the process is then reused. Snippets are abandoned after 60 seconds.

Snippets must not show a user interface — `AllplanUtility.ShowMessageBox`, file dialogs and the like. There is no ALLPLAN window to host them, so the call never returns and the snippet runs into the timeout.

```json
{
  "ok": true,
  "data": {
    "output": "(30000.0, NemAll_Python_Geometry.eServiceResult.POSITIVE_ORIENTATION)\n"
  }
}
```


# Changelog

All notable changes to `pythonparts-mcp` are documented here.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.3.0.post1] — 2026-11-06

Documentation-only release; the code is the same as 0.3.0.

### Fixed

- The MCP configuration in the README no longer points `uvx` at TestPyPI. It installs from
  PyPI.org.
- The `get_allplan_info` response example renders as a code block.
- The `inspect_symbol` example shows the full response, including `overloads`, `magic_methods`
  and `stub_file`. The README also lists `--product-name` and says that unexpanded `${...}`
  values count as not set.
- Removed links to the private GitHub repository from the README and the package metadata.

## [0.3.0] — 2026-11-06

### Added

- **`set_allplan_paths`** — sets the ALLPLAN Std and/or Usr directory at runtime. Each value
  must be an absolute path to an existing directory; if one is rejected, nothing changes. The
  paths apply at once to every tool, including type checks, without a restart. When the host
  provides `PLUGIN_DATA`, they are saved to `PLUGIN_DATA/config.json`, so they survive plugin
  updates; otherwise they last for the session and the response says they were not persisted.
  `COPILOT_PLUGIN_DATA` and `CLAUDE_PLUGIN_DATA` are used when `PLUGIN_DATA` is not set, since
  Claude Code sets only `CLAUDE_PLUGIN_DATA`.

### Changed

- `--std-path` and `--usr-path` are now optional. Each path is taken from its argument, else
  from `PLUGIN_DATA/config.json`, else it stays unset. Empty values, `REPLACE-WITH-`
  placeholders and a missing or invalid `config.json` count as unset and never stop the server.
- With the Std or Usr path unset, `get_allplan_info` reports it as
  `"Not set. Use set_allplan_paths()"`. `get_python_env_info`, `list_site_packages`,
  `typecheck_file`, `inspect_symbol` and `run_snippet_in_sandbox` still work, leave that
  path's entries out of `sys.path`, and add a top-level `note` naming the unset path.
- `get_allplan_info` adds `data.warnings` when a set Std or Usr path does not exist.
- The `inspect_symbol` and `run_snippet_in_sandbox` workers restart on their next call after
  the paths change, so they pick up the new `sys.path`.

## [0.2.0] — 2026-09-16

### Added

- **`run_snippet_in_sandbox`** — runs a Python snippet against the ALLPLAN libraries and
  returns its `print()` output, so an agent can check geometry math or API behaviour instead
  of guessing at it.

  The snippet runs in a separate process under ALLPLAN's own interpreter, which means
  ALLPLAN does not need to be running and the snippet cannot reach the user's drawing or
  project data. The ALLPLAN interface modules are pre-imported as globals; `document` and
  `coord_input` do not exist, and calls that open a user interface will hang until the
  60-second timeout. Each call gets a fresh set of globals, so snippets must be
  self-contained.

  The worker process is started on first use and reused, so only the first call pays for
  loading the ALLPLAN DLLs.

### Fixed

- `inspect_symbol` declared a 30-second timeout but never applied it, so a wedged worker
  could hang the server indefinitely. The timeout is now enforced, and a worker that times
  out, crashes or desyncs is replaced on the next call.

## [0.1.2] — 2026-09-03

### Fixed

- FastMCP imports updated for the current FastMCP release.

## [0.1.1] — 2026-08-06

### Changed

- `get_runtime_context` split into `get_allplan_info`, `get_python_env_info` and
  `list_site_packages`.
- `inspect_symbol` now keeps one worker process alive for the lifetime of the server
  instead of spawning one per call.

### Fixed

- Corrected the declared project dependencies.

## [0.1.0] — 2026-07-23

Initial packaged release, exposing `get_runtime_context`, `typecheck_file` and
`inspect_symbol`.
