Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'node:fs/promises'
import { platform } from 'node:os'
import { MCPConfigLinterService } from './services/mcp-config-linter-service.ts'
import { MCPServerManagerService } from './services/mcp-server-manager-service.ts'

Expand Down Expand Up @@ -39,22 +40,40 @@ interface MCPFileGroupsResult {
type MCPFilePathGroupsRecord = Record<string, MCPFileGroups>
type MCPFileGroupsResultRecord = Record<string, MCPFileGroupsResult>

const osSpecificPaths: { [key: string]: MCPFilePath[] } = {
claude: [],
cursor: []
}

if (platform() === 'win32') {
osSpecificPaths['claude'] = [
{ filePath: `${process.env.APPDATA}\\Claude\\claude_desktop_config.json`, type: 'global' }
]
osSpecificPaths['cursor'] = [
{ filePath: `${process.env.HOME}\\.cursor\\mcp.json`, type: 'global' },
{ filePath: '.cursor\\mcp.json', type: 'local' }
]
} else {
osSpecificPaths['claude'] = [
{ filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' }
]
osSpecificPaths['cursor'] = [
{ filePath: '~/.cursor/mcp.json', type: 'global' },
{ filePath: '.cursor/mcp.json', type: 'local' }
]
}

export class MCPFiles {
private mcpFilePathGroups: MCPFilePathGroupsRecord = {
claude: {
name: 'claude-desktop',
friendlyName: 'Claude Desktop',
paths: [
{ filePath: '~/Library/Application Support/Claude/claude_desktop_config.json', type: 'global' },
]
paths: osSpecificPaths['claude']
},
cursor: {
name: 'cursor',
friendlyName: 'Cursor',
paths: [
{ filePath: '~/.cursor/mcp.json', type: 'global' },
{ filePath: '.cursor/mcp.json', type: 'local' },
]
paths: osSpecificPaths['cursor']
}
}

Expand Down
28 changes: 27 additions & 1 deletion src/services/mcp-server-manager-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,34 @@ export class MCPServerManagerService {

// Then iterate the map to check for matches
let mcpServerDetection: MatchedProcess | undefined

for (const [pid, processData] of processMap) {
if (this.isCommandMatch(processData.commandTokens, pid, processData.ppid)) {
const commandMatchLinux = this.isCommandMatch(processData.commandTokens, pid, processData.ppid)
let commandMatchWin32 = false
if (platform() === 'win32') {
// for Windows, we need to change commandTokens to also match another pattern
// where the command starts with `cmd` then follows potentially several command-line
// flags like /c /d and then the actual command.
// This is because Claude Desktop on Windows automatically starts MCP Servers like that
// even if the command specified in the MCP config is just `uvx` or `npx`.

let commandTokensOnWin32 = processData.commandTokens
if (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].toLowerCase().startsWith('cmd')) {
// If the first token is 'cmd', we need to skip it and check the next tokens
commandTokensOnWin32 = commandTokensOnWin32.slice(1)

// Skip any additional flags like /c, /d, etc.
while (commandTokensOnWin32.length > 0 && commandTokensOnWin32[0].startsWith('/')) {
commandTokensOnWin32 = commandTokensOnWin32.slice(1)
}
}

commandMatchWin32 = this.isCommandMatch(commandTokensOnWin32, pid, processData.ppid)
}

const commandMatch = commandMatchLinux || commandMatchWin32

if (commandMatch) {
mcpServerDetection = {
pid,
commandLine: processData.commandTokens.join(' '),
Expand Down
Loading