Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SharpCliMcp

A standard MCP (Model Context Protocol) CLI execution server built on ModelContextProtocol SDK + CliWrap.

Executes one or more CLI commands via CliWrap's native pipe API. Supports single commands, command pipelines (using |), and batch sequential execution.

⚠️ Does NOT support interactive processes (ssh, REPL, vim, less, top, etc.). Those require a PTY.


1. Get & Publish

# Clone the repository
git clone https://github.com/Axvser/SharpCliMcp.git
cd SharpCliMcp

# Restore dependencies
dotnet restore

# Publish to a custom MCP installation path (for VeloxDev McpScope)
dotnet publish -c Release -o /path/to/your/.evn/mcp/dotnet/sharp-cli-mcp

Published layout:

/path/to/your/.evn/mcp/dotnet/sharp-cli-mcp/
├── SharpCliMcp.dll
├── SharpCliMcp.runtimeconfig.json
├── CliWrap.dll
├── ModelContextProtocol.dll
└── ...

2. MCP Tools

2.1 execute_command

Execute one or more CLI commands. Supports pipes (|) for native command chaining.

Parameter Type Required Description
commands string[] ✅ Commands to execute
workingDirectory string? ❌ Working directory for all commands
timeoutMs int? ❌ Timeout in milliseconds

2.2 which

Locate an executable on the system PATH.

Parameter Type Required Description
command string ✅ Executable name (e.g. "dotnet", "git")

3. Usage

3.1 Raw ModelContextProtocol SDK

using ModelContextProtocol.Client;
using ModelContextProtocol.Transport;

await using var client = await McpClient.CreateAsync(
    new StdioClientTransport(new()
    {
        Command = "dotnet",
        Arguments = ["run", "--project", @"E:\Projects\SharpCliMcp", "--no-build"],
    }),
    new McpClientOptions { ClientInfo = new() { Name = "MyApp", Version = "1.0.0" } }
);

// Single command
await client.CallToolAsync("execute_command", new()
{
    ["commands"] = new[] { "dotnet --version" }
});

// Pipeline: chain commands with |
await client.CallToolAsync("execute_command", new()
{
    ["commands"] = new[] { "dir | findstr .cs | sort" }
});

// Batch: sequential execution
await client.CallToolAsync("execute_command", new()
{
    ["commands"] = new[]
    {
        "git status",
        "git log --oneline -3"
    }
});

// Check if a tool exists
await client.CallToolAsync("which", new()
{
    ["command"] = "python"
});

3.2 VeloxDev.Core.Extension (McpScope)

Prerequisite: Publish to the McpScope installation directory:

dotnet publish -c Release -o .evn/mcp/dotnet/sharp-cli-mcp

Configuration & invocation:

using Microsoft.Extensions.AI;
using VeloxDev.AI.MCP;

var scope = new McpScope();
var tools = await scope.LoadAsync([
    new McpServerConfiguration
    {
        Name = "CLI Tools",
        RunMode = McpServerRunMode.Dotnet,
        Package = "sharp-cli-mcp/SharpCliMcp.dll",
    }
]);

var execute = (AIFunction)tools.First(t => t.Name == "execute_command");

// Run a single command
var result = await execute.InvokeAsync(new AIFunctionArguments
{
    ["commands"] = new[] { "dotnet --version" },
});
Console.WriteLine(result);

Project Structure

SharpCliMcp/
├── SharpCliMcp.csproj   ← Dependencies: CliWrap + ModelContextProtocol
├── Program.cs            ← Entry point with MCP server setup
├── Tools/
│   └── CliTool.cs        ← [McpServerToolType] execute_command + which
└── README.md

About

MCP for CliWrap

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages