leejunyoung5819 mc-paper-plugin-test-mcp-26.3
공개마인크래프트 26.3 Paper 서버의 플러그인 테스트를 하려는 AI 에이전트를 위한 MCP 도구
| 1 | // MCP stdio server for QA agents. Thin proxy: every tool call goes to the shared daemon |
| 2 | // (auto-started), screenshots come back as image content. |
| 3 | import fs from 'node:fs'; |
| 4 | import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; |
| 5 | import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; |
| 6 | import { TOOLS } from './tools.ts'; |
| 7 | import { call } from './rpc.ts'; |
| 8 | |
| 9 | const INSTRUCTIONS = `mc-tester drives REAL Minecraft 26.3 clients against a local Paper test server running the plugin under test. |
| 10 | Plugins under test: plugins_list shows which jars load; plugins_set (add/remove, restart:true) changes them and saves mct.config.json. |
| 11 | Typical loop: server_start -> client_launch {name:"Bot1"} -> rcon (give items / set state) -> teleport next to an NPC -> interact_entity -> screen (read the GUI as JSON) -> click_item / click_slot -> wait_for {chat: ...} -> verify with rcon (server truth) and state/screen (client view) -> screenshot when visual proof helps. |
| 12 | - Prefer server-side verification (rcon + the plugin's admin/debug commands) for balances and inventories; the client view can lag. |
| 13 | - Every action tool accepts screenshot:true to get an image of the result. |
| 14 | - world_snapshot once ("base"), then world_reset "base" before tests that must be deterministic. |
| 15 | - Turn reproducible checks into YAML scenarios under scenarios/ and run them with run_scenario.`; |
| 16 | |
| 17 | const server = new McpServer({ name: 'mc-tester', version: '0.1.0' }, { instructions: INSTRUCTIONS }); |
| 18 | |
| 19 | function imageFor(p: unknown) { |
| 20 | if (typeof p !== 'string' || !p.endsWith('.png') || !fs.existsSync(p)) return null; |
| 21 | return { type: 'image' as const, data: fs.readFileSync(p).toString('base64'), mimeType: 'image/png' }; |
| 22 | } |
| 23 | |
| 24 | for (const t of TOOLS) { |
| 25 | server.registerTool(t.name, { description: t.description, inputSchema: t.shape }, async (args: any) => { |
| 26 | try { |
| 27 | const result = await call(t.name, args ?? {}); |
| 28 | const content: any[] = [{ type: 'text', text: JSON.stringify(result, null, 2) }]; |
| 29 | const imgs = [result?.screenshot, t.name === 'screenshot' ? result?.path : null]; |
| 30 | if (Array.isArray(result?.screenshots)) imgs.push(...result.screenshots.slice(-4)); |
| 31 | for (const p of imgs) { |
| 32 | const img = imageFor(p); |
| 33 | if (img) content.push(img); |
| 34 | } |
| 35 | return { content }; |
| 36 | } catch (e) { |
| 37 | return { isError: true, content: [{ type: 'text', text: (e as Error).message }] }; |
| 38 | } |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | await server.connect(new StdioServerTransport()); |