Commit 78ea28e
authored
First-class tool names: (mcp.v1.tool_name) option + Gemini-safe mangling (#46)
* gen: force mangled tool names to start with a letter
Providers disagree on the leading character of a function name: Gemini
requires a letter or underscore, OpenAI and Anthropic also accept
digits. The base-36 hash prefix of a mangled name can start with a
digit, and Gemini then rejects the entire request with "Invalid
function name" -- a single over-long proto method bricks every
Gemini-backed agent using the server (live failure:
morningstar-securities GetEquityResearchReport, 2026-06-10).
Map a leading digit onto 'g'..'p'. Hashes already starting with a
letter are unchanged, so only the names that were broken on Gemini
change.
* gen: add (mcp.v1.tool_name) option for first-class tool names
Derived tool names are an encoding of proto full names, not names a
model should read: 40+ characters of package prefix, hash-truncated
when too long. This makes high-fidelity names a first-class feature:
rpc GetEquityResearchReport(...) returns (...) {
option (mcp.v1.tool_name) = "get_equity_research_report";
}
The option affects only the MCP tool layer -- runtime.Tool.Name in
generated registration code and in dynamic RegisterService. Generated
Go identifiers stay proto-derived. Unset means the derived name,
exactly as before.
Guard rails:
- the value must match ^[a-zA-Z_][a-zA-Z0-9_-]{0,63}$, the
intersection of every provider's function-name rules; codegen fails
on an invalid value.
- duplicate tool names fail codegen across the whole generation run
(one ToolNameRegistry per plugin invocation). Derived names are
unique by construction, so duplicates can only come from the option.
- the dynamic path falls back to the derived name on an invalid or
colliding configured name: a gateway must keep serving, and derived
names are always safe.
With MCPs declaring their own short names, consumers that prefix
tools (agent runtimes prefix "mcpname__") stop running into length
mangling, and models get names worth reading.
* gen: harden tool_name option per Codex review
- A configured name squatting on a later method's derived name made
the dynamic-path fallback recompute that same derived name and call
AddTool twice with it. The fallback now de-collides with a numeric
suffix; AddTool is never called twice with one name.
- An explicitly authored (mcp.v1.tool_name) = "" was indistinguishable
from an unset option and slipped past codegen validation.
ConfiguredToolName now reports presence separately (HasExtension),
so the generator rejects it.
- Tighten validation to lowercase: ^[a-z_][a-z0-9_-]{0,63}$. Derived
and mangled names always contain an UpperCamel "<Service>Service_"
segment, so a lowercase-only configured name can never be mistaken
for one by downstream de-mangling heuristics (aigw's toolname.Short
keys on exactly that segment) -- configured names provably pass
through them untouched.
* gen: regenerate annotations.pb.go for the lowercase tool-name rule
The proto source comment was tightened to ^[a-z_][a-z0-9_-]{0,63}$
but the generated file still carried the old uppercase-permitting
doc -- the extension docs are the public API surface and must not
contradict the validator. Caught by review.
* gen: golden-test tool naming, scope dup guard per service
Add testdata/tool_naming.proto to the golden generation test, pinning
all three naming behaviors in emitted .pb.mcp.go output: a configured
(mcp.v1.tool_name) emitted verbatim ("get_dashboard"), a derived name
unchanged, and a >64-char name hash-truncated with a letter-leading
prefix. Existing goldens are byte-identical, proving the default path
did not move. The annotations proto is vendored into the testdata buf
module (buf modules cannot depend on local sibling dirs); its Go
output is suppressed so mcp/v1/annotations.proto registers exactly
once (pkg/mcpv1).
Re-scope the duplicate-name guard from per-run to per-service and
drop ToolNameRegistry. A plugin run's file set is not a deployment
unit: in a monorepo every MCP proto generates in one run, and two
different MCPs may legitimately both name a tool "get_dashboard" --
they never share a server. The only statically decidable collision is
within one service (one Register<Service>Handler call), which is
where the guard now lives.1 parent 954bf16 commit 78ea28e
26 files changed
Lines changed: 1720 additions & 6 deletions
File tree
- pkg
- generator
- gen
- mcpv1
- testdata
- gen
- go/testdata
- testdataconnect
- testdatamcp
- proto
- mcp/v1
- testdata
- proto
- mcp/v1
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
165 | 181 | | |
166 | 182 | | |
167 | 183 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| 47 | + | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
94 | 108 | | |
95 | 109 | | |
96 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
533 | 543 | | |
534 | 544 | | |
535 | 545 | | |
| |||
544 | 554 | | |
545 | 555 | | |
546 | 556 | | |
547 | | - | |
| 557 | + | |
548 | 558 | | |
549 | 559 | | |
550 | 560 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
0 commit comments