Skip to content

fix: MCP error -32603: Cannot read properties of undefined (reading 'toLowerCase') #2054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

caizhiqiangzeyuan
Copy link

@caizhiqiangzeyuan caizhiqiangzeyuan commented Jun 9, 2025

fix the bug 2044

Description

1.Safer Query Handling:
Since query is typed as string, we skip unnecessary safety checks and directly process it with lowerQuery = query.trim().toLowerCase()

2.Extracted Matching Logic:
Created reusable checkMatch helper that encapsulates:
Type checking (typeof text === 'string')
Normalization (trim()+toLowerCase())
Search logic (includes())

3.Performance Optimizations:
Pre-computes lowerQuery once instead of per-filter iteration
Eliminates repeated arrow function creation in array operations

4.Improved Readability:
Flattened nested conditions
Clear separation of concerns between filtering steps
More descriptive variable names

Server Details

  • Server: The search_nodes function in the MCP memory server fails with a JavaScript error when attempting to search the knowledge graph. The error indicates that the search function is trying to call .toLowerCase() on an undefined value without proper input validation.
  • Changes to: Map to safe lower case

Motivation and Context

bug address

How Has This Been Tested?

Yes, Cursor and Claude.

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

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