Skip to content

fix(codegen): disambiguate tool names that sanitize to a JS/TS reserved word#137

Merged
bug-ops merged 1 commit into
masterfrom
133-reserved-keyword-tool-name
Jul 9, 2026
Merged

fix(codegen): disambiguate tool names that sanitize to a JS/TS reserved word#137
bug-ops merged 1 commit into
masterfrom
133-reserved-keyword-tool-name

Conversation

@bug-ops

@bug-ops bug-ops commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • resolve_typescript_names now seeds the shared disambiguation used set with the JS/TS reserved word list before resolving each tool's identifier, so a tool named delete, typeof, eval, arguments, etc. gets the same numeric-suffix disambiguation as a genuine name collision instead of being emitted verbatim as an invalid function identifier.
  • sanitize_ts_identifier itself is left untouched, since it is also used to sanitize object property keys, where reserved words are syntactically legal.
  • Reserved-word list includes eval/arguments, which are not formally reserved words but are forbidden as a strict-mode BindingIdentifier (a function declaration's name); generated code is always an ES module, hence always strict mode.

Test plan

  • test_resolve_typescript_names_disambiguates_reserved_words — unit coverage for delete, typeof, class, new, import, export, in, instanceof, void, enum, eval, arguments
  • test_resolve_typescript_names_reserved_word_avoids_existing_collision — reserved-word fallback doesn't collide with an unrelated tool that already claims the fallback identifier
  • test_generate_sanitizes_reserved_word_tool_name — generator-level regression test asserting the emitted .ts file never contains export async function delete( and does contain the disambiguated form
  • cargo +nightly fmt --check
  • cargo +stable clippy --all-targets --all-features --workspace -- -D warnings
  • cargo nextest run --all-features --workspace --no-fail-fast
  • cargo test --doc --all-features --workspace

Closes #133

@github-actions github-actions Bot added area: codegen Code generation crate: mcp-codegen Changes to mcp-codegen crate (TypeScript code generation) type: documentation Documentation changes (*.md, docs/, comments) breaking change Contains breaking API changes (requires major version bump) release Release preparation (changelog, version bumps) labels Jul 9, 2026
…ed word

resolve_typescript_names now checks a sanitized tool name against the set
of JS/TS reserved words (including eval/arguments, which strict mode
forbids as a function-declaration BindingIdentifier) and disambiguates
matches with the same numeric-suffix strategy already used for name
collisions. Previously a tool named delete or typeof produced
export async function delete(...), a hard syntax error that also broke
the generated index.ts re-export.

Closes #133
@bug-ops
bug-ops enabled auto-merge (squash) July 9, 2026 15:46
@bug-ops
bug-ops force-pushed the 133-reserved-keyword-tool-name branch from 140fb9e to 7716c22 Compare July 9, 2026 15:46
@bug-ops
bug-ops merged commit 7ebf92c into master Jul 9, 2026
17 checks passed
@bug-ops
bug-ops deleted the 133-reserved-keyword-tool-name branch July 9, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: codegen Code generation breaking change Contains breaking API changes (requires major version bump) crate: mcp-codegen Changes to mcp-codegen crate (TypeScript code generation) release Release preparation (changelog, version bumps) type: documentation Documentation changes (*.md, docs/, comments)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

codegen: tool name sanitizing to a JS/TS reserved keyword (e.g. "delete", "typeof") produces non-compiling generated TypeScript

1 participant