From 4f455e534673d8656979fc4fd8bfa39fa2ffa7b5 Mon Sep 17 00:00:00 2001 From: anannya03 Date: Wed, 3 Sep 2025 17:48:52 -0700 Subject: [PATCH 1/2] Checkpoint from VS Code for coding agent session --- .../ClientToolTests.cs | 13 ++--- .../Client/CommandTestsBase.cs | 12 ++++- .../Client/Helpers/LiveTestFixture.cs | 48 ++++++++++++++++++- eng/scripts/Compare-Environment.ps1 | 0 4 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 eng/scripts/Compare-Environment.ps1 diff --git a/core/Azure.Mcp.Core/tests/Azure.Mcp.Core.LiveTests/ClientToolTests.cs b/core/Azure.Mcp.Core/tests/Azure.Mcp.Core.LiveTests/ClientToolTests.cs index 3d908a085..a188f8c88 100644 --- a/core/Azure.Mcp.Core/tests/Azure.Mcp.Core.LiveTests/ClientToolTests.cs +++ b/core/Azure.Mcp.Core/tests/Azure.Mcp.Core.LiveTests/ClientToolTests.cs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using System.Reflection; using System.Text.Json; using Azure.Mcp.Tests; +using Azure.Mcp.Tests.Client; using Azure.Mcp.Tests.Client.Helpers; using ModelContextProtocol; using ModelContextProtocol.Client; @@ -12,15 +12,12 @@ namespace Azure.Mcp.Core.LiveTests; -public class ClientToolTests : IAsyncLifetime +public class ClientToolTests : CommandTestsBase { - private readonly ITestOutputHelper _output; - private IMcpClient _client = default!; - private LiveTestSettings _settings = default!; - - public ClientToolTests(ITestOutputHelper output) + public ClientToolTests(ITestOutputHelper output) : base(output) { - _output = output; + // Set arguments for all mode with debug logging + SetArguments("server", "start", "--mode", "all", "--debug"); } public async ValueTask InitializeAsync() diff --git a/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/CommandTestsBase.cs b/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/CommandTestsBase.cs index d07e1a563..934a5bdcb 100644 --- a/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/CommandTestsBase.cs +++ b/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/CommandTestsBase.cs @@ -89,13 +89,23 @@ public virtual async ValueTask InitializeAsync() Name = "Test Server", Command = executablePath, Arguments = arguments, - // Redirect stderr to shared log for later output during test failure + // Redirect stderr to both shared log and current test output StandardErrorLines = line => { lock (_lock) { _serverErrorLog.Add(line); } + + // Also output to current test's output helper for immediate visibility + try + { + Output.WriteLine($"[MCP Server] {line}"); + } + catch + { + // Ignore if output helper is not available (e.g., during disposal) + } } }; diff --git a/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/Helpers/LiveTestFixture.cs b/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/Helpers/LiveTestFixture.cs index 70d0cad86..2e17818dd 100644 --- a/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/Helpers/LiveTestFixture.cs +++ b/core/Azure.Mcp.Core/tests/Azure.Mcp.Tests/Client/Helpers/LiveTestFixture.cs @@ -3,6 +3,7 @@ using System.Reflection; using ModelContextProtocol.Client; +using Xunit; namespace Azure.Mcp.Tests.Client.Helpers; @@ -11,6 +12,7 @@ public class LiveTestFixture : LiveTestSettingsFixture public IMcpClient Client { get; private set; } = default!; private string[]? _customArguments; + private readonly List _serverErrors = new(); /// /// Sets custom arguments for the MCP server. Call this before InitializeAsync(). @@ -21,6 +23,11 @@ public void SetArguments(params string[] arguments) _customArguments = arguments; } + /// + /// Gets any stderr output from the MCP server for debugging purposes. + /// + public IReadOnlyList ServerErrors => _serverErrors.AsReadOnly(); + public override async ValueTask InitializeAsync() { await base.InitializeAsync(); @@ -35,7 +42,24 @@ public override async ValueTask InitializeAsync() { Name = "Test Server", Command = executablePath, - Arguments = arguments + Arguments = arguments, + // Capture stderr output for debugging + StandardErrorLines = line => + { + _serverErrors.Add(line); + // Also output to test context if available for immediate visibility + try + { + if (TestContext.Current != null) + { + System.Diagnostics.Debug.WriteLine($"[MCP Server] {line}"); + } + } + catch + { + // Ignore if TestContext is not available + } + } }; if (!string.IsNullOrEmpty(Settings.TestPackage)) @@ -47,6 +71,26 @@ public override async ValueTask InitializeAsync() var clientTransport = new StdioClientTransport(transportOptions); - Client = await McpClientFactory.CreateAsync(clientTransport); + try + { + // Add timeout protection like in CommandTestsBase + using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(2)); + var clientTask = McpClientFactory.CreateAsync(clientTransport); + Client = await clientTask.WaitAsync(cts.Token); + } + catch (TimeoutException) + { + var errorSummary = _serverErrors.Count > 0 ? + $"Server errors: {string.Join("; ", _serverErrors.TakeLast(5))}" : + "No server error output captured"; + throw new TimeoutException($"MCP client initialization timed out after 2 minutes. {errorSummary}"); + } + catch (OperationCanceledException) + { + var errorSummary = _serverErrors.Count > 0 ? + $"Server errors: {string.Join("; ", _serverErrors.TakeLast(5))}" : + "No server error output captured"; + throw new OperationCanceledException($"MCP client initialization was cancelled or timed out. {errorSummary}"); + } } } diff --git a/eng/scripts/Compare-Environment.ps1 b/eng/scripts/Compare-Environment.ps1 new file mode 100644 index 000000000..e69de29bb From b25a520fda101a0000f1351d97e26aea918a2b8e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 4 Sep 2025 00:48:57 +0000 Subject: [PATCH 2/2] Initial plan