Commit fab9021
committed
fix(mcp): share the tool-name rule instead of re-deriving it in extension.js
Review on #41. mcpAllowAlways hand-rolled its own regex to validate what "Always
allow" writes into levelcode.ai.mcp.toolPolicy, and that second copy of the
naming rule had drifted from the one mcpConfig owns.
The reviewer flagged three things. One is not true, one is, and checking the
first turned up a worse bug underneath it.
NOT TRUE — "tool names containing extra `__` are rejected". They are not:
`_` is inside the character class, so the leading group absorbs them and
`github__foo__bar` matches.
TRUE, and worse than reported — a name can legitimately have NO separator at all.
When a server's name alone reaches the 64-char cap, namespaceToolName truncates
INSIDE that first segment and appends a hash tag:
namespaceToolName('s'.repeat(70), 'tool') -> 'ssss…ssss_a1b2c3' // no '__'
The old regex required `__`, so it rejected a name this module itself produced and
"Always allow" silently did nothing for that server.
TRUE — no length bound, so a malformed message could persist an arbitrarily long
settings key. And Object.assign over the existing setting hands a literal
`__proto__` (which survives JSON.parse as a real own key) to the prototype setter
rather than copying it.
Fixed by moving the rule to where it belongs: mcpConfig now exports
isNamespacedToolName (alphabet + MAX_TOOL_NAME bound) and its existing safeCopy,
and extension.js uses both. One definition, beside the function whose output it
describes.
One trap worth recording: relaxing the separator requirement silently removed an
ACCIDENTAL protection — `__proto__` failed the old regex only because it has no
non-underscore character before its `__`. isNamespacedToolName therefore rejects
UNSAFE_KEYS explicitly, so the guarantee no longer rides on an unrelated rule
keeping a particular shape. My own new test caught that regression.
47 mcpConfig cases (up from 44); 23 suites, 0 failures.1 parent f8d542a commit fab9021
3 files changed
Lines changed: 91 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
776 | 776 | | |
777 | 777 | | |
778 | 778 | | |
779 | | - | |
780 | | - | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
781 | 786 | | |
782 | 787 | | |
783 | 788 | | |
784 | | - | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
785 | 793 | | |
786 | | - | |
| 794 | + | |
| 795 | + | |
787 | 796 | | |
788 | 797 | | |
789 | 798 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
222 | 252 | | |
223 | 253 | | |
224 | 254 | | |
| |||
452 | 482 | | |
453 | 483 | | |
454 | 484 | | |
455 | | - | |
| 485 | + | |
| 486 | + | |
456 | 487 | | |
457 | 488 | | |
458 | 489 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
546 | 591 | | |
0 commit comments