Skip to content

Add Amp plugin for Unity MCP#1118

Open
range-et wants to merge 2 commits into
CoplayDev:betafrom
range-et:feat/amp-plugin
Open

Add Amp plugin for Unity MCP#1118
range-et wants to merge 2 commits into
CoplayDev:betafrom
range-et:feat/amp-plugin

Conversation

@range-et
Copy link
Copy Markdown

@range-et range-et commented May 11, 2026

Type of Change

New feature: Added .amp/plugins/unity-mcp.ts to enable Amp-to-Unity integration.

Changes Made

Plugin Architecture: Implemented a thin TypeScript plugin that acts as a REST proxy to the existing Python MCP server.

Tool Consolidation: Registered a single unity tool in Amp. This tool uses a tool parameter to dispatch commands to the Python server’s 38+ underlying Unity tools, significantly reducing context window token overhead.

Command Registry: Added a Unity: Status command to the palette for instance discovery via the /api/instances endpoint.

Lifecycle Management: Integrated a session.start listener to log server reachability and active Unity instance counts upon plugin initialization.

Configuration Support: Exposed UNITY_MCP_SERVER_URL and UNITY_MCP_TIMEOUT_MS for environment-based overrides.

Testing: Added unit tests for the REST proxy logic to satisfy CI/CodeRabbit requirements (overriding the initial "out of scope" plan).

Testing/Screenshots

Activation: Verified via amp plugins list; the unity tool and session.start listener are correctly reported as active.

Execution: Successfully ran amp plugins exec .amp/plugins/unity-mcp.ts session.start --data '{}', confirming reachability of the live Python server and instance reporting.

Model Interaction: Confirmed the model successfully references the unity-mcp-orchestrator skill for downstream schema details without requiring local schema duplication.

Documentation Updates

[x] Updated in-code documentation for the unity tool parameters.
[x] Documented environment variables (UNITY_MCP_SERVER_URL, UNITY_MCP_TIMEOUT_MS) in the plugin header.
[n/a] External docs (README) updates—deferred until the Python server orchestration is finalized.

Related Issues

Relates to: Existing unity-mcp Python server implementation.

Summary by CodeRabbit

  • New Features

    • Integrated Unity tool for sending commands and checking server connectivity
    • Status monitoring that reports connected instances on session start
    • Environment variables to configure server URL and timeouts
  • Tests

    • Added unit tests covering timeout parsing, URL normalization, command construction, network/error handling, and abort behavior
  • Chores

    • Added CI workflow to run the plugin test suite with Bun

Review Change Stack

Adds .amp/plugins/unity-mcp.ts — a thin Amp plugin that exposes a single
`unity` tool. The tool POSTs to the existing Python MCP server's
/api/command REST endpoint, so the Python side keeps the full tool catalog
and Amp only sees one tool definition (low token cost).

- Single tool: { tool, params, unity_instance? }
- Palette command: 'Unity: Status' (hits /api/instances)
- Configurable via UNITY_MCP_SERVER_URL and UNITY_MCP_TIMEOUT_MS
- session.start logs whether a Unity instance is connected

Amp-Thread-ID: https://ampcode.com/threads/T-019e144f-2307-731e-b3d4-d3bcd4b298b3
Co-authored-by: Amp <amp@ampcode.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 11, 2026

📝 Walkthrough

Walkthrough

Adds a new Amp plugin that proxies Unity MCP REST calls, with helpers for URL/timeouts/command building, unit tests exercising network/error/timeout behaviors, and a GitHub Actions workflow to run the tests.

Changes

Unity MCP Plugin

Layer / File(s) Summary
Config & Timeouts
.amp/plugins/unity-mcp.ts
Defines DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, and probe timeout constants.
Public Types
.amp/plugins/unity-mcp.ts
Adds CommandBody and FetchLike types.
URL & Timeout Utilities
.amp/plugins/unity-mcp.ts
normalizeBaseUrl() strips trailing slashes; resolveTimeoutMs() parses and validates timeout strings.
Command Body Construction
.amp/plugins/unity-mcp.ts
buildCommandBody() validates tool, normalizes/coerces params, and conditionally includes unity_instance.
Unreachable/Error Formatting
.amp/plugins/unity-mcp.ts
formatUnreachableError() returns a structured JSON error string for network/abort failures.
Server Communication Functions
.amp/plugins/unity-mcp.ts
postCommand() POSTs to /api/command with an abortable timeout; listInstances() GETs /api/instances; both return response text or structured error JSON.
Tool Description
.amp/plugins/unity-mcp.ts
Exports UNITY_TOOL_DESCRIPTION used when registering the unity tool.
Plugin Entry & Hooks
.amp/plugins/unity-mcp.ts
Default export resolves env, registers unity tool and status command, and adds session.start probe that logs instance count or reachability failure.
Unit Tests
.amp/plugins/__tests__/unity-mcp.test.ts
Bun tests for helpers and network helpers; covers timeout parsing, URL normalization, command-body validation, error formatting, postCommand/listInstances behaviors, and abort/fetch rejection cases.

CI: Amp Plugin Tests workflow

Layer / File(s) Summary
Workflow Triggers & Filters
.github/workflows/amp-plugin-tests.yml
push/pull_request/workflow_dispatch triggers with path filters for .amp/plugins/** and the workflow file.
CI Job: Bun test runner
.github/workflows/amp-plugin-tests.yml
Job checks out repo, installs Bun, and runs bun test against ./.amp/plugins/__tests__.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I nibble bytes and tidy hops,
Sending commands through little stops,
Probes and timeouts hum along,
Tests keep steady, stout, and strong,
A rabbit cheers: the plugin hops! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title clearly summarizes the main change: adding an Amp plugin for Unity MCP, which aligns with the changeset's primary objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description comprehensively covers all required template sections including type of change, changes made, testing approach, documentation updates, and related issues.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.amp/plugins/unity-mcp.ts:
- Around line 20-30: The TIMEOUT_MS constant can become NaN or non-positive from
process.env and cause immediate aborts in postCommand; replace the simple
Number(...) assignment with robust parsing that ensures a finite positive
integer (e.g., parseInt/Number, check Number.isFinite and >0) and clamp to a
sane default (120000 ms) using Math.max or a conditional fallback before it's
used to create the timer in postCommand; update the TIMEOUT_MS definition (and
any uses in postCommand where ctrl/timer are created) so the timeout is always a
positive finite millisecond value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ae07087f-5624-434d-a4a5-7983484503ba

📥 Commits

Reviewing files that changed from the base of the PR and between a2a5edf and eef3f76.

📒 Files selected for processing (1)
  • .amp/plugins/unity-mcp.ts

Comment thread .amp/plugins/unity-mcp.ts Outdated
- Harden UNITY_MCP_TIMEOUT_MS parsing: clamp NaN/non-numeric/non-positive/
  non-finite values to the 120s default. Without this, Number(undefined)
  yields NaN and AbortController fires immediately, aborting every request
  before the network is touched.

- Add JSDoc/TSDoc on every exported symbol and the plugin entry point to
  satisfy the 80% docstring coverage check.

- Refactor: extract pure helpers (resolveTimeoutMs, normalizeBaseUrl,
  buildCommandBody, formatUnreachableError, postCommand, listInstances)
  with an injectable FetchLike type so they can be unit-tested without a
  live network.

- Add 28 unit tests in .amp/plugins/__tests__/unity-mcp.test.ts covering
  timeout parsing edge cases, URL normalization, body construction,
  unreachable-error formatting, and postCommand/listInstances behavior
  (success, non-2xx with body, non-2xx without body, network failure,
  timeout abort).

- Add .github/workflows/amp-plugin-tests.yml to run 'bun test' on every
  push/PR that touches .amp/plugins/**.

Amp-Thread-ID: https://ampcode.com/threads/T-019e144f-2307-731e-b3d4-d3bcd4b298b3
Co-authored-by: Amp <amp@ampcode.com>
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.

1 participant