feat(tools): make repo the canonical repo-identifier arg; name now an alias (#38)
Every caller (claude.ai connector, LLMs primed on gitea/GitHub) sends the repo identifier as `repo`, but the 33 per-repo identifier tools advertised `name`. The v0.2.8 shim aliased repo->name so it worked, yet the advertised inputSchema still said `name` — a misleading contract, with the shim load-bearing. - Flip all 33 identifier tools: schema property + required + struct field/tag from `name` to `repo`. A compliant `repo` caller now matches the struct directly; the shim is pure back-compat. - normalizeAliases is now bidirectional (name<->repo), so legacy `name` callers still resolve, and repo_create / create_project_from_template — whose `name` means "name of the NEW repo", not an existing-repo id — keep `name` and still accept `repo`. - `number`/`index` left as-is (out of scope; separate pre-existing quirk where pr_merge advertises `index` rather than `number`). - Tests: schema-canonical assertion + flipped alias round-trip (explicit `repo` wins over `name`). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -21,19 +21,21 @@ func parseArgs(raw json.RawMessage, dst any) error {
|
||||
return json.Unmarshal(normalizeAliases(raw), dst)
|
||||
}
|
||||
|
||||
// normalizeAliases maps the near-universal gitea/GitHub argument names onto the
|
||||
// idiosyncratic ones these tools declare: `repo` -> `name`, `index` -> `number`.
|
||||
// Every MCP caller (the claude.ai connector, LLMs primed on gitea's own API)
|
||||
// reaches for `repo`/`index`; without this the unmatched fields zero-valued the
|
||||
// upstream path segment and produced gitea's misleading /api/swagger 404 (#36).
|
||||
// The alias key is left intact so a tool whose real field IS `index`
|
||||
// (e.g. pr_merge) is unaffected.
|
||||
// normalizeAliases reconciles the two spellings of the repo identifier so a tool
|
||||
// works whichever the caller sends. `repo` is the canonical, idiomatic name that
|
||||
// identifier tools now advertise (#38); `name` is kept as a back-compat alias.
|
||||
// The mapping is bidirectional: `name`->`repo` fills the new canonical for old
|
||||
// callers, and `repo`->`name` still fills the two create tools (repo_create,
|
||||
// create_project_from_template) whose `name` legitimately means "name of the new
|
||||
// repo". `index`->`number` is kept for the issue tools whose canonical is
|
||||
// `number`. An explicit canonical value always wins over its alias.
|
||||
func normalizeAliases(raw json.RawMessage) json.RawMessage {
|
||||
var m map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
return raw // not a JSON object — leave untouched
|
||||
}
|
||||
changed := aliasInto(m, "name", "repo")
|
||||
changed = aliasInto(m, "repo", "name") || changed
|
||||
changed = aliasInto(m, "number", "index") || changed
|
||||
if !changed {
|
||||
return raw
|
||||
|
||||
Reference in New Issue
Block a user