MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / getTools

Method getTools

src/mcp/tools.ts:2400–2472  ·  view source on GitHub ↗

* Get tool definitions with dynamic descriptions based on project size. * The codegraph_explore tool description includes a budget recommendation * scaled to the number of indexed files. Honors the CODEGRAPH_MCP_TOOLS * allowlist so a trimmed surface is reflected in ListTools.

()

Source from the content-addressed store, hash-verified

2398 * allowlist so a trimmed surface is reflected in ListTools.
2399 */
2400 getTools(): ToolDefinition[] {
2401 const allow = this.toolAllowlist();
2402 // No explicit allowlist → the default 4-tool surface (see
2403 // DEFAULT_MCP_TOOLS for the evidence). An allowlist replaces the
2404 // default entirely, so any defined tool can be re-enabled.
2405 let visible = allow
2406 ? tools.filter(t => allow.has(t.name.replace(/^codegraph_/, '')))
2407 : tools.filter(t => DEFAULT_MCP_TOOLS.has(t.name.replace(/^codegraph_/, '')));
2408 // No default project loaded → no-root-index case (#993): a gateway server
2409 // started outside any repo, or a monorepo root whose indexes live in
2410 // sub-projects. With nothing to fall back to, EVERY call needs an explicit
2411 // projectPath, so mark it required in the schema — a high-salience nudge the
2412 // agent acts on, where SERVER_INSTRUCTIONS_NO_ROOT_INDEX's prose alone
2413 // wasn't enough (the reporter had to add an AGENTS.md note). `this.cg` is
2414 // settled by `retryInitIfNeeded()` before `handleToolsList` calls us, so a
2415 // null here means "genuinely no default", not a startup race. When a default
2416 // IS open we leave projectPath optional (below): a bare call falls back to
2417 // it, exactly as in the common single-project launch.
2418 if (!this.cg) return withRequiredProjectPath(visible);
2419
2420 try {
2421 const stats = this.cg.getStats();
2422 const budget = getExploreBudget(stats.fileCount);
2423
2424 // Tiny-repo tool gating: on projects under TINY_REPO_FILE_THRESHOLD
2425 // files, only expose the core trio (search, node, explore) — one
2426 // below even the 4-tool default: at this scale callers, too, reduces
2427 // to one grep. (Historical note: the audit below ran when context and
2428 // trace still existed; its "5 core tools" are today's trio.)
2429 //
2430 // n=2 audits ruled out cutting below 5 tools:
2431 // - 3-tool gate (search + context + trace): cost regressed on
2432 // cobra/ky/sinatra. The agent fell back to raw Reads to cover
2433 // what codegraph_node + codegraph_explore would have answered.
2434 // - 1-tool gate (search only): catastrophic regression — express
2435 // went from -43% WIN to +107% LOSS. With only search, the agent
2436 // can't navigate the call graph structurally and reads everything.
2437 //
2438 // 5 is the empirical lower bound. Tools beyond search/context/
2439 // node/explore/trace pay overhead that the agent doesn't recoup
2440 // on tiny-repo flow questions.
2441 // ITER4: raise threshold 150 → 500 so single-file frameworks
2442 // (sinatra at 159, slim_framework around 200) also get the
2443 // 5-tool surface. The empirical 5-tool floor was set on <150
2444 // probes; iter3 measurement showed sinatra is structurally the
2445 // SAME problem as cobra (single-file WITHOUT-arm Read wins),
2446 // so it deserves the same gating.
2447 const TINY_REPO_FILE_THRESHOLD = 500;
2448 const TINY_REPO_CORE_TOOLS = new Set([
2449 'codegraph_explore',
2450 'codegraph_search',
2451 'codegraph_node',
2452 ]);
2453 // The gate trims only the default surface. An explicit
2454 // CODEGRAPH_MCP_TOOLS allowlist is the operator's choice and wins on
2455 // any repo size, so every tool it names stays listed (#3462).
2456 if (!allow && stats.fileCount < TINY_REPO_FILE_THRESHOLD) {
2457 visible = visible.filter(t => TINY_REPO_CORE_TOOLS.has(t.name));

Callers 4

handleToolsListMethod · 0.80
listedFunction · 0.80

Calls 6

toolAllowlistMethod · 0.95
withRequiredProjectPathFunction · 0.85
getExploreBudgetFunction · 0.85
hasMethod · 0.80
mapMethod · 0.80
getStatsMethod · 0.45

Tested by 1

listedFunction · 0.64