callees/impact/files/status stay fully functional (handlers, CLI, library
API untouched; CODEGRAPH_MCP_TOOLS re-enables any) but are no longer
LISTED by default. Evidence: codegraph_impact appears in zero recorded
eval runs ever; its blast-radius info already arrives inline on explore
(Blast radius section) and node (dependents note). callees is redundant
by construction (a symbol's body IS its callee list). files/status
"reduce to one grep" per the tiny-repo audit, and staleness banners
already inline pending-sync. callers stays: exhaustive call-site
enumeration (incl. callback registrations, per-definition sections) is
the one job explore/node don't replicate. Fewer tools = fewer mis-picks
+ ~300 schema tokens saved per session; presence itself steers.
server-instructions rewritten around the 4-tool surface ("what does X
call" → node body+trail; "what breaks" → callers + inline blast radius).
Tiny-repo gate unchanged (its trio ⊆ the default set); stale gate
comment corrected (context/trace are long gone — its "5 core tools" are
today's trio).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
70 lines
2.7 KiB
TypeScript
70 lines
2.7 KiB
TypeScript
/**
|
|
* CODEGRAPH_MCP_TOOLS allowlist — lets an operator (or an A/B harness) trim the
|
|
* exposed MCP tool surface without touching the client config. Inert when unset.
|
|
* Filtering happens in ListTools (getTools) and is enforced again on execute().
|
|
*/
|
|
import { describe, it, expect, afterEach } from 'vitest';
|
|
import { ToolHandler } from '../src/mcp/tools';
|
|
|
|
const ENV = 'CODEGRAPH_MCP_TOOLS';
|
|
|
|
describe('CODEGRAPH_MCP_TOOLS allowlist', () => {
|
|
const original = process.env[ENV];
|
|
afterEach(() => {
|
|
if (original === undefined) delete process.env[ENV];
|
|
else process.env[ENV] = original;
|
|
});
|
|
|
|
const listed = () => new ToolHandler(null).getTools().map(t => t.name).sort();
|
|
|
|
it('exposes the default 4-tool surface when unset', () => {
|
|
delete process.env[ENV];
|
|
// The default set (see DEFAULT_MCP_TOOLS): explore + node are the
|
|
// validated workhorses, search the cheap lookup, callers the one
|
|
// irreplaceable enumerator. callees/impact/files/status stay defined
|
|
// and executable but unlisted — impact appeared in ZERO recorded runs.
|
|
expect(listed()).toEqual([
|
|
'codegraph_callers',
|
|
'codegraph_explore',
|
|
'codegraph_node',
|
|
'codegraph_search',
|
|
]);
|
|
});
|
|
|
|
it('re-enables an unlisted tool via the allowlist (impact)', () => {
|
|
process.env[ENV] = 'explore,impact';
|
|
expect(listed()).toEqual(['codegraph_explore', 'codegraph_impact']);
|
|
});
|
|
|
|
it('filters ListTools to the allowlisted short names', () => {
|
|
process.env[ENV] = 'explore,search,node';
|
|
expect(listed()).toEqual(['codegraph_explore', 'codegraph_node', 'codegraph_search']);
|
|
});
|
|
|
|
it('accepts fully-qualified codegraph_ names and ignores whitespace', () => {
|
|
process.env[ENV] = ' codegraph_explore , search ';
|
|
expect(listed()).toEqual(['codegraph_explore', 'codegraph_search']);
|
|
});
|
|
|
|
it('treats an empty/whitespace value as unset (default surface)', () => {
|
|
process.env[ENV] = ' ';
|
|
expect(listed()).toHaveLength(4);
|
|
expect(listed()).toContain('codegraph_explore');
|
|
});
|
|
|
|
it('rejects a disabled tool on execute (defense in depth)', async () => {
|
|
process.env[ENV] = 'node';
|
|
const res = await new ToolHandler(null).execute('codegraph_explore', {});
|
|
expect(res.isError).toBe(true);
|
|
expect(res.content[0].text).toMatch(/disabled via CODEGRAPH_MCP_TOOLS/);
|
|
});
|
|
|
|
it('lets an allowlisted tool past the guard', async () => {
|
|
process.env[ENV] = 'search';
|
|
// No CodeGraph attached, so it fails *after* the allowlist guard — the
|
|
// "disabled" message must NOT appear, proving the guard passed it through.
|
|
const res = await new ToolHandler(null).execute('codegraph_search', { query: 'x' });
|
|
expect(res.content[0].text).not.toMatch(/disabled via CODEGRAPH_MCP_TOOLS/);
|
|
});
|
|
});
|