urfave-cli-mcp

by thepwagner

225 downloads
Not rated
GitHub

About

urfave-cli-mcp is a Go package that reuses a urfave/cli application as a Model Context Protocol (MCP) server. It crawls the application's Command tree and exposes subcommands as MCP tools, supporting descriptions, flags, default values, and required flags. It is intended for…

Details

Author
thepwagner
Downloads
225
Categories
Developer Tools

- Crawls the entire urfave/cli Command tree.
- Exposes subcommands as MCP tools automatically.
- Supports flag descriptions, default values, and required flags.
- Invokes tools by forking the current process.
- Returns stdout as the tool result.
- Enables one‑line reuse of query‑only CLIs as MCP servers.

Add the urfaveclimcp.NewMCPCommand(App) command to your application's Commands slice, as shown in the example. The package will then handle the MCP protocol, exposing subcommands as tools that are invoked by forking the current process and returning stdout as the result.

urfave-cli-mcp

This is a quick hack for reusing a urfave/cli app as an Model Context Protocol server.
It crawls the Command tree provided and exposes subcommands as MCP tools. Supports descriptions, flags, default values, and required flags.
Tools are invoked by forking the current process, and returning stdout as the result.

I'm using it to reuse query-only CLIs as an MCP server with one line of code.
It might also be useful to create new MCP servers, as you can iterate tools as a CLI before exposing to an MCP client.

Example

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)
}

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.