Implementation:1broseidon Ketch config NormalizeMCPTools
| Knowledge Sources | |
|---|---|
| Domains | MCP, Configuration |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
Validates and normalizes the `mcp_tools` allowlist: trims/lowercases, rejects blank/unknown/duplicate names, and returns the result in canonical order so server instructions stay deterministic.
Description
NormalizeMCPTools is the fail-loud validation for the `mcp_tools` config key. Entries are trimmed and lowercased; blank, unknown, and duplicate names are rejected (the error lists the valid names). The result is returned in canonical registration order, regardless of input order. A nil/empty list means "no restriction" and returns nil (publish all six). MCPToolNames returns a copy of the canonical list. Validation runs at `config set`, on the `KETCH_MCP_TOOLS` env override, and at server startup.
Usage
Called by `NewServer` and by the `config set`/env overlay validation paths. Unlisted tools are never registered; `serverInstructions` is generated from the enabled set so a pruned server never advertises what it won't answer.
Code Reference
Source Location
- Repository: ketch
- File: config/mcp_tools.go
Signature
var mcpToolNames = []string{"search", "code", "docs", "scrape", "crawl", "tag"}
// MCPToolNames returns a copy of the canonical tool list, in registration order.
func MCPToolNames() []string
// NormalizeMCPTools validates an operator-configured mcp_tools allowlist.
// A nil/empty list means "no restriction" and returns nil.
func NormalizeMCPTools(list []string) ([]string, error)
Import
import "github.com/1broseidon/ketch/config"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| list | []string | No | Raw allowlist (JSON array or comma-separated); empty = publish all |
Outputs
| Name | Type | Description |
|---|---|---|
| return | []string | Canonical-ordered allowlist, or nil (publish all) |
| return error | error | Blank, unknown, or duplicate entry (error lists valid names) |
Usage Examples
Validation At Server Startup
tools, err := config.NormalizeMCPTools(cfg.MCPTools)
if err != nil { return err } // [precondition]
if len(tools) == 0 {
tools = config.MCPToolNames() // publish all six
}