GitHub Stars
32
User Rating
Not Rated
Favorites
0
Views
3
Forks
2
Issues
1
Transform any Cobra CLI into an MCP server
Ophis automatically converts your existing Cobra commands into MCP tools that Claude can use.
Import
go get github.com/njayp/ophis
Quick Start
Add MCP server commands to your command tree.
MCP commands can be added anywhere in a command tree. Below is an example of a main()
that adds MCP commands to a root command. Alternatively, this logic can be placed in your createMyRootCommand()
.
package main
import (
"os"
"github.com/njayp/ophis"
)
func main() {
rootCmd := createMyRootCommand()
// Add MCP server commands
rootCmd.AddCommand(ophis.Command(nil))
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
Enable in Claude Desktop or VSCode
./my-cli mcp claude enable
# Restart Claude Desktop
./my-cli mcp vscode enable
# Ensure Copilot is in Agent Mode
Your CLI commands are now available as mcp server tools!
Configuration
The ophis.Command()
function accepts an optional *ophis.Config
parameter to customize the MCP server behavior:
import (
"log/slog"
"github.com/njayp/ophis"
"github.com/njayp/ophis/tools"
)
config := &ophis.Config{
// Customize command filtering and output handling
GeneratorOptions: []tools.GeneratorOption{
// Command filtering
tools.AddFilter(tools.Exclude([]string{"dangerous"})),
// Custom output handler
tools.WithHandler(myCustomHandler),
},
// Configure logging (logs to stderr)
SloggerOptions: &slog.HandlerOptions{
Level: slog.LevelDebug,
},
}
rootCmd.AddCommand(ophis.Command(config))
Default Behavior
When called with nil
config, the MCP server:
- Excludes hidden, "mcp", "help", and "completion" commands
- Returns command output as plain text
- Logs at info level
Command Filtering
Control which commands are exposed as MCP tools:
// Only expose specific commands
tools.WithFilters(tools.Allow([]string{"get", "list", "describe"}))
// Or exclude specific commands (in addition to defaults)
tools.AddFilter(tools.Exclude([]string{"delete", "destroy"}))
// Custom filter function
tools.AddFilter(func(cmd *cobra.Command) bool {
// Exclude admin commands
return !strings.HasPrefix(cmd.Name(), "admin-")
})
Custom Output Handler
The output handler will be applied to all tools. See proposal #9.
// Return the data as an image instead of as text
tools.WithHandler(func(ctx context.Context, request mcp.CallToolRequest, data []byte, err error) *mcp.CallToolResult {
return mcp.NewToolResultImage(data)
})
// Or add middleware
tools.WithHandler(func(ctx context.Context, request mcp.CallToolRequest, data []byte, err error) *mcp.CallToolResult {
// Your middleware here
return tools.DefaultHandler(ctx, request, data, err)
})
MCP Command Tree
ophis.Command
returns the following tree of commands:
mcp
├── start # Start MCP server on stdio
├── tools # Export available MCP tools as JSON
├── claude
│ ├── enable # Enable Helm MCP in Claude Desktop
│ ├── disable # Disable Helm MCP in Claude Desktop
│ └── list # List MCP configurations in Claude Desktop
└── vscode
├── enable # Enable Helm MCP in VS Code
├── disable # Disable Helm MCP in VS Code
└── list # List MCP configurations in VS Code
Examples
Contributing
Contributions welcome! See CONTRIBUTING.md
5
Followers
33
Repositories
0
Gists
0
Total Contributions