-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (46 loc) · 2.11 KB
/
Copy pathProgram.cs
File metadata and controls
49 lines (46 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
using SharpCliMcp.Tools;
Console.Error.WriteLine("[SharpCliMcp] Starting...");
await StartServer();
static async Task StartServer()
{
var transport = new StdioServerTransport("SharpCliMcp");
var options = new McpServerOptions
{
ServerInfo = new Implementation { Name = "SharpCliMcp", Version = "1.0.0" },
Capabilities = new ServerCapabilities { Tools = new() },
ToolCollection =
[
McpServerTool.Create(
async (string[] commands,
string? workingDirectory = null,
int? timeoutMs = null) =>
await CliTool.ExecuteAsync(commands, workingDirectory, timeoutMs),
new McpServerToolCreateOptions
{
Name = "execute_command",
Title = "Execute CLI command",
Description = "Execute one or more CLI commands via CliWrap. " +
"Use pipe (|) between commands to chain them natively. " +
"Multiple commands in the array run sequentially. " +
"⚠️ Does NOT support interactive processes (ssh, REPL, vim, less, top). " +
"Returns stdout, stderr, and exit code for each command or pipeline.",
}),
McpServerTool.Create(
async (string command) =>
await CliTool.FindExecutableAsync(command),
new McpServerToolCreateOptions
{
Name = "which",
Title = "Locate executable",
Description = "Find the full path of an executable via PATH. " +
"Uses where (Windows) or which (Unix). " +
"Useful for checking if a tool is available before running it.",
}),
],
};
await using var server = McpServer.Create(transport, options);
Console.Error.WriteLine("[SharpCliMcp] Ready. Use tools 'execute_command' and 'which'.");
await server.RunAsync();
}