fix: correct 6 bugs across multiple servers - #3623
Conversation
`for...in` iterates enumerable own properties, which a Map does not expose for its entries. The SIGINT handler's cleanup loop therefore never executed, leaking active transports on shutdown. Replaced with `for...of` which correctly iterates Map entries. Made-with: Cursor
The bare catch block on the ENOENT path for new files was catching all errors, including the "Access denied" error thrown when the parent directory resolves outside allowed directories. This replaced a security-relevant error with a misleading "Parent directory does not exist" message. Now the inner catch re-throws access-denied errors. Made-with: Cursor
The condition used && between two startsWith checks for different URI prefixes (text vs blob), which can never both be true for the same URI. The intent is to reject URIs matching neither prefix. Changed to negate both checks so the guard correctly throws for unknown URIs. Made-with: Cursor
The tool appends to thoughtHistory on every invocation, so repeated calls with identical arguments produce different results (thoughtHistoryLength increments and duplicate entries appear). This makes the tool non-idempotent, and clients relying on the hint for automatic retries could corrupt the thinking chain. Made-with: Cursor
The nested try/catch structure meant that if fs.rename() failed during memory.json → memory.jsonl migration (e.g. permission error), the exception would bubble into the outer catch which silently returned the new path. The server would then start with a non-existent file and overwrite the user's data on the first write. Restructured to separate the access checks so rename failures propagate to the caller. Made-with: Cursor
The response handler referenced 'color' and 'petType' fields that do not exist in the elicitation request schema, so they would never have values. Meanwhile, fields actually defined in the schema (firstLine, untitledSingleSelectEnum, untitledMultipleSelectEnum, titledSingleSelectEnum, titledMultipleSelectEnum, legacyTitledEnum) were never displayed. Removed the dead references and added handlers for all schema-defined fields. Made-with: Cursor
|
@claude review |
|
Claude finished @cliffhall's task in 1m 54s —— View job PR Review: fix: correct 6 bugs across multiple servers
All 6 fixes are legitimate, well-scoped, and correct. The diagnosis in the PR description is accurate for each one. Here is a detailed assessment: Fix 1 —
|
| Fix | File | Severity | Verdict |
|---|---|---|---|
for...in on Map |
streamableHttp.ts |
Critical (resource leak on shutdown) | ✅ Correct |
| Access-denied error swallowed | filesystem/lib.ts |
High (security error misrepresented) | ✅ Correct |
| Always-false guard | templates.ts |
Medium (every URI accepted as valid) | ✅ Correct |
idempotentHint: true |
sequentialthinking/index.ts |
Medium (incorrect hint can corrupt chains) | ✅ Correct |
| Rename error swallowed | memory/index.ts |
Medium (data loss on migration failure) | ✅ Correct |
| Dead field references | trigger-elicitation-request.ts |
Medium (silently missing output) | ✅ Correct |
All fixes are minimal, targeted, and don't alter intended semantics. No new tests are included, though the changes to validatePath and ensureMemoryFilePath would benefit from test coverage to prevent regressions. Overall this is a clean, well-described PR — I'd recommend merging.
LuuOW
left a comment
There was a problem hiding this comment.
Technical audit: Verified MCP server implementation for consistency with current SDK patterns.
Description
This PR fixes 6 confirmed bugs found across multiple server implementations via systematic code audit. Each fix is a separate commit for ease of review.
Bug Fixes
1. CRITICAL:
for...inon Map never iterates entries (streamableHttp.ts)The SIGINT shutdown handler used
for...into iterate aMap<string, StreamableHTTPServerTransport>. SinceMapentries are not enumerable own properties, the loop body never executed, meaning active transports were never closed on shutdown — causing resource leaks.Fix: Changed to
for...ofwhich correctly iterates Map entries.2. HIGH: Inner catch swallows access-denied security error (filesystem/lib.ts)
In
validatePath, when a new file's parent directory exists but is outside allowed directories, the "Access denied" error thrown on line 131 was immediately caught by the barecatchon line 134 and replaced with a misleading "Parent directory does not exist" message.Fix: The inner catch now re-throws errors that start with "Access denied".
3. MEDIUM: Always-false guard condition in parseResourceId (templates.ts)
The guard
uri.startsWith(textUriBase) && uri.startsWith(blobUriBase)is always false since a URI cannot start with both"demo://resource/dynamic/text"and"demo://resource/dynamic/blob". The intended check was to reject URIs matching neither prefix.Fix: Added
!negation to bothstartsWithchecks.4. MEDIUM: Incorrect idempotentHint on sequential thinking tool (index.ts)
The tool was marked
idempotentHint: true, but it appends tothoughtHistoryon every call, making repeated identical calls produce differentthoughtHistoryLengthvalues and duplicate entries. Clients relying on this hint for auto-retry could corrupt the thinking chain.Fix: Changed
idempotentHinttofalse.5. MEDIUM: Memory migration rename error silently swallowed (memory/index.ts)
The nested try/catch structure meant that if
fs.rename()failed duringmemory.json → memory.jsonlmigration (e.g. permission error), the exception would bubble into the outer catch which silently returned the new path. The server would start with a non-existent file and overwrite the user's data on the first write.Fix: Restructured to flat try/catch blocks so rename errors propagate to the caller.
6. MEDIUM: Elicitation response handler references non-existent schema fields (trigger-elicitation-request.ts)
The response handler referenced
colorandpetTypefields that were not defined in the elicitation request schema (thus always undefined), while omitting fields that are actually in the schema:firstLine,untitledSingleSelectEnum,untitledMultipleSelectEnum,titledSingleSelectEnum,titledMultipleSelectEnum, andlegacyTitledEnum.Fix: Removed dead field references and added handlers for all schema-defined fields.
Server Details
Motivation and Context
These bugs were found through systematic code audit. Each is a clear, unambiguous defect with a deterministic fix that doesn't alter intended semantics.
How Has This Been Tested?
Each fix was verified by reading the original code, confirming the bug exists, applying the minimal correct fix, and re-reading the modified code. The changes are minimal and localized.
Breaking Changes
None. All fixes correct existing behavior to match documented intent.
Types of changes
Checklist
Additional context
All 6 commits are independent and can be cherry-picked individually if needed.