servers icon indicating copy to clipboard operation
servers copied to clipboard

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

Open caizhiqiangzeyuan opened this issue 7 months ago • 0 comments

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

  • [x] 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

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

Additional context

caizhiqiangzeyuan avatar Jun 09 '25 14:06 caizhiqiangzeyuan