refactor/mcptools: split buildCLITools and the capability-request handler into helpers #93

Merged
pti merged 1 commit from refactor/complexity-mcptools into main 2026-10-19 22:33:20 +02:00
Owner

Part of #71, the mcptools slice, the two worst functions in the repo. buildCLITools was at Sonar cognitive complexity 55 and the capability-request handler closure at 36. buildCLITools now delegates to ruleDescription, flagToolOption, flagIsBoolean and logSanitizedToolName, and the request handler to handleCapabilityRequest with stringSlice and parseFlagTypes. Flag-type precedence is unchanged, explicit constraint over introspection over name heuristic with string as the default for an unknown valueless flag. Reviewer pass built the full MCP tool schema for a config covering every precedence case on main and on this branch and found the JSON byte-identical, and ran the new request handler tests against main's handler to prove they pin pre-existing behaviour. The handler had no tests before, request_tool_test.go adds them. 🤖 Generated with Claude Code

Part of #71, the mcptools slice, the two worst functions in the repo. buildCLITools was at Sonar cognitive complexity 55 and the capability-request handler closure at 36. buildCLITools now delegates to ruleDescription, flagToolOption, flagIsBoolean and logSanitizedToolName, and the request handler to handleCapabilityRequest with stringSlice and parseFlagTypes. Flag-type precedence is unchanged, explicit constraint over introspection over name heuristic with string as the default for an unknown valueless flag. Reviewer pass built the full MCP tool schema for a config covering every precedence case on main and on this branch and found the JSON byte-identical, and ran the new request handler tests against main's handler to prove they pin pre-existing behaviour. The handler had no tests before, request_tool_test.go adds them. 🤖 Generated with Claude Code
refactor(mcptools): split buildCLITools and the capability-request handler into helpers
All checks were successful
Lint / lint (pull_request) Successful in 1m1s
Lint / sonarqube (pull_request) Has been skipped
79f7203133
buildCLITools (Sonar cognitive complexity 55) and
RegisterRequestCapabilityTool (36) exceeded the go:S3776 threshold of 25
(issue #71). Extract the per-rule steps of buildCLITools
(logSanitizedToolName, ruleDescription, flagToolOption, flagIsBoolean)
and move the request handler closure into handleCapabilityRequest with
stringSlice and parseFlagTypes helpers.

Behaviour-neutral: same log lines, error strings, schema output and
ordering. The capability-request handler had no test coverage, so add
request_tool_test.go pinning its argument parsing and response text
before the move's benefit is relied upon.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pti merged commit f8b7126460 into main 2026-10-19 22:33:20 +02:00
pti deleted branch refactor/complexity-mcptools 2026-10-19 22:33:20 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pti/wraptool!93
No description provided.