Skip to content

Commit 502a09d

Browse files
authored
Linux-related stdio fixes and update version (#22)
- Modified `GetCommand` to return OS-specific commands and changed return type to `string?`. - Improved `InitializeCommand` for better command initialization and logging. - Cleaned up using directives in `Log.cs` and `SseClientTransport.cs`. - Updated `CreateNoWindow` property in `StdioClientTransport` to be OS-dependent. - Bumped version number in `mcpdotnet.csproj` to 1.0.1.1.
1 parent 535d342 commit 502a09d

6 files changed

Lines changed: 16 additions & 22 deletions

File tree

‎README.MD‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ while (true)
166166
- Performance optimization
167167
- SSE server support
168168
- Authentication
169-
- Linux/Mac support for stdio transport
170169

171170
## License
172171

‎src/mcpdotnet/Client/McpClientFactory.cs‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,45 +135,44 @@ private static int ParseOrDefault(IDictionary<string, string>? options, string k
135135
return defaultValue;
136136
}
137137

138-
private string GetCommand(McpServerConfig config)
138+
private string? GetCommand(McpServerConfig config)
139139
{
140140
if (config.TransportOptions == null ||
141141
string.IsNullOrEmpty(config.TransportOptions.GetValueOrDefault("command")))
142142
{
143143
return config.Location!;
144144
}
145145

146-
return $"cmd.exe";
146+
return OperatingSystem.IsWindows() ? "cmd.exe" : config.TransportOptions?.GetValueOrDefault("command");
147147
}
148148

149149
/// <summary>
150150
/// Initializes a non-shell command by injecting a /c {command} argument, as the command will be run in a shell.
151151
/// </summary>
152152
private void InitializeCommand(McpServerConfig config)
153153
{
154-
155154
string endpointName = $"Client ({config.Id}: {config.Name})";
156155

157156
// If the command is empty or already contains cmd.exe, we don't need to do anything
158157
var command = config.TransportOptions?.GetValueOrDefault("command");
159-
if (string.IsNullOrEmpty(command))
158+
159+
if (string.IsNullOrEmpty(command) || !OperatingSystem.IsWindows())
160160
{
161161
return;
162162
}
163163

164-
if (command.Contains("cmd.exe"))
164+
// On Windows, we need to wrap non-shell commands with cmd.exe /c
165+
if (command.ToLowerInvariant().Contains("cmd.exe"))
165166
{
166167
_logger.SkippingShellWrapper(endpointName);
167168
return;
168169
}
169170

170-
// If the command is not empty and does not contain cmd.exe, we need to inject /c {command}
171-
if (config.TransportOptions != null && !string.IsNullOrEmpty(command))
172-
{
173-
_logger.PromotingCommandToShellArgumentForStdio(endpointName, command, config.TransportOptions.GetValueOrDefault("arguments") ?? "");
174-
config.TransportOptions["arguments"] = config.TransportOptions.ContainsKey("arguments")
175-
? $"/c {command} {config.TransportOptions["arguments"]}"
176-
: $"/c {command}";
177-
}
171+
// If the command is not empty and does not contain cmd.exe, we need to inject /c {command} (usually npx or uvicorn)
172+
// This is because the stdio transport will not work correctly if the command is not run in a shell
173+
_logger.PromotingCommandToShellArgumentForStdio(endpointName, command, config.TransportOptions!.GetValueOrDefault("arguments") ?? "");
174+
config.TransportOptions!["arguments"] = config.TransportOptions.ContainsKey("arguments")
175+
? $"/c {command} {config.TransportOptions["arguments"]}"
176+
: $"/c {command}";
178177
}
179178
}

‎src/mcpdotnet/Logging/Log.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using McpDotNet.Configuration;
2-
using McpDotNet.Protocol.Messages;
1+
using McpDotNet.Protocol.Messages;
32
using Microsoft.Extensions.Logging;
43

54
namespace McpDotNet.Logging;

‎src/mcpdotnet/Protocol/Transport/SseClientTransport.cs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-

2-
using System.Diagnostics.Tracing;
3-
using System.Text.Json;
1+
using System.Text.Json;
42
using System.Text;
53
using McpDotNet.Protocol.Messages;
64
using McpDotNet.Configuration;
@@ -9,7 +7,6 @@
97
using System.Net.Http.Headers;
108
using System.Text.Json.Serialization;
119
using McpDotNet.Utils.Json;
12-
using System.Threading;
1310

1411
namespace McpDotNet.Protocol.Transport;
1512

‎src/mcpdotnet/Protocol/Transport/StdioClientTransport.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task ConnectAsync(CancellationToken cancellationToken = default)
6161
RedirectStandardInput = true,
6262
RedirectStandardOutput = true,
6363
RedirectStandardError = true,
64-
CreateNoWindow = true,
64+
CreateNoWindow = OperatingSystem.IsWindows(),
6565
WorkingDirectory = _options.WorkingDirectory ?? Environment.CurrentDirectory,
6666
};
6767

‎src/mcpdotnet/mcpdotnet.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PropertyGroup>
1010
<!-- license and package properties -->
1111
<PackageId>mcpdotnet</PackageId>
12-
<Version>1.0.0.1</Version>
12+
<Version>1.0.1.1</Version>
1313
<Authors>PederHP</Authors>
1414
<Description>.NET client library for the Model Context Protocol (MCP)</Description>
1515
<PackageProjectUrl>https://github.com/PederHP/mcpdotnet</PackageProjectUrl>

0 commit comments

Comments
 (0)