IvanMurzak / IvanMurzak/Unity-MCP

feat(connection): RFC 8628 device flow + machine credential store + zero-button boot

Open
#876 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
4.3k
Forks
379
Avg merge
6h 52m
Merged PRs (30d)
17

Description

Summary

Wire the real ai-game.dev sign-in for the Unity Editor plugin (mcp-authorize d1, PR 2 of the chain). Foundation PR #875 already adopted McpPlugin 7.0.0-preview.1 (vendored) and migrated UnityConnectionConfig.TokenCredentialProvider (behavior-preserving). This PR implements the RFC 8628 device-authorization grant against the live authorization server, persists the credential into the shared per-machine credential store, and connects signed-in on boot with zero UI interaction.

Context

  • Design refs: .claude/design/mcp-authorize/{03-auth-flows.md (Flow B), 06-engine-plugins.md, 09-user-workflows.md}; task tasks/d1-unity-plugin.md.
  • The Authorization Server is live at https://ai-game.dev (issuer).
  • McpPlugin 7.0 already ships MachineCredentialStore + MachineCredentials + PluginCredentialProvider (auto-adopt, proactive/reactive refresh via an injected ITokenRefresher) + ConnectionCredentialCoordinator (on-401 refresh→reconnect); this PR provides the Unity device-flow + refresher and wires the provider into the Cloud-mode connection.
  • Mirrors the sibling engine device-flow PRs (Godot #265 / Unreal #212).

Proposed approach

  1. DeviceAuthService: RFC 8628 alias — POST /oauth/device_authorization (form client_id=unity-mcp-plugin + scope=mcp:plugin) → poll POST /oauth/token with the urn:ietf:params:oauth:grant-type:device_code grant → ES256 access JWT + rotating refresh token.
    1. DeviceAuthFlow: injectable state machine (client / browser-open / poll-delay injectable) so it runs against a mocked AS with no live network in CI; honours interval / slow_down / authorization_pending / access_denied / expired_token.
    1. UnityTokenRefresher (ITokenRefresher): exchanges the refresh token for a fresh access token at /oauth/token; fails closed.
    1. AccountCredentialService: owns a PluginCredentialProvider over the shared machine store (~/.ai-game-dev/credentials.json, 0600 / DPAPI); auto-adopt on boot, proactive refresh at connect, on-401 refresh+reconnect via ConnectionCredentialCoordinator.
    1. Wire the Cloud credential provider into UnityConnectionConfig.CredentialProvider (machine-store JWT wins in Cloud mode; falls back to the mode-routed token; ignored in Custom/Local).

Acceptance criteria

  • Zero-button: a seeded machine store → editor boots connected in Cloud mode with no UI interaction.
  • Device-flow / store / refresher / provider unit tests pass against a mocked authorization server (no live network in CI).
  • Unity plugin compiles; full EditMode suite green on the local worktree Editor.
  • Unity CI matrix green.

Scope note: instance-metadata handshake / ProjectIdentity marker (PR 3), port change (PR 4), config-writer UI flip / token-field removal (PR 5), and live e2e (PR 6) are out of scope for this PR.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tasks/d1-unity-plugin.md and the referenced Flow B design, then inspect UnityConnectionConfig.CredentialProvider and the sibling Godot and Unreal device-flow changes. Run the mocked authorization-server unit tests and the Unity EditMode suite. Done means the seeded machine store enables zero-button Cloud startup, device flow and refresh behavior pass without live network access, and the Unity CI matrix is green.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
authentication, desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.