Skip to content

Commit 587551a

Browse files
Fix relative path resolution in sample app.
1 parent 9d835a0 commit 587551a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

samples/QuickstartClient/Program.cs

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

78
var builder = Host.CreateApplicationBuilder(args);
89

@@ -89,6 +90,16 @@ static void PromptForInput()
8990
[var script] when script.EndsWith(".py") => ("python", args),
9091
[var script] when script.EndsWith(".js") => ("node", args),
9192
[var script] when Directory.Exists(script) || (File.Exists(script) && script.EndsWith(".csproj")) => ("dotnet", ["run", "--project", script]),
92-
_ => ("dotnet", ["run", "--project", "../QuickstartWeatherServer"])
93+
_ => ("dotnet", ["run", "--project", Path.Combine(GetCurrentSourceDirectory(), "../QuickstartWeatherServer")])
9394
};
95+
}
96+
97+
static string GetCurrentSourceDirectory([CallerFilePath] string? currentFile = null)
98+
{
99+
if (string.IsNullOrWhiteSpace(currentFile))
100+
{
101+
throw new ArgumentException(nameof(currentFile));
102+
}
103+
104+
return Path.GetDirectoryName(currentFile) ?? throw new InvalidOperationException("Unable to determine source directory.");
94105
}

0 commit comments

Comments
 (0)