Skip to content

Commit e788691

Browse files
committed
fix: Always apply pagination to context_get to prevent token limit errors
- Modified context_get handler to always use the enhanced query path - Ensures consistent pagination with default limit of 100 items - Prevents MCP token limit errors when querying large channels - Removes the unpaginated simple query path that was causing issues This fixes the issue where context_get would return all items in a channel without pagination, causing responses to exceed the 25000 token limit.
1 parent 1e087d3 commit e788691

File tree

1 file changed

+4
-67
lines changed

1 file changed

+4
-67
lines changed

src/index.ts

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -651,21 +651,10 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
651651
} = args;
652652
const targetSessionId = specificSessionId || currentSessionId || ensureSession();
653653

654-
// Use enhanced query for complex queries or when we need pagination
655-
// This ensures default pagination is applied when needed
656-
if (
657-
sort !== undefined ||
658-
limit !== undefined ||
659-
offset ||
660-
createdAfter ||
661-
createdBefore ||
662-
keyPattern ||
663-
priorities ||
664-
channel ||
665-
channels ||
666-
includeMetadata ||
667-
(!key && !category) // If listing all items without filters, use pagination
668-
) {
654+
// Always use enhanced query to ensure consistent pagination
655+
// This prevents token limit issues when querying large datasets
656+
// Removed the conditional check since we always want to use this path
657+
{
669658
const result = repositories.contexts.queryEnhanced({
670659
sessionId: targetSessionId,
671660
key,
@@ -798,58 +787,6 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
798787
],
799788
};
800789
}
801-
802-
// Backward compatible simple queries
803-
let rows;
804-
if (key) {
805-
// Use getAccessibleByKey to respect privacy
806-
const item = repositories.contexts.getAccessibleByKey(targetSessionId, key);
807-
rows = item ? [item] : [];
808-
} else {
809-
// Use getAccessibleItems for listing
810-
rows = repositories.contexts.getAccessibleItems(targetSessionId, { category });
811-
}
812-
813-
if (rows.length === 0) {
814-
return {
815-
content: [
816-
{
817-
type: 'text',
818-
text: 'No matching context found',
819-
},
820-
],
821-
};
822-
}
823-
824-
if (key && rows.length === 1) {
825-
// Single item requested
826-
const item = rows[0] as any;
827-
return {
828-
content: [
829-
{
830-
type: 'text',
831-
text: item.value,
832-
},
833-
],
834-
};
835-
}
836-
837-
// Multiple items
838-
const items = rows
839-
.map(
840-
(r: any) =>
841-
`• [${r.priority}] ${r.key}: ${r.value.substring(0, 100)}${r.value.length > 100 ? '...' : ''}`
842-
)
843-
.join('\n');
844-
845-
return {
846-
content: [
847-
{
848-
type: 'text',
849-
text: `Found ${rows.length} context items:\n\n${items}`,
850-
},
851-
],
852-
};
853790
}
854791

855792
// File Caching

0 commit comments

Comments
 (0)