Skip to content

fix(codegen): sanitize JSDoc strings and add package.json to generated output#91

Merged
bug-ops merged 1 commit into
masterfrom
87-86-codegen-sanitize
May 3, 2026
Merged

fix(codegen): sanitize JSDoc strings and add package.json to generated output#91
bug-ops merged 1 commit into
masterfrom
87-86-codegen-sanitize

Conversation

@bug-ops

@bug-ops bug-ops commented May 3, 2026

Copy link
Copy Markdown
Owner

Summary

Changes

crates/mcp-codegen/src/progressive/generator.rs

  • Added sanitize_jsdoc(s: &str, max_len: usize) -> String — replaces */ with *\/, strips CR/LF, truncates to max_len chars
  • Applied sanitizer in create_tool_context (tool name, description) and create_index_context (server_name, server_version, each tool description)
  • Added package.json generation in generate() and generate_with_categories()
  • Added unit tests: test_sanitize_jsdoc_* (4 cases) and test_generate_sanitizes_jsdoc_injection
  • Updated test_generate_progressive_files to expect 5 files

crates/mcp-codegen/tests/progressive_generation.rs

  • Updated file count expectations (now 6 for 3-tool server, 3 for empty server)
  • Added package.json assertions

Test plan

  • cargo +stable clippy --all-targets --all-features --workspace -- -D warnings — clean
  • cargo nextest run --all-features --workspace --no-fail-fast — 641 passed
  • cargo test --doc --all-features --workspace — 9 passed
  • cargo +nightly fmt --check — clean

Closes #87
Closes #86

@github-actions github-actions Bot added 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 May 3, 2026
@bug-ops
bug-ops enabled auto-merge (squash) May 3, 2026 13:03
@codecov-commenter

codecov-commenter commented May 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #91      +/-   ##
==========================================
+ Coverage   88.97%   89.03%   +0.06%     
==========================================
  Files          33       33              
  Lines        7708     7751      +43     
==========================================
+ Hits         6858     6901      +43     
  Misses        850      850              
Flag Coverage Δ
mcp-cli 89.03% <100.00%> (+0.06%) ⬆️
mcp-codegen 89.03% <100.00%> (+0.06%) ⬆️
mcp-core 89.03% <100.00%> (+0.06%) ⬆️
mcp-files 89.03% <100.00%> (+0.06%) ⬆️
mcp-introspector 89.03% <100.00%> (+0.06%) ⬆️
mcp-server 89.03% <100.00%> (+0.06%) ⬆️
mcp-skill 89.03% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
crates/mcp-codegen/src/progressive/generator.rs 96.25% <100.00%> (+0.52%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…d output

Closes #87: server-controlled strings (name, version, tool name, tool
description) are now sanitized before interpolation into JSDoc block
comments. The sanitizer replaces "*/" with "*\/", strips CR/LF, and
truncates to 256 chars for name/description and 64 chars for version.

Closes #86: ProgressiveGenerator::generate() and
generate_with_categories() now emit package.json with {"type":"module"}
in the server output root, eliminating the Node.js
MODULE_TYPELESS_PACKAGE_JSON performance warning on every tool execution.
@bug-ops
bug-ops force-pushed the 87-86-codegen-sanitize branch from e7dc0b5 to 00cf31d Compare May 3, 2026 13:12
@bug-ops
bug-ops merged commit 326f35b into master May 3, 2026
17 checks passed
@bug-ops
bug-ops deleted the 87-86-codegen-sanitize branch May 3, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

2 participants