diff --git a/src/main/services/MCPService.ts b/src/main/services/MCPService.ts index 21a518aa..e8a0807b 100644 --- a/src/main/services/MCPService.ts +++ b/src/main/services/MCPService.ts @@ -2,6 +2,7 @@ import os from 'node:os' import path from 'node:path' import { isLinux, isMac, isWin } from '@main/constant' +import { makeSureDirExists } from '@main/utils' import { getBinaryName, getBinaryPath } from '@main/utils/process' import { Client } from '@modelcontextprotocol/sdk/client/index.js' import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js' @@ -82,12 +83,18 @@ class McpService { args.unshift('x') } } - if (server.registryUrl) { server.env = { ...server.env, NPM_CONFIG_REGISTRY: server.registryUrl } + + // if the server name is mcp-auto-install, use the mcp-registry.json file in the bin directory + if (server.name === 'mcp-auto-install') { + const binPath = await getBinaryPath() + makeSureDirExists(binPath) + server.env.MCP_REGISTRY_PATH = path.join(binPath, 'mcp-registry.json') + } } } else if (server.command === 'uvx' || server.command === 'uv') { cmd = await getBinaryPath(server.command) diff --git a/src/main/utils/index.ts b/src/main/utils/index.ts index 29595621..4a6fde67 100644 --- a/src/main/utils/index.ts +++ b/src/main/utils/index.ts @@ -46,3 +46,9 @@ export function dumpPersistState() { export const runAsyncFunction = async (fn: () => void) => { await fn() } + +export function makeSureDirExists(dir: string) { + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }) + } +} diff --git a/src/main/utils/process.ts b/src/main/utils/process.ts index e10cdc4b..36a0d731 100644 --- a/src/main/utils/process.ts +++ b/src/main/utils/process.ts @@ -42,7 +42,11 @@ export async function getBinaryName(name: string): Promise { return name } -export async function getBinaryPath(name: string): Promise { +export async function getBinaryPath(name?: string): Promise { + if (!name) { + return path.join(os.homedir(), '.cherrystudio', 'bin') + } + const binaryName = await getBinaryName(name) const binariesDir = path.join(os.homedir(), '.cherrystudio', 'bin') const binariesDirExists = await fs.existsSync(binariesDir)