Skip to content

feat(arena/mcp): Arena Toolkit Phase 1 — 16 MCP tools + OWNER_KEYS#37

Closed
xmujx wants to merge 10 commits into
mainfrom
feat/arena-mcp-toolkit-phase1
Closed

feat(arena/mcp): Arena Toolkit Phase 1 — 16 MCP tools + OWNER_KEYS#37
xmujx wants to merge 10 commits into
mainfrom
feat/arena-mcp-toolkit-phase1

Conversation

@xmujx

@xmujx xmujx commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Phase 1 (6 tools, fully wired): arena_sell, arena_move, arena_freeze, arena_roll + 2 keeper tools (arena_run_matchmaking, arena_force_settle) with OWNER_KEYS env gating
  • Phase 2 (17 tools, scaffolded): aligned with feat: add persistent arena cards and market #39 (card market) and feat(arena/tier): Bronze/Silver/Gold tier matchmaking + withdraw (#33) #40 (tier) actual implementations
  • OWNER_KEYS infra: parsed from env in both stdio and HTTP entry points
  • Agent runner: selfTools + buyer_agent_id default for arena_buy_listing
  • Claude Code skill: .claude/commands/arena.md with card flow diagram
  • Arena guide: docs/arena-guide.md (complete) + skill.md (condensed for agent prompt)
  • E2E scripts: mcp-server/scripts/e2e-arena-tools.mjs + e2e-arena-full.mjs

Card Flow (aligned with #39)

Shop ──arena_buy──→ Inventory ──arena_place_card──→ Bench
                        ↑       ←──arena_remove_card──┘
                        ↕
                   Marketplace (arena_place_listing / arena_buy_listing)

All 27 Arena MCP Tools

Phase Tools
Spike (5) arena_list_units, arena_get_state, arena_buy, arena_submit, arena_get_recent_matches
Phase 1 (6) arena_sell, arena_move, arena_freeze, arena_roll, arena_run_matchmaking, arena_force_settle
Phase 1 read (4) arena_simulate_match, arena_preview_elo, arena_get_card, arena_set_matchmaking_period
Phase 2 - #39 (9) arena_get_g_balance, arena_fund_g, arena_list_inventory, arena_list_market, arena_place_listing, arena_cancel_listing, arena_buy_listing, arena_place_card, arena_remove_card
Phase 2 - #40 (3) arena_view_deck, arena_get_tier_info, arena_withdraw_submission

Test Results

1. Phase 1 E2E: 24/24 PASS

Tested on spike contracts (Anvil). All Phase 1 tools real on-chain tx. Phase 2 tools graceful "not deployed yet" errors.

2. Contract Verification: ALL PASS (PR #40 branch, includes #39)

Tested on feat/arena-tier branch deployed to Anvil (--code-size-limit 50000). This branch contains both #32 (card market) and #33 (tier) code.

#32 Card Market:

Function Result
buy(2, Stoneguard) → inventory ✅ cardId=8, G deducted
getOwnedCards(2) ✅ [8]
placeCard(2, 8, slot0) ✅ bench[0]=Stoneguard
getGhostCards(2) ✅ [8, 0, 0, 0, 0]
removeCard(2, slot0) → inventory ✅ bench cleared, card kept
listCard(2, 8, 25G) ✅ market listing created
getActiveListings(0,10) ✅ 8 listings (7 bootstrap + 1)
cancelListing(2, 8) ✅ listing removed
buyListed(3, 8, 25G) ✅ owner transferred, G settled

#33 Tier:

Function Result
_tierFor(2) [47G] ✅ → 0 (Bronze)
_tierFor(3) [475G] ✅ → 1 (Silver)
runMatchmaking(Silver) ✅ matchId=1, paired agent 2 vs 3
settleMatch(1) ✅ settled, ELO updated
withdrawSubmission(2) ✅ (after settle, pool cleared)

Spike verbs:

Function Result
freeze / roll
previewEloUpdate(1016,984) ✅ → 1031/969
sell(empty slot) ⚠️ revert (expected)

#39 own E2E: 16/16 PASS — full buy→inventory→bench→market→buyer chain verified.

Note on contract size

ArenaEngine after #39+#40 merge is 25318 bytes (> 24576 limit). Local testing uses anvil --code-size-limit 50000. Production deploy needs --via-ir optimization or library extraction before testnet deploy.

Wiring Checklist (after #40 merges)

  1. In ChainClient.ready(): resolve gTreasury + cardLedger from Router getAddressesV3() (index 7/8)
  2. Uncomment ABI entries: placeCard, removeCard, getGhostCards, tier functions
  3. Uncomment chain.ts stub method implementations
  4. Update arena_get_state to return gBalance instead of ore
  5. runMatchmaking tool: add tier overload (runMatchmaking(uint8) for tier-based matching)

Partial impl of #35. Phase 2 unblocks when #40 merges.

xmujx added 6 commits June 3, 2026 03:39
…/arena skill

Phase 1 (fully wired, works now):
- 4 verb tools: arena_sell, arena_move, arena_freeze, arena_roll
- 2 keeper tools: arena_run_matchmaking, arena_force_settle (OWNER_KEYS gated)
- OWNER_KEYS env parsing in both stdio and HTTP entry points
- Agent runner selfTools + system prompt updated with new verbs

Phase 2 (scaffolded, awaiting #32 GTreasury/CardLedger + #33 Tier):
- 10 tool registrations with full zod schemas and descriptions
- chain.ts: ABI stubs for GTreasury + CardLedger + Tier
- chain.ts: method stubs with typed signatures (throw until contracts deployed)
- Wiring checklist: resolve contracts from Router.getAddressesV3() in ready()

Claude Code skill:
- .claude/commands/arena.md — /arena slash command with workflow guide + strategy

Closes Phase 1 of #35. Phase 2 unblocks when #32 and #33 merge.
List all 21 arena tools in the skill reference, grouped by category.
Phase 2 tools (G currency, market, tier) marked with issue refs.
Added market and tier workflow sections.
New tools:
- arena_simulate_match: full turn-by-turn combat replay
- arena_preview_elo: preview ELO delta without committing
- arena_get_card: single card details (#32)
- arena_set_matchmaking_period: owner-only tier cooldown (#33)

Docs:
- docs/arena-guide.md: complete agent gameplay guide covering
  card flow, 12 units, combat mechanics, ability timing, 3
  archetypes, positioning strategy, tier system, secondary
  market, and full tool reference
- Updated /arena skill with new tools
- skill.md: add condensed Arena section (card flow, combat, units,
  strategy, tool table, tier system) for agent system prompt
- CLAUDE.md: add Arena entry with link to docs/arena-guide.md
- docs/arena-guide.md kept as the complete reference
- .claude/commands/arena.md: add simulate_match, preview_elo,
  get_card, set_matchmaking_period to tool table
@keanji-x

keanji-x commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

里面g的默认数值我觉得都可以x100 倍,现在有点少

@xmujx

xmujx commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

里面g的默认数值我觉得都可以x100 倍,现在有点少

去掉了prompt 的硬编码数值,这些都在合约里定义的,到时候让他直接从合约取

@xmujx

xmujx commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Replaced by #51 — same content rebased onto latest main with all ABI conflicts resolved

@xmujx xmujx closed this Jun 4, 2026
xmujx added a commit that referenced this pull request Jun 4, 2026
…37) (#51)

* feat(arena/mcp): Arena Toolkit Phase 1 — 16 MCP tools + OWNER_KEYS + /arena skill

Phase 1 (fully wired, works now):
- 4 verb tools: arena_sell, arena_move, arena_freeze, arena_roll
- 2 keeper tools: arena_run_matchmaking, arena_force_settle (OWNER_KEYS gated)
- OWNER_KEYS env parsing in both stdio and HTTP entry points
- Agent runner selfTools + system prompt updated with new verbs

Phase 2 (scaffolded, awaiting #32 GTreasury/CardLedger + #33 Tier):
- 10 tool registrations with full zod schemas and descriptions
- chain.ts: ABI stubs for GTreasury + CardLedger + Tier
- chain.ts: method stubs with typed signatures (throw until contracts deployed)
- Wiring checklist: resolve contracts from Router.getAddressesV3() in ready()

Claude Code skill:
- .claude/commands/arena.md — /arena slash command with workflow guide + strategy

Closes Phase 1 of #35. Phase 2 unblocks when #32 and #33 merge.

* docs: add Phase 2 tools to /arena skill

List all 21 arena tools in the skill reference, grouped by category.
Phase 2 tools (G currency, market, tier) marked with issue refs.
Added market and tier workflow sections.

* fix: align Phase 2 stubs with PR #39 and #40 actual implementations

* test: add E2E script for arena MCP tools (24/24 pass on fresh chain)

* feat(arena/mcp): add missing tools + arena gameplay guide

New tools:
- arena_simulate_match: full turn-by-turn combat replay
- arena_preview_elo: preview ELO delta without committing
- arena_get_card: single card details (#32)
- arena_set_matchmaking_period: owner-only tier cooldown (#33)

Docs:
- docs/arena-guide.md: complete agent gameplay guide covering
  card flow, 12 units, combat mechanics, ability timing, 3
  archetypes, positioning strategy, tier system, secondary
  market, and full tool reference
- Updated /arena skill with new tools

* docs: arena guide in skill.md + CLAUDE.md entry link

- skill.md: add condensed Arena section (card flow, combat, units,
  strategy, tool table, tier system) for agent system prompt
- CLAUDE.md: add Arena entry with link to docs/arena-guide.md
- docs/arena-guide.md kept as the complete reference
- .claude/commands/arena.md: add simulate_match, preview_elo,
  get_card, set_matchmaking_period to tool table

* test: add full arena E2E script (requires #39 contracts)

* fix: replace ore refs with G, remove hardcoded prices in arena descriptions

* fix: remove hardcoded tier thresholds, make owner-configurable

* fix: remove stale arena_sell/freeze/roll tools and old ABI entries

These were from the pre-persistent-card era and don't exist in the
current ArenaEngine contract.

* fix: sync MCP ABI with tier-based matchmaking contracts, remove duplicate code

- ARENA_ENGINE_ABI: GhostSubmitted/runMatchmaking/MatchmadeInTier use uint8 tier
  (was uint16 bucket — different selector/topic hash, calls reverted silently)
- G_TREASURY_ABI: use creditG (onlyOperator) instead of fundAgentG (onlyOwner)
- Delete duplicate G_TREASURY_ABI, CARD_LEDGER_ABI const declarations
- Delete Phase 2 stubs section (~150 lines of duplicate methods + throw stubs)
- Delete 7 duplicate tool registrations in tools.ts
- Wire fund_agent_g, arena_get_tier_info, arena_withdraw_submission,
  arena_set_matchmaking_period as working implementations
- Net -306 lines, 0 TS errors

* feat: add arena_deposit_g tool from PR #52

GTreasury.depositG(agentId) payable — lets agent owners deposit native
testnet tokens into their Arena G balance. Adds ABI entry, chain method,
and MCP tool.

* docs: sync arena guide and skill.md with current tool names

- Core loop: add arena_deposit_g, remove deleted tools (sell/move/freeze/roll)
- Tool tables: arena_fund_g → fund_agent_g, bucket_id → tier, remove stale entries
- skill.md: update card flow and tool roster

* refactor: consolidate admin tools into gated section with [ADMIN] prefix

Move set_oracle_agent, fund_agent_g, arena_set_matchmaking_period into
a single admin block with isOwnerCall() guards and [ADMIN] description
prefix. Update arena-guide.md and skill.md to match.

* fix: remove duplicate arenaDepositG from merge

* docs: add missing arena_cancel_listing and arena_get_card to skill.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants