MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / discoverSources

Function discoverSources

src/commands/migrate.ts:247–313  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

245
246/** Discover every available migration source on the current machine. */
247export function discoverSources(): MigrationSource[] {
248 const sources: MigrationSource[] = [];
249
250 const claudeCodeUserPath = path.join(
251 os.homedir(),
252 ".claude",
253 "settings.json",
254 );
255 const claudeCodeUserServers = readMcpServers(claudeCodeUserPath);
256 if (Object.keys(claudeCodeUserServers).length > 0) {
257 sources.push({
258 id: "claude-code-user",
259 label: sourceLabel("claude-code-user"),
260 configPath: claudeCodeUserPath,
261 servers: claudeCodeUserServers,
262 });
263 }
264
265 // ~/.claude.json can hold entries in two layers: the root mcpServers block
266 // (user-scope, written by `claude mcp add -s user …`) and per-project
267 // entries under `projects.<path>.mcpServers`. Both can define a server with
268 // the same name; Claude treats the per-project one as the override. To
269 // avoid showing the same name twice in the picker, we collect both layers
270 // and drop any project-layer name that the root layer also has.
271 const claudeCodeJsonPath = path.join(os.homedir(), ".claude.json");
272 const rootServers = readClaudeCodeRootServers();
273 const projectServers = readClaudeCodeProjectServers();
274 const rootNames = new Set(Object.keys(rootServers));
275
276 if (Object.keys(rootServers).length > 0) {
277 sources.push({
278 id: "claude-code-json-user",
279 label: sourceLabel("claude-code-json-user"),
280 configPath: claudeCodeJsonPath,
281 servers: rootServers,
282 });
283 }
284
285 if (Object.keys(projectServers).length > 0) {
286 const deduped: Record<string, McpServerConfig> = {}
287 for (const [name, cfg] of Object.entries(projectServers)) {
288 if (rootNames.has(name)) continue
289 deduped[name] = cfg
290 }
291 if (Object.keys(deduped).length > 0) {
292 sources.push({
293 id: "claude-code-project",
294 label: sourceLabel("claude-code-project"),
295 configPath: claudeCodeJsonPath,
296 servers: deduped,
297 })
298 }
299 }
300
301 const claudeDesktopPath = claudeDesktopConfigPath();
302 const claudeDesktopServers = readMcpServers(claudeDesktopPath);
303 if (Object.keys(claudeDesktopServers).length > 0) {
304 sources.push({

Callers 2

runMigrateFunction · 0.85
listMigrationEntriesFunction · 0.85

Calls 5

readMcpServersFunction · 0.85
sourceLabelFunction · 0.85
claudeDesktopConfigPathFunction · 0.85

Tested by

no test coverage detected