Skip to main content
Glama

Unity-MCP

by TSavo

ユニティ-MCP

モデルコンテキストプロトコル (MCP) を使用した Unity と AI アシスタント間のブリッジ。

概要

Unity-MCPは、Unityゲーム開発向けのモデルコンテキストプロトコル(Model Context Protocol)のオープンソース実装です。AIアシスタントが標準化されたインターフェースを介してUnityゲーム環境と対話できるようにすることで、AIを活用したゲーム開発、自動テスト、シーン分析、ランタイムデバッグが可能になります。

建築

永続性のために AILogger を使用するようにアーキテクチャが簡素化され、別個のサーバー コンポーネントが不要になりました。

AI Assistant <-> Unity-MCP STDIO Client <-> Unity Client <-> AILogger
  • AIアシスタントプロトコルを使用してUnity-MCP STDIOクライアントと通信します。
  • Unity-MCP STDIOクライアント: コマンドをUnityクライアントに転送し、結果をAILoggerに保存します。
  • Unityクライアント: Unityでコマンドを実行し、結果を返します
  • AILogger : ログと結果を後から取得できるように保存します

Unity-MCP STDIOクライアントは、コード実行とクエリの両方のエンドポイントを提供するUnityクライアントと直接通信します。クエリツールは、クエリをreturn文でラップすることで、コード実行に変換します。

特徴

  • Unity ランタイム環境で C# コードを実行する
  • ゲームオブジェクトとそのコンポーネントを検査する
  • シーンの階層と構造を分析する
  • テストを実行して結果を受け取る
  • ゲームオブジェクトとコンポーネントのメソッドを呼び出す
  • 実行中にゲームの状態を変更する

展開オプション

  • Unity エディター拡張機能: ゲーム実行サイクルを超えて存続するエディター拡張機能
  • Dockerコンテナ: ネットワーク経由でUnityと通信するコンテナ化されたバージョン
  • NPX パッケージ: NPX 経由でインストールおよび実行できる Node.js パッケージ

ドキュメント

はじめる

Unity-MCP を使い始めるには、次の手順に従います。

  1. リポジトリをクローンします。
    git clone https://github.com/TSavo/Unity-MCP.git cd Unity-MCP
  2. 依存関係をインストールします:
    npm install
  3. プロジェクトをビルドします。
    npm run build
  4. MCP STDIO クライアントを起動します。
    npm start
    これにより、Unity と通信し、永続性のために AILogger を使用する MCP STDIO クライアントが起動します。注意: AILogger がhttp://localhost:3030で実行されていることを確認するか、AI_LOGGER_URL 環境変数を AILogger インスタンスを指すように設定してください。
  5. テストを実行します:
    # Run all tests npm test # Run only unit tests npm run test:unit # Run only e2e tests npm run test:e2e # Run tests with a specific pattern npm test -- --testNamePattern="should return the server manifest" npm run test:unit -- --testNamePattern="should return the server manifest" npm run test:e2e -- --testNamePattern="should discover the test server"

詳細な手順については、インストール ガイドを参照してください。

AIアシスタントへの接続

Unity-MCP ブリッジを AI アシスタントに接続するには、MCP 構成ファイルを作成する必要があります。

{ "mcpServers": { "unity-ai-bridge": { "url": "http://localhost:8080/sse" } } }

このファイルをAIアシスタントの適切な場所に配置してください。Claudeの場合、通常はClaudeデスクトップアプリの設定ディレクトリ内にあります。

利用可能なツール

Unity-MCP ブリッジは次のツールを提供します。

  1. execute_code : Unity で C# コードを直接実行します。
  2. query : ドット表記を使用してクエリを実行し、オブジェクト、プロパティ、メソッドにアクセスします。
  3. get_logs : AILogger からログを取得します。
  4. get_log_by_name : AILogger から特定のログを取得します。

使用例

Unityでコードを実行する

execute_codeツールを使用して、Unity で C# コードを実行できます。コードは Unity ランタイム環境で実行され、結果は AILogger に保存され、後で取得できます。

JSON-RPCリクエスト
{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "execute_code", "arguments": { "code": "Debug.Log(\"Hello from Unity!\"); return GameObject.FindObjectsOfType<GameObject>().Length;", "timeout": 5000 } } }
JSON-RPCレスポンス
{ "jsonrpc": "2.0", "id": 1, "result": { "content": [ { "type": "text", "text": "{\"status\":\"success\",\"logName\":\"unity-execute-1712534400000\",\"result\":{\"success\":true,\"result\":42,\"logs\":[\"Hello from Unity!\"],\"executionTime\":123}}" } ] } }

Unityオブジェクトのクエリ

queryツールを使用してUnityオブジェクトをクエリできます。これにより、ドット表記を使用してオブジェクト、プロパティ、メソッドにアクセスできます。

JSON-RPCリクエスト
{ "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": { "name": "query", "arguments": { "query": "Camera.main.transform.position", "timeout": 5000 } } }
JSON-RPCレスポンス
{ "jsonrpc": "2.0", "id": 2, "result": { "content": [ { "type": "text", "text": "{\"status\":\"success\",\"logName\":\"unity-query-1712534400000\",\"result\":{\"success\":true,\"result\":{\"x\":0,\"y\":1,\"z\":-10},\"executionTime\":45}}" } ] } }

AILoggerから結果を取得する

get_log_by_nameツールを使用して、AILogger から以前の操作の結果を取得できます。

JSON-RPCリクエスト
{ "jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": { "name": "get_log_by_name", "arguments": { "log_name": "unity-execute-1712534400000", "limit": 1 } } }
JSON-RPCレスポンス
{ "jsonrpc": "2.0", "id": 3, "result": { "content": [ { "type": "text", "text": "{\"status\":\"success\",\"name\":\"unity-execute-1712534400000\",\"entries\":[{\"id\":\"123e4567-e89b-12d3-a456-426614174000\",\"name\":\"unity-execute-1712534400000\",\"data\":{\"result\":{\"success\":true,\"result\":42,\"logs\":[\"Hello from Unity!\"],\"executionTime\":123},\"timestamp\":\"2025-04-08T00:00:00.000Z\"},\"timestamp\":\"2025-04-08T00:00:00.000Z\"}]}" } ] } }

使用例

AI アシスタントが Unity ツールにアクセスできるようになると、次のようなタスクを実行するように依頼できます。

Can you execute the following C# code in Unity? GameObject.Find("Player").transform.position = new Vector3(0, 1, 0);

ライセンス

マサチューセッツ工科大学

著者

Tサボ( @TSavo

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

コード実行、シーン分析、ランタイムデバッグのための標準化されたインターフェースを通じて AI が Unity ゲーム環境と対話できるようにする、Unity と AI アシスタント間のブリッジです。

  1. 概要
    1. 建築
  2. 特徴
    1. 展開オプション
      1. ドキュメント
        1. はじめる
          1. AIアシスタントへの接続
            1. 利用可能なツール
          2. 使用例
            1. Unityでコードを実行する
            2. Unityオブジェクトのクエリ
            3. AILoggerから結果を取得する
            4. 使用例
          3. ライセンス
            1. 著者

              Related MCP Servers

              • -
                security
                A
                license
                -
                quality
                A server that enables AI assistants to understand and interact with Unity projects in real-time, providing access to scene hierarchy, project settings, and the ability to execute code directly in the Unity Editor.
                Last updated -
                80
                MIT License
                • Linux
                • Apple
              • -
                security
                F
                license
                -
                quality
                A protocol server that bridges AI assistants with Unity projects, allowing them to analyze code, parse scenes, generate scripts, and perform other Unity operations through specialized tools.
                Last updated -
                TypeScript
                • Linux
                • Apple
              • -
                security
                F
                license
                -
                quality
                A bridge that enables controlling Unity Editor through natural language commands via AI assistants, allowing users to create materials, build projects, manage scenes, and configure settings without manual interaction.
                Last updated -
                57
                • Apple
                • Linux
              • -
                security
                F
                license
                -
                quality
                A personal AI coding assistant that connects to various development environments and helps automate tasks, provide codebase insights, and improve coding decisions by leveraging the Model Context Protocol.
                Last updated -
                Python
                • Apple
                • Linux

              View all related MCP servers

              MCP directory API

              We provide all the information about MCP servers via our MCP API.

              curl -X GET 'https://glama.ai/api/mcp/v1/servers/TSavo/Unity-MCP'

              If you have feedback or need assistance with the MCP directory API, please join our Discord server