Skip to content

Commit a09fe5d

Browse files
authored
Merge pull request #16 from mkreyman/fix/context-get-pagination
fix: Always apply pagination to context_get to prevent token limit errors
2 parents 1e087d3 + fb9b917 commit a09fe5d

File tree

3 files changed

+6
-526
lines changed

3 files changed

+6
-526
lines changed

jest.config.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@ module.exports = {
33
preset: 'ts-jest',
44
testEnvironment: 'node',
55
testMatch: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],
6-
collectCoverageFrom: [
7-
'src/**/*.ts',
8-
'!src/**/*.d.ts',
9-
'!src/**/__tests__/**',
10-
'!src/index.ts',
11-
'!src/server.ts',
12-
],
6+
collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts', '!src/**/__tests__/**', '!src/index.ts'],
137
coverageThreshold: {
148
global: {
159
branches: 80,
@@ -36,4 +30,4 @@ module.exports = {
3630
detectOpenHandles: true,
3731
maxWorkers: 1,
3832
globalTeardown: './src/test-helpers/global-teardown.js',
39-
};
33+
};

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)