Skip to content
Merged
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
14 changes: 14 additions & 0 deletions __tests__/security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ describe('MCP Input Validation', () => {
expect(result.content[0].text).toContain('non-empty string');
});

it('should truncate oversized codegraph_context output', async () => {
const oversizedContext = Array.from({ length: 400 }, (_, i) => `line-${i} ${'x'.repeat(80)}`).join('\n');
const fakeCg = {
buildContext: async () => oversizedContext,
};
const fakeHandler = new ToolHandler(fakeCg as unknown as CodeGraph);

const result = await fakeHandler.execute('codegraph_context', { task: 'find example' });

expect(result.isError).toBeFalsy();
expect(result.content[0].text.length).toBeLessThan(oversizedContext.length);
expect(result.content[0].text).toContain('... (output truncated)');
});

it('should reject non-string symbol in codegraph_impact', async () => {
const result = await handler.execute('codegraph_impact', { symbol: [] });
expect(result.isError).toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions src/mcp/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,11 @@ export class ToolHandler {

// buildContext returns string when format is 'markdown'
if (typeof context === 'string') {
return this.textResult(context + reminder);
return this.textResult(this.truncateOutput(context + reminder));
}

// If it returns TaskContext, format it
return this.textResult(this.formatTaskContext(context) + reminder);
return this.textResult(this.truncateOutput(this.formatTaskContext(context) + reminder));
}

/**
Expand Down