claude-pascal-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": "0.0.1",
3
+ "configurations": [
4
+ {
5
+ "name": "pascal-preview",
6
+ "runtimeExecutable": "D:/projects/python/claude-pascal-mcp/.venv/Scripts/pythonw.exe",
7
+ "runtimeArgs": ["-m", "pascal_mcp.preview_bridge"],
8
+ "port": 18080,
9
+ "autoPort": true
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,74 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ build:
11
+ name: Build distributions
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Install uv
17
+ uses: astral-sh/setup-uv@v4
18
+
19
+ - name: Set up Python
20
+ run: uv python install 3.12
21
+
22
+ - name: Build sdist and wheel
23
+ run: uv build
24
+
25
+ - name: Upload build artifacts
26
+ uses: actions/upload-artifact@v4
27
+ with:
28
+ name: dist
29
+ path: dist/
30
+
31
+ publish-pypi:
32
+ name: Publish to PyPI
33
+ needs: build
34
+ runs-on: ubuntu-latest
35
+ if: startsWith(github.ref, 'refs/tags/v')
36
+ environment:
37
+ name: pypi
38
+ url: https://pypi.org/p/claude-pascal-mcp
39
+ permissions:
40
+ id-token: write
41
+ steps:
42
+ - name: Download build artifacts
43
+ uses: actions/download-artifact@v4
44
+ with:
45
+ name: dist
46
+ path: dist/
47
+
48
+ - name: Publish to PyPI via trusted publishing
49
+ uses: pypa/gh-action-pypi-publish@release/v1
50
+
51
+ github-release:
52
+ name: Attach artifacts to GitHub Release
53
+ needs: publish-pypi
54
+ runs-on: ubuntu-latest
55
+ if: startsWith(github.ref, 'refs/tags/v')
56
+ permissions:
57
+ contents: write
58
+ steps:
59
+ - uses: actions/checkout@v4
60
+
61
+ - name: Download build artifacts
62
+ uses: actions/download-artifact@v4
63
+ with:
64
+ name: dist
65
+ path: dist/
66
+
67
+ - name: Create GitHub Release
68
+ env:
69
+ GH_TOKEN: ${{ github.token }}
70
+ run: |
71
+ gh release create "${GITHUB_REF_NAME}" \
72
+ --title "${GITHUB_REF_NAME}" \
73
+ --generate-notes \
74
+ dist/*
@@ -0,0 +1,32 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ *.egg
9
+
10
+ # Virtual environments
11
+ .venv/
12
+ venv/
13
+ env/
14
+
15
+ # IDE
16
+ .idea/
17
+ .vscode/
18
+ *.swp
19
+ *.swo
20
+
21
+ # OS
22
+ .DS_Store
23
+ Thumbs.db
24
+
25
+ # Compiled Pascal output from tests
26
+ *.exe
27
+ *.dcu
28
+ *.o
29
+ *.ppu
30
+
31
+ # uv lock
32
+ uv.lock
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tina4 Community
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,349 @@
1
+ # Claude Pascal MCP — Team Handbook
2
+
3
+ A self-contained guide for uploading to Claude Teams / project knowledge. Everything a teammate needs to set up and use the Claude Pascal MCP server lives in this file.
4
+
5
+ Repo: `git@github.com:tina4stack/claude-pascal-mcp.git`
6
+ License: MIT
7
+
8
+ ---
9
+
10
+ ## What this is
11
+
12
+ An MCP (Model Context Protocol) server that lets Claude compile, run, and interact with Pascal/Delphi desktop applications. It bundles five capability areas:
13
+
14
+ 1. **Pascal/Delphi compilation** — Free Pascal (`fpc`), Delphi 32-bit (`dcc32`), and Delphi 64-bit (`dcc64`).
15
+ 2. **Windows desktop automation** — screenshot, click, type, and key-send to running app windows without stealing focus.
16
+ 3. **IDE observer** — capture screenshots of RAD Studio / Delphi / Lazarus and surface compiler errors with surrounding source context.
17
+ 4. **Android device automation (ADB)** — screenshots, taps, swipes, text input, key events, app management, and file transfer.
18
+ 5. **Preview bridge** — a Starlette HTTP server that serves live screenshots of desktop apps so Claude's web preview panel can interact with them.
19
+
20
+ ---
21
+
22
+ ## Prerequisites
23
+
24
+ - **Python 3.11+**
25
+ - **[uv](https://docs.astral.sh/uv/)** package manager
26
+ - **A Pascal compiler** — Free Pascal, Delphi, or RAD Studio. If none are installed, the `setup_fpc` tool will download and install Free Pascal for you.
27
+ - **Windows** for the desktop-automation and IDE-observer tools (uses Win32 APIs).
28
+ - **ADB on `PATH`** for the Android tools (ships with Android SDK Platform Tools).
29
+
30
+ The server auto-detects compilers in this priority order:
31
+
32
+ 1. Free Pascal (`fpc`)
33
+ 2. Delphi 64-bit (`dcc64`)
34
+ 3. Delphi 32-bit (`dcc32`)
35
+
36
+ It checks the system `PATH` first, then known install directories:
37
+
38
+ - `C:\FPC\*\bin\*\fpc.exe`
39
+ - `C:\Lazarus\fpc\*\bin\*\fpc.exe`
40
+ - `C:\Program Files (x86)\Embarcadero\Studio\*\bin\dcc*.exe`
41
+
42
+ You can always pass an explicit `compiler="C:\\full\\path\\to\\dcc64.exe"` to override detection.
43
+
44
+ ---
45
+
46
+ ## First-time setup
47
+
48
+ Three ways to install — pick the one that fits.
49
+
50
+ ### A. From PyPI (recommended once published)
51
+
52
+ No clone, no `uv sync` — `uvx` fetches and runs in one shot:
53
+
54
+ ```bash
55
+ uvx --from claude-pascal-mcp pascal-mcp
56
+ ```
57
+
58
+ `.mcp.json`:
59
+
60
+ ```json
61
+ {
62
+ "mcpServers": {
63
+ "pascal-dev": {
64
+ "command": "uvx",
65
+ "args": ["--from", "claude-pascal-mcp", "pascal-mcp"]
66
+ }
67
+ }
68
+ }
69
+ ```
70
+
71
+ ### B. From GitHub (no PyPI account needed)
72
+
73
+ Run it straight from the repo. Pin a tag for reproducibility.
74
+
75
+ ```bash
76
+ uvx --from git+https://github.com/tina4stack/claude-pascal-mcp pascal-mcp
77
+ ```
78
+
79
+ `.mcp.json`:
80
+
81
+ ```json
82
+ {
83
+ "mcpServers": {
84
+ "pascal-dev": {
85
+ "command": "uvx",
86
+ "args": ["--from", "git+https://github.com/tina4stack/claude-pascal-mcp", "pascal-mcp"]
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ ### C. Local dev clone (for contributors)
93
+
94
+ ```bash
95
+ git clone git@github.com:tina4stack/claude-pascal-mcp.git
96
+ cd claude-pascal-mcp
97
+ uv sync
98
+
99
+ # Run the MCP server (stdio mode)
100
+ uv run pascal-mcp
101
+
102
+ # Or run the preview bridge (HTTP mode)
103
+ uv run pascal-preview
104
+ ```
105
+
106
+ `.mcp.json`:
107
+
108
+ ```json
109
+ {
110
+ "mcpServers": {
111
+ "pascal-dev": {
112
+ "command": "uv",
113
+ "args": ["run", "--directory", "/path/to/claude-pascal-mcp", "pascal-mcp"]
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
119
+ ### Register with Claude Code
120
+
121
+ Pick the matching install form:
122
+
123
+ ```bash
124
+ claude mcp add --transport stdio pascal-dev -- uvx --from claude-pascal-mcp pascal-mcp
125
+ claude mcp add --transport stdio pascal-dev -- uvx --from git+https://github.com/tina4stack/claude-pascal-mcp pascal-mcp
126
+ claude mcp add --transport stdio pascal-dev -- uv run --directory /path/to/claude-pascal-mcp pascal-mcp
127
+ ```
128
+
129
+ ### Register with Claude Desktop
130
+
131
+ Add the same `mcpServers` block to `claude_desktop_config.json`.
132
+
133
+ ### Enable the preview bridge
134
+
135
+ Add to `.claude/launch.json` in the project you're working in:
136
+
137
+ ```json
138
+ {
139
+ "version": "0.0.1",
140
+ "configurations": [
141
+ {
142
+ "name": "pascal-preview",
143
+ "runtimeExecutable": "/path/to/claude-pascal-mcp/.venv/Scripts/pythonw.exe",
144
+ "runtimeArgs": ["-m", "pascal_mcp.preview_bridge"],
145
+ "port": 18080,
146
+ "autoPort": true
147
+ }
148
+ ]
149
+ }
150
+ ```
151
+
152
+ Then call `preview_start("pascal-preview")` from Claude Code to open the preview panel.
153
+
154
+ ---
155
+
156
+ ## Driving it from Claude — example prompts
157
+
158
+ - "Compile and run this Pascal program." → `run_pascal`
159
+ - "Build my project at `C:\src\MyApp\MyApp.dproj`." → `build_dproj`
160
+ - "Generate a Delphi app with a button and a memo, then launch it." → `compile_delphi_project` + `launch_app`
161
+ - "Screenshot the RAD Studio IDE and tell me what compiler errors are showing." → `observe_ide` + `read_ide_errors`
162
+ - "Take a screenshot of my running app and click the Save button." → `screenshot_app` + `app_click`
163
+ - "What Android devices are connected? Tap the login button at (540, 1200)." → `adb_devices` + `adb_tap`
164
+
165
+ The MCP server instructs Claude to **always route Pascal/Delphi work through these tools** — never `msbuild`, raw shell calls to `dcc32`, etc. That keeps compiler invocation, output capture, and path handling consistent across the team.
166
+
167
+ ### Critical tool distinctions
168
+
169
+ | Need | Use | Don't confuse with |
170
+ |------|-----|---------------------|
171
+ | Compile a snippet of source | `compile_pascal` | — |
172
+ | Build a real, existing `.dproj` (multi-unit, custom search paths, defines, resources) | `build_dproj` | `compile_delphi_project` |
173
+ | Scaffold a throwaway demo project from a template (TButton/TEdit/TLabel/TMemo) | `compile_delphi_project` | `build_dproj` |
174
+ | Run a console program and capture output | `run_pascal` | `launch_app` |
175
+ | Launch a GUI app that needs to keep running | `launch_app` | `run_pascal` |
176
+ | Syntax check without linking | `check_syntax` | — |
177
+
178
+ ---
179
+
180
+ ## Full tool reference
181
+
182
+ ### Pascal/Delphi
183
+
184
+ | Tool | Description |
185
+ |------|-------------|
186
+ | `get_compiler_info` | Detect available compilers and show versions. |
187
+ | `compile_pascal` | Compile a single-file Pascal source. |
188
+ | `build_dproj` | Build an existing `.dproj` with its own units, search paths, defines, resources. |
189
+ | `compile_delphi_project` | Generate a new throwaway Delphi project from a template (DPR + PAS + DFM). Cannot build an existing `.dproj`. |
190
+ | `run_pascal` | Compile and execute a console program, capturing stdout/stderr. |
191
+ | `launch_app` | Compile and launch a GUI app in the background (no focus stealing). |
192
+ | `check_syntax` | Syntax check only — no linking. |
193
+ | `parse_form` | Parse DFM / FMX / LFM form files. |
194
+ | `setup_fpc` | Download and install Free Pascal as a fallback if no compiler is found. |
195
+
196
+ ### Windows desktop interaction
197
+
198
+ | Tool | Description |
199
+ |------|-------------|
200
+ | `screenshot_app` | Capture a screenshot of a running app window (non-intrusive). |
201
+ | `list_app_windows` | List visible windows on the desktop. |
202
+ | `app_click` | Click a Windows app window at screenshot pixel coordinates. |
203
+ | `app_type` | Type text into a Windows app window. |
204
+ | `app_key` | Send a key or shortcut (`ctrl+a`, `enter`, `alt+f4`, …) to a window. |
205
+
206
+ Clicks use `PostMessage` with automatic child-window targeting so they land on the correct control. Typing and key events use `SendInput` for full Unicode and modifier support.
207
+
208
+ ### IDE observer
209
+
210
+ | Tool | Description |
211
+ |------|-------------|
212
+ | `observe_ide` | Capture an IDE screenshot and scan project files. |
213
+ | `read_ide_errors` | Read source code around compiler error locations. |
214
+ | `list_project_files` | List source files in a Delphi / Lazarus project. |
215
+
216
+ ### Android (ADB)
217
+
218
+ All ADB tools accept an optional `device` serial. With a single device connected, it auto-selects.
219
+
220
+ | Tool | Description |
221
+ |------|-------------|
222
+ | `adb_devices` | List connected devices with model, Android version, screen size. |
223
+ | `adb_device_info` | Detailed info for a specific device. |
224
+ | `adb_screenshot` | Capture the device screen. |
225
+ | `adb_tap` / `adb_swipe` | Touch interaction at pixel coordinates. |
226
+ | `adb_type_text` | Type text (auto-escapes for `adb shell`). |
227
+ | `adb_key` | Send a key event. Aliases: `home`, `back`, `enter`, `menu`, `power`, `volume_up`, `volume_down`, `tab`, `delete`, `space`, `escape`, `app_switch`. |
228
+ | `adb_install` | Install an APK. |
229
+ | `adb_list_packages` | List installed packages (optional filter). |
230
+ | `adb_launch_app` | Launch an app by package name. |
231
+ | `adb_stop_app` | Force-stop an app. |
232
+ | `adb_push` / `adb_pull` | Push or pull files between PC and device. |
233
+
234
+ ---
235
+
236
+ ## Project templates (`compile_delphi_project`)
237
+
238
+ You specify components and event handlers, and the tool emits the correct DPR, PAS, and DFM files. Templates automatically pick the right uses-clause style:
239
+
240
+ - **Modern Delphi** (RAD Studio) → namespaced units (`Vcl.Forms`, `System.SysUtils`).
241
+ - **Legacy Delphi 7** → non-namespaced units (`Forms`, `SysUtils`).
242
+
243
+ Form definitions (DFM) and event wiring between DFM and PAS are generated for you.
244
+
245
+ ### Example
246
+
247
+ ```
248
+ compile_delphi_project(
249
+ project_name="HelloWorld",
250
+ form_caption="My App",
251
+ components='[{"type": "TButton", "name": "btnHello", "caption": "Click Me",
252
+ "left": 100, "top": 100, "width": 120, "height": 35,
253
+ "event": "btnHelloClick"}]',
254
+ events='[{"name": "btnHelloClick", "body": "ShowMessage(\'Hello!\');"}]',
255
+ compiler="C:\\Path\\To\\dcc64.exe"
256
+ )
257
+ ```
258
+
259
+ This produces:
260
+ - `HelloWorld.dpr` — project file with proper uses clause
261
+ - `uMain.pas` — unit with form class, component declarations, event handlers
262
+ - `uMain.dfm` — form definition with component properties
263
+
264
+ Supported component types in templates: `TButton`, `TEdit`, `TLabel`, `TMemo`.
265
+
266
+ ---
267
+
268
+ ## Preview bridge
269
+
270
+ The preview bridge lets Claude see and interact with running Pascal desktop apps through its web-based preview panel. It runs as a Python/Starlette HTTP server.
271
+
272
+ ```
273
+ Claude preview tools (preview_start / preview_screenshot / preview_click)
274
+ │ HTTP
275
+
276
+ Preview Bridge Server (Python / Starlette)
277
+ / → HTML page with live screenshot viewer
278
+ /api/screenshot → PNG of target window
279
+ /api/controls → enumerate child controls with positions
280
+ /api/click → click at coordinates or by control hwnd
281
+ /api/type → send keystrokes to target window
282
+ /api/move → move window to screen position
283
+ /api/resize → resize window
284
+ │ Win32 PrintWindow API
285
+
286
+ Running Pascal desktop application
287
+ ```
288
+
289
+ ### HTTP API
290
+
291
+ | Route | Method | Description |
292
+ |-------|--------|-------------|
293
+ | `/` | GET | HTML page with auto-refreshing screenshot viewer. |
294
+ | `/api/screenshot` | GET | PNG screenshot of target window. |
295
+ | `/api/windows` | GET | List visible windows. |
296
+ | `/api/target` | POST | Set target window by title. |
297
+ | `/api/controls` | GET | Enumerate child controls (buttons, inputs, …). |
298
+ | `/api/click` | POST | Click by coordinates or direct control hwnd. |
299
+ | `/api/type` | POST | Send text or key combos (`ctrl+a`, `enter`, …). |
300
+ | `/api/drag` | POST | Drag from one point to another. |
301
+ | `/api/move` | POST | Move target window. |
302
+ | `/api/resize` | POST | Resize target window. |
303
+ | `/api/window-info` | GET | Window position, size, client-area offset. |
304
+ | `/api/console` | GET | Console output from launched apps. |
305
+ | `/api/launch` | POST | Launch an executable. |
306
+
307
+ ### Click methods (most to least reliable)
308
+
309
+ 1. **Direct control click** — `{"hwnd": "12345"}` sends `BM_CLICK` directly to a control handle. Works regardless of DPI, multiple monitors, or foreground state. Get hwnds from `/api/controls`.
310
+ 2. **Client-area coordinates** — `{"x": 200, "y": 142, "client": true}` uses `ClientToScreen` for proper DPI handling.
311
+ 3. **Window-relative coordinates** — `{"x": 312, "y": 261}` — raw coordinates in the screenshot image space.
312
+
313
+ ---
314
+
315
+ ## Workflows worth knowing
316
+
317
+ ### Driving a desktop Delphi app from Claude
318
+
319
+ 1. `screenshot_app` — capture the current UI.
320
+ 2. Identify pixel coordinates of the target element.
321
+ 3. `app_click` to click. Use `app_type` to enter text into the focused field. Use `app_key` for keyboard shortcuts.
322
+
323
+ ### Driving an Android device from Claude
324
+
325
+ 1. `adb_devices` — pick a device (auto-selected when only one is attached).
326
+ 2. `adb_screenshot` — see the current screen.
327
+ 3. `adb_tap` / `adb_swipe` / `adb_type_text` / `adb_key` — drive the UI.
328
+ 4. `adb_install` / `adb_launch_app` / `adb_stop_app` — manage apps.
329
+ 5. `adb_push` / `adb_pull` — transfer files in either direction.
330
+
331
+ ### Diagnosing IDE compile errors
332
+
333
+ 1. `observe_ide` — screenshot the IDE and scan its project files.
334
+ 2. `read_ide_errors` — pull source context around each reported error.
335
+
336
+ ---
337
+
338
+ ## Repo layout
339
+
340
+ - `src/pascal_mcp/server.py` — MCP tool registrations.
341
+ - `src/pascal_mcp/compiler.py` — compiler detection and invocation.
342
+ - `src/pascal_mcp/preview_bridge.py` — Starlette HTTP server for the live preview.
343
+
344
+ ---
345
+
346
+ ## Support
347
+
348
+ - Issues: open one on the repo.
349
+ - License: MIT.