Skip to content

[plan] Fix mcpToolParams() to auto-extract parameter names via reflection instead of hardcoded map #30121

@github-actions

Description

@github-actions

Objective

Replace the hardcoded mcpToolParams() map in mcp_argument_validation.go with reflection-based extraction of JSON tag names from tool input structs, eliminating a known maintenance hazard.

Context

From discussion #30108 (Go Fan module review): mcp_argument_validation.go contains a hardcoded map of tool names to valid parameter names, marked with a // MAINTENANCE: comment acknowledging the drift risk. The same reflection pass used for JSON schema generation can auto-extract JSON tag names.

Approach

  1. Locate mcpToolParams() in pkg/cli/mcp_argument_validation.go
  2. Instead of the static map, register tool input struct types alongside tool registration
  3. Use reflect to iterate the struct's fields and collect json tag names at startup
  4. Replace the hardcoded map lookup with the reflected names
  5. Remove the // MAINTENANCE: comment and hardcoded entries

Alternatively, build the map once at server init by passing tool input struct types to the validation setup.

Files to Modify

  • pkg/cli/mcp_argument_validation.go — replace hardcoded map with reflection
  • pkg/cli/mcp_server.go — pass struct type info to validation setup if needed
  • pkg/cli/mcp_argument_validation_test.go — update/add tests

Acceptance Criteria

  • mcpToolParams() no longer contains a hardcoded list of parameter names
  • Parameter names are derived from JSON struct tags via reflection
  • Adding a new field to a tool input struct automatically includes it in validation
  • Existing "did you mean?" behavior is preserved
  • make test-unit passes

Generated by Plan Command for issue #discussion #30108 · ● 308.5K ·

  • expires on May 6, 2026, 9:41 AM UTC

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions