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.
This commit is contained in:
parent
535d342367
commit
502a09d9fc
6 changed files with 16 additions and 22 deletions
|
|
@ -166,7 +166,6 @@ while (true)
|
|||
- Performance optimization
|
||||
- SSE server support
|
||||
- Authentication
|
||||
- Linux/Mac support for stdio transport
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ public class McpClientFactory
|
|||
return defaultValue;
|
||||
}
|
||||
|
||||
private string GetCommand(McpServerConfig config)
|
||||
private string? GetCommand(McpServerConfig config)
|
||||
{
|
||||
if (config.TransportOptions == null ||
|
||||
string.IsNullOrEmpty(config.TransportOptions.GetValueOrDefault("command")))
|
||||
|
|
@ -143,7 +143,7 @@ public class McpClientFactory
|
|||
return config.Location!;
|
||||
}
|
||||
|
||||
return $"cmd.exe";
|
||||
return OperatingSystem.IsWindows() ? "cmd.exe" : config.TransportOptions?.GetValueOrDefault("command");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -151,29 +151,28 @@ public class McpClientFactory
|
|||
/// </summary>
|
||||
private void InitializeCommand(McpServerConfig config)
|
||||
{
|
||||
|
||||
string endpointName = $"Client ({config.Id}: {config.Name})";
|
||||
|
||||
// If the command is empty or already contains cmd.exe, we don't need to do anything
|
||||
var command = config.TransportOptions?.GetValueOrDefault("command");
|
||||
if (string.IsNullOrEmpty(command))
|
||||
|
||||
if (string.IsNullOrEmpty(command) || !OperatingSystem.IsWindows())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (command.Contains("cmd.exe"))
|
||||
// On Windows, we need to wrap non-shell commands with cmd.exe /c
|
||||
if (command.ToLowerInvariant().Contains("cmd.exe"))
|
||||
{
|
||||
_logger.SkippingShellWrapper(endpointName);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the command is not empty and does not contain cmd.exe, we need to inject /c {command}
|
||||
if (config.TransportOptions != null && !string.IsNullOrEmpty(command))
|
||||
{
|
||||
_logger.PromotingCommandToShellArgumentForStdio(endpointName, command, config.TransportOptions.GetValueOrDefault("arguments") ?? "");
|
||||
config.TransportOptions["arguments"] = config.TransportOptions.ContainsKey("arguments")
|
||||
? $"/c {command} {config.TransportOptions["arguments"]}"
|
||||
: $"/c {command}";
|
||||
}
|
||||
// If the command is not empty and does not contain cmd.exe, we need to inject /c {command} (usually npx or uvicorn)
|
||||
// This is because the stdio transport will not work correctly if the command is not run in a shell
|
||||
_logger.PromotingCommandToShellArgumentForStdio(endpointName, command, config.TransportOptions!.GetValueOrDefault("arguments") ?? "");
|
||||
config.TransportOptions!["arguments"] = config.TransportOptions.ContainsKey("arguments")
|
||||
? $"/c {command} {config.TransportOptions["arguments"]}"
|
||||
: $"/c {command}";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using McpDotNet.Configuration;
|
||||
using McpDotNet.Protocol.Messages;
|
||||
using McpDotNet.Protocol.Messages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace McpDotNet.Logging;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
|
||||
using System.Diagnostics.Tracing;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text;
|
||||
using McpDotNet.Protocol.Messages;
|
||||
using McpDotNet.Configuration;
|
||||
|
|
@ -9,7 +7,6 @@ using McpDotNet.Logging;
|
|||
using System.Net.Http.Headers;
|
||||
using System.Text.Json.Serialization;
|
||||
using McpDotNet.Utils.Json;
|
||||
using System.Threading;
|
||||
|
||||
namespace McpDotNet.Protocol.Transport;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public sealed class StdioClientTransport : TransportBase, IClientTransport
|
|||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true,
|
||||
CreateNoWindow = OperatingSystem.IsWindows(),
|
||||
WorkingDirectory = _options.WorkingDirectory ?? Environment.CurrentDirectory,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<PropertyGroup>
|
||||
<!-- license and package properties -->
|
||||
<PackageId>mcpdotnet</PackageId>
|
||||
<Version>1.0.0.1</Version>
|
||||
<Version>1.0.1.1</Version>
|
||||
<Authors>PederHP</Authors>
|
||||
<Description>.NET client library for the Model Context Protocol (MCP)</Description>
|
||||
<PackageProjectUrl>https://github.com/PederHP/mcpdotnet</PackageProjectUrl>
|
||||
|
|
|
|||
Loading…
Reference in a new issue