Allow named MCP servers in Claude stages

Add validated per-stage MCP allowlists while keeping builtin tools separate. Enable matching Claude Code permission rules only for Claude stages, reject unsupported harnesses, and document the unattended-stage safety model.
This commit is contained in:
2026-11-13 16:06:48 +00:00
parent eeb07e5645
commit b01cfd8eb3
9 changed files with 138 additions and 7 deletions
+32 -1
View File
@@ -148,7 +148,11 @@ func ToolNames(def Definition) ([]string, bool, error) {
switch name {
case "websearch", "webfetch", "read", "glob", "grep", "edit", "shell":
default:
return nil, true, fmt.Errorf("unsupported tool %q", name)
if _, _, ok, err := MCPToolName(name); err != nil {
return nil, true, err
} else if !ok {
return nil, true, fmt.Errorf("unsupported tool %q", name)
}
}
if seen[name] {
return nil, true, fmt.Errorf("duplicate tool %s", name)
@@ -165,6 +169,33 @@ func ToolNames(def Definition) ([]string, bool, error) {
// text-only stage.
var legacyTools = []string{"read", "glob", "grep", "edit", "shell"}
var mcpToolName = regexp.MustCompile(`^mcp:([A-Za-z0-9_-]+)(?:/([A-Za-z0-9_-]+))?$`)
// MCPToolName validates and splits a named MCP allowlist entry.
func MCPToolName(name string) (server, tool string, ok bool, err error) {
if !strings.HasPrefix(name, "mcp:") {
return "", "", false, nil
}
match := mcpToolName.FindStringSubmatch(name)
if match == nil {
return "", "", true, fmt.Errorf("invalid MCP tool %q; use mcp:<server> or mcp:<server>/<tool> with letters, digits, _ or -", name)
}
return match[1], match[2], true, nil
}
// MCPTools returns named MCP entries in declaration order.
func MCPTools(tools []string) ([]string, error) {
var result []string
for _, name := range tools {
if _, _, ok, err := MCPToolName(name); err != nil {
return nil, err
} else if ok {
result = append(result, name)
}
}
return result, nil
}
// effectiveTools is the single materialisation point for the tools a model
// stage is permitted. A present tools block (including an explicit empty block)
// is returned exactly as parsed by ToolNames; an absent block yields the legacy