1
0
Fork 0
mirror of https://github.com/imjasonh/mamba synced 2026-07-07 00:42:25 +00:00
mamba/README.md
Jason Hall 7d05d40e04
initial commit
Signed-off-by: Jason Hall <jason@chainguard.dev>
2025-07-14 09:51:37 -04:00

1.8 KiB

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 args array parameter
  • Preserves command hierarchy using underscore-separated tool names (e.g., math_add for 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