Documentation
¶
Overview ¶
Package climcp projects a urfave/cli v3 command tree as a Model Context Protocol (MCP) server. See docs/climcp.md.
Index ¶
- Constants
- func AddrFromEnv(fallback string) string
- func AttachMCP(root *cli.Command, opts Options)
- func NewServer(root *cli.Command, opts Options) (*mcp.Server, error)
- func RunStreamableHTTP(ctx context.Context, root *cli.Command, opts Options, srv HTTPServerOptions) error
- func ServeStdio(ctx context.Context, root *cli.Command, opts Options) error
- func StreamableHTTPHandler(root *cli.Command, opts Options) (http.Handler, error)
- func WriteJSON(w io.Writer, v any) error
- type HTTPServerOptions
- type Options
- type ToolInput
Examples ¶
Constants ¶
const MetaSessionIDField = "claudeSessionId"
MetaSessionIDField is the wire-level key read off MCP params._meta. See docs/session.md.
Variables ¶
This section is empty.
Functions ¶
func AddrFromEnv ¶
AddrFromEnv returns os.Getenv("ADDR") if non-empty, otherwise fallback. See docs/serve.md for the convention.
func AttachMCP ¶
AttachMCP appends an "mcp" subcommand group to root with "serve" and "serve-http" leaves. See docs/attach.md.
func NewServer ¶
NewServer wires up an *mcp.Server with one tool per leaf command in root. Caller is responsible for running the server on a transport.
Example ¶
Project a urfave/cli command tree as an MCP server. See docs/climcp.md.
package main
import (
"fmt"
climcp "github.com/coilysiren/cli-mcp"
"github.com/urfave/cli/v3"
)
func main() {
app := &cli.Command{
Name: "demo",
Commands: []*cli.Command{
{Name: "hello", Usage: "greet someone"},
},
}
srv, err := climcp.NewServer(app, climcp.Options{Name: "demo", Version: "v0.0.0"})
fmt.Println("ok:", srv != nil && err == nil)
}
Output: ok: true
func RunStreamableHTTP ¶
func RunStreamableHTTP(ctx context.Context, root *cli.Command, opts Options, srv HTTPServerOptions) error
RunStreamableHTTP builds the projected MCP server and serves it over Streamable HTTP. Blocks until ctx is cancelled. See docs/serve.md.
func ServeStdio ¶
ServeStdio is the convenience entry point: build a server from root and run it over stdio until the context is cancelled or the peer disconnects.
func StreamableHTTPHandler ¶
StreamableHTTPHandler returns an http.Handler exposing the projected command tree over MCP Streamable HTTP. See docs/climcp.md.
Example ¶
StreamableHTTPHandler returns an http.Handler for MCP remote transport. See docs/serve.md.
package main
import (
"fmt"
climcp "github.com/coilysiren/cli-mcp"
"github.com/urfave/cli/v3"
)
func main() {
app := &cli.Command{
Name: "demo",
Commands: []*cli.Command{{Name: "hello"}},
}
handler, err := climcp.StreamableHTTPHandler(app, climcp.Options{Name: "demo", Version: "v0.0.0"})
fmt.Println("ok:", handler != nil && err == nil)
}
Output: ok: true
Types ¶
type HTTPServerOptions ¶
type HTTPServerOptions struct {
// Addr is the listen address. Default "127.0.0.1:8080".
Addr string
// MCPPath is the Streamable HTTP handler mount route. Default "/mcp".
MCPPath string
// HealthPath is a GET endpoint returning 200 + "ok\n". Default "/healthz".
HealthPath string
// DisableHealth suppresses the healthcheck endpoint when true.
DisableHealth bool
// Landing, if non-empty, is served as text/plain on GET /.
Landing string
// ReadHeaderTimeout is forwarded to http.Server. Default 10s.
ReadHeaderTimeout time.Duration
}
HTTPServerOptions configure RunStreamableHTTP. See docs/serve.md.
type Options ¶
type Options struct {
// Name is the MCP server name advertised to the client. Required.
Name string
// Version is the MCP server version. Required.
Version string
// SkipPaths lists dot-joined command paths to hide as MCP tools.
SkipPaths []string
// IncludeGroups exposes non-leaf groups as MCP tools printing --help.
IncludeGroups bool
// NameJoiner joins command-path segments. Default "_". Use "." if
// every consumer handles dots. SkipPaths always uses dots internally.
NameJoiner string
}
Options configure the MCP server projection. See docs/climcp.md.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
annotated-favorites
command
Command annotated-favorites projects a CLI carrying webops.* metadata.
|
Command annotated-favorites projects a CLI carrying webops.* metadata. |
|
composition-with-guard
command
Command composition-with-guard shows cli-mcp composed with cli-guard.
|
Command composition-with-guard shows cli-mcp composed with cli-guard. |
|
dual-mode
command
Command dual-mode shows cli-mcp's headline shape: one binary, both CLI and MCP server.
|
Command dual-mode shows cli-mcp's headline shape: one binary, both CLI and MCP server. |
|
large-tree
command
Command large-tree projects a realistic multi-level CLI over stdio.
|
Command large-tree projects a realistic multi-level CLI over stdio. |
|
serve
command
Command serve runs a tiny CLI as an MCP server over stdio.
|
Command serve runs a tiny CLI as an MCP server over stdio. |
|
serve-http
command
Command serve-http runs a CLI as MCP over Streamable HTTP.
|
Command serve-http runs a CLI as MCP over Streamable HTTP. |
|
skip-paths
command
Command skip-paths demonstrates Options.SkipPaths and IncludeGroups.
|
Command skip-paths demonstrates Options.SkipPaths and IncludeGroups. |
|
treebuilders
Package treebuilders exports each example's *cli.Command tree.
|
Package treebuilders exports each example's *cli.Command tree. |