{"record":{"id":"1da71e5adcfb7776","repo":"CoplayDev/unity-mcp","slug":"failed-to-register-with-claude-code-stderr-std","errorCode":null,"errorMessage":"Failed to register with Claude Code:\n{stderr}\n{stdout}","messagePattern":"Failed to register with Claude Code:\n(.+?)\n(.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs","lineNumber":920,"sourceCode":"                else\n                {\n                    args = $\"mcp add --scope local --transport http UnityMCP {httpUrl}\";\n                }\n            }\n            else\n            {\n                // Use --scope local to register in the project-local config, avoiding conflicts with user-level config (#664)\n                args = $\"mcp add --scope local --transport stdio UnityMCP -- \\\"{uvxPath}\\\" {uvxDevFlags}{fromArgs} {packageName}\";\n            }\n\n            // Remove any existing registrations from ALL scopes to prevent stale config conflicts (#664)\n            McpLog.Info(\"Removing any existing UnityMCP registrations from all scopes before adding...\");\n            RemoveFromAllScopes(claudePath, projectDir, pathPrepend);\n\n            // Now add the registration\n            if (!ExecPath.TryRun(claudePath, args, projectDir, out var stdout, out var stderr, 15000, pathPrepend))\n            {\n                throw new InvalidOperationException($\"Failed to register with Claude Code:\\n{stderr}\\n{stdout}\");\n            }\n\n            McpLog.Info($\"Successfully registered with Claude Code using {(useHttpTransport ? \"HTTP\" : \"stdio\")} transport.\");\n            client.SetStatus(McpStatus.Configured);\n            client.configuredTransport = serverTransport;\n        }\n\n        /// <summary>\n        /// Thread-safe unregistration using pre-captured values.\n        /// </summary>\n        private void UnregisterWithCapturedValues(string projectDir, string claudePath, string pathPrepend)\n        {\n            if (string.IsNullOrEmpty(claudePath))\n            {\n                throw new InvalidOperationException(\"Claude CLI not found. Please install Claude Code first.\");\n            }\n\n            // Remove from ALL scopes to ensure complete cleanup (#664)","sourceCodeStart":902,"sourceCodeEnd":938,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs#L902-L938","documentation":"RegisterWithCapturedValues() runs `claude mcp add --scope local ...` via ExecPath.TryRun with a 15-second timeout. If the process exits non-zero (TryRun returns false), it throws InvalidOperationException embedding both stderr and stdout. The actual failure reason is in the stderr text — common causes include invalid arguments, authentication errors, scope conflicts, or the binary being present but broken.","triggerScenarios":"The `claude mcp add` subprocess fails: wrong CLI version (missing --scope or --transport flags), malformed URL, authentication required, the binary exists but errors at runtime, or the 15-second timeout is exceeded.","commonSituations":"Claude Code CLI version mismatch (older version without --scope local support). The HTTP URL is malformed or unreachable. A stale registration in a different scope blocks the add. The process exceeds the 15-second timeout on a slow machine.","solutions":["Read the stderr in the exception message — it contains the exact CLI error.","Update Claude Code to the latest version: `npm update -g @anthropic-ai/claude-code`.","Run the exact `claude mcp add` command from GetManualSnippet() manually in a terminal to see the full error output.","If a stale registration conflicts, run `claude mcp remove UnityMCP` in all scopes before retrying.","For timeout issues, check if Claude CLI is prompting for input interactively (it cannot in a subprocess)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { configurator.Configure(); }\ncatch (InvalidOperationException ex)\n{ Debug.LogError($\"Claude registration failed:\\n{ex.Message}\"); ShowManualSnippet(); }","preventionTips":["Keep Claude Code updated to support current CLI flags (--scope, --transport).","Remove stale UnityMCP registrations from all scopes before reconfiguring.","Run the manual `claude mcp add` command in a terminal to diagnose interactively."],"tags":["configuration","claude-cli","subprocess","registration","thread-safe"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}