Skip to content

Commit f678623

Browse files
committed
Add GitHub Actions workflow and update copilot instructions
- Add build-dlls.yml workflow to build Debug and Release DLLs on push/PR - Update copilot-instructions.md with comprehensive architecture details - Document build paths, thread safety patterns, and resource management - Add examples for adding new tools and resources
1 parent b41941f commit f678623

File tree

2 files changed

+118
-15
lines changed

2 files changed

+118
-15
lines changed

.github/copilot-instructions.md

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
Cheat Engine MCP Server — a C# plugin that exposes Cheat Engine functionality as MCP tools over SSE (Server-Sent Events) using the official [Model Context Protocol C# SDK](https://github.com/modelcontextprotocol/csharp-sdk).
66

7+
**Key Architecture**:
8+
- **MCP SSE Server**: ASP.NET Core app on `http://127.0.0.1:6300` with SSE at `/sse`
9+
- **CE Plugin Host**: Runs inside Cheat Engine process, manages server lifecycle via menu
10+
- **CESDK Submodule**: C# wrapper for CE's Lua API (git submodule dependency)
11+
- **Single DLL**: All dependencies embedded, copy to CE plugins folder to deploy
12+
713
## Cheat Engine Lua API Reference
814

915
The full CE Lua API documentation is at `C:\Program Files\Cheat Engine\celua.txt`. Always consult this file when:
@@ -14,54 +20,64 @@ The full CE Lua API documentation is at `C:\Program Files\Cheat Engine\celua.txt
1420
## Build and Test
1521

1622
```bash
17-
# Initialize submodule (first time)
23+
# Initialize submodule (first time only)
1824
git submodule update --init --recursive
1925

20-
# Build
26+
# Build Debug
2127
dotnet build
2228

2329
# Build Release
2430
dotnet build -c Release
2531
```
2632

27-
Deploy: copy `ce-mcp.dll` from `bin/` to Cheat Engine plugins directory, enable in CE, use "MCP" menu.
33+
**Deploy**: Copy `ce-mcp.dll` from `bin/x64/Debug/net10.0-windows/` (or Release) to Cheat Engine plugins directory, enable in CE, use "MCP" → "Start MCP Server" menu.
34+
35+
**Requirements**: .NET 10.0 SDK, CE 7.6.2+, ASP.NET Core 10.0 runtime. CE must have `ce.runtimeconfig.json` set to .NET 10.0 (see README).
2836

2937
## Architecture
3038

3139
### Core Components
3240

33-
- **Plugin.cs** — Main CE plugin entry point (`CESDKPluginClass`). Manages MCP server lifecycle, registers Lua functions for CE menu integration, provides WPF config UI.
34-
- **McpServer.cs** — MCP SSE server using `ModelContextProtocol.AspNetCore`. Registers all tools via `WithTools<T>()` and maps endpoints with `MapMcp()`.
35-
- **ServerConfig.cs** — Configuration management (host/port/name). Loads from `%APPDATA%\CeMCP\config.json` with env var overrides (`MCP_HOST`, `MCP_PORT`).
41+
- **Plugin.cs** — Main CE plugin entry point (`McpPlugin : CheatEnginePlugin`). Manages MCP server lifecycle, registers Lua functions for CE menu integration (`toggle_mcp_server`, `show_mcp_config`), provides WPF config UI. Handles assembly resolution for WPF components.
42+
- **McpServer.cs** — MCP SSE server using `ModelContextProtocol.AspNetCore`. Registers all tools via `WithTools<T>()`, resources via `WithResources<T>()`, and maps endpoints with `MapMcp()`. Runs ASP.NET Core with minimal logging in background task.
43+
- **ServerConfig.cs** — Configuration management (host/port/name). Loads from `%APPDATA%\CeMCP\config.json` with env var overrides (`MCP_HOST`, `MCP_PORT`). Uses source-generated JSON serialization.
44+
- **ThemeHelper.cs** — Cross-platform dark mode detection (Windows registry, macOS `defaults`, Linux GTK settings)
3645

3746
### Tools (`src/Tools/`)
3847

39-
All tools use `[McpServerToolType]` on the class and `[McpServerTool]` + `[Description]` on methods. Tools are static classes with static methods. Each returns anonymous objects with `success` boolean and either result data or `error` message.
48+
All tools use `[McpServerToolType]` on the class and `[McpServerTool(Name = "tool_name")]` + `[Description]` on methods. Tools are static classes with static methods. Each returns anonymous objects with `success` boolean and either result data or `error` message.
4049

41-
- **ProcessTool** — Process and thread management (list/open/get processes, list threads)
42-
- **MemoryTool** — Memory read and write (bytes, int8/16/32/64, float, double, string)
43-
- **ScanTool** — Memory scanning (AOB pattern scan, value scan with first/next, reset)
44-
- **AssemblyTool** — Disassembly and address resolution
50+
- **ProcessTool** — Process and thread management (list/open processes, get current process ID)
51+
- **MemoryTool** — Memory read and write (bytes, int8/16/32/64, float, double, string, AOB patterns)
52+
- **ScanTool** — Memory scanning (first scan, next scan, reset, AOB scan) using MemScan/FoundList
53+
- **AssemblyTool** — Disassembly and address resolution (symbol lookups)
4554
- **AddressListTool** — Cheat table CRUD operations (get/add/update/delete/clear records)
4655
- **LuaExecutionTool** — Execute arbitrary Lua scripts in CE with stack management
4756
- **ConversionTool** — String format conversion (MD5, ANSI/UTF8)
4857

58+
### Resources (`src/Resources/`)
59+
60+
Resources use `[McpServerResourceType]` on class and `[McpServerResource(UriTemplate = "scheme://path")]` + `[Description]` on methods. Resources are read-only state/data (vs tools which perform actions). Return JSON strings.
61+
62+
- **ProcessResources**`process://current` (opened process info), `process://threads` (thread list)
63+
4964
### SDK Layer (`CESDK/`)
5065

5166
Git submodule — C# wrapper around Cheat Engine's Lua API. Key classes: `MemoryAccess`, `Process`, `AOBScanner`, `Disassembler`, `AddressResolver`, `MemScan`, `FoundList`, `AddressList`, `ThreadList`, `Converter`, `Speedhack`, `Debugger`, `SymbolWaiter`.
5267

5368
### Views (`src/Views/`)
5469

55-
- **ConfigWindow.xaml/.cs** — WPF config window. Supports dark/light theme via `ThemeHelper`.
70+
- **ConfigWindow.xaml/.cs** — WPF config window. Supports dark/light theme via `ThemeHelper`. Runs in STA thread with dispatcher for cross-thread UI updates.
5671

5772
## Adding New Tools
5873

5974
1. Create a new file in `src/Tools/` with `[McpServerToolType]` class attribute
6075
2. Add static methods with `[McpServerTool(Name = "tool_name")]` and `[Description("...")]`
61-
3. Use `[Description]` on parameters for schema generation
76+
3. Use `[Description]` on parameters for MCP schema generation
6277
4. Return anonymous objects: `new { success = true, ... }` or `new { success = false, error = "..." }`
6378
5. Register in `McpServer.cs` via `.WithTools<Tools.YourTool>()`
6479
6. Consult `C:\Program Files\Cheat Engine\celua.txt` for correct Lua function signatures
80+
7. Use `CESDK.Synchronize(() => { ... })` for AddressList/UI operations that must run on CE's main thread
6581

6682
Example:
6783
```csharp
@@ -72,15 +88,40 @@ public static class MyTool
7288
public static object MyAction([Description("Input param")] string input)
7389
{
7490
try {
75-
// ... CE SDK calls ...
76-
return new { success = true, result = "done" };
91+
// Use Synchronize for AddressList operations
92+
var result = CESDK.Synchronize(() => {
93+
var al = new AddressList();
94+
return al.Count;
95+
});
96+
return new { success = true, result };
7797
} catch (Exception ex) {
7898
return new { success = false, error = ex.Message };
7999
}
80100
}
81101
}
82102
```
83103

104+
## Adding New Resources
105+
106+
1. Create a new file in `src/Resources/` with `[McpServerResourceType]` class attribute
107+
2. Add static methods with `[McpServerResource(UriTemplate = "scheme://path", Title = "...")]` and `[Description]`
108+
3. Return JSON string (use `System.Text.Json.JsonSerializer.Serialize`)
109+
4. Register in `McpServer.cs` via `.WithResources<Resources.YourResource>()`
110+
111+
Example:
112+
```csharp
113+
[McpServerResourceType]
114+
public static class MyResource
115+
{
116+
[McpServerResource(UriTemplate = "mydata://info", Title = "My Data"),
117+
Description("Returns my data")]
118+
public static string GetInfo()
119+
{
120+
return JsonSerializer.Serialize(new { data = "value" });
121+
}
122+
}
123+
```
124+
84125
## Code Style
85126

86127
- C# with nullable reference types enabled, `TreatWarningsAsErrors`
@@ -97,6 +138,22 @@ public static class MyTool
97138
- **Dark mode**: UI adapts via Windows registry check (`ThemeHelper.IsInDarkMode()`)
98139
- Default server: `http://127.0.0.1:6300` with MCP SSE at `/sse`
99140
- **CE Lua API docs**: `C:\Program Files\Cheat Engine\celua.txt` — the authoritative reference for all CE Lua functions, objects, and their parameters
141+
- **WPF Assembly Resolution**: Plugin.cs registers AssemblyResolve handler to fix WPF's `Application.LoadComponent` in CE host process
142+
- **Config location**: `%APPDATA%\CeMCP\config.json` for persistent settings, env vars `MCP_HOST`/`MCP_PORT` override
143+
144+
## Project Configuration
145+
146+
- **Target**: `net10.0-windows` with WPF, x64 platform only
147+
- **Self-contained**: All dependencies embedded in single DLL
148+
- **Roll-forward**: `Major` to find available ASP.NET Core runtime
149+
- **Package**: `ModelContextProtocol.AspNetCore` v0.8.0-preview.1
150+
- **Assembly name**: `ce-mcp.dll` for CE plugin loader
151+
- **Output path**: `bin/x64/Debug/net10.0-windows/ce-mcp.dll` (or Release)
152+
153+
## GitHub Actions
154+
155+
- **build-dlls.yml** — Builds Debug and Release DLLs on push/PR, uploads as artifacts
156+
- **build.yml** — SonarQube analysis workflow
100157

101158
## CESDK Submodule
102159

.github/workflows/build-dlls.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build DLLs
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
build:
12+
runs-on: windows-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Setup .NET
21+
uses: actions/setup-dotnet@v4
22+
with:
23+
dotnet-version: "10.0.x"
24+
25+
- name: Restore dependencies
26+
run: dotnet restore
27+
28+
- name: Build Debug
29+
run: dotnet build -c Debug --no-restore
30+
31+
- name: Build Release
32+
run: dotnet build -c Release --no-restore
33+
34+
- name: Upload Debug DLL
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: ce-mcp-debug
38+
path: bin/x64/Debug/net10.0-windows/ce-mcp.dll
39+
if-no-files-found: error
40+
41+
- name: Upload Release DLL
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: ce-mcp-release
45+
path: bin/x64/Release/net10.0-windows/ce-mcp.dll
46+
if-no-files-found: error

0 commit comments

Comments
 (0)