Skip to content
Back to search

ophis

Transform any Cobra CLI into an MCP server

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/njayp--ophis/badge.svg)](/listings/njayp--ophis)

HTML

<a href="/listings/njayp--ophis"><img src="/api/listings/njayp--ophis/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Install

go get github.com/njayp/ophis

Add to your CLI

package main

import (
    "os"
    "github.com/njayp/ophis"
)

func main() {
    rootCmd := createMyRootCommand()
    rootCmd.AddCommand(ophis.Command(nil))

    if err := rootCmd.Execute(); err != nil {
        os.Exit(1)
    }
}

Enable in Claude Desktop, VSCode, or Cursor

# Claude Desktop
./my-cli mcp claude enable
# Restart Claude Desktop

# VSCode (requires Copilot in Agent Mode)
./my-cli mcp vscode enable

# Cursor
./my-cli mcp cursor enable

Your CLI commands are now available as MCP tools!

Stream over HTTP

Expose your MCP server over HTTP for remote access:

./my-cli mcp stream --host localhost --port 8080

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 149 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. ![Project Logo](./logo.png)
  2. **Transform any Cobra CLI into an MCP server**
  3. Ophis automatically converts your Cobra commands into MCP tools, and provides CLI commands for integration with Claude Desktop, VSCode, and Cursor.
  4. ## Quick Start
  5. ### Install
  6. ```bash
  7. go get github.com/njayp/ophis
  8. ```
  9. ### Add to your CLI
  10. ```go
  11. package main
  12. import (
  13. "os"
  14. "github.com/njayp/ophis"
  15. )
  16. func main() {
  17. rootCmd := createMyRootCommand()
  18. rootCmd.AddCommand(ophis.Command(nil))
  19. if err := rootCmd.Execute(); err != nil {
  20. os.Exit(1)
  21. }
  22. }
  23. ```
  24. ### Enable in Claude Desktop, VSCode, or Cursor
  25. ```bash
  26. # Claude Desktop
  27. ./my-cli mcp claude enable
  28. # Restart Claude Desktop
  29. # VSCode (requires Copilot in Agent Mode)
  30. ./my-cli mcp vscode enable
  31. # Cursor
  32. ./my-cli mcp cursor enable
  33. ```
  34. Your CLI commands are now available as MCP tools!
  35. ### Stream over HTTP
  36. Expose your MCP server over HTTP for remote access:
  37. ```bash
  38. ./my-cli mcp stream --host localhost --port 8080
  39. ```
  40. ## Commands
  41. The `ophis.Command(nil)` adds these subcommands to your CLI (the default command name is `mcp`, configurable via `Config.CommandName`):
  42. ```
  43. mcp
  44. ├── start # Start MCP server on stdio
  45. ├── stream # Stream MCP server over HTTP
  46. ├── tools # Export available MCP tools as JSON
  47. ├── claude
  48. │ ├── enable # Add server to Claude Desktop config
  49. │ ├── disable # Remove server from Claude Desktop config
  50. │ └── list # List Claude Desktop MCP servers
  51. ├── vscode
  52. │ ├── enable # Add server to VSCode config
  53. │ ├── disable # Remove server from VSCode config
  54. │ └── list # List VSCode MCP servers
  55. └── cursor
  56. ├── enable # Add server to Cursor config
  57. ├── disable # Remove server from Cursor config
  58. └── list # List Cursor MCP servers
  59. ```
  60. ## Configuration
  61. Control which commands and flags are exposed as MCP tools using selectors. By default, all commands and flags are exposed (except hidden/deprecated).
  62. ```go
  63. config := &ophis.Config{
  64. Selectors: []ophis.Selector{
  65. {
  66. CmdSelector: ophis.AllowCmdsContaining("get", "list"),
  67. LocalFlagSelector: ophis.ExcludeFlags("token", "secret"),
  68. InheritedFlagSelector: ophis.NoFlags, // Exclude persistent flags
  69. // Middleware wraps command execution
  70. Middleware: func(ctx context.Context, req *mcp.CallToolRequest, in ophis.ToolInput, next func(context.Context, *mcp.CallToolRequest, ophis.ToolInput) (*mcp.CallToolResult, ophis.ToolOutput, error)) (*mcp.CallToolResult, ophis.ToolOutput, error) {
  71. ctx, cancel := context.WithTimeout(ctx, time.Minute)
  72. defer cancel()
  73. return next(ctx, req, in)
  74. },
  75. },
  76. },
  77. }
  78. rootCmd.AddCommand(ophis.Command(config))
  79. ```
  80. ### Custom Command Name
  81. By default the ophis command is named `mcp`. If your CLI already uses `mcp` for something else, set `CommandName` to avoid the collision:
  82. ```go
  83. config := &ophis.Config{
  84. CommandName: "agent",
  85. }
  86. rootCmd.AddCommand(ophis.Command(config))
  87. ```
  88. The command tree, editor config (`enable`/`disable`), and internal filters all use the configured name automatically.
  89. ### Default Environment Variables
  90. Editors launch MCP server subprocesses with a minimal environment. On macOS this means a PATH of just `/usr/bin:/bin:/usr/sbin:/sbin`, so tools like `helm`, `kubectl`, or `docker` installed via mise/homebrew/nix won't be found. Use `DefaultEnv` to capture the current PATH (or any other variables) at `enable` time:
  91. ```go
  92. config := &ophis.Config{
  93. DefaultEnv: map[string]string{
  94. "PATH": os.Getenv("PATH"),
  95. },
  96. }
  97. rootCmd.AddCommand(ophis.Command(config))
  98. ```
  99. These are merged into the editor config written by `enable`. User-provided `--env` values take precedence on conflict.
  100. See [docs/config.md](docs/config.md) for detailed configuration options.
  101. ## How It Works
  102. Ophis bridges Cobra commands and the Model Context Protocol:
  103. 1. **Command Discovery**: Recursively walks your Cobra command tree
  104. 2. **Schema Generation**: Creates JSON schemas from command flags and arguments ([docs/schema.md](docs/schema.md))
  105. 3. **Tool Execution**: Spawns your CLI as a subprocess and captures output ([docs/execution.md](docs/execution.md))
  106. ## Contributing
  107. Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md).

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.