leejunyoung5819 mc-paper-plugin-test-mcp-26.3
공개마인크래프트 26.3 Paper 서버의 플러그인 테스트를 하려는 AI 에이전트를 위한 MCP 도구
| 1 | // CLI for humans, CI and agents without MCP: |
| 2 | // npm run mct -- <tool> [key=value ... | '{json}'] |
| 3 | // npm run mct -- scenario scenarios/demo-shop.yaml |
| 4 | // npm run mct -- login [profile] (Microsoft device-code login, needs a human) |
| 5 | // npm run mct -- tools | daemon-stop | daemon-status |
| 6 | import { TOOLS, TOOL_MAP } from './tools.ts'; |
| 7 | import { call, daemonUp, shutdownDaemon } from './rpc.ts'; |
| 8 | import { ensureDirs } from './config.ts'; |
| 9 | import { microsoftIdentity } from './auth.ts'; |
| 10 | |
| 11 | function parseArgs(rest: string[]): Record<string, unknown> { |
| 12 | if (rest.length === 1 && rest[0].trim().startsWith('{')) return JSON.parse(rest[0]); |
| 13 | const out: Record<string, unknown> = {}; |
| 14 | for (const a of rest) { |
| 15 | const i = a.indexOf('='); |
| 16 | if (i < 0) throw new Error(`expected key=value, got '${a}'`); |
| 17 | const k = a.slice(0, i); |
| 18 | const v = a.slice(i + 1); |
| 19 | if (v === 'true' || v === 'false') out[k] = v === 'true'; |
| 20 | else if (v !== '' && !Number.isNaN(Number(v)) && /^-?[\d.]+$/.test(v)) out[k] = Number(v); |
| 21 | else if (v.startsWith('[') || v.startsWith('{')) out[k] = JSON.parse(v); |
| 22 | else out[k] = v; |
| 23 | } |
| 24 | return out; |
| 25 | } |
| 26 | |
| 27 | async function main() { |
| 28 | const [cmd, ...rest] = process.argv.slice(2); |
| 29 | if (!cmd || cmd === 'help' || cmd === '--help') { |
| 30 | console.log('usage: npm run mct -- <tool> [key=value ...]\n npm run mct -- scenario <file.yaml>\n npm run mct -- login [profile]\n npm run mct -- tools | daemon-status | daemon-stop'); |
| 31 | return; |
| 32 | } |
| 33 | if (cmd === 'tools') { |
| 34 | for (const t of TOOLS) console.log(`${t.name.padEnd(18)} ${Object.keys(t.shape).join(', ')}`); |
| 35 | return; |
| 36 | } |
| 37 | if (cmd === 'daemon-status') { |
| 38 | console.log(JSON.stringify({ running: await daemonUp() })); |
| 39 | return; |
| 40 | } |
| 41 | if (cmd === 'daemon-stop') { |
| 42 | console.log(JSON.stringify({ stopped: await shutdownDaemon() })); |
| 43 | return; |
| 44 | } |
| 45 | if (cmd === 'login') { |
| 46 | ensureDirs(); |
| 47 | const profile = rest[0] ?? 'default'; |
| 48 | const id = await microsoftIdentity(profile, (p) => { |
| 49 | console.log(`\nOpen ${p.verificationUri} and enter the code: ${p.userCode}\n`); |
| 50 | }); |
| 51 | console.log(JSON.stringify({ loggedIn: true, profile, minecraftName: id.name, uuid: id.uuid })); |
| 52 | return; |
| 53 | } |
| 54 | if (cmd === 'scenario') { |
| 55 | const r = await call('run_scenario', { file: rest[0], stop_on_fail: true }); |
| 56 | console.log(JSON.stringify(r, null, 2)); |
| 57 | process.exitCode = r.passed ? 0 : 1; |
| 58 | return; |
| 59 | } |
| 60 | if (!TOOL_MAP.has(cmd)) throw new Error(`unknown tool '${cmd}' (npm run mct -- tools)`); |
| 61 | const r = await call(cmd, parseArgs(rest)); |
| 62 | console.log(JSON.stringify(r, null, 2)); |
| 63 | } |
| 64 | |
| 65 | main().catch((e) => { |
| 66 | console.error(`error: ${(e as Error).message}`); |
| 67 | process.exitCode = 1; |
| 68 | }); |