urfave cli mcp
这是一个快速的黑客重用 urfave/cli 应用程序作为模型上下文协议服务器。 它爬行 Command 树提供并公开子命令作为MCP工具。支持描述、标志、默认值和所需标志。 通过分叉当前进程并返回stdout作为结果来调用工具。
我使用它将只查询的CLI重用为一行代码的MCP服务器。 创建新的MCP服务器也可能很有用,因为您可以在向MCP客户端公开之前将工具作为CLI进行迭代。
示例
package main
import (
"context"
"fmt"
"os"
urfaveclimcp "github.com/thepwagner/urfave-cli-mcp"
"github.com/urfave/cli/v3"
)
var App = &cli.Command{
Name: "hello",
Usage: "say hello",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Usage: "the name to say hello to",
Value: "World",
},
},
Action: func(_ context.Context, c *cli.Command) error {
fmt.Println("Hello,", c.String("name"))
return nil
},
}
func main() {
// Pass the root command you want to expose, then add the "mcp" command to your App
App.Commands = append(App.Commands, urfaveclimcp.NewMCPCommand(App))
App.Run(context.Background(), os.Args)
}
