mgba_ping
Verify that the mGBA emulator is running with the Lua bridge loaded; receive 'pong' if connected.
Instructions
Check connectivity to the mGBA bridge. Returns 'pong' if the emulator is running and the Lua bridge is loaded.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:43-48 (schema)Tool definition for mgba_ping, including its schema (name, description, empty inputSchema).
const TOOLS: Tool[] = [ { name: "mgba_ping", description: "Check connectivity to the mGBA bridge. Returns 'pong' if the emulator is running and the Lua bridge is loaded.", inputSchema: { type: "object", properties: {} }, }, - src/tools.ts:266-269 (handler)Handler for the mgba_ping tool. Calls the mGBA bridge with method 'ping' and returns the result as text.
case "mgba_ping": { const r = await mgba.call<string>("ping"); return ok(r); } - src/tools.ts:258-261 (registration)Registration of all tools via ListToolsRequestSchema and CallToolRequestSchema handlers on the server.
export function registerTools(server: Server, mgba: MgbaClient): void { server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS })); server.setRequestHandler(CallToolRequestSchema, async (req) => { - src/tools.ts:247-249 (helper)Helper function 'ok' that wraps a text string into the MCP content response format.
function ok(text: string) { return { content: [{ type: "text" as const, text }] }; } - src/mgba.ts:89-131 (helper)The MgbaClient.call() method that sends an RPC request (e.g., 'ping') over TCP socket and returns the result.
async call<T = unknown>( method: string, params?: Record<string, unknown>, ): Promise<T> { // Lazy (re)connect — bridge.lua reloads kill the socket, and the user // shouldn't have to restart the MCP host every time they edit the script. if (!this.socket || this.socket.destroyed) { try { await this.connect(); } catch (err) { throw new Error( `Cannot reach mGBA bridge at ${this.host}:${this.port}. ` + `Make sure mGBA is running with bridge.lua loaded (Tools > Scripting). ` + `Underlying error: ${(err as Error).message}`, ); } } return new Promise<T>((resolve, reject) => { const sock = this.socket; if (!sock) { reject(new Error("socket vanished after connect")); return; } const id = this.nextId++; this.pending.set(id, (resp) => { if (resp.error) { reject(new Error(`mGBA RPC error [${resp.error.code}]: ${resp.error.message}`)); } else { resolve(resp.result as T); } }); const msg = JSON.stringify({ id, method, params: params ?? {} }) + "\n"; sock.write(msg, (err) => { if (err) { this.pending.delete(id); reject(err); } }); }); }