Skip to content

Commit 7488137

Browse files
committed
Migrate from REST API to MCP SSE, refactor UI to XAML, target .NET 10
- Replace ASP.NET Minimal API with MCP SSE server using ModelContextProtocol.AspNetCore - Rewrite all 11 tool classes to MCP [McpServerToolType]/[McpServerTool] pattern - Refactor ConfigWindow from code-only to XAML with code-behind - Add AssemblyResolve handler for WPF XAML in CE plugin context - Target net10.0-windows with global.json pinning SDK 10.0 - Add copilot-instructions.md, remove CLAUDE.md - Update README with .NET 10 requirements and ce.runtimeconfig.json instructions - Fix SSE test connection (ResponseHeadersRead), replace Open SSE with Copy URL
1 parent e886dc6 commit 7488137

24 files changed

+1164
-1650
lines changed

.github/copilot-instructions.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Project Guidelines
2+
3+
## Project Overview
4+
5+
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).
6+
7+
## Build and Test
8+
9+
```bash
10+
# Initialize submodule (first time)
11+
git submodule update --init --recursive
12+
13+
# Build
14+
dotnet build
15+
16+
# Build Release
17+
dotnet build -c Release
18+
```
19+
20+
Deploy: copy `ce-mcp.dll` from `bin/` to Cheat Engine plugins directory, enable in CE, use "MCP" menu.
21+
22+
## Architecture
23+
24+
### Core Components
25+
26+
- **Plugin.cs** — Main CE plugin entry point (`CESDKPluginClass`). Manages MCP server lifecycle, registers Lua functions for CE menu integration, provides WPF config UI.
27+
- **McpServer.cs** — MCP SSE server using `ModelContextProtocol.AspNetCore`. Registers all tools via `WithTools<T>()` and maps endpoints with `MapMcp()`.
28+
- **ServerConfig.cs** — Configuration management (host/port/name). Loads from `%APPDATA%\CeMCP\config.json` with env var overrides (`MCP_HOST`, `MCP_PORT`).
29+
30+
### Tools (`src/Tools/`)
31+
32+
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.
33+
34+
- **ProcessTool** — List processes, open by ID/name, get current process
35+
- **LuaExecutionTool** — Execute Lua scripts in CE with stack management
36+
- **MemoryReadTool** — Read memory (bytes, int32, int64, float, string)
37+
- **MemoryWriteTool** — Write memory values
38+
- **AOBScanTool** — Array of Bytes pattern scanning
39+
- **DisassembleTool** — Disassemble instructions at address
40+
- **AddressTool** — Resolve address expressions
41+
- **ConversionTool** — String format conversion (MD5, ANSI/UTF8)
42+
- **ThreadListTool** — List process threads
43+
- **MemScanTool** — Memory value scanning with first/next scan pattern
44+
- **AddressListTool** — Cheat table CRUD operations
45+
46+
### SDK Layer (`CESDK/`)
47+
48+
Git submodule — C# wrapper around Cheat Engine's Lua API. Key classes: `LuaEngine`, `MemoryAccess`, `Process`, `AOBScanner`, `Disassembler`, `MemScan`, `AddressList`.
49+
50+
### Views (`src/Views/`)
51+
52+
- **ConfigWindow.cs** — WPF config window (code-only, no XAML). Supports dark/light theme via `ThemeHelper`.
53+
54+
## Adding New Tools
55+
56+
1. Create a new file in `src/Tools/` with `[McpServerToolType]` class attribute
57+
2. Add static methods with `[McpServerTool(Name = "tool_name")]` and `[Description("...")]`
58+
3. Use `[Description]` on parameters for schema generation
59+
4. Return anonymous objects: `new { success = true, ... }` or `new { success = false, error = "..." }`
60+
5. Register in `McpServer.cs` via `.WithTools<Tools.YourTool>()`
61+
62+
Example:
63+
```csharp
64+
[McpServerToolType]
65+
public static class MyTool
66+
{
67+
[McpServerTool(Name = "my_action"), Description("Does something useful")]
68+
public static object MyAction([Description("Input param")] string input)
69+
{
70+
try {
71+
// ... CE SDK calls ...
72+
return new { success = true, result = "done" };
73+
} catch (Exception ex) {
74+
return new { success = false, error = ex.Message };
75+
}
76+
}
77+
}
78+
```
79+
80+
## Code Style
81+
82+
- C# with nullable reference types enabled, `TreatWarningsAsErrors`
83+
- Target: `net9.0-windows`, WPF enabled, x64 platform
84+
- Tools use static classes/methods, not instance-based
85+
- Wrap CE SDK calls in try-catch, always return structured response objects
86+
- Use proper Lua stack management (`GetTop`, `Pop`) when interacting with Lua
87+
88+
## Important Notes
89+
90+
- **Lua stack**: Always clean up with `lua.Pop()` calls after reading values
91+
- **CE thread safety**: Use `CESDK.CESDK.Synchronize()` for operations that must run on CE's main thread (e.g., AddressList operations)
92+
- **Memory scanning**: Requires scan → `WaitTillDone()``foundList.Initialize()` sequence
93+
- **Dark mode**: UI adapts via Windows registry check (`ThemeHelper.IsInDarkMode()`)
94+
- Default server: `http://127.0.0.1:6300` with MCP SSE at `/sse`
95+
96+
## CESDK Submodule
97+
98+
The `CESDK/` directory is a git submodule providing the Cheat Engine SDK wrapper library:
99+
100+
- **Core**: `CESDK.cs`, `CheatEnginePlugin.cs`, `PluginContext.cs`
101+
- **Lua**: `LuaEngine.cs` (high-level), `LuaNative.cs` (low-level C API)
102+
- **Memory**: `MemoryScanner.cs`, `ScanConfiguration.cs`, `ScanResults.cs`
103+
- **System**: `SystemInfo.cs`, `CEInterop.cs`
104+
105+
Plugin pattern: inherit `CheatEnginePlugin`, implement `Name`/`OnEnable()`/`OnDisable()`, access Lua via `PluginContext.Lua`.

CLAUDE.md

Lines changed: 0 additions & 218 deletions
This file was deleted.

CeMCP.csproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net9.0-windows</TargetFramework>
3+
<TargetFramework>net10.0-windows</TargetFramework>
44
<OutputType>Library</OutputType>
55
<AssemblyName>ce-mcp</AssemblyName>
66
<RootNamespace>CEMCP</RootNamespace>
@@ -22,23 +22,21 @@
2222
<!-- Generate runtime config to help find framework assemblies -->
2323
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
2424

25-
<!-- Force .NET 9.0.10 to match NuGet package versions -->
26-
<RuntimeFrameworkVersion>9.0.10</RuntimeFrameworkVersion>
27-
2825
<!-- WPF -->
2926
<UseWPF>true</UseWPF>
3027
<PlatformTarget>x64</PlatformTarget>
3128
<Platforms>x64</Platforms>
3229
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
30+
31+
<!-- Allow roll-forward to find available ASP.NET Core runtime -->
32+
<RollForward>Major</RollForward>
3333
</PropertyGroup>
3434

3535
<ItemGroup>
3636
<FrameworkReference Include="Microsoft.AspNetCore.App" />
3737
</ItemGroup>
3838

3939
<ItemGroup>
40-
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
41-
<PackageReference Include="Scalar.AspNetCore" Version="2.9.0" />
42-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.10" />
40+
<PackageReference Include="ModelContextProtocol.AspNetCore" Version="0.8.0-preview.1" />
4341
</ItemGroup>
4442
</Project>

CeMCP.csproj.user

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project>
22
<PropertyGroup>
33
<UnoPlatformIDE>vscode</UnoPlatformIDE>
4-
<UnoPlatformIDEVersion>1.106.2</UnoPlatformIDEVersion>
5-
<UnoPlatformExtension>unoplatform.vscode 0.23.6</UnoPlatformExtension>
4+
<UnoPlatformIDEVersion>1.109.0</UnoPlatformIDEVersion>
5+
<UnoPlatformExtension>unoplatform.vscode 0.24.1</UnoPlatformExtension>
66
<UnoRemoteControlPort>0</UnoRemoteControlPort>
7-
<UnoVSCodeCSharpExtension>ms-dotnettools.csharp 2.100.11</UnoVSCodeCSharpExtension>
8-
<UnoVSCodeCSharpDevKitExtension>ms-dotnettools.csdevkit 1.80.7</UnoVSCodeCSharpDevKitExtension>
7+
<UnoVSCodeCSharpExtension>ms-dotnettools.csharp 2.120.3</UnoVSCodeCSharpExtension>
8+
<UnoVSCodeCSharpDevKitExtension>ms-dotnettools.csdevkit 2.10.3</UnoVSCodeCSharpDevKitExtension>
99
</PropertyGroup>
1010
</Project>

0 commit comments

Comments
 (0)