* 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.
()
| 918 | * allowlist so a trimmed surface is reflected in ListTools. |
| 919 | */ |
| 920 | getTools(): ToolDefinition[] { |
| 921 | const allow = this.toolAllowlist(); |
| 922 | // No explicit allowlist → the default 4-tool surface (see |
| 923 | // DEFAULT_MCP_TOOLS for the evidence). An allowlist replaces the |
| 924 | // default entirely, so any defined tool can be re-enabled. |
| 925 | let visible = allow |
| 926 | ? tools.filter(t => allow.has(t.name.replace(/^codegraph_/, ''))) |
| 927 | : tools.filter(t => DEFAULT_MCP_TOOLS.has(t.name.replace(/^codegraph_/, ''))); |
| 928 | // No default project loaded → no-root-index case (#993): a gateway server |
| 929 | // started outside any repo, or a monorepo root whose indexes live in |
| 930 | // sub-projects. With nothing to fall back to, EVERY call needs an explicit |
| 931 | // projectPath, so mark it required in the schema — a high-salience nudge the |
| 932 | // agent acts on, where SERVER_INSTRUCTIONS_NO_ROOT_INDEX's prose alone |
| 933 | // wasn't enough (the reporter had to add an AGENTS.md note). `this.cg` is |
| 934 | // settled by `retryInitIfNeeded()` before `handleToolsList` calls us, so a |
| 935 | // null here means "genuinely no default", not a startup race. When a default |
| 936 | // IS open we leave projectPath optional (below): a bare call falls back to |
| 937 | // it, exactly as in the common single-project launch. |
| 938 | if (!this.cg) return withRequiredProjectPath(visible); |
| 939 | |
| 940 | try { |
| 941 | const stats = this.cg.getStats(); |
| 942 | const budget = getExploreBudget(stats.fileCount); |
| 943 | |
| 944 | // Tiny-repo tool gating: on projects under TINY_REPO_FILE_THRESHOLD |
| 945 | // files, only expose the core trio (search, node, explore) — one |
| 946 | // below even the 4-tool default: at this scale callers, too, reduces |
| 947 | // to one grep. (Historical note: the audit below ran when context and |
| 948 | // trace still existed; its "5 core tools" are today's trio.) |
| 949 | // |
| 950 | // n=2 audits ruled out cutting below 5 tools: |
| 951 | // - 3-tool gate (search + context + trace): cost regressed on |
| 952 | // cobra/ky/sinatra. The agent fell back to raw Reads to cover |
| 953 | // what codegraph_node + codegraph_explore would have answered. |
| 954 | // - 1-tool gate (search only): catastrophic regression — express |
| 955 | // went from -43% WIN to +107% LOSS. With only search, the agent |
| 956 | // can't navigate the call graph structurally and reads everything. |
| 957 | // |
| 958 | // 5 is the empirical lower bound. Tools beyond search/context/ |
| 959 | // node/explore/trace pay overhead that the agent doesn't recoup |
| 960 | // on tiny-repo flow questions. |
| 961 | // ITER4: raise threshold 150 → 500 so single-file frameworks |
| 962 | // (sinatra at 159, slim_framework around 200) also get the |
| 963 | // 5-tool surface. The empirical 5-tool floor was set on <150 |
| 964 | // probes; iter3 measurement showed sinatra is structurally the |
| 965 | // SAME problem as cobra (single-file WITHOUT-arm Read wins), |
| 966 | // so it deserves the same gating. |
| 967 | const TINY_REPO_FILE_THRESHOLD = 500; |
| 968 | const TINY_REPO_CORE_TOOLS = new Set([ |
| 969 | 'codegraph_explore', |
| 970 | 'codegraph_search', |
| 971 | 'codegraph_node', |
| 972 | ]); |
| 973 | if (stats.fileCount < TINY_REPO_FILE_THRESHOLD) { |
| 974 | visible = visible.filter(t => TINY_REPO_CORE_TOOLS.has(t.name)); |
| 975 | } |
| 976 | |
| 977 | return visible.map(tool => { |