Metadata-Version: 2.5
Name: pythonparts-mcp
Version: 0.2.0
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: [CHANGELOG.md](CHANGELOG.md).

---

## 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": [
    "--index", "https://test.pypi.org/simple",
    "--index-strategy", "unsafe-best-match",
    "pythonparts-mcp",
    "--allplan-version", "2026",
    "--std-path", "X:\\Path\\To\\Allplan\\Std",
    "--usr-path", "X:\\Path\\To\\Allplan\\Usr\\Local"
  ]
}
```

**Arguments:**

| Argument | Description | Example |
|---|---|---|
| `--allplan-version` | Installed ALLPLAN version | `2026` |
| `--std-path` | Path to ALLPLAN's `Std` directory | `C:\Data\Allplan\Allplan 2026\Std` |
| `--usr-path` | Path to ALLPLAN's user directory. Located under `Usr\<username>` or `Usr\Local` depending on your ALLPLAN configuration. | `C:\Users\Jane\Nemetschek\Allplan\2026\Usr\Local` |

The `prg` and `etc` paths are resolved automatically from the Windows registry.

---

## 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.

```json
{
  "ok": true,
  "data": {
    "version": "2026.0.0",
    "paths": {
      "prg": "C:\\Program Files\\Allplan\\Allplan 2026\\Prg",
      "etc": "C:\\ProgramData\\Nemetschek\\Allplan\\2026\\etc",
      "std": "X:\\Path\\To\\Allplan\\Std",
      "usr": "X:\\Path\\To\\Allplan\\Usr\\Local"
    }
  }
}
```

### `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.

```json
{
  "ok": true,
  "data": {
    "symbol": "NemAll_Python_Geometry.Point3D",
    "category": "class",
    "module": "NemAll_Python_Geometry",
    "docstring": "...",
    "signature": null,
    "members": ["X", "Y", "Z", "..."]



  }
}
```

### `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"
  }
}
```
