MCPcopy
hub / github.com/21st-dev/1code / getAllCodexMcpConfigHandler

Function getAllCodexMcpConfigHandler

src/main/lib/trpc/routers/codex.ts:965–1027  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

963}
964
965export async function getAllCodexMcpConfigHandler() {
966 const globalSnapshot = await resolveCodexMcpSnapshot({ includeTools: true })
967 const globalServers = globalSnapshot.groups[0]?.mcpServers || []
968 const globalByName = new Map(
969 globalServers.map((server) => [server.name, getCodexServerIdentity(server)]),
970 )
971
972 const groups: CodexMcpSnapshot["groups"] = [...globalSnapshot.groups]
973
974 // Only enumerate projects the app knows about (DB-backed projects).
975 // Do not scan ~/.codex/config.toml project entries.
976 const projectPathSet = new Set<string>()
977
978 try {
979 const db = getDatabase()
980 const dbProjects = db.select({ path: projectsTable.path }).from(projectsTable).all()
981 for (const project of dbProjects) {
982 if (typeof project.path === "string" && project.path.trim().length > 0) {
983 projectPathSet.add(project.path)
984 }
985 }
986 } catch (error) {
987 console.error("[codex.getAllMcpConfig] Failed to read projects from DB:", error)
988 }
989
990 const projectPaths = [...projectPathSet].sort((a, b) => a.localeCompare(b))
991 const projectResults = await Promise.allSettled(
992 projectPaths.map(async (projectPath) => {
993 const projectSnapshot = await resolveCodexMcpSnapshot({
994 lookupPath: projectPath,
995 includeTools: true,
996 })
997 const effectiveServers = projectSnapshot.groups[0]?.mcpServers || []
998 const projectOnlyServers = effectiveServers.filter((server) => {
999 const globalIdentity = globalByName.get(server.name)
1000 if (!globalIdentity) return true
1001 return globalIdentity !== getCodexServerIdentity(server)
1002 })
1003
1004 if (projectOnlyServers.length === 0) {
1005 return null
1006 }
1007
1008 return {
1009 groupName: basename(projectPath) || projectPath,
1010 projectPath,
1011 mcpServers: projectOnlyServers,
1012 }
1013 }),
1014 )
1015
1016 for (const result of projectResults) {
1017 if (result.status === "fulfilled" && result.value) {
1018 groups.push(result.value)
1019 continue
1020 }
1021 if (result.status === "rejected") {
1022 console.error("[codex.getAllMcpConfig] Failed to resolve project MCP snapshot:", result.reason)

Callers 2

index.tsFile · 0.90
codex.tsFile · 0.85

Calls 4

getDatabaseFunction · 0.90
resolveCodexMcpSnapshotFunction · 0.85
getCodexServerIdentityFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected