Skip to main content
Glama

ppsspp_read_string

Read a null-terminated UTF-8 string from PSP memory at a given address. Use to extract in-game text, dialogue, or file names for analysis.

Instructions

PURPOSE: Read a null-terminated UTF-8 string from PSP memory at the given address. USAGE: Use for in-game text, character names, dialogue, file names — anywhere the PSP stores a C-style null-terminated string. Stops at the first 0x00 byte. BEHAVIOR: No side effects — pure read. Reads bytes until null terminator, decodes as UTF-8. Returns an error if the address is outside valid memory, or if the string runs past valid memory before hitting a null. RETURNS: Single line 'ADDR_HEX: "STRING"'.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesPSP physical address. PSP memory layout: user RAM starts at 0x08800000 (or 0x08000000 — varies by firmware allocation), kernel RAM at 0x08000000-0x087FFFFF, VRAM at 0x04000000-0x041FFFFF, scratchpad at 0x00010000-0x00013FFF, hardware regs at 0xBC000000+. Most game state lives in user RAM. Note PPSSPP may also accept 0x88xxxxxx kernel-mode mirrors of the same physical memory.

Implementation Reference

  • Handler for ppsspp_read_string tool. Calls PPSSPP's 'memory.readString' with the address and 'utf-8' type, then returns the string in JSON format: 'ADDR_HEX: "STRING"'.
    case "ppsspp_read_string": {
      const r = await pp.call<{ value: string }>("memory.readString", { address: a(), type: "utf-8" });
      return ok(`${addrHex(a())}: ${JSON.stringify(r.value ?? "")}`);
    }
  • Tool schema definition for ppsspp_read_string. Defines the tool name, description (null-terminated UTF-8 string reader), and input schema requiring an 'address' integer parameter.
    {
      name: "ppsspp_read_string",
      description:
        "PURPOSE: Read a null-terminated UTF-8 string from PSP memory at the given address. " +
        "USAGE: Use for in-game text, character names, dialogue, file names — anywhere the PSP stores a C-style null-terminated string. Stops at the first 0x00 byte. " +
        "BEHAVIOR: No side effects — pure read. Reads bytes until null terminator, decodes as UTF-8. Returns an error if the address is outside valid memory, or if the string runs past valid memory before hitting a null. " +
        "RETURNS: Single line 'ADDR_HEX: \"STRING\"'.",
      inputSchema: {
        type: "object",
        required: ["address"],
        properties: {
          address: { type: "integer", minimum: 0, description: ADDRESS_PARAM_DESC },
        },
        additionalProperties: false,
      },
    },
  • src/tools.ts:405-613 (registration)
    The registerTools function registers the tool list and call handler on the MCP server. The ppsspp_read_string case is part of the CallToolRequestSchema switch statement.
    export function registerTools(server: Server, pp: PpssppClient): void {
      server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
    
      server.setRequestHandler(CallToolRequestSchema, async (req) => {
        const { name, arguments: args = {} } = req.params;
        const p = args as Record<string, unknown>;
        const a = () => p.address as number;
    
        switch (name) {
          case "ppsspp_ping": {
            const r = await pp.call<{ version?: string; name?: string }>("version");
            return ok(`pong (${r.name ?? "PPSSPP"} ${r.version ?? "(unknown version)"})`);
          }
    
          case "ppsspp_get_info": {
            const status = await pp.call<{ game?: { id?: string; title?: string; version?: string } | null; paused?: boolean; stepping?: boolean }>("game.status");
            const lines: string[] = [];
            if (status.game) {
              lines.push(`Title:   ${status.game.title ?? "(unavailable)"}`);
              lines.push(`Disc ID: ${status.game.id ?? "(unavailable)"}`);
              lines.push(`Version: ${status.game.version ?? "(unavailable)"}`);
            } else {
              lines.push("No game loaded.");
            }
            const state = status.stepping ? "stepping (paused)" : status.paused ? "paused" : "running";
            lines.push(`State:   ${state}`);
            return ok(lines.join("\n"));
          }
    
          case "ppsspp_read8": {
            const r = await pp.call<{ value: number }>("memory.read_u8", { address: a() });
            return ok(`${addrHex(a())}: ${fmtHex(r.value)}`);
          }
          case "ppsspp_read16": {
            const r = await pp.call<{ value: number }>("memory.read_u16", { address: a() });
            return ok(`${addrHex(a())}: ${fmtHex(r.value)}`);
          }
          case "ppsspp_read32": {
            const r = await pp.call<{ value: number }>("memory.read_u32", { address: a() });
            return ok(`${addrHex(a())}: ${fmtHex(r.value)}`);
          }
          case "ppsspp_read_range": {
            const r = await pp.call<{ base64: string }>("memory.read", { address: a(), size: p.size });
            const bytes = Buffer.from(r.base64 ?? "", "base64");
            const hex = Array.from(bytes).map((b) => b.toString(16).padStart(2, "0").toUpperCase()).join(" ");
            return ok(`${addrHex(a())} [${bytes.length} bytes]:\n${hex}`);
          }
          case "ppsspp_read_string": {
            const r = await pp.call<{ value: string }>("memory.readString", { address: a(), type: "utf-8" });
            return ok(`${addrHex(a())}: ${JSON.stringify(r.value ?? "")}`);
          }
    
          case "ppsspp_write8": {
            await pp.call("memory.write_u8", { address: a(), value: p.value });
            return ok(`Wrote ${fmtHex(p.value)} → ${addrHex(a())}`);
          }
          case "ppsspp_write16": {
            await pp.call("memory.write_u16", { address: a(), value: p.value });
            return ok(`Wrote ${fmtHex(p.value)} → ${addrHex(a())}`);
          }
          case "ppsspp_write32": {
            await pp.call("memory.write_u32", { address: a(), value: p.value });
            return ok(`Wrote ${fmtHex(p.value)} → ${addrHex(a())}`);
          }
          case "ppsspp_write_range": {
            const bytes = Buffer.from(p.bytes as number[]);
            const base64 = bytes.toString("base64");
            await pp.call("memory.write", { address: a(), base64 });
            return ok(`Wrote ${bytes.length} bytes → ${addrHex(a())}`);
          }
    
          case "ppsspp_press_buttons": {
            await pp.call("input.buttons.send", { buttons: p.buttons });
            const pressed = Object.entries(p.buttons as Record<string, boolean>)
              .filter(([, v]) => v).map(([k]) => k);
            return ok(`Set buttons: ${pressed.length ? pressed.join("+") : "(all released)"}`);
          }
          case "ppsspp_press_button": {
            await pp.call("input.buttons.press", { button: p.button, duration: p.duration ?? 1 });
            return ok(`Pressed ${p.button} for ${p.duration ?? 1} frames (auto-released)`);
          }
          case "ppsspp_send_analog": {
            await pp.call("input.analog.send", { stick: p.stick, x: p.x, y: p.y });
            return ok(`Set analog stick ${p.stick} to (${p.x}, ${p.y})`);
          }
    
          case "ppsspp_pause": {
            // cpu.stepping is fire-and-forget per PPSSPP source ("No immediate
            // response. Once CPU is stepping, a 'cpu.stepping' event will be
            // sent."). Send it, then poll cpu.status until stepping=true.
            await pp.fireAndForget("cpu.stepping");
            await pp.waitForState((s) => s.stepping === true);
            return ok("Emulation paused");
          }
          case "ppsspp_resume": {
            await pp.fireAndForget("cpu.resume");
            await pp.waitForState((s) => s.stepping === false);
            return ok("Emulation resumed");
          }
          case "ppsspp_step": {
            const r = await pp.call<{ pc?: number }>("cpu.stepInto");
            return ok(`Stepped one instruction. PC: ${r.pc !== undefined ? addrHex(r.pc) : "(unknown)"}`);
          }
          case "ppsspp_reset": {
            await pp.call("game.reset");
            return ok("Game reset");
          }
          case "ppsspp_screenshot": {
            // PPSSPP's gpu.buffer.* events all require CORE_STEPPING_CPU (or GPU
            // stepping) state — they fail with "Neither CPU or GPU is stepping"
            // otherwise. We transparently pause→capture→resume so callers can
            // screenshot any time without managing pause state. If the emulator
            // was already paused, we leave it paused.
            //
            // source='render' (default) uses gpu.buffer.renderColor → reads the
            // active GPU render target. Safer: GPU_GetCurrentFramebuffer hits a
            // different code path than the crash-prone GPU_GetOutputFramebuffer.
            //
            // source='output' uses gpu.buffer.screenshot → reads the final
            // composited output (what's on screen, post scaling/shaders). Can
            // CRASH PPSSPP on some games: upstream has an `_assert_(buf != nullptr)`
            // after GPU_GetOutputFramebuffer that fires when the function returns
            // true with a null buffer (observed on some homebrew). We can't catch
            // a process abort from outside, but v0.1.2's auto-reconnect means MCP
            // recovers when PPSSPP is relaunched.
            const source = (p.source as string | undefined) ?? "render";
            const event  = source === "output" ? "gpu.buffer.screenshot" : "gpu.buffer.renderColor";
            const statusBefore = await pp.call<{ stepping?: boolean; paused?: boolean }>("cpu.status");
            const wasStepping = !!statusBefore.stepping;
            if (!wasStepping) {
              await pp.fireAndForget("cpu.stepping");
              await pp.waitForState((s) => s.stepping === true);
            }
            try {
              // type: "base64" returns the raw base64 payload; the default "uri"
              // returns a "data:image/png;base64,..." prefix which we'd have to strip.
              const r = await pp.call<{ base64?: string; uri?: string }>(event, { type: "base64" });
              let b64 = r.base64;
              if (!b64 && r.uri) {
                // Belt-and-suspenders: if PPSSPP returned a URI anyway, strip the prefix.
                const m = /^data:image\/png;base64,(.*)$/.exec(r.uri);
                if (m) b64 = m[1];
              }
              if (!b64) {
                throw new Error(`PPSSPP did not return screenshot data from ${event} (no game loaded, or framebuffer not readable?)`);
              }
              return {
                content: [
                  { type: "text" as const, text: `Screenshot captured (source: ${source}, event: ${event}).` },
                  { type: "image" as const, data: b64, mimeType: "image/png" },
                ],
              };
            } finally {
              if (!wasStepping) {
                try {
                  await pp.fireAndForget("cpu.resume");
                  await pp.waitForState((s) => s.stepping === false, { timeoutMs: 2000 });
                } catch { /* best-effort */ }
              }
            }
          }
    
          case "ppsspp_get_registers": {
            // PPSSPP's cpu.getAllRegs returns categories with PARALLEL arrays:
            //   { categories: [{ name, registerNames: [...], uintValues: [...], floatValues: [...] }] }
            // Not an array of {name, value} objects as I first assumed.
            const r = await pp.call<{
              categories?: Array<{
                name: string;
                registerNames?: string[];
                uintValues?: number[];
                floatValues?: string[];
              }>;
            }>("cpu.getAllRegs");
            const lines: string[] = [];
            for (const cat of r.categories ?? []) {
              lines.push(`── ${cat.name} ──`);
              const names = cat.registerNames ?? [];
              const vals  = cat.uintValues ?? [];
              for (let i = 0; i < Math.max(names.length, vals.length); i++) {
                const nm = names[i] ?? `r${i}`;
                const v  = vals[i];
                lines.push(`  ${nm.padEnd(8)} = ${v !== undefined ? addrHex(v) : "(unavailable)"}`);
              }
            }
            return ok(lines.join("\n") || "(no registers returned)");
          }
    
          case "ppsspp_breakpoint_add": {
            await pp.call("cpu.breakpoint.add", { address: a() });
            return ok(`Breakpoint added at ${addrHex(a())}`);
          }
          case "ppsspp_breakpoint_remove": {
            await pp.call("cpu.breakpoint.remove", { address: a() });
            return ok(`Breakpoint removed at ${addrHex(a())}`);
          }
          case "ppsspp_breakpoint_list": {
            const r = await pp.call<{ breakpoints?: Array<{ address: number; enabled?: boolean; condition?: string }> }>("cpu.breakpoint.list");
            const bps = r.breakpoints ?? [];
            if (bps.length === 0) return ok("No breakpoints set.");
            const lines = bps.map((b) => `  ${addrHex(b.address)} ${b.enabled === false ? "(disabled)" : ""}${b.condition ? ` if ${b.condition}` : ""}`);
            return ok(`${bps.length} breakpoint${bps.length === 1 ? "" : "s"}:\n${lines.join("\n")}`);
          }
    
          default:
            throw new Error(`Unknown tool: ${name}`);
        }
      });
    }
  • The PpssppClient.call method used by the handler to send a ticketed JSON-RPC request (event: 'memory.readString') to PPSSPP via WebSocket and await the response.
    async call<T extends Record<string, unknown> = Record<string, unknown>>(
      event: string,
      params: Record<string, unknown> = {},
    ): Promise<T> {
      // Auto-(re)connect on demand. PPSSPP can be launched, closed, relaunched
      // at any point during the MCP server's lifetime; ensureConnected() will
      // bring the socket back up (or throw a clear error if PPSSPP isn't
      // reachable). Without this, a single failed connect at MCP boot would
      // leave every subsequent tool call broken until MCP-client restart.
      await this.ensureConnected();
      return new Promise<T>((resolve, reject) => {
        const ticket = `t${this.nextTicket++}`;
        const pending: PendingCmd = {
          ticket,
          resolve: (r) => resolve(r as T),
          reject,
        };
    
        const timer = setTimeout(() => {
          this.inflight.delete(ticket);
          reject(new Error(
            `PPSSPP call "${event}" timed out (${this.timeoutMs}ms) — ` +
            `is PPSSPP running with "Allow remote debugger" enabled?`,
          ));
        }, this.timeoutMs);
        const origResolve = pending.resolve, origReject = pending.reject;
        pending.resolve = (r) => { clearTimeout(timer); origResolve(r); };
        pending.reject  = (e) => { clearTimeout(timer); origReject(e); };
    
        this.inflight.set(ticket, pending);
        const msg = JSON.stringify({ event, ticket, ...params });
        if (process.env.MCP_PPSSPP_DEBUG) {
          process.stderr.write(`[trace] TX: ${msg}\n`);
        }
        this.ws!.send(msg);
      });
    }
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description discloses that it is a pure read with no side effects, explains the reading mechanism (stops at null), decoding as UTF-8, and error conditions for invalid addresses or memory boundary violations. Since no annotations are provided, this is thorough.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with labeled sections (PURPOSE, USAGE, BEHAVIOR, RETURNS) and is concise without redundancy. Every sentence adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the single parameter and lack of annotations, the description covers all necessary aspects: purpose, usage, behavior, return format, and error handling. The return format is specified, which is helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already provides a detailed description of the address parameter (memory layout, ranges). The tool description does not add new semantic information beyond the schema, so the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Read' and the resource 'a null-terminated UTF-8 string from PSP memory'. It distinguishes itself from sibling tools like ppsspp_read8/16/32 which read raw numeric values.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly lists use cases: 'in-game text, character names, dialogue, file names'. It could be improved by mentioning when not to use (e.g., binary data not null-terminated) but the context and sibling names imply alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dmang-dev/mcp-ppsspp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server