Skip to content

fix: 删除 edit tool 中的旧逻辑处理, 现在已经不需要这些处理了, 大模型够屌#1251

Merged
claude-code-best merged 2 commits into
mainfrom
fixture/remove-old-edit-tool-condition
May 28, 2026
Merged

fix: 删除 edit tool 中的旧逻辑处理, 现在已经不需要这些处理了, 大模型够屌#1251
claude-code-best merged 2 commits into
mainfrom
fixture/remove-old-edit-tool-condition

Conversation

@claude-code-best
Copy link
Copy Markdown
Owner

@claude-code-best claude-code-best commented May 28, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Fixed TypeScript type compatibility in IDE notification handlers.
  • Refactor

    • Simplified file matching logic during edits for more predictable results.
    • Removed unnecessary quote style processing from file editing operations.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3f473175-5b09-413b-8745-7bf3808285c1

📥 Commits

Reviewing files that changed from the base of the PR and between c982104 and 0e39283.

📒 Files selected for processing (14)
  • packages/builtin-tools/src/tools/FileEditTool/FileEditTool.ts
  • packages/builtin-tools/src/tools/FileEditTool/UI.tsx
  • packages/builtin-tools/src/tools/FileEditTool/__tests__/utils.test.ts
  • packages/builtin-tools/src/tools/FileEditTool/utils.ts
  • src/cli/print.ts
  • src/components/FileEditToolDiff.tsx
  • src/entrypoints/cli.tsx
  • src/hooks/useIdeAtMentioned.ts
  • src/hooks/useIdeLogging.ts
  • src/hooks/useIdeSelection.ts
  • src/hooks/usePromptsFromClaudeInChrome.tsx
  • src/services/mcp/useManageMCPConnections.ts
  • src/services/mcp/vscodeSdkMcp.ts
  • tsconfig.json
 ______________________________________
< Be a super developer. Go home early. >
 --------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fixture/remove-old-edit-tool-condition

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can use oxc to improve the quality of JavaScript and TypeScript code reviews.

Add a configuration file to your project to customize how CodeRabbit runs oxc.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

📝 Walkthrough

Walkthrough

The PR removes quote-style preservation and fuzzy string matching from the FileEditTool edit pipeline, simplifying string matching to exact substring checks. It also systematically adds TypeScript type casts to MCP notification handler schema registrations across multiple files and excludes a build directory from TypeScript compilation.

Changes

FileEditTool Quote-Style Preservation Removal

Layer / File(s) Summary
Quote normalization utilities removal and findActualString simplification
packages/builtin-tools/src/tools/FileEditTool/utils.ts
Removed exported curly-quote constants (LEFT_SINGLE_CURLY_QUOTE, RIGHT_SINGLE_CURLY_QUOTE, LEFT_DOUBLE_CURLY_QUOTE, RIGHT_DOUBLE_CURLY_QUOTE) and normalizeQuotes() function; replaced fuzzy matching in findActualString() with exact substring-only check, eliminating quote and whitespace normalization fallbacks.
FileEditTool patch generation simplification
packages/builtin-tools/src/tools/FileEditTool/FileEditTool.ts
Removed preserveQuoteStyle import; updated validation comment to reference exact-match behavior; simplified call() to pass new_string directly to getPatchForEdit after resolving actualOldString via findActualString() fallback.
Rejection diff and component integration updates
packages/builtin-tools/src/tools/FileEditTool/UI.tsx, src/components/FileEditToolDiff.tsx
Removed preserveQuoteStyle from imports; updated rejection diff loading to use actual matched substring without quote-style rewriting; adjusted component normalizeEdit to set only old_string to matched substring.
Test suite updates
packages/builtin-tools/src/tools/FileEditTool/__tests__/utils.test.ts
Removed entire normalizeQuotes and preserveQuoteStyle test suites; simplified findActualString tests by removing curly-quote normalization and tab/space normalization cases, replacing with single CJK matching test.

MCP Handler Type Compatibility and Build Configuration

Layer / File(s) Summary
MCP notification handler schema type casting
src/cli/print.ts, src/entrypoints/cli.tsx, src/hooks/useIdeAtMentioned.ts, src/hooks/useIdeLogging.ts, src/hooks/useIdeSelection.ts, src/hooks/usePromptsFromClaudeInChrome.tsx, src/services/mcp/useManageMCPConnections.ts, src/services/mcp/vscodeSdkMcp.ts
Added as any type cast to notification schema arguments (ChannelMessageNotificationSchema(), ChannelPermissionRequestNotificationSchema(), ChannelPermissionNotificationSchema(), AtMentionedSchema(), LogEventSchema(), SelectionChangedSchema(), ClaudeInChromePromptNotificationSchema(), LogEventNotificationSchema()) in setNotificationHandler calls to satisfy TypeScript handler signature requirements.
TypeScript compilation configuration update
tsconfig.json
Expanded exclude array to include packages/remote-control-server/web in addition to node_modules.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A string match simplified, no more curly quotes to chase,
Exact finds replace the fuzzy dance of space,
Type casts sprinkle through the MCP land,
Build configs tidy with a gentle hand—
Simpler edits, cleaner code, all as planned!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is in Chinese and describes removing old logic handling from the edit tool, which aligns with the main changes removing quote normalization and preservation utilities.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fixture/remove-old-edit-tool-condition

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/services/mcp/vscodeSdkMcp.ts (1)

71-80: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Replace as any with double assertion pattern.

The coding guidelines prohibit as any type assertions in production code. Use the double assertion pattern as unknown as SpecificType instead to maintain type safety.

As per coding guidelines, prohibit as any type assertions in production code; in test files, as any is permitted for mock data. Use as unknown as SpecificType double assertion or interface supplementation when type mismatches occur.

♻️ Proposed fix using double assertion
     client.client.setNotificationHandler(
-      LogEventNotificationSchema() as any,
+      LogEventNotificationSchema() as unknown as Parameters<typeof client.client.setNotificationHandler>[0],
       async notification => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/mcp/vscodeSdkMcp.ts` around lines 71 - 80, The code uses an
unsafe "as any" cast in the client.client.setNotificationHandler call for
LogEventNotificationSchema; replace the "as any" with a double assertion to the
correct notification type (e.g., LogEventNotificationSchema() as unknown as
NotificationType) so the handler signature is typed safely; update the cast
where LogEventNotificationSchema() is passed and ensure the notification.params
destructure (eventName, eventData) and the logEvent call keep the same shape but
now use the proper SpecificType instead of any (locate the cast at the
client.client.setNotificationHandler invocation and replace with the
double-assertion pattern).
src/services/mcp/useManageMCPConnections.ts (1)

506-531: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Replace as any with double assertion pattern.

The coding guidelines prohibit as any type assertions in production code. Use the double assertion pattern as unknown as SpecificType instead to maintain type safety while satisfying the handler signature requirements.

As per coding guidelines, prohibit as any type assertions in production code; in test files, as any is permitted for mock data. Use as unknown as SpecificType double assertion or interface supplementation when type mismatches occur.

♻️ Proposed fix using double assertion
           client.client.setNotificationHandler(
-            ChannelMessageNotificationSchema() as any,
+            ChannelMessageNotificationSchema() as unknown as Parameters<typeof client.client.setNotificationHandler>[0],
             async notification => {
             client.client.setNotificationHandler(
-              ChannelPermissionNotificationSchema() as any,
+              ChannelPermissionNotificationSchema() as unknown as Parameters<typeof client.client.setNotificationHandler>[0],
               async notification => {

Also applies to: 541-557

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/services/mcp/useManageMCPConnections.ts` around lines 506 - 531, Replace
the prohibited "as any" cast used when registering the notification handler with
a double assertion to maintain type safety: in the call to
client.client.setNotificationHandler where ChannelMessageNotificationSchema() is
currently cast as any, change it to ChannelMessageNotificationSchema() as
unknown as <appropriate handler type> (use the real handler/interface type
expected by setNotificationHandler) and do the same replacement for the similar
occurrence around lines 541-557; locate usages by the symbols
client.client.setNotificationHandler and ChannelMessageNotificationSchema to
ensure you pick the correct specific handler type for the double assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/cli/print.ts`:
- Line 4969: The registration uses ChannelMessageNotificationSchema() as any
which breaks the repo typing rule; replace the unsafe cast with a compliant cast
matching the first parameter type of connection.client.setNotificationHandler
(e.g. ChannelMessageNotificationSchema() as unknown as Parameters<typeof
connection.client.setNotificationHandler>[0]) or create a small typed helper to
perform that conversion and use it in the MCP handler registration so the schema
is properly typed instead of using as any; update both occurrences around
ChannelMessageNotificationSchema and ensure the handler signature still aligns
with setNotificationHandler.

In `@src/entrypoints/cli.tsx`:
- Line 149: The registration uses ChannelPermissionRequestNotificationSchema()
as any which disables typing; replace the cast by calling the correct
setNotificationHandler overload so notification.params is strongly typed — e.g.,
use the overload that accepts the SDK params-schema (pass
ChannelPermissionRequestNotificationSchema without casting and/or use the
generic/typed overload on server.setNotificationHandler) or supply the literal
method-name string overload if appropriate; update the handler registration
(server.setNotificationHandler and ChannelPermissionRequestNotificationSchema)
so notification.params has the proper typed shape instead of any.

In `@src/hooks/useIdeAtMentioned.ts`:
- Line 50: The registration currently passes AtMentionedSchema() as any into
ideClient.client.setNotificationHandler which strips type safety; replace the
cast by using a proper typed cast such as casting via unknown to the expected
handler schema (e.g. AtMentionedSchema() as unknown as
<ExpectedNotificationSchemaType>) or refactor so the schema/handler types align
with setNotificationHandler's expected generic/parameter types; update the call
in useIdeAtMentioned.ts (around ideClient.client.setNotificationHandler and the
AtMentionedSchema() usage) to remove "as any" and supply the correct typed cast
or adjusted types so the handler registration is type-safe.

In `@src/hooks/useIdeLogging.ts`:
- Line 30: Replace the unsafe `as any` cast used when registering the
notification handler: locate the `setNotificationHandler(LogEventSchema() as
any, ...)` call and remove `as any`, supplying a concrete typed value
instead—either cast via `as unknown as <SpecificNotificationType>` that matches
the SDK signature or create a small typed wrapper/schema that conforms to the
expected notification payload type; ensure the replacement uses the
`LogEventSchema` output typed to the handler signature so
`setNotificationHandler` receives a non-`any` typed schema.

In `@src/hooks/useIdeSelection.ts`:
- Line 113: The cast "SelectionChangedSchema() as any" in the selection
notification handler setup within useIdeSelection.ts bypasses typing rules;
replace it by either creating a proper typed adapter/interface that matches the
notification contract or use a safe double assertion (e.g.
"SelectionChangedSchema() as unknown as <ExpectedNotificationType>") where
<ExpectedNotificationType> is the exact type the handler (selection notification
registration) expects; update the code around the SelectionChangedSchema() call
(and the handler registration function) to use that concrete type instead of
"any".

In `@src/hooks/usePromptsFromClaudeInChrome.tsx`:
- Line 51: The call to mcpClient.client.setNotificationHandler currently uses
ClaudeInChromePromptNotificationSchema() as any which bypasses type safety;
replace the unsafe cast by asserting the schema to the correct typed shape
(e.g., use ClaudeInChromePromptNotificationSchema() as unknown as
ExpectedNotificationType) or define the proper notification/params interface and
cast to that instead so the notification handler registered via
mcpClient.client.setNotificationHandler maintains strict payload typing; update
types accordingly where ClaudeInChromePromptNotificationSchema and the handler
callback are declared.

---

Outside diff comments:
In `@src/services/mcp/useManageMCPConnections.ts`:
- Around line 506-531: Replace the prohibited "as any" cast used when
registering the notification handler with a double assertion to maintain type
safety: in the call to client.client.setNotificationHandler where
ChannelMessageNotificationSchema() is currently cast as any, change it to
ChannelMessageNotificationSchema() as unknown as <appropriate handler type> (use
the real handler/interface type expected by setNotificationHandler) and do the
same replacement for the similar occurrence around lines 541-557; locate usages
by the symbols client.client.setNotificationHandler and
ChannelMessageNotificationSchema to ensure you pick the correct specific handler
type for the double assertion.

In `@src/services/mcp/vscodeSdkMcp.ts`:
- Around line 71-80: The code uses an unsafe "as any" cast in the
client.client.setNotificationHandler call for LogEventNotificationSchema;
replace the "as any" with a double assertion to the correct notification type
(e.g., LogEventNotificationSchema() as unknown as NotificationType) so the
handler signature is typed safely; update the cast where
LogEventNotificationSchema() is passed and ensure the notification.params
destructure (eventName, eventData) and the logEvent call keep the same shape but
now use the proper SpecificType instead of any (locate the cast at the
client.client.setNotificationHandler invocation and replace with the
double-assertion pattern).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3f473175-5b09-413b-8745-7bf3808285c1

📥 Commits

Reviewing files that changed from the base of the PR and between c982104 and 0e39283.

📒 Files selected for processing (14)
  • packages/builtin-tools/src/tools/FileEditTool/FileEditTool.ts
  • packages/builtin-tools/src/tools/FileEditTool/UI.tsx
  • packages/builtin-tools/src/tools/FileEditTool/__tests__/utils.test.ts
  • packages/builtin-tools/src/tools/FileEditTool/utils.ts
  • src/cli/print.ts
  • src/components/FileEditToolDiff.tsx
  • src/entrypoints/cli.tsx
  • src/hooks/useIdeAtMentioned.ts
  • src/hooks/useIdeLogging.ts
  • src/hooks/useIdeSelection.ts
  • src/hooks/usePromptsFromClaudeInChrome.tsx
  • src/services/mcp/useManageMCPConnections.ts
  • src/services/mcp/vscodeSdkMcp.ts
  • tsconfig.json

Comment thread src/cli/print.ts
// the turn after they arrive.
connection.client.setNotificationHandler(
ChannelMessageNotificationSchema(),
ChannelMessageNotificationSchema() as any,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show surrounding code for the referenced line numbers
sed -n '4940,4995p' src/cli/print.ts | nl -ba | sed -n '1,120p'
echo "----"
sed -n '5010,5070p' src/cli/print.ts | nl -ba | sed -n '1,120p'

# Also search for any remaining "as any" in this file (ts/tsx production rule)
rg -n "as any" src/cli/print.ts

# And locate setNotificationHandler usage patterns in this file
rg -n "setNotificationHandler" src/cli/print.ts

Repository: claude-code-best/claude-code

Length of output: 115


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="src/cli/print.ts"

# Helper to print a snippet with real line numbers
print_snippet () {
  local start="$1"
  local end="$2"
  sed -n "${start},${end}p" "$file" | awk -v start="$start" '{printf "%d:%s\n", start+NR-1, $0}'
}

echo "== Snippet around 4969 =="
print_snippet 4955 4985
echo

echo "== Snippet around 5045 =="
print_snippet 5030 5060
echo

echo "== Search for 'as any' in this file =="
rg -n "as any" "$file" || true
echo

echo "== setNotificationHandler occurrences in this file =="
rg -n "setNotificationHandler" "$file" -n

Repository: claude-code-best/claude-code

Length of output: 3127


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the schema definition
rg -n "ChannelMessageNotificationSchema" -S . || true

# Inspect where setNotificationHandler is typed/declared (best-effort)
rg -n "setNotificationHandler\\(" -S src/cli/print.ts

# If types are in node_modules, search for a declaration (best-effort)
rg -n "setNotificationHandler\\s*<|setNotificationHandler\\s*\\(" -S node_modules 2>/dev/null | head -n 50 || true

Repository: claude-code-best/claude-code

Length of output: 729


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Inspect ChannelMessageNotificationSchema implementation
echo "== src/services/mcp/channelNotification.ts =="
sed -n '1,200p' src/services/mcp/channelNotification.ts | nl -ba | sed -n '1,200p'

echo "----"

# 2) Inspect useManageMCPConnections usage (including any other casts)
echo "== src/services/mcp/useManageMCPConnections.ts (around ChannelMessageNotificationSchema usage) =="
sed -n '470,560p' src/services/mcp/useManageMCPConnections.ts | nl -ba

echo "----"

# 3) Inspect the print.ts sections around the problematic lines (larger context)
echo "== src/cli/print.ts around 4940-4990 =="
sed -n '4920,5020p' src/cli/print.ts | nl -ba

echo "----"

echo "== src/cli/print.ts around 5025-5075 =="
sed -n '5010,5085p' src/cli/print.ts | nl -ba

echo "----"

# 4) Locate typings for setNotificationHandler in node_modules (best-effort)
echo "== Typings for setNotificationHandler (d.ts) =="
rg -n "setNotificationHandler" node_modules -S --glob '*.d.ts' 2>/dev/null | head -n 50 || true

echo "----"

# 5) If node_modules search is empty, also try searching in repo for "interface .*NotificationHandler" etc
echo "== Repo search for notification handler typing hints =="
rg -n "NotificationHandler|notification handler|setNotificationHandler\\s*:" src -S || true

Repository: claude-code-best/claude-code

Length of output: 179


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Use awk to add line numbers (nl may not exist)
lnshow () { awk -v s="$1" '{printf "%d:%s\n", s+NR-1, $0}'; }

echo "== src/services/mcp/channelNotification.ts =="
start=1; end=200
sed -n "${start},${end}p" src/services/mcp/channelNotification.ts | lnshow $start

echo "----"

echo "== src/services/mcp/useManageMCPConnections.ts (around first usage) =="
start=470; end=560
sed -n "${start},${end}p" src/services/mcp/useManageMCPConnections.ts | lnshow $start

echo "----"

echo "== src/cli/print.ts around 4960-4985 =="
start=4950; end=4990
sed -n "${start},${end}p" src/cli/print.ts | lnshow $start

echo "----"

echo "== src/cli/print.ts around 5038-5065 =="
start=5035; end=5070
sed -n "${start},${end}p" src/cli/print.ts | lnshow $start

echo "----"

echo "== typings for setNotificationHandler (node_modules, d.ts) =="
rg -n "setNotificationHandler" node_modules --glob '*.d.ts' -S 2>/dev/null | head -n 80 || true

Repository: claude-code-best/claude-code

Length of output: 16749


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate lazySchema implementation + types
rg -n "export (const|function) lazySchema|lazySchema\\s*=" src -S
fd -a "lazySchema" src || true
fd -a "lazySchema.ts" . || true
# Show the file
lazy_file="$(rg -l "lazySchema\\b" src/utils/lazySchema.* 2>/dev/null | head -n 1 || true)"
if [ -n "${lazy_file}" ] && [ -f "${lazy_file}" ]; then
  sed -n '1,200p' "${lazy_file}" | awk 'NR<=200{print NR ":" $0}'
else
  # fallback: try exact path from imports: ../../utils/lazySchema.js maybe is TS/JS
  for p in src/utils/lazySchema.ts src/utils/lazySchema.js src/utils/lazySchema.tsx; do
    if [ -f "$p" ]; then echo "== $p =="; sed -n '1,200p' "$p" | awk '{print NR":"$0}'; fi
  done
fi

# Also inspect where setNotificationHandler is typed within repo (if any wrapper exists)
rg -n "setNotificationHandler\\s*\\(" src -S
rg -n "setNotificationHandler\\s*:" src -S

# Inspect other notification handler schema casts patterns
rg -n "NotificationSchema\\(\\) as any" src -S

Repository: claude-code-best/claude-code

Length of output: 2006


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Print imports/definitions at top of src/cli/print.ts to see MCP client types
sed -n '1,220p' src/cli/print.ts | awk '{print NR ":" $0}'

echo "----"

# Find where "connection" is typed/constructed in print.ts
rg -n "const connection|let connection|type .*connection|interface .*connection" src/cli/print.ts
rg -n "useMCP|mcp|`@modelcontextprotocol`|Client|setNotificationHandler" src/cli/print.ts | head -n 80

echo "----"

# Jump to around first setNotificationHandler in print.ts
start=1320; end=1460
sed -n "${start},${end}p" src/cli/print.ts | awk '{print (NR+('$start'-1)) ":" $0}'

echo "----"

# Inspect src/hooks/usePromptsFromClaudeInChrome.tsx for how they cast schema (pattern)
sed -n '1,120p' src/hooks/usePromptsFromClaudeInChrome.tsx | awk '{print NR ":" $0}'

Repository: claude-code-best/claude-code

Length of output: 23902


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search within MCP-related source for setNotificationHandler type annotations or wrappers
rg -n "setNotificationHandler" src/services/mcp -S

# Inspect MCP connection types to find client type definition
rg -n "export type|export interface|interface|type .*MCPServerConnection|ConnectedMCPServer|client:" src/services/mcp/types.* -S
ls -la src/services/mcp | head -n 50

# Show likely types file(s) around exported connection types
for f in src/services/mcp/types.ts src/services/mcp/types.js src/services/mcp/*types*; do
  if [ -f "$f" ]; then
    echo "== $f ==";
    wc -l "$f";
    sed -n '1,220p' "$f" | awk '{print NR":"$0}';
  fi
done

# Also look for wrapper around sdk client in src/services/mcp/client.*
for f in src/services/mcp/client.* src/services/mcp/*client*.*; do
  if [ -f "$f" ]; then
    echo "== $f ==";
    rg -n "setNotificationHandler" "$f" -S || true
  fi
done

Repository: claude-code-best/claude-code

Length of output: 17454


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Repo top-level =="
ls -ლა

echo "== node_modules presence =="
if [ -d node_modules ]; then
  echo "node_modules exists"
  ls -la node_modules | head -n 50
else
  echo "node_modules missing"
fi

echo "== Search for MCP SDK typings =="
# Try common places
for base in node_modules/@modelcontextprotocol/sdk node_modules/@modelcontextprotocol/* .bun/node_modules/@modelcontextprotocol/sdk .bun/node_modules/@modelcontextprotocol/*; do
  if [ -d "$base" ]; then
    echo "-- checking $base"
    rg -n "setNotificationHandler" "$base" -S --glob '*.d.ts' --glob '*.ts' --glob '*.tsx' 2>/dev/null | head -n 50 || true
  fi
done

echo "== Find any NotificationHandler types in repo/node_modules =="
rg -n "NotificationHandler" node_modules/@modelcontextprotocol/sdk -S --glob '*.d.ts' 2>/dev/null | head -n 50 || true

echo "== Fallback: locate the sdk client type file =="
# locate Client declaration in node_modules
rg -n "export (class|interface|type) Client" node_modules/@modelcontextprotocol/sdk -S --glob '*.d.ts' 2>/dev/null | head -n 50 || true

Repository: claude-code-best/claude-code

Length of output: 175


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Top-level (safe) =="
ls -la | head -n 100

echo "== Check for node_modules directories =="
[ -d node_modules ] && echo "node_modules exists" || echo "node_modules missing"
[ -d .bun ] && echo ".bun exists" || echo ".bun missing"
find . -maxdepth 3 -type d -name "node_modules" 2>/dev/null | head -n 20
find . -maxdepth 4 -type d -name "`@modelcontextprotocol`" 2>/dev/null | head -n 20

echo "== Search setNotificationHandler in any .d.ts we can find =="
rg -n "setNotificationHandler" . \
  --glob '*.d.ts' --glob '*.ts' --glob '*.tsx' --glob '!**/dist/**' --glob '!**/build/**' \
  -S 2>/dev/null | head -n 80 || true

echo "== Search specifically for MCP SDK Client type =="
rg -n "`@modelcontextprotocol/sdk`" . -S --glob '*.d.ts' --glob '*.ts' --glob '*.tsx' 2>/dev/null | head -n 80 || true

Repository: claude-code-best/claude-code

Length of output: 13177


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find where the SDK is vendored in this repo (since node_modules is missing)
rg -n "\"`@modelcontextprotocol/sdk/client/index`\\.js\"|`@modelcontextprotocol/sdk/client/index`\\.js" -S . || true
rg -n "`@modelcontextprotocol/sdk/client/index`" -S . || true

# Inspect src/services/mcp/client.ts to see how Client is used/typed
sed -n '1,220p' src/services/mcp/client.ts | awk '{print NR":"$0}' | head -n 220

echo "----"

# Look for the Client class/type re-export in vendored SDK
# (search for "class Client" or "setNotificationHandler" in vendor/packages)
rg -n "class Client|setNotificationHandler\\s*\\(" vendor packages -S --glob '*.ts' --glob '*.js' --glob '*.d.ts' 2>/dev/null | head -n 80 || true

echo "----"

# Specifically search for "setNotificationHandler(" implementations in repo/vendor
rg -n "setNotificationHandler\\s*\\(" . -S --glob '*.*' --glob '!**/dist/**' --glob '!**/build/**' 2>/dev/null | head -n 120 || true

Repository: claude-code-best/claude-code

Length of output: 13861


Replace ChannelMessageNotificationSchema() as any in MCP handler registration (src/cli/print.ts:4969, 5045).

as any violates the repo rule for production typing on notification handler schemas. Replace with a compliant typed cast (as unknown as ...) matching the first parameter type of connection.client.setNotificationHandler (or introduce a typed helper).

Suggested direction
-  connection.client.setNotificationHandler(
-    ChannelMessageNotificationSchema() as any,
+  const channelSchema =
+    ChannelMessageNotificationSchema() as unknown as Parameters<
+      typeof connection.client.setNotificationHandler
+    >[0]
+  connection.client.setNotificationHandler(
+    channelSchema,
     async notification => {
       // ...
     },
   )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cli/print.ts` at line 4969, The registration uses
ChannelMessageNotificationSchema() as any which breaks the repo typing rule;
replace the unsafe cast with a compliant cast matching the first parameter type
of connection.client.setNotificationHandler (e.g.
ChannelMessageNotificationSchema() as unknown as Parameters<typeof
connection.client.setNotificationHandler>[0]) or create a small typed helper to
perform that conversion and use it in the MCP handler registration so the schema
is properly typed instead of using as any; update both occurrences around
ChannelMessageNotificationSchema and ensure the handler signature still aligns
with setNotificationHandler.

Comment thread src/entrypoints/cli.tsx
logForDebugging,
registerPermissionHandler(server, handler) {
server.setNotificationHandler(ChannelPermissionRequestNotificationSchema(), async notification =>
server.setNotificationHandler(ChannelPermissionRequestNotificationSchema() as any, async notification =>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show surrounding lines for the referenced line number
sed -n '130,175p' src/entrypoints/cli.tsx | nl -ba | sed -n '1,80p'

# Confirm exact "as any" usage on that line pattern
rg -n "ChannelPermissionRequestNotificationSchema\(\)\s+as\s+any" src/entrypoints/cli.tsx || true

# Count any remaining "as any" in this file
rg -n "\bas\s+any\b" src/entrypoints/cli.tsx || true

Repository: claude-code-best/claude-code

Length of output: 115


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Print a small window around the referenced line (149)
sed -n '140,160p' src/entrypoints/cli.tsx

# Exact match check for the cited pattern
rg -n "ChannelPermissionRequestNotificationSchema\(\)\s+as\s+any" src/entrypoints/cli.tsx || true

# Count/locate any "as any" in this file
rg -n "\bas\s+any\b" src/entrypoints/cli.tsx || true

Repository: claude-code-best/claude-code

Length of output: 982


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show more context around the exact line with the as any
sed -n '120,170p' src/entrypoints/cli.tsx | nl -ba

# Find all occurrences of the schema in the codebase (to locate its type/definition usage)
rg -n "ChannelPermissionRequestNotificationSchema\(" -S src || true

# Locate setNotificationHandler type signature/usages
rg -n "setNotificationHandler\(" -S src || true

# If server type or notification types are imported/declared, capture relevant imports near top of file
rg -n "^import " src/entrypoints/cli.tsx | head -n 200

Repository: claude-code-best/claude-code

Length of output: 115


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show context with line numbers (no nl dependency)
awk 'NR>=120 && NR<=170 {printf "%d:%s\n", NR, $0}' src/entrypoints/cli.tsx

# Find all occurrences of the schema symbol
rg -n "ChannelPermissionRequestNotificationSchema" src || true

# Find setNotificationHandler signature/usages
rg -n "setNotificationHandler" src || true

# Show the relevant imports/typing near the top of cli.tsx
awk 'NR<=120 {print NR ":" $0}' src/entrypoints/cli.tsx | sed -n '1,120p'

Repository: claude-code-best/claude-code

Length of output: 10005


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Inspect the schema definition
sed -n '1,220p' src/services/mcp/channelNotification.ts

# 2) Locate setNotificationHandler type signatures/usages in our MCP server code
rg -n "setNotificationHandler\s*<|setNotificationHandler\(" src/services/mcp src/cli src/hooks src/entrypoints -S || true

# 3) Look for the underlying server type import in cli.tsx
sed -n '1,120p' src/entrypoints/cli.tsx

# 4) Find the server variable type / where server is created within cli.tsx (around weixin branch usage)
rg -n "const server|new .*Server|create.*Server|server\s*=" src/entrypoints/cli.tsx || true

Repository: claude-code-best/claude-code

Length of output: 15443


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find all "NotificationSchema() as any" patterns in repo
rg -n "NotificationSchema\(\)\s+as\s+any" src || true

# Find all "setNotificationHandler(... as any" patterns (broader)
rg -n "setNotificationHandler\([^)]*as\s+any" src || true

# Find "as unknown as" usages around notification handlers
rg -n "setNotificationHandler\([^)]*as\s+unknown\s+as" src || true
rg -n "as\s+unknown\s+as\s+.*Notification" src || true

# Inspect how lazySchema is typed (may tell us expected schema type)
rg -n "function lazySchema|export const lazySchema|lazySchema<" src/utils/lazySchema.ts src/utils/lazySchema.* || true
sed -n '1,200p' src/utils/lazySchema.ts

# Locate the weixin handler cast line usage context (small window)
awk 'NR>=130 && NR<=160 {print NR ":" $0}' src/entrypoints/cli.tsx

Repository: claude-code-best/claude-code

Length of output: 2703


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show contexts for other setNotificationHandler as any usages
for f in \
  src/services/mcp/vscodeSdkMcp.ts \
  src/hooks/usePromptsFromClaudeInChrome.tsx \
  src/services/mcp/useManageMCPConnections.ts \
  src/cli/print.ts \
; do
  echo "---- $f ----"
  rg -n "setNotificationHandler" "$f" -S || true
  done

# Show specific windows around each match in key files
sed -n '50,110p' src/services/mcp/vscodeSdkMcp.ts
sed -n '1,90p' src/hooks/usePromptsFromClaudeInChrome.tsx
sed -n '470,570p' src/services/mcp/useManageMCPConnections.ts
sed -n '4920,5070p' src/cli/print.ts

# Check for any setNotificationHandler usage without 'as any'
rg -n "setNotificationHandler\([^)]*\)" src -S | head -n 200
rg -n "setNotificationHandler\(" src -S | rg -v "as\s+any" || true

Repository: claude-code-best/claude-code

Length of output: 17737


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show contexts for other setNotificationHandler as any usages
for f in \
  src/services/mcp/vscodeSdkMcp.ts \
  src/hooks/usePromptsFromClaudeInChrome.tsx \
  src/services/mcp/useManageMCPConnections.ts \
  src/cli/print.ts \
; do
  echo "---- $f ----"
  rg -n "setNotificationHandler" "$f" -S || true
done

# Show specific windows around each match in key files
sed -n '50,110p' src/services/mcp/vscodeSdkMcp.ts
sed -n '1,120p' src/hooks/usePromptsFromClaudeInChrome.tsx
sed -n '480,570p' src/services/mcp/useManageMCPConnections.ts
sed -n '4940,5070p' src/cli/print.ts

# Check for any setNotificationHandler usage without 'as any'
echo "---- setNotificationHandler not using 'as any' ----"
rg -n "setNotificationHandler\(" src -S | rg -v "as\s+any" || true

Repository: claude-code-best/claude-code

Length of output: 16883


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find where MCP client/server types are declared
rg -n "setNotificationHandler" src/services/mcp -S

# Inspect the main types file(s)
ls src/services/mcp

# Targeted reads around likely type defs
sed -n '1,220p' src/services/mcp/types.ts
sed -n '1,260p' src/services/mcp/client.ts
sed -n '1,260p' src/services/mcp/server.ts 2>/dev/null || true

# If setNotificationHandler is only in SDK types, capture the import path for types file
rg -n "from '`@modelcontextprotocol/sdk`'" src/services/mcp -S

Repository: claude-code-best/claude-code

Length of output: 16925


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Look for any local type/interface definitions for setNotificationHandler
rg -n "setNotificationHandler\s*[:=]\s*<|setNotificationHandler\s*\(" src/services/mcp -S || true

# Look for notification schema typing helpers used with setNotificationHandler
rg -n "NotificationSchema|notificationSchema|setNotificationHandler<|NotificationHandler" src/services/mcp -S || true

# Search for removeNotificationHandler typings as a clue
rg -n "removeNotificationHandler\s*[:=]" src/services/mcp -S || true

# Ensure we only target the relevant handler call sites
rg -n "ChannelPermissionRequestNotificationSchema\(\)\s+as\s+any" -S src || true

Repository: claude-code-best/claude-code

Length of output: 3375


🌐 Web query:

@modelcontextprotocol/sdk setNotificationHandler notification schema typing as any

💡 Result:

In the current version of the @modelcontextprotocol/sdk (as of May 2026), the setNotificationHandler method has evolved away from requiring schema objects for standard MCP notifications [1][2]. For standard protocol notifications, you simply pass the method name as a string [2]. Type safety is automatically maintained through internal maps like NotificationTypeMap, so you do not need to explicitly type the notification schema [1][2]. Example for a standard notification: server.setNotificationHandler('notifications/message', (notification) => { console.log(notification.params.data); }); For custom (vendor-prefixed) methods, the SDK provides a 3-argument overload that accepts a validator-agnostic paramsSchema (compatible with Standard Schema libraries like Zod, Valibot, or ArkType) [3][2]. This allows you to define validation schemas for custom notifications without forcing them to 'any' [3]. Example for a custom notification using Zod: server.setNotificationHandler('vendor/custom-event', myZodSchema, (params, notification) => { // params is validated against myZodSchema // notification is the raw notification object }); If you absolutely need to bypass validation or accept any structure for a custom method, you can use the 3-argument form with a permissive schema or by manually handling the raw notification object [3][2]. However, the idiomatic approach is to use a specific Standard Schema to ensure type safety [2].

Citations:


Avoid as any in production setNotificationHandler registration.

src/entrypoints/cli.tsx registers the handler with ChannelPermissionRequestNotificationSchema() as any, bypassing the repo’s strict typing rule for production code. Replace the as any with the correct setNotificationHandler overload (e.g., method-name string or the SDK’s typed params-schema overload) so notification.params is typed without any.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/entrypoints/cli.tsx` at line 149, The registration uses
ChannelPermissionRequestNotificationSchema() as any which disables typing;
replace the cast by calling the correct setNotificationHandler overload so
notification.params is strongly typed — e.g., use the overload that accepts the
SDK params-schema (pass ChannelPermissionRequestNotificationSchema without
casting and/or use the generic/typed overload on server.setNotificationHandler)
or supply the literal method-name string overload if appropriate; update the
handler registration (server.setNotificationHandler and
ChannelPermissionRequestNotificationSchema) so notification.params has the
proper typed shape instead of any.

if (ideClient) {
ideClient.client.setNotificationHandler(
AtMentionedSchema(),
AtMentionedSchema() as any,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/hooks/useIdeAtMentioned.ts"

# Ensure file exists and show a small window around the cited line.
if [ ! -f "$FILE" ]; then
  echo "Missing file: $FILE"
  exit 1
fi

echo "=== $FILE (around line 45-60) ==="
nl -ba "$FILE" | sed -n '45,60p'

echo
echo "=== Exact matches for 'AtMentionedSchema' in $FILE ==="
rg -n "AtMentionedSchema" "$FILE" || true

echo
echo "=== Exact matches for ' as any' in $FILE ==="
rg -n " as any" "$FILE" || true

Repository: claude-code-best/claude-code

Length of output: 193


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/hooks/useIdeAtMentioned.ts"

if [ ! -f "$FILE" ]; then
  echo "Missing file: $FILE"
  exit 1
fi

echo "=== $FILE (around lines 45-60) ==="
cat -n "$FILE" | sed -n '45,60p'

echo
echo "=== Exact matches for 'AtMentionedSchema' in $FILE ==="
rg -n "AtMentionedSchema" "$FILE" || true

echo
echo "=== Exact matches for 'as any' in $FILE ==="
rg -n "as any" "$FILE" || true

Repository: claude-code-best/claude-code

Length of output: 1066


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/hooks/useIdeAtMentioned.ts"

echo "=== File head (1-120) ==="
cat -n "$FILE" | sed -n '1,120p'

echo
echo "=== Search for type assertions in this file ==="
rg -n "as any|unknown as|as unknown|lazySchema" "$FILE" || true

Repository: claude-code-best/claude-code

Length of output: 3042


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search for setNotificationHandler definition/usages to determine its parameter types.
rg -n "setNotificationHandler" -S . || true

# Narrow search for notification handler typing around MCP client/server.
rg -n "setNotificationHandler\\s*\\(" -S src || true

# Look for the interface/type that defines the notification handler registration.
rg -n "NotificationHandler|notification handler|setNotificationHandler" src -S || true

# If types are in services/mcp, inspect likely files.
fd -a --type f "types.js" src/services/mcp || true
fd -a --type f "types.ts" src/services/mcp || true
fd -a --type f "client" src/services/mcp || true

Repository: claude-code-best/claude-code

Length of output: 7752


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect MCP types and client signatures for setNotificationHandler
sed -n '150,230p' src/services/mcp/types.ts
echo "----"
sed -n '2960,3060p' src/services/mcp/client.ts
echo "----"
sed -n '3000,3120p' src/services/mcp/client.ts

Repository: claude-code-best/claude-code

Length of output: 10312


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the exact setNotificationHandler signatures/types used in the codebase.
echo "=== src/services/mcp/client.ts: setNotificationHandler occurrences ==="
rg -n "setNotificationHandler\\s*\\(" src/services/mcp/client.ts

echo
echo "=== packages/@ant/claude-for-chrome-mcp/src/types.ts: setNotificationHandler occurrences ==="
rg -n "setNotificationHandler\\s*\\(" packages/@ant/claude-for-chrome-mcp/src/types.ts

# Print surrounding type/interface definition for the package signature.
echo
echo "=== Context around packages/@ant/claude-for-chrome-mcp/src/types.ts setNotificationHandler ==="
LINE="$(rg -n "setNotificationHandler\\s*\\(" packages/@ant/claude-for-chrome-mcp/src/types.ts | head -n1 | cut -d: -f1)"
START=$((LINE-20))
END=$((LINE+30))
sed -n "${START},${END}p" packages/@ant/claude-for-chrome-mcp/src/types.ts

Repository: claude-code-best/claude-code

Length of output: 143


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== setNotificationHandler in src/services/mcp/client.ts (plain text) ==="
rg -n "setNotificationHandler" src/services/mcp/client.ts || true

echo
echo "=== setNotificationHandler in packages/@ant/claude-for-chrome-mcp/src/types.ts ==="
rg -n "setNotificationHandler" packages/@ant/claude-for-chrome-mcp/src/types.ts || true

echo
echo "=== Print the definition area in packages/@ant/claude-for-chrome-mcp/src/types.ts ==="
# Grab lines around the first hit
LINE="$(rg -n "setNotificationHandler" packages/@ant/claude-for-chrome-mcp/src/types.ts | head -n1 | cut -d: -f1)"
START=$((LINE-20))
END=$((LINE+40))
sed -n "${START},${END}p" packages/@ant/claude-for-chrome-mcp/src/types.ts

Repository: claude-code-best/claude-code

Length of output: 1555


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the overload/implementation that supports (schema, handler) usage.
rg -n "setNotificationHandler\\s*\\(" packages/@ant/claude-for-chrome-mcp/src | head -n 50

echo "----"
# Print the implementation in mcpSocketClient.ts around public setNotificationHandler
FILE="packages/@ant/claude-for-chrome-mcp/src/mcpSocketClient.ts"
if [ -f "$FILE" ]; then
  LINE="$(rg -n "setNotificationHandler\\s*\\(" "$FILE" | head -n1 | cut -d: -f1)"
  START=$((LINE-30))
  END=$((LINE+80))
  sed -n "${START},${END}p" "$FILE"
fi

echo "----"
# Print the implementation in mcpSocketPool.ts around public setNotificationHandler
FILE="packages/@ant/claude-for-chrome-mcp/src/mcpSocketPool.ts"
if [ -f "$FILE" ]; then
  LINE="$(rg -n "setNotificationHandler\\s*\\(" "$FILE" | head -n1 | cut -d: -f1)"
  START=$((LINE-30))
  END=$((LINE+90))
  sed -n "${START},${END}p" "$FILE"
fi

echo "----"
# Print any other types in bridgeClient.ts
FILE="packages/@ant/claude-for-chrome-mcp/src/bridgeClient.ts"
if [ -f "$FILE" ]; then
  LINE="$(rg -n "setNotificationHandler\\s*\\(" "$FILE" | head -n1 | cut -d: -f1)"
  START=$((LINE-40))
  END=$((LINE+80))
  sed -n "${START},${END}p" "$FILE"
fi

Repository: claude-code-best/claude-code

Length of output: 10817


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the type/implementation behind ideClient.client.setNotificationHandler(schema, handler)
rg -n "getConnectedIdeClient" -S src || true
rg -n "setNotificationHandler\\(" -S src/services/mcp src/utils src/hooks || true

echo "----"
# Inspect the IDE utils that provide ideClient
FILE="src/utils/ide.js"
if [ -f "$FILE" ]; then
  sed -n '1,220p' "$FILE"
else
  echo "Missing $FILE"
fi

echo "----"
# Inspect the MCP vscode SDK wrapper where setNotificationHandler is likely typed for (schema, handler)
FILE="src/services/mcp/vscodeSdkMcp.ts"
if [ -f "$FILE" ]; then
  sed -n '1,220p' "$FILE"
else
  echo "Missing $FILE"
fi

Repository: claude-code-best/claude-code

Length of output: 6134


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Inspect the VSCode MCP wrapper where setNotificationHandler(schema, handler) is used.
FILE="src/services/mcp/vscodeSdkMcp.ts"
if [ -f "$FILE" ]; then
  echo "=== $FILE around setNotificationHandler ==="
  rg -n "setNotificationHandler\\(" "$FILE"
  LINE="$(rg -n "setNotificationHandler\\(" "$FILE" | head -n1 | cut -d: -f1)"
  START=$((LINE-30))
  END=$((LINE+60))
  sed -n "${START},${END}p" "$FILE"
else
  echo "Missing $FILE"
fi

# 2) Find the type/interface for notification schemas / handler registration in src/services/mcp.
echo
echo "=== Search for NotificationSchema types in src/services/mcp ==="
rg -n "NotificationSchema|notification schema|Schema.*notification|Zod.*notification" src/services/mcp -S || true

# 3) Find any other overload/implementation that defines setNotificationHandler with (schema, handler) args.
echo
echo "=== Search for setNotificationHandler implementations in repo (schema, handler) ==="
rg -n "setNotificationHandler\\s*\\(\\s*[^,]+\\s*," -S src packages | head -n 50

# 4) Search for schema-related handler types near ideClient usage.
echo
echo "=== Search for types of notification handlers ==="
rg -n "setNotificationHandler\\s*<|type .*Notification.*Handler|interface .*Notification.*Handler" -S src packages || true

Repository: claude-code-best/claude-code

Length of output: 4606


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for f in src/hooks/useIdeLogging.ts src/hooks/useIdeSelection.ts src/hooks/useIdeAtMentioned.ts; do
  echo "==== $f (around setNotificationHandler) ===="
  rg -n "setNotificationHandler" "$f" || true
  LINE="$(rg -n "setNotificationHandler" "$f" | head -n1 | cut -d: -f1 || true)"
  if [ -n "${LINE:-}" ]; then
    START=$((LINE-15))
    END=$((LINE+35))
    sed -n "${START},${END}p" "$f"
  fi
  echo
done

Repository: claude-code-best/claude-code

Length of output: 3988


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate lazySchema implementation
fd -a --type f "lazySchema" src/utils src -0 | head -n 20 || true
fd -a --type f "lazySchema" packages src -0 | head -n 20 || true

# Show lazySchema implementation
FILE="$(fd -a --type f "lazySchema" src/utils packages src | head -n 1 || true)"
echo "Using file: $FILE"
if [ -n "$FILE" ] && [ -f "$FILE" ]; then
  sed -n '1,200p' "$FILE"
fi

Repository: claude-code-best/claude-code

Length of output: 1855


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Find setNotificationHandler type in src/services/mcp/types.ts
FILE="src/services/mcp/types.ts"
echo "=== setNotificationHandler in $FILE ==="
rg -n "setNotificationHandler" "$FILE" || true

echo
# Print a wider window around the first hit if present
LINE="$(rg -n "setNotificationHandler" "$FILE" | head -n1 | cut -d: -f1 || true)"
if [ -n "${LINE:-}" ]; then
  START=$((LINE-60))
  END=$((LINE+60))
  echo "=== Context $FILE:$START-$END ==="
  sed -n "${START},${END}p" "$FILE"
fi

# 2) Inspect ConnectedMCPServer.client type if it's defined via Client import/alias
echo
echo "=== Top of src/services/mcp/types.ts ==="
sed -n '1,120p' "$FILE"

# 3) Inspect getConnectedIdeClient return type / actual client used
IDEO_FILE="src/utils/ide.ts"
echo
echo "=== getConnectedIdeClient in $IDEO_FILE ==="
rg -n "export function getConnectedIdeClient" "$IDEO_FILE"
LINE2="$(rg -n "export function getConnectedIdeClient" "$IDEO_FILE" | head -n1 | cut -d: -f1)"
START2=$((LINE2-40))
END2=$((LINE2+40))
sed -n "${START2},${END2}p" "$IDEO_FILE"

Repository: claude-code-best/claude-code

Length of output: 6277


🌐 Web query:

@modelcontextprotocol/sdk client setNotificationHandler signature schema handler

💡 Result:

In the MCP TypeScript SDK (v2+), the setNotificationHandler signature has evolved from a Zod-schema-based approach to a method-string-based approach [1][2]. There are currently two primary ways to register a notification handler [2]: 1. Method String + Handler: client.setNotificationHandler(method: string, handler: (notification: any) => void | Promise); In this form, you pass the notification method string directly. The handler receives the full notification object [1]. 2. Method String + Schema + Handler: client.setNotificationHandler(method: string, paramsSchema: StandardSchemaV1, handler: (params: any) => void | Promise); This ergonomic 3-argument form (introduced in v2) allows you to pass a validator-agnostic schema (e.g., Zod, Valibot, or ArkType) [2]. In this case, the handler receives the validated params directly, with the _meta field stripped and absent parameters normalized to an empty object [1][2]. Previous versions of the SDK (v1) used Zod schemas directly as the first argument, such as: server.setNotificationHandler(LoggingMessageNotificationSchema, notification => {... }); The modern approach simplifies registration by removing the need to import individual *NotificationSchema constants for every handler [1][2].

Citations:


Remove as any from IDE at-mentioned handler registration

src/hooks/useIdeAtMentioned.ts passes AtMentionedSchema() as any into ideClient.client.setNotificationHandler(...). Replace the as any with a properly typed cast (per guidelines, use as unknown as <expected schema type> or adjust types so the registration matches setNotificationHandler’s schema/params types) so production code doesn’t lose type safety.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useIdeAtMentioned.ts` at line 50, The registration currently passes
AtMentionedSchema() as any into ideClient.client.setNotificationHandler which
strips type safety; replace the cast by using a proper typed cast such as
casting via unknown to the expected handler schema (e.g. AtMentionedSchema() as
unknown as <ExpectedNotificationSchemaType>) or refactor so the schema/handler
types align with setNotificationHandler's expected generic/parameter types;
update the call in useIdeAtMentioned.ts (around
ideClient.client.setNotificationHandler and the AtMentionedSchema() usage) to
remove "as any" and supply the correct typed cast or adjusted types so the
handler registration is type-safe.

// Register the log event handler
ideClient.client.setNotificationHandler(
LogEventSchema(),
LogEventSchema() as any,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove the as any cast in src/hooks/useIdeLogging.ts when registering setNotificationHandler.
setNotificationHandler(LogEventSchema() as any, ...) violates the “no as any in production code” rule and weakens notification payload typing—replace it with a concrete, non-any schema type (per guidelines, e.g. as unknown as <SpecificType> or a typed wrapper that matches the SDK signature).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useIdeLogging.ts` at line 30, Replace the unsafe `as any` cast used
when registering the notification handler: locate the
`setNotificationHandler(LogEventSchema() as any, ...)` call and remove `as any`,
supplying a concrete typed value instead—either cast via `as unknown as
<SpecificNotificationType>` that matches the SDK signature or create a small
typed wrapper/schema that conforms to the expected notification payload type;
ensure the replacement uses the `LogEventSchema` output typed to the handler
signature so `setNotificationHandler` receives a non-`any` typed schema.

// Register notification handler for selection_changed events
ideClient.client.setNotificationHandler(
SelectionChangedSchema(),
SelectionChangedSchema() as any,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/hooks/useIdeSelection.ts"

echo "== File exists? =="
ls -la "$FILE" || true

echo
echo "== Lines around 113 =="
nl -ba "$FILE" | sed -n '90,140p'

echo
echo "== Search for 'as any' in file =="
rg -n "as any" "$FILE" || true

echo
echo "== Locate SelectionChangedSchema usage =="
rg -n "SelectionChangedSchema" "$FILE" || true

echo
echo "== Show type/context of setNotificationHandler call =="
# Try to capture a larger context region
nl -ba "$FILE" | sed -n '100,130p'

Repository: claude-code-best/claude-code

Length of output: 255


Replace as any cast in selection notification handler setup.

SelectionChangedSchema() as any in src/hooks/useIdeSelection.ts bypasses the production “no as any” rule; replace it with a typed adapter / double assertion (as unknown as <ExpectedType>) or proper interfaces to preserve the selection notification contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useIdeSelection.ts` at line 113, The cast "SelectionChangedSchema()
as any" in the selection notification handler setup within useIdeSelection.ts
bypasses typing rules; replace it by either creating a proper typed
adapter/interface that matches the notification contract or use a safe double
assertion (e.g. "SelectionChangedSchema() as unknown as
<ExpectedNotificationType>") where <ExpectedNotificationType> is the exact type
the handler (selection notification registration) expects; update the code
around the SelectionChangedSchema() call (and the handler registration function)
to use that concrete type instead of "any".


if (mcpClient) {
mcpClient.client.setNotificationHandler(ClaudeInChromePromptNotificationSchema(), notification => {
mcpClient.client.setNotificationHandler(ClaudeInChromePromptNotificationSchema() as any, notification => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/hooks/usePromptsFromClaudeInChrome.tsx"

# Show the relevant section around the reported line
echo "---- $FILE (lines near 51) ----"
nl -ba "$FILE" | sed -n '35,80p'

# Confirm whether any "as any" exists in this file
echo "---- rg 'as any' in $FILE ----"
rg -n --fixed-string "as any" "$FILE" || true

# Find definition/typing for setNotificationHandler usage
echo "---- rg setNotificationHandler ----"
rg -n "setNotificationHandler" src/hooks/usePromptsFromClaudeInChrome.tsx src || true

# Locate ClaudeInChromePromptNotificationSchema definition and its return type
echo "---- rg ClaudeInChromePromptNotificationSchema ----"
rg -n "ClaudeInChromePromptNotificationSchema" src || true

# Locate notification schema type / exported types for MCP client if present
echo "---- rg setNotificationHandler typing in repo ----"
rg -n "setNotificationHandler\\(" . || true

Repository: claude-code-best/claude-code

Length of output: 202


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/hooks/usePromptsFromClaudeInChrome.tsx"

echo "---- $FILE (lines near 51) ----"
# Use awk for line-numbered output
awk 'NR>=40 && NR<=70 {printf "%4d  %s\n", NR, $0}' "$FILE" || true

echo "---- rg 'as any' in $FILE ----"
rg -n --fixed-string "as any" "$FILE" || true

echo "---- rg setNotificationHandler ----"
rg -n "setNotificationHandler" src || true

echo "---- rg ClaudeInChromePromptNotificationSchema ----"
rg -n "ClaudeInChromePromptNotificationSchema" src || true

Repository: claude-code-best/claude-code

Length of output: 3757


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/hooks/usePromptsFromClaudeInChrome.tsx"

echo "---- $FILE (lines 1-80) ----"
awk 'NR<=80 {printf "%4d  %s\n", NR, $0}' "$FILE" | sed -n '1,80p'

echo "---- $FILE: rg 'as any' ----"
rg -n "as any" "$FILE" || true

echo "---- rg 'lazySchema' usage/definition ----"
rg -n "lazySchema\\(" src || true

echo "---- rg setNotificationHandler typing in repo ----"
rg -n "setNotificationHandler\\(" src/services/mcp src/hooks src/entrypoints src/cli || true

Repository: claude-code-best/claude-code

Length of output: 36051


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- Inspect src/services/mcp/vscodeSdkMcp.ts around setNotificationHandler ----"
sed -n '1,140p' src/services/mcp/vscodeSdkMcp.ts

echo "---- Inspect src/services/mcp/types.ts ----"
sed -n '1,260p' src/services/mcp/types.ts

echo "---- Inspect src/services/mcp/elicitationHandler.ts around setNotificationHandler ----"
sed -n '130,240p' src/services/mcp/elicitationHandler.ts

echo "---- Inspect src/entrypoints/cli.tsx around setNotificationHandler ----"
sed -n '110,190p' src/entrypoints/cli.tsx

echo "---- Inspect src/services/mcp/useManageMCPConnections.ts around setNotificationHandler calls ----"
sed -n '470,760p' src/services/mcp/useManageMCPConnections.ts

Repository: claude-code-best/claude-code

Length of output: 31683


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- Inspect src/services/mcp/channelNotification.ts ----"
sed -n '1,220p' src/services/mcp/channelNotification.ts

echo "---- Inspect src/services/mcp/vscodeSdkMcp.ts LogEventNotificationSchema usage ----"
rg -n "LogEventNotificationSchema" src/services/mcp/vscodeSdkMcp.ts

echo "---- Inspect src/services/mcp/vscodeSdkMcp.ts for any other as any ----"
rg -n "as any" src/services/mcp/vscodeSdkMcp.ts

Repository: claude-code-best/claude-code

Length of output: 9072


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check whether node_modules exists and find MCP SDK typings
ls -la node_modules >/dev/null 2>&1 && echo "node_modules present" || echo "node_modules missing"

# Find the declaration/implementation file for the SDK client
rg -n "setNotificationHandler" node_modules/@modelcontextprotocol 2>/dev/null | head -n 50 || true
rg -n "setNotificationHandler" . --glob '*.{d.ts,ts,tsx}' | head -n 50 || true

# Try to locate the SDK client index.js / d.ts
fd -a "client" node_modules/@modelcontextprotocol 2>/dev/null | head -n 50 || true
fd -a "index.d.ts" node_modules/@modelcontextprotocol 2>/dev/null | head -n 50 || true
fd -a "*sdk*client*" node_modules/@modelcontextprotocol 2>/dev/null | head -n 50 || true

Repository: claude-code-best/claude-code

Length of output: 2334


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="src/hooks/usePromptsFromClaudeInChrome.tsx"
echo "---- $FILE line count ----"
wc -l "$FILE"

echo "---- $FILE (lines 1-220) ----"
awk 'NR<=220 {printf "%4d  %s\n", NR, $0}' "$FILE"

echo "---- packages/@ant/claude-for-chrome-mcp/src/types.ts: setNotificationHandler ----"
sed -n '150,240p' packages/@ant/claude-for-chrome-mcp/src/types.ts

echo "---- packages/@ant/claude-for-chrome-mcp/src/mcpSocketClient.ts: setNotificationHandler ----"
sed -n '220,320p' packages/@ant/claude-for-chrome-mcp/src/mcpSocketClient.ts

echo "---- packages/@ant/claude-for-chrome-mcp/src/mcpSocketPool.ts: setNotificationHandler ----"
sed -n '1,120p' packages/@ant/claude-for-chrome-mcp/src/mcpSocketPool.ts

echo "---- packages/@ant/claude-for-chrome-mcp/src/bridgeClient.ts: setNotificationHandler ----"
sed -n '240,320p' packages/@ant/claude-for-chrome-mcp/src/bridgeClient.ts

echo "---- packages/@ant/claude-for-chrome-mcp/src/mcpServer.ts: setNotificationHandler usage ----"
sed -n '60,110p' packages/@ant/claude-for-chrome-mcp/src/mcpServer.ts

Repository: claude-code-best/claude-code

Length of output: 16268


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- Find where ConnectedMCPServer is constructed (client assignment) ----"
rg -n "type: 'connected'|client: Client|client\\s*:\\s*client\\b|ConnectedMCPServer" src/services/mcp || true

echo "---- Inspect src/services/mcp/client.js (MCP client wrapper) ----"
sed -n '1,240p' src/services/mcp/client.js 2>/dev/null || true
sed -n '1,260p' src/services/mcp/client.ts 2>/dev/null || true
sed -n '1,260p' src/services/mcp/client/index.ts 2>/dev/null || true

echo "---- Inspect src/services/mcp/connection creation (useManageMCPConnections.ts) ----"
rg -n "new Client|createClient|`@modelcontextprotocol/sdk/client`|from '`@modelcontextprotocol`" src/services/mcp/useManageMCPConnections.ts src/services/mcp -S || true

Repository: claude-code-best/claude-code

Length of output: 14179


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "setNotificationHandler\\s*\\(" . --glob '*.d.ts' --glob '*.{ts,tsx}' --glob '*.js' --glob '*.mjs' || true

echo "---- look for type signature patterns: ----"
rg -n "setNotificationHandler\\s*<|setNotificationHandler\\s*\\(" . --glob '*.d.ts' || true

echo "---- look for removeNotificationHandler signature too (same typing): ----"
rg -n "removeNotificationHandler\\s*\\(" . --glob '*.d.ts' || true

Repository: claude-code-best/claude-code

Length of output: 2333


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "---- Find 'as unknown as' around setNotificationHandler ----"
rg -n "setNotificationHandler\\([^\\)]*as unknown as|as unknown as[^\\n]*setNotificationHandler" src packages --glob '*.ts' --glob '*.tsx' --glob '*.js' --glob '*.mjs' || true

echo "---- Find other Zod schema + setNotificationHandler casts (no as any) ----"
rg -n "setNotificationHandler\\(.*Schema\\(\\)" src --glob '*.ts' --glob '*.tsx' || true

echo "---- Find any type assertions patterns for notification handler schemas ----"
rg -n "PromptNotificationSchema\\(\\)|NotificationSchema\\(\\)|Channel.*NotificationSchema\\(\\)" src --glob '*.ts' --glob '*.tsx' | head -n 200

Repository: claude-code-best/claude-code

Length of output: 1325


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for f in \
  src/hooks/useIdeSelection.ts \
  src/hooks/useIdeLogging.ts \
  src/hooks/useIdeAtMentioned.ts \
  src/services/mcp/elicitationHandler.ts \
  src/entrypoints/cli.tsx \
  src/cli/print.ts
do
  echo "---- $f: setNotificationHandler contexts ----"
  rg -n "setNotificationHandler" "$f" || true
done

# Show the exact blocks around the matches for the TSX/TS files
echo "---- Dump surrounding lines for the key hooks ----"
sed -n '90,150p' src/hooks/useIdeSelection.ts
sed -n '1,90p' src/hooks/useIdeLogging.ts
sed -n '1,90p' src/hooks/useIdeAtMentioned.ts
sed -n '150,220p' src/services/mcp/elicitationHandler.ts
sed -n '130,170p' src/entrypoints/cli.tsx
sed -n '4940,4985p' src/cli/print.ts
sed -n '5025,5070p' src/cli/print.ts

Repository: claude-code-best/claude-code

Length of output: 13548


Remove as any from Chrome MCP notification handler registration

src/hooks/usePromptsFromClaudeInChrome.tsx (line 51) uses ClaudeInChromePromptNotificationSchema() as any in setNotificationHandler, violating the “no as any in production code” rule. Replace with a type-safe as unknown as <expected schema/type> assertion (or define the correct notification/params type) so the handler’s payload stays strictly typed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/usePromptsFromClaudeInChrome.tsx` at line 51, The call to
mcpClient.client.setNotificationHandler currently uses
ClaudeInChromePromptNotificationSchema() as any which bypasses type safety;
replace the unsafe cast by asserting the schema to the correct typed shape
(e.g., use ClaudeInChromePromptNotificationSchema() as unknown as
ExpectedNotificationType) or define the proper notification/params interface and
cast to that instead so the notification handler registered via
mcpClient.client.setNotificationHandler maintains strict payload typing; update
types accordingly where ClaudeInChromePromptNotificationSchema and the handler
callback are declared.

@mintlify
Copy link
Copy Markdown

mintlify Bot commented May 28, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ccb-863780bf 🟢 Ready View Preview May 28, 2026, 1:28 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@claude-code-best claude-code-best merged commit a91653a into main May 28, 2026
7 checks passed
tinyplan pushed a commit to tinyplan/claude-code that referenced this pull request May 29, 2026
* refactor: remove tab/quote normalization from FileEditTool

* fix: resolve pre-existing typecheck errors (zod v4 compat + RCS web exclude)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant