MCPcopy
hub / github.com/Doorman11991/smallcode / initCodeGraph

Function initCodeGraph

bin/mcp_bridge.js:99–158  ·  view source on GitHub ↗
(version)

Source from the content-addressed store, hash-verified

97}
98
99async function initCodeGraph(version) {
100 const child = startCodeGraphMCP();
101 if (!child) return false;
102
103 // Use actual package version if not provided
104 let resolvedVersion = version;
105 if (!resolvedVersion) {
106 try {
107 const pkg = require('../package.json');
108 resolvedVersion = pkg.version;
109 } catch {}
110 if (!resolvedVersion) resolvedVersion = '0.9.2';
111 }
112
113 const initResult = await mcpCall('initialize', {
114 protocolVersion: '2024-11-05',
115 capabilities: {},
116 clientInfo: { name: 'smallcode', version: resolvedVersion },
117 });
118
119 if (!initResult) {
120 mcpProcess = null;
121 return false;
122 }
123
124 const listResult = await mcpCall('tools/call', { name: 'list_repos', arguments: {} });
125 let alreadyIndexed = 0;
126 if (listResult && listResult.content) {
127 try {
128 const data = JSON.parse(listResult.content[0]?.text || '{}');
129 alreadyIndexed = data.total || 0;
130 } catch {}
131 }
132
133 if (alreadyIndexed > 0) return true;
134
135 const cwd = process.cwd();
136 const subProjects = [];
137 try {
138 const entries = fs.readdirSync(cwd, { withFileTypes: true });
139 for (const entry of entries) {
140 if (!entry.isDirectory()) continue;
141 if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'venv') continue;
142 const subPath = path.join(cwd, entry.name);
143 const markers = ['package.json', 'Cargo.toml', 'go.mod', 'pyproject.toml', 'src'];
144 const hasMarker = markers.some(m => fs.existsSync(path.join(subPath, m)));
145 if (hasMarker) subProjects.push({ path: subPath, name: entry.name });
146 }
147 } catch {}
148
149 if (subProjects.length > 0) {
150 for (const proj of subProjects.slice(0, 8)) {
151 await mcpCall('tools/call', { name: 'index_repo', arguments: { path: proj.path, name: proj.name } });
152 }
153 } else {
154 await mcpCall('tools/call', { name: 'index_repo', arguments: { path: cwd, name: path.basename(cwd) } });
155 }
156

Callers 1

runTUIFunction · 0.85

Calls 2

startCodeGraphMCPFunction · 0.85
mcpCallFunction · 0.85

Tested by

no test coverage detected