{
  "args": [
    "-c",
    "import sys, json, os, time\n\nREQ_F = os.path.join(os.getenv('TEMP'), 'ce_mcp_req.txt')\nRES_F = os.path.join(os.getenv('TEMP'), 'ce_mcp_res.txt')\n\ndef clean():\n    for p in [REQ_F, RES_F]:\n        if os.path.exists(p):\n            try:\n                os.remove(p)\n            except:\n                pass\n\nwhile True:\n    line = sys.stdin.readline()\n    if not line:\n        break\n    try:\n        req = json.loads(line)\n\n        if req.get('method') == 'initialize':\n            cv = req.get('params', {}).get('protocolVersion', '2025-11-25')\n            sys.stdout.write(json.dumps({\n                'jsonrpc': '2.0',\n                'id': req['id'],\n                'result': {\n                    'protocolVersion': cv,\n                    'capabilities': {'tools': {}},\n                    'serverInfo': {'name': 'ce', 'version': '1.6'}\n                }\n            }) + '\\n')\n            sys.stdout.flush()\n\n        elif req.get('method') == 'tools/list':\n            tools = [\n                {\n                    \"name\": \"read_memory\",\n                    \"description\": \"Read memory from a specified address. Supports single value reading or continuous hex dump blocks.\",\n                    \"inputSchema\": {\n                        \"type\": \"object\",\n                        \"properties\": {\n                            \"addr\": {\"type\": \"string\", \"description\": \"Hex address\"},\n                            \"type\": {\"type\": \"string\", \"description\": \"Bytes to read. Use 1, 2, 4, 8 for single numeric values (Byte, Word, Dword, Qword). Pass a value > 8 (e.g. 16, 32, 64) to read a continuous hex dump block.\"},\n                            \"hex\": {\"type\": \"string\", \"description\": \"Set to 'true' to return value as hexadecimal string (e.g. '0xA1A52D8'). Default returns decimal number.\"}\n                        },\n                        \"required\": [\"addr\"]\n                    }\n                },\n                {\n                    \"name\": \"write_memory\",\n                    \"description\": \"Modify the value of a specified memory address.\",\n                    \"inputSchema\": {\n                        \"type\": \"object\",\n                        \"properties\": {\n                            \"addr\": {\"type\": \"string\", \"description\": \"Hex address\"},\n                            \"val\": {\"type\": \"string\", \"description\": \"Value to write (decimal or hex string with 0x prefix)\"},\n                            \"type\": {\"type\": \"string\", \"description\": \"Bytes to write: 1, 2, 4, 8\"},\n                            \"hex\": {\"type\": \"string\", \"description\": \"Set to 'true' to interpret val as a hexadecimal number (e.g. '0xFF' writes 255).\"}\n                        },\n                        \"required\": [\"addr\", \"val\"]\n                    }\n                },\n                {\n                    \"name\": \"disassemble\",\n                    \"description\": \"Get disassembly lines starting from a specified address.\",\n                    \"inputSchema\": {\n                        \"type\": \"object\",\n                        \"properties\": {\n                            \"addr\": {\"type\": \"string\", \"description\": \"Hex address\"},\n                            \"count\": {\"type\": \"string\", \"description\": \"Number of instructions to fetch\"}\n                        },\n                        \"required\": [\"addr\"]\n                    }\n                },\n                {\n                    \"name\": \"get_modules\",\n                    \"description\": \"Get the complete list of process modules, including their base addresses and memory sizes.\",\n                    \"inputSchema\": {\"type\": \"object\", \"properties\": {}}\n                },\n                {\n                    \"name\": \"aob_scan\",\n                    \"description\": \"Scan memory using an Array of Bytes pattern globally. Supports placeholders like ??.\",\n                    \"inputSchema\": {\n                        \"type\": \"object\",\n                        \"properties\": {\n                            \"aob\": {\"type\": \"string\", \"description\": \"Space-separated hex pattern, e.g. '33 FF 7F 00'\"}\n                        },\n                        \"required\": [\"aob\"]\n                    }\n                },\n                {\n                    \"name\": \"get_address\",\n                    \"description\": \"Resolve module symbol names or complex multi-level pointer expressions into physical memory absolute addresses.\",\n                    \"inputSchema\": {\n                        \"type\": \"object\",\n                        \"properties\": {\n                            \"expr\": {\"type\": \"string\", \"description\": \"Standard CE expression syntax, e.g. 'Game.exe+1000' or '[[[Game.exe+BASE_OFFSET]+0x14]+0x8]'\"}\n                        },\n                        \"required\": [\"expr\"]\n                    }\n                },\n                {\n                    \"name\": \"auto_assemble\",\n                    \"description\": \"Execute a standard Cheat Engine Auto Assemble (AA) code injection script directly into process memory.\",\n                    \"inputSchema\": {\n                        \"type\": \"object\",\n                        \"properties\": {\n                            \"script\": {\"type\": \"string\", \"description\": \"Full multi-line Auto Assemble script text\"}\n                        },\n                        \"required\": [\"script\"]\n                    }\n                },\n                {\n                    \"name\": \"calc\",\n                    \"description\": \"Hexadecimal calculator supporting Lua arithmetic expressions. Use 0x prefix for hex numbers, e.g. '0xA1A528C+0x4C' returns both decimal and hex results.\",\n                    \"inputSchema\": {\n                        \"type\": \"object\",\n                        \"properties\": {\n                            \"expr\": {\"type\": \"string\", \"description\": \"Lua arithmetic expression using hex (0x) or decimal numbers. Supports +, -, *, /, bit operations (band, bor, bxor, etc.), and math functions.\"}\n                        },\n                        \"required\": [\"expr\"]\n                    }\n                }\n            ]\n            sys.stdout.write(json.dumps({\n                'jsonrpc': '2.0',\n                'id': req['id'],\n                'result': {'tools': tools}\n            }) + '\\n')\n            sys.stdout.flush()\n\n        elif req.get('method') == 'tools/call':\n            name = req['params']['name']\n            args = req['params'].get('arguments', {})\n            clean()\n\n            raw_script = args.get('script', '')\n            safe_script = raw_script.replace('\\n', '_LF_').replace('\\r', '')\n\n            payload = [\n                name,\n                f\"addr={args.get('addr', '')}\",\n                f\"val={args.get('val', '')}\",\n                f\"type={args.get('type', '4')}\",\n                f\"count={args.get('count', '5')}\",\n                f\"aob={args.get('aob', '')}\",\n                f\"expr={args.get('expr', '')}\",\n                f\"script={safe_script}\",\n                f\"hex={args.get('hex', '')}\",\n            ]\n\n            with open(REQ_F, 'w', encoding='utf-8') as f:\n                f.write('\\n'.join(payload))\n\n            res_text = json.dumps({'status': 'error', 'message': 'Cheat Engine response timeout.'})\n            start = time.time()\n            while time.time() - start < 3.0:\n                if os.path.exists(RES_F):\n                    time.sleep(0.02)\n                    try:\n                        with open(RES_F, 'r', encoding='utf-8') as f:\n                            res_text = f.read()\n                        clean()\n                        break\n                    except:\n                        pass\n                time.sleep(0.02)\n\n            sys.stdout.write(json.dumps({\n                'jsonrpc': '2.0',\n                'id': req['id'],\n                'result': {'content': [{'type': 'text', 'text': res_text}], 'isError': False}\n            }) + '\\n')\n            sys.stdout.flush()\n\n    except:\n        pass"
  ],
  "command": "python"
}