miller/pkg/terminals/help/api.go
John Kerl 41f5188bd0
Add mlr mcp MCP server + agent playbook, with a --no-shell gate (#2098 PR7) (#2133)
* Plan: flesh out PR7 (MCP server + Agent Skill) design

stdio transport (no HTTP port), mlr mcp terminal in the main binary,
SDK-vs-handroll decision, tool list, in-process vs subprocess split,
run-tool safety (--no-shell prerequisite), single-sourced skill, tests.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Add mlr mcp: MCP server + agent playbook; --no-shell gate (#2098 PR7)

New terminal `mlr mcp` runs a Model Context Protocol server over stdio
(spawned by MCP clients; no network port), exposing five tools --
list_capabilities, which, validate_dsl, describe_data, run -- plus an
agent playbook as MCP prompt/resource. Catalog tools are served
in-process from the help registries; the rest subprocess this same
binary with MLR_ERRORS_JSON=1, a timeout, and an output cap.

Prerequisite: a new --no-shell flag / MLR_NO_SHELL env var (one-way
gate) disables the DSL system/exec functions, piped redirects, and
--prepipe/--prepipex; the MCP server sets it on the commands it runs
unless started with --allow-shell.

Adds the github.com/modelcontextprotocol/go-sdk dependency.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Force LF checkout for the embedded SKILL.md (Windows CI fix)

go:embed embeds checkout bytes, so a CRLF checkout on Windows made the
embedded playbook differ per platform and failed
TestPlaybookHasFrontmatter. Pin the file to eol=lf in .gitattributes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Move no-shell test DSL into per-case mlr files (Windows CI fix)

Inline single-quoted DSL in cmd files is mangled by the Windows shell
(single quotes are not quote characters there); the harness's
put -f ${CASEDIR}/mlr pattern avoids shell quoting entirely.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 19:41:49 -04:00

65 lines
2.1 KiB
Go

// Exported accessors over the machine-readable help catalog, for callers
// outside this package -- in particular the `mlr mcp` server, which serves
// the same catalog/index/search over MCP that `mlr help --as-json` and
// `mlr which` serve over the command line.
package help
import (
"github.com/johnkerl/miller/v6/pkg/cli"
"github.com/johnkerl/miller/v6/pkg/dsl/cst"
"github.com/johnkerl/miller/v6/pkg/transformers"
)
// BuildFullCatalog returns the entire help catalog: the same document emitted
// by `mlr help --as-json`.
func BuildFullCatalog() *CatalogForJSON {
return buildFullCatalog()
}
// CatalogSchemaVersion returns the current catalog-shape version; see the
// catalogSchemaVersion const.
func CatalogSchemaVersion() int {
return catalogSchemaVersion
}
// BuildIndex returns the lightweight capability index: the same list emitted
// by `mlr help --as-json --index`.
func BuildIndex() []IndexEntryForJSON {
return buildIndex()
}
// CollectVerbs returns the structured views of the named verbs, or all verbs
// if names is empty. Unknown names are skipped.
func CollectVerbs(names []string) []*transformers.VerbInfoForJSON {
return collectVerbs(names)
}
// CollectFunctions is CollectVerbs for DSL builtin functions.
func CollectFunctions(names []string) []*cst.FunctionInfoForJSON {
return collectFunctions(names)
}
// CollectFlags is CollectVerbs for main-level flags.
func CollectFlags(names []string) []*cli.FlagInfoForJSON {
return collectFlags(names)
}
// CollectKeywords is CollectVerbs for DSL keywords.
func CollectKeywords(names []string) []*cst.KeywordInfoForJSON {
return collectKeywords(names)
}
// WhichSearch scores every catalog item against the query and returns matches
// in descending score order, along with the same confidence signal `mlr
// which` reports via its exit code: true when the top result's name contains
// a query token.
func WhichSearch(query string) (results []WhichResultEntry, confident bool) {
tokens := whichTokenize(query)
if len(tokens) == 0 {
return nil, false
}
results = whichSearch(tokens)
confident = len(results) > 0 && results[0].nameHit
return results, confident
}