
njayp/ophis 是从 https://github.com/njayp/ophis. 导入的 MCP 服务器候选人
概览
njayp/ophis 是从 https://github.com/njayp/ophis. 导入的 MCP 服务器候选人
概述(AI 翻译)
将任何Cobra CLI转换为MCP服务器
Ophis 会自动将你的 Cobra 命令转换为 MCP 工具,并提供 CLI 命令,方便与 Claude Desktop、VSCode 和 Cursor 集成。
快速启动
安装
添加到你的CLI中
在 Claude Desktop、VSCode 或光标中启用
你的CLI命令现在可以作为MCP工具使用!
通过HTTP流
通过HTTP公开你的MCP服务器以便远程访问:
命令
ophis.Command(nil) 会将这些子命令添加到你的 CLI(默认命令名为 mcp,可通过 Config.CommandName 配置):
配置
通过选择器控制哪些命令和标志作为MCP工具暴露。默认情况下,所有命令和标志都会被暴露(隐藏或弃用除外)。
自定义命令名称
默认情况下,ophi命令名为mcp。如果您的CLI已经将mcp用于其他用途,请设置CommandName以避免碰撞:
命令树、编辑器配置([enable/disable)和内部过滤器都会自动使用配置的名称。
默认环境变量
编辑器在最小环境下启动MCP服务器子进程。
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Transform any Cobra CLI into an MCP server
Ophis automatically converts your Cobra commands into MCP tools, and provides CLI commands for integration with Claude Desktop, VSCode, and Cursor.
Quick Start
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
Commands
The ophis.Command(nil) adds these subcommands to your CLI (the default command name is mcp, configurable via Config.CommandName):
mcp
├── start # Start MCP server on stdio
├── stream # Stream MCP server over HTTP
├── tools # Export available MCP tools as JSON
├── claude
│ ├── enable # Add server to Claude Desktop config
│ ├── disable # Remove server from Claude Desktop config
│ └── list # List Claude Desktop MCP servers
├── vscode
│ ├── enable # Add server to VSCode config
│ ├── disable # Remove server from VSCode config
│ └── list # List VSCode MCP servers
└── cursor
├── enable # Add server to Cursor config
├── disable # Remove server from Cursor config
└── list # List Cursor MCP servers
Configuration
Control which commands and flags are exposed as MCP tools using selectors. By default, all commands and flags are exposed (except hidden/deprecated).
config := &ophis.Config{
Selectors: []ophis.Selector{
{
CmdSelector: ophis.AllowCmdsContaining("get", "list"),
LocalFlagSelector: ophis.ExcludeFlags("token", "secret"),
InheritedFlagSelector: ophis.NoFlags, // Exclude persistent flags
// Middleware wraps command execution
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) {
ctx, cancel := context.WithTimeout(ctx, time.Minute)
defer cancel()
return next(ctx, req, in)
},
},
},
}
rootCmd.AddCommand(ophis.Command(config))
Custom Command Name
By default the ophis command is named mcp. If your CLI already uses mcp for something else, set CommandName to avoid the collision:
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →