Skip to main content
Glama
McpServerInfo.cs6.94 kB
using UnityEngine; using UnityEditor; using System.Text; namespace LocalMcp.UnityServer { /// <summary> /// Displays MCP Server information and API endpoints in Unity Editor /// </summary> public static class McpServerInfo { [MenuItem("MCP/Server/Show API Info", false, 102)] public static void ShowApiInfo() { StringBuilder sb = new StringBuilder(); sb.AppendLine("==========================================="); sb.AppendLine("Unity MCP Server - API Information"); sb.AppendLine("==========================================="); sb.AppendLine(); // Server Status sb.AppendLine("【Server Status】"); bool wsRunning = UnityMcpServer.Instance != null && UnityMcpServer.Instance.IsRunning; bool httpRunning = UnityMcpHttpServer.Instance != null; sb.AppendLine($"WebSocket Server: {(wsRunning ? "RUNNING" : "STOPPED")}"); sb.AppendLine($"HTTP Server: {(httpRunning ? "RUNNING" : "STOPPED")}"); sb.AppendLine(); // Endpoints sb.AppendLine("【HTTP API Endpoints】"); sb.AppendLine("Base URL: http://localhost:5051"); sb.AppendLine(); sb.AppendLine("1. Health Check (GET)"); sb.AppendLine(" Endpoint: /health"); sb.AppendLine(" Example: curl http://localhost:5051/health"); sb.AppendLine(); sb.AppendLine("2. MCP JSON-RPC API (POST)"); sb.AppendLine(" Endpoint: /api/mcp"); sb.AppendLine(" Content-Type: application/json"); sb.AppendLine(); sb.AppendLine(" Example:"); sb.AppendLine(" curl -X POST http://localhost:5051/api/mcp \\"); sb.AppendLine(" -H \"Content-Type: application/json\" \\"); sb.AppendLine(" -d '{"); sb.AppendLine(" \"jsonrpc\": \"2.0\","); sb.AppendLine(" \"method\": \"unity.scene.list\","); sb.AppendLine(" \"params\": {\"maxDepth\": 1},"); sb.AppendLine(" \"id\": 1"); sb.AppendLine(" }'"); sb.AppendLine(); // WebSocket sb.AppendLine("【WebSocket Endpoint】"); sb.AppendLine("URL: ws://localhost:5050"); sb.AppendLine("Protocol: MCP (Model Context Protocol)"); sb.AppendLine(); // Method Examples sb.AppendLine("【Available Methods (Examples)】"); sb.AppendLine("- unity.scene.list"); sb.AppendLine("- unity.gameObject.list"); sb.AppendLine("- unity.component.list"); sb.AppendLine("- unity.component.inspect"); sb.AppendLine("- unity.component.add"); sb.AppendLine("- unity.component.setField"); sb.AppendLine("- unity.component.setSerializedProperty"); sb.AppendLine("- unity.editor.play"); sb.AppendLine("- unity.editor.stop"); sb.AppendLine("- unity.test.runAll"); sb.AppendLine("- unity.compile.status"); sb.AppendLine("- unity.connection.status"); sb.AppendLine(); sb.AppendLine("For full API list, see CHANGELOG.md"); sb.AppendLine(); // Claude Code Configuration sb.AppendLine("【Claude Code Configuration】"); sb.AppendLine("For Claude Code Desktop, use WebSocket endpoint:"); sb.AppendLine(); sb.AppendLine("// claude_desktop_config.json"); sb.AppendLine("{"); sb.AppendLine(" \"mcpServers\": {"); sb.AppendLine(" \"unity\": {"); sb.AppendLine(" \"command\": \"npx\","); sb.AppendLine(" \"args\": ["); sb.AppendLine(" \"@modelcontextprotocol/server-websocket\","); sb.AppendLine(" \"ws://localhost:5050\""); sb.AppendLine(" ]"); sb.AppendLine(" }"); sb.AppendLine(" }"); sb.AppendLine("}"); sb.AppendLine(); // Test Commands sb.AppendLine("【Test Commands】"); sb.AppendLine("1. Test Health Check:"); sb.AppendLine(" curl http://localhost:5051/health"); sb.AppendLine(); sb.AppendLine("2. Test API:"); sb.AppendLine(" curl -X POST http://localhost:5051/api/mcp \\"); sb.AppendLine(" -H \"Content-Type: application/json\" \\"); sb.AppendLine(" -d '{\"jsonrpc\":\"2.0\",\"method\":\"unity.connection.status\",\"params\":{},\"id\":1}'"); sb.AppendLine(); sb.AppendLine("3. Run Test Scripts:"); sb.AppendLine(" cd tests && ./run_all_tests.sh"); sb.AppendLine(); sb.AppendLine("==========================================="); string info = sb.ToString(); Debug.Log(info); // Also show in EditorUtility dialog EditorUtility.DisplayDialog( "Unity MCP Server - API Information", "API情報をConsoleに出力しました。\n\n" + "詳細はConsoleウィンドウを確認してください。\n\n" + "重要: HTTPエンドポイントは /api/mcp です\n" + "(テストスクリプトは修正が必要)", "OK" ); } [MenuItem("MCP/Server/Copy API Test Command", false, 103)] public static void CopyApiTestCommand() { string command = "curl -X POST http://localhost:5051/api/mcp -H \"Content-Type: application/json\" -d '{\"jsonrpc\":\"2.0\",\"method\":\"unity.connection.status\",\"params\":{},\"id\":1}'"; GUIUtility.systemCopyBuffer = command; Debug.Log($"[MCP] Copied to clipboard: {command}"); EditorUtility.DisplayDialog( "Command Copied", "API test command copied to clipboard!\n\n" + "Paste in terminal to test the connection.", "OK" ); } [MenuItem("MCP/Server/Open API Documentation", false, 104)] public static void OpenApiDocumentation() { string changelogPath = System.IO.Path.Combine(Application.dataPath, "..", "Packages", "com.local.mcp.unityserver", "CHANGELOG.md"); if (System.IO.File.Exists(changelogPath)) { Application.OpenURL($"file://{changelogPath}"); } else { EditorUtility.DisplayDialog( "Documentation", "CHANGELOG.md not found.\n\n" + "Please check the package directory for API documentation.", "OK" ); } } } }

Latest Blog Posts

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/dsgarage/UniMCP4CC'

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