Documentation
¶
Overview ¶
Package mcp implements the embedded MCP server that exposes the Escape CLI commands as MCP tools over HTTP.
Index ¶
- func InjectAuthContext(ctx context.Context, req *http.Request) context.Context
- func RegisterBuiltinTools(server *mcpserver.MCPServer, specs []ToolSpec)
- func RegisterCommandTools(server *mcpserver.MCPServer, specs []ToolSpec, options CommandExecutionOptions)
- type Auth
- type CommandExecutionOptions
- type ExecutionOptions
- type ExecutionResult
- type FlagBinding
- type Server
- type ServerOptions
- type ToolSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InjectAuthContext ¶
InjectAuthContext derives a context that carries the credentials extracted from the incoming HTTP request so downstream tool handlers can access them.
func RegisterBuiltinTools ¶
RegisterBuiltinTools registers the MCP-native helper tools (e.g. the tool discovery endpoint) that ship with the embedded server.
func RegisterCommandTools ¶
func RegisterCommandTools( server *mcpserver.MCPServer, specs []ToolSpec, options CommandExecutionOptions, )
RegisterCommandTools walks the supplied specs and registers one MCP handler per tool on the server. Each handler spawns a bounded CLI subprocess.
Types ¶
type Auth ¶
Auth carries the credentials extracted from an incoming MCP request, forwarded to the CLI subprocess through sanitized environment variables.
type CommandExecutionOptions ¶
type CommandExecutionOptions struct {
PublicAPIURL string
}
CommandExecutionOptions carries the shared runtime inputs the tool handlers need that are not part of a specific tool spec.
type ExecutionOptions ¶
type ExecutionOptions struct {
Command []string
DisplayCommand []string
Body any
Auth Auth
PublicAPIURL string
}
ExecutionOptions carries the request-scoped inputs ExecuteCLICommand needs to spawn one CLI subprocess.
type ExecutionResult ¶
type ExecutionResult struct {
Stdout string
Stderr string
StdoutTruncated bool
StderrTruncated bool
ExitCode int
Payload any
}
ExecutionResult is the captured stdout/stderr/exit-code plus the parsed JSON payload (when the CLI produced valid JSON on stdout).
func ExecuteCLICommand ¶
func ExecuteCLICommand(ctx context.Context, options ExecutionOptions) (*ExecutionResult, error)
ExecuteCLICommand spawns the current escape-cli binary with the supplied command + arguments, forwards authentication through a sanitized environment, pipes the optional request body to stdin, and returns the structured result. The caller is responsible for binding a timeout on ctx.
type FlagBinding ¶
FlagBinding maps an MCP tool property to a CLI flag on the underlying Cobra command, including the type the value must be rendered as.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the embedded MCP server that exposes CLI commands over HTTP.
func NewServer ¶
func NewServer(options ServerOptions) *Server
NewServer builds a non-started embedded MCP server from the supplied options.
type ServerOptions ¶
ServerOptions configures the embedded HTTP-based MCP server.
type ToolSpec ¶
type ToolSpec struct {
Name string
Path string
Description string
Tool mcpgo.Tool
Command []string
PositionalArgs []string
FlagBindings []FlagBinding
BodyProperty string
// AllowExtraArgs opts the tool into reading a free-form `args` string array
// from the request payload and forwarding it verbatim to the subprocess.
// Off by default so the Cobra-to-MCP mapping remains an explicit allowlist.
AllowExtraArgs bool
}
ToolSpec fully describes one CLI-backed MCP tool: its MCP-level metadata plus the subprocess invocation plan (command path, positional + flag bindings, and optional stdin body property).