mirror of
https://github.com/imjasonh/mamba
synced 2026-07-07 00:42:25 +00:00
No description
|
|
||
|---|---|---|
| cmd/josh | ||
| example | ||
| go.mod | ||
| go.sum | ||
| mcp.go | ||
| README.md | ||
| test_mcp_capabilities.sh | ||
| test_mcp_tools.sh | ||
cobra-mcp
A Go library that bridges Cobra CLI applications with the Model Context Protocol (MCP), allowing any Cobra-based CLI tool to be exposed as an MCP server.
Installation
go get github.com/imjasonh/mamba
Usage
Add MCP support to your existing Cobra application with a single function call:
package main
import (
"github.com/imjasonh/mamba"
"github.com/spf13/cobra"
)
func main() {
rootCmd := &cobra.Command{
Use: "myapp",
Short: "My CLI application",
}
// Add your existing commands...
// Add MCP server support
mamba.AddMCPCommand(rootCmd)
rootCmd.Execute()
}
This adds an mcp subcommand to your CLI. Run it to start the MCP server:
myapp mcp
How it works
The library automatically:
- Exposes all runnable Cobra commands as MCP tools
- Maps command flags to tool parameters with appropriate types (string, boolean, number)
- Handles positional arguments via an
argsarray parameter - Preserves command hierarchy using underscore-separated tool names (e.g.,
math_addfor subcommand) - Captures command output and returns it as text content
Example
See the example CLI for a complete demonstration featuring:
- Simple commands with flags
- Nested subcommands
- Required and optional parameters
- Boolean, string, and numeric flag types
- Positional arguments
Integration with Claude Desktop
To use your CLI with Claude Desktop, add it to your MCP settings:
{
"mcpServers": {
"myapp": {
"command": "/path/to/myapp",
"args": ["mcp"]
}
}
}
Requirements
- Go 1.19+
- Cobra v1.0+
- mark3labs/mcp-go v0.2.0+
License
MIT