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

Method getTools

src/mcp/tools.ts:961–1030  ·  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

959 * allowlist so a trimmed surface is reflected in ListTools.
960 */
961 getTools(): ToolDefinition[] {
962 const allow = this.toolAllowlist();
963 // No explicit allowlist → the default 4-tool surface (see
964 // DEFAULT_MCP_TOOLS for the evidence). An allowlist replaces the
965 // default entirely, so any defined tool can be re-enabled.
966 let visible = allow
967 ? tools.filter(t => allow.has(t.name.replace(/^codegraph_/, '')))
968 : tools.filter(t => DEFAULT_MCP_TOOLS.has(t.name.replace(/^codegraph_/, '')));
969 // No default project loaded → no-root-index case (#993): a gateway server
970 // started outside any repo, or a monorepo root whose indexes live in
971 // sub-projects. With nothing to fall back to, EVERY call needs an explicit
972 // projectPath, so mark it required in the schema — a high-salience nudge the
973 // agent acts on, where SERVER_INSTRUCTIONS_NO_ROOT_INDEX's prose alone
974 // wasn't enough (the reporter had to add an AGENTS.md note). `this.cg` is
975 // settled by `retryInitIfNeeded()` before `handleToolsList` calls us, so a
976 // null here means "genuinely no default", not a startup race. When a default
977 // IS open we leave projectPath optional (below): a bare call falls back to
978 // it, exactly as in the common single-project launch.
979 if (!this.cg) return withRequiredProjectPath(visible);
980
981 try {
982 const stats = this.cg.getStats();
983 const budget = getExploreBudget(stats.fileCount);
984
985 // Tiny-repo tool gating: on projects under TINY_REPO_FILE_THRESHOLD
986 // files, only expose the core trio (search, node, explore) — one
987 // below even the 4-tool default: at this scale callers, too, reduces
988 // to one grep. (Historical note: the audit below ran when context and
989 // trace still existed; its "5 core tools" are today's trio.)
990 //
991 // n=2 audits ruled out cutting below 5 tools:
992 // - 3-tool gate (search + context + trace): cost regressed on
993 // cobra/ky/sinatra. The agent fell back to raw Reads to cover
994 // what codegraph_node + codegraph_explore would have answered.
995 // - 1-tool gate (search only): catastrophic regression — express
996 // went from -43% WIN to +107% LOSS. With only search, the agent
997 // can't navigate the call graph structurally and reads everything.
998 //
999 // 5 is the empirical lower bound. Tools beyond search/context/
1000 // node/explore/trace pay overhead that the agent doesn't recoup
1001 // on tiny-repo flow questions.
1002 // ITER4: raise threshold 150 → 500 so single-file frameworks
1003 // (sinatra at 159, slim_framework around 200) also get the
1004 // 5-tool surface. The empirical 5-tool floor was set on <150
1005 // probes; iter3 measurement showed sinatra is structurally the
1006 // SAME problem as cobra (single-file WITHOUT-arm Read wins),
1007 // so it deserves the same gating.
1008 const TINY_REPO_FILE_THRESHOLD = 500;
1009 const TINY_REPO_CORE_TOOLS = new Set([
1010 'codegraph_explore',
1011 'codegraph_search',
1012 'codegraph_node',
1013 ]);
1014 if (stats.fileCount < TINY_REPO_FILE_THRESHOLD) {
1015 visible = visible.filter(t => TINY_REPO_CORE_TOOLS.has(t.name));
1016 }
1017
1018 return visible.map(tool => {

Callers 4

handleToolsListMethod · 0.80
listedFunction · 0.80

Calls 5

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

Tested by 1

listedFunction · 0.64