Create and Publish Business Websites in seconds. AI will gather all the details about your website and generate link to your website.

MCP-Cobra
MCP-Cobra is a Go library that integrates the Cobra command-line interface framework with the Model Context Protocol (MCP). This library allows you to expose your Cobra CLI commands as MCP tools, making them accessible to AI assistants and other MCP clients.
Features
- Automatically convert Cobra commands to MCP tools
- Support for various flag types (string, int, bool, float)
- Seamless integration with existing Cobra-based CLIs
- Run your CLI application in traditional command-line mode or as an MCP server
Installation
go get github.com/PlusLemon/mcp-cobra
Usage
To use MCP-Cobra, you need to:
- Create a Cobra command structure as usual
- Initialize an MCP server with your root command
- Serve the MCP server via stdio when needed
Example:
package main
import (
"fmt"
"os"
"github.com/PlusLemon/mcp-cobra/mcp"
"github.com/spf13/cobra"
)
func main() {
rootCmd := &cobra.Command{
Use: "myapp",
Short: "My application description",
}
// Add your commands and flags...
// Check if the application should run as an MCP server
if len(os.Args) > 1 && os.Args[1] == "mcp-server" {
mcpServer := mcp.NewMCPServer(rootCmd)
if err := mcpServer.ServeStdio(); err != nil {
fmt.Printf("MCP server error: %v\n", err)
os.Exit(1)
}
} else {
// Run as a normal CLI application
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
}
Example: foocli
The foocli
directory contains a complete working example of MCP-Cobra in action.
What it does
foocli
is a simple CLI application with a greet
command that prints a greeting message. It can run both as a traditional CLI and as an MCP server.
Running the example
As a CLI:
# Build the example
go build -o bin/foo ./foocli
# Run as a regular CLI
./bin/foo greet --name "World"
# Output: Hello, World!
As an MCP server:
# Run as an MCP server
./bin/foo mcp-server
When running as an MCP server, the greet
command is exposed as an MCP tool that can be invoked by MCP clients.
Example Code
package main
import (
"fmt"
"os"
"github.com/PlusLemon/mcp-cobra/mcp"
"github.com/spf13/cobra"
)
func main() {
rootCmd := &cobra.Command{
Use: "foo",
Short: "Foo Demo CLI",
}
// Define subcommand
var greetWord string
greetCmd := &cobra.Command{
Use: "greet",
Short: "Greet someone",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Hello, %s!\n", greetWord)
},
}
greetCmd.Flags().StringVar(&greetWord, "name", "Foo", "Name to greet")
rootCmd.AddCommand(greetCmd)
if len(os.Args) > 1 && os.Args[1] == "mcp-server" {
mcpServer := mcp.NewMCPServer(rootCmd)
if err := mcpServer.ServeStdio(); err != nil {
fmt.Printf("MCP server error: %v\n", err)
os.Exit(1)
}
} else {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
}
How It Works
When running in MCP server mode, MCP-Cobra analyzes your Cobra command structure and converts each command to an MCP tool. Command flags are converted to tool parameters with appropriate types and metadata.
When an MCP client calls a tool, MCP-Cobra:
- Maps the tool call to the appropriate Cobra command
- Converts the tool parameters to command flags
- Executes the command
- Captures the command output
- Returns the result to the MCP client
License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
相关推荐
Text your favorite pet, after answering 10 questions about their everyday lives!
Carbon footprint calculations breakdown and advices on how to reduce it
You're in a stone cell – can you get out? A classic choose-your-adventure interactive fiction game, based on a meticulously-crafted playbook. With a medieval fantasy setting, infinite choices and outcomes, and dice!
Evaluates language quality of texts, responds with a numerical score between 50-150.
Discover A More Robust Business: Craft tailored value proposition statements, develop a comprehensive business model canvas, conduct detailed PESTLE analysis, and gain strategic insights on enhancing business model elements like scalability, cost structure, and market competition strategies. (v1.18)
Best-in-class AI domain names scoring engine and availability checker. Brandability, domain worth, root keywords and more.
Structured recipes for food and desserts – ingredient lists and step-by-step recipe instructions from any input. Become surprised, try something new or breathe life into grandma's old recipe notebook.
🧑🚀 全世界最好的 llM 资料总结(数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Resumen de los mejores recursos del mundo.
Plataforma de automatización de flujo de trabajo de código justo con capacidades de IA nativas. Combine el edificio visual con código personalizado, auto-anfitrión o nube, más de 400 integraciones.
🔥 1Panel proporciona una interfaz web intuitiva y un servidor MCP para administrar sitios web, archivos, contenedores, bases de datos y LLM en un servidor de Linux.
Este repositorio es para el desarrollo del servidor Azure MCP, llevando el poder de Azure a sus agentes.
Este proyecto fue creado para demostrar cómo podemos conectarnos con diferentes protocolos de contexto del modelo (MCP).
⛓️Rulego es un marco de motor de regla de orquestación de componentes de alta generación de alto rendimiento, de alto rendimiento y de alto rendimiento para GO.
Traducción de papel científico en PDF con formatos preservados - 基于 Ai 完整保留排版的 PDF 文档全文双语翻译 , 支持 支持 支持 支持 支持 支持 支持 支持 支持 支持 支持 支持 等服务 等服务 等服务 提供 提供 提供 提供 提供 提供 提供 提供 提供 提供 提供 提供 cli/mcp/docker/zotero
Reviews

user_MW1lzfsi
mcp-cobra by PlusLemon is an outstanding application that has revolutionized my workflow. Its intuitive interface and robust features make it incredibly easy to manage tasks efficiently. If you're looking for a reliable and user-friendly tool, this is a game-changer. Highly recommended!

user_05VprB86
I've been using mcp-cobra by PlusLemon for a while, and it's been a game-changer. The seamless integration and user-friendly interface make it a standout product. It caters to all my needs efficiently and effectively, enhancing my productivity. Highly recommend!

user_NaMDItNm
As a loyal user of mcp applications, I can confidently say that mcp-cobra by PlusLemon stands out remarkably. Its seamless interface and powerful tools have boosted my productivity significantly. The user-friendly experience coupled with its sophisticated features make mcp-cobra a top-notch application in its category. Highly recommended for anyone looking to streamline their workflow effectively!

user_HA9FC7Dv
I've been using the mcp-cobra application by PlusLemon, and it's simply fantastic! The interface is user-friendly and intuitive, making it easy to navigate through different features. It's clear that a lot of thought was put into the design and functionality. Highly recommend it to anyone looking for a reliable and efficient tool!

user_ifAwrK9D
As a devoted user of the mcp application, I am thoroughly impressed with mcp-cobra by PlusLemon. It’s intuitive, fast, and extremely efficient. From the moment you start using it, the welcoming message sets the tone for a seamless experience. The product link and start URL are straightforward, making navigation easy. Highly recommend if you're looking for quality and performance!

user_JkePHQxI
As a dedicated user of MCP applications, I am thrilled with the performance of mcp-cobra! PlusLemon has truly outdone themselves with this product. The interface is user-friendly and the functionality is top-notch. It has significantly improved my workflow. Highly recommended for anyone looking to enhance their productivity!