Repository navigation
Commit 26a6e40
committed
fix(mcp): truncate tool names exceeding 64 chars to fit provider limit
OpenAI's tool-use API rejects tools[].function.name strings longer than
64 chars. When an MCP server's combined <sanitized-server>_<sanitized-tool>
overflows, the provider returns 400 and opencode silently dies because
the error never reaches the TUI — exactly the symptom in anomalyco#3523.
Add buildToolName() next to sanitize/toolName in mcp/catalog.ts.
Combined names <=64 chars pass through byte-for-byte; overflows truncate
to prefix(55) + '_' + hash(8) where hash is Hash.fast(combined).slice(0,8).
Hash.fast is already imported elsewhere in the package, so no new
dependency. The hash suffix is the collision-safety point: two tools
whose first 64 chars match do NOT silently collapse into a single
registry key. Every truncation emits Effect.logWarning.
Apply at the two provider-facing toolName consumers in mcp/index.ts
(instructions() and tools()); the ':'-separated keys in fetch() for
prompts/resources aren't subject to the 64-char limit and stay alone.
Refs: anomalyco#3523
Closes: anomalyco#35231 parent e00890c commit 26a6e40
2 files changed
Lines changed: 57 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
121 | 151 | | |
122 | 152 | | |
123 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
614 | 614 | | |
615 | 615 | | |
616 | 616 | | |
617 | | - | |
| 617 | + | |
618 | 618 | | |
619 | 619 | | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
625 | 637 | | |
626 | 638 | | |
627 | 639 | | |
| |||
681 | 693 | | |
682 | 694 | | |
683 | 695 | | |
684 | | - | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
685 | 705 | | |
686 | 706 | | |
687 | 707 | | |
| |||
0 commit comments