MCPcopy
hub / github.com/codeaashu/claude-code / readClaudeDesktopMcpServers

Function readClaudeDesktopMcpServers

src/utils/claudeDesktop.ts:98–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96}
97
98export async function readClaudeDesktopMcpServers(): Promise<
99 Record<string, McpServerConfig>
100> {
101 if (!SUPPORTED_PLATFORMS.includes(getPlatform())) {
102 throw new Error(
103 'Unsupported platform - Claude Desktop integration only works on macOS and WSL.',
104 )
105 }
106 try {
107 const configPath = await getClaudeDesktopConfigPath()
108
109 let configContent: string
110 try {
111 configContent = await readFile(configPath, { encoding: 'utf8' })
112 } catch (e: unknown) {
113 const code = getErrnoCode(e)
114 if (code === 'ENOENT') {
115 return {}
116 }
117 throw e
118 }
119
120 const config = safeParseJSON(configContent)
121
122 if (!config || typeof config !== 'object') {
123 return {}
124 }
125
126 const mcpServers = (config as Record<string, unknown>).mcpServers
127 if (!mcpServers || typeof mcpServers !== 'object') {
128 return {}
129 }
130
131 const servers: Record<string, McpServerConfig> = {}
132
133 for (const [name, serverConfig] of Object.entries(
134 mcpServers as Record<string, unknown>,
135 )) {
136 if (!serverConfig || typeof serverConfig !== 'object') {
137 continue
138 }
139
140 const result = McpStdioServerConfigSchema().safeParse(serverConfig)
141
142 if (result.success) {
143 servers[name] = result.data
144 }
145 }
146
147 return servers
148 } catch (error) {
149 logError(error)
150 return {}
151 }
152}
153

Callers 1

mcpAddFromDesktopHandlerFunction · 0.85

Calls 6

getPlatformFunction · 0.85
readFileFunction · 0.85
getErrnoCodeFunction · 0.85
entriesMethod · 0.80
logErrorFunction · 0.70

Tested by

no test coverage detected