mcp

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package mcp exposes specd's existing command handlers as Model Context Protocol (MCP) tools over a JSON-RPC 2.0 stdio transport. It adds no business logic: every tool call is a thin re-dispatch into the same handlers the CLI drives. The package is stdlib-only — the JSON-RPC framing and MCP envelopes are hand-rolled on encoding/json, with no third-party MCP SDK.

Index

Constants

This section is empty.

Variables

View Source
var IntentToolCount = len(intentTools)

IntentToolCount is the number of intent-level tools exposed alongside the command-mirror tools. Exported so external tests can assert tools/list parity.

Functions

func HostConfig

func HostConfig(name, root string) (dest, content string, ok bool)

HostConfig returns the dest hint and config content for the named MCP host. The content string has /path/to/your/project replaced with root when root is non-empty. Returns ("", "", false) for an unknown host name.

func HostNames

func HostNames() []string

HostNames returns the sorted list of supported MCP host names.

func Serve

func Serve(r io.Reader, w io.Writer, dispatch Dispatcher, cfg *core.Config) error

Serve runs the MCP stdio loop until the input stream closes. It reads framed JSON-RPC requests from r, dispatches each into the existing command handlers, and writes framed responses to w. A malformed request never tears down the loop: it yields a JSON-RPC error and the server keeps reading (R5). All diagnostics belong on stderr; r/w carry only protocol bytes.

cfg carries the loaded project config so tools/list can filter the advertised tool set; a nil cfg means "expose everything" (backward-compatible default).

func ServeHTTP

func ServeHTTP(addr string, dispatch Dispatcher, cfg *core.Config) error

ServeHTTP exposes the same JSON-RPC dispatch as the stdio Serve loop over an opt-in HTTP transport (R4). It is a second front door onto the identical request router — it adds transport, never business logic:

  • POST /rpc : a single JSON-RPC 2.0 request body → its JSON-RPC response.
  • GET|POST /sse : the same dispatch, returned as one server-sent event frame.

The listener binds loopback by default (R4.2): a bare or empty address is rewritten to 127.0.0.1 so spec contents never leave the host unless an operator supplies an explicit external address. Tool calls are serialised with a mutex because callTool's capture() swaps the process-global os.Stdout; concurrent dispatch would interleave captured output (R7). The stdio path is untouched, so leaving --http unset keeps today's behaviour byte-identical (R4.3). Stdlib-only, no third-party MCP SDK (R4.4).

func ServeHTTPPinned

func ServeHTTPPinned(addr string, dispatch Dispatcher, cfg *core.Config, pinned string) error

ServeHTTPPinned exposes the same dispatch with optional pinned active spec affinity. Blank pin preserves historical global fallback.

func ServePinned

func ServePinned(r io.Reader, w io.Writer, dispatch Dispatcher, cfg *core.Config, pinned string) error

ServePinned runs MCP with an optional pinned active spec slug. A blank pin preserves the historical global fallback.

Types

type Dispatcher

type Dispatcher func(command string, args cli.Args) (int, bool)

Dispatcher runs a registered specd command and reports whether it was known. It mirrors cmd.Dispatch exactly; injecting it keeps this package free of an import cycle with internal/cmd.

type HostEntry

type HostEntry struct {
	// Dest is a human-readable hint for where to paste the config snippet.
	Dest string
	// contains filtered or unexported fields
}

HostEntry describes a supported MCP host.

type ProbeError

type ProbeError struct {
	Kind ProbeFailureKind
	Step string
	Err  error
}

func (*ProbeError) Error

func (e *ProbeError) Error() string

func (*ProbeError) Unwrap

func (e *ProbeError) Unwrap() error

type ProbeFailureKind

type ProbeFailureKind string
const (
	ProbeFailureTimeout          ProbeFailureKind = "timeout"
	ProbeFailureTransport        ProbeFailureKind = "transport"
	ProbeFailureMalformed        ProbeFailureKind = "malformed_response"
	ProbeFailureRPC              ProbeFailureKind = "rpc_error"
	ProbeFailureProtocolMismatch ProbeFailureKind = "protocol_mismatch"
	ProbeFailureMissingTool      ProbeFailureKind = "missing_tool"
)

type ProbeResult

type ProbeResult struct {
	ProtocolVersion    string        `json:"protocolVersion"`
	ToolCount          int           `json:"toolCount"`
	RequiredTools      []string      `json:"requiredTools"`
	OrchestrationTools []string      `json:"orchestrationTools"`
	Latency            time.Duration `json:"-"`
	LatencyMillis      int64         `json:"latencyMillis"`
}

func Probe

func Probe(ctx context.Context, dispatch Dispatcher, timeout time.Duration) (ProbeResult, error)

Probe performs an in-process MCP lifecycle check without executing a shell or starting a network listener.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL