Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/memory/__tests__/search-nodes-schema.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, it, expect } from 'vitest';
import { SearchNodesQuerySchema, SEARCH_QUERY_MAX_LENGTH } from '../index.js';

describe('search_nodes input schema', () => {
it('should accept a normal query', () => {
expect(SearchNodesQuerySchema.safeParse('Alice').success).toBe(true);
expect(SearchNodesQuerySchema.safeParse('works at Acme Corp').success).toBe(true);
});

it('should accept a query at exactly the max length', () => {
const atLimit = 'a'.repeat(SEARCH_QUERY_MAX_LENGTH);
expect(SearchNodesQuerySchema.safeParse(atLimit).success).toBe(true);
});

it('should reject a query longer than the max length', () => {
const oversized = 'a'.repeat(SEARCH_QUERY_MAX_LENGTH + 1);
const result = SearchNodesQuerySchema.safeParse(oversized);
expect(result.success).toBe(false);
});

it('should still reject non-string input', () => {
expect(SearchNodesQuerySchema.safeParse(42).success).toBe(false);
expect(SearchNodesQuerySchema.safeParse(null).success).toBe(false);
});
});
9 changes: 8 additions & 1 deletion src/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,21 @@ server.registerTool(
}
);

export const SEARCH_QUERY_MAX_LENGTH = 2048;

export const SearchNodesQuerySchema = z
.string()
.max(SEARCH_QUERY_MAX_LENGTH)
.describe("The search query to match against entity names, types, and observation content");

// Register search_nodes tool
server.registerTool(
"search_nodes",
{
title: "Search Nodes",
description: "Search for nodes in the knowledge graph based on a query",
inputSchema: {
query: z.string().describe("The search query to match against entity names, types, and observation content")
query: SearchNodesQuerySchema
},
outputSchema: {
entities: z.array(EntitySchema),
Expand Down