Skip to content

Commit 92fd8b2

Browse files
Fix relative path resolution in sample app. (#572)
* Fix relative path resolution in sample app. * Update samples/QuickstartClient/Program.cs * Fix build
1 parent ab51400 commit 92fd8b2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

samples/QuickstartClient/Program.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using Microsoft.Extensions.Configuration;
44
using Microsoft.Extensions.Hosting;
55
using ModelContextProtocol.Client;
6+
using System.Diagnostics;
7+
using System.Runtime.CompilerServices;
68

79
var builder = Host.CreateApplicationBuilder(args);
810

@@ -89,6 +91,12 @@ static void PromptForInput()
8991
[var script] when script.EndsWith(".py") => ("python", args),
9092
[var script] when script.EndsWith(".js") => ("node", args),
9193
[var script] when Directory.Exists(script) || (File.Exists(script) && script.EndsWith(".csproj")) => ("dotnet", ["run", "--project", script]),
92-
_ => ("dotnet", ["run", "--project", "../QuickstartWeatherServer"])
94+
_ => ("dotnet", ["run", "--project", Path.Combine(GetCurrentSourceDirectory(), "../QuickstartWeatherServer")])
9395
};
96+
}
97+
98+
static string GetCurrentSourceDirectory([CallerFilePath] string? currentFile = null)
99+
{
100+
Debug.Assert(!string.IsNullOrWhiteSpace(currentFile));
101+
return Path.GetDirectoryName(currentFile) ?? throw new InvalidOperationException("Unable to determine source directory.");
94102
}

0 commit comments

Comments
 (0)