mysql_list_sites
List all available Local WordPress sites and their current running status. Provides an overview of local development environments.
Instructions
List all available Local WordPress sites and their running status
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:124-130 (schema)Tool schema registration for 'mysql_list_sites' - defines the tool's name, description, and input schema (no inputs needed).
name: 'mysql_list_sites', description: 'List all available Local WordPress sites and their running status', inputSchema: { type: 'object', properties: {}, }, }, - src/index.ts:261-297 (handler)Handler for 'mysql_list_sites' tool - calls listAvailableSites() and returns the list of sites with their running status, plus the current site ID.
case 'mysql_list_sites': { try { const sites = listAvailableSites(); return { content: [ { type: 'text', text: JSON.stringify( { sites, currentSiteId: currentSiteSelection?.siteInfo.siteId || null, }, null, 2 ), }, ], }; } catch (listError: unknown) { const message = listError instanceof Error ? listError.message : String(listError); return { content: [ { type: 'text', text: JSON.stringify( { error: 'Failed to list sites', message, }, null, 2 ), }, ], }; } } - src/local-detector.ts:413-433 (handler)Implementation of listAvailableSites() - loads Local's sites.json config, checks each site's MySQL socket existence to determine running status, and returns site info.
export function listAvailableSites(): Array<{ id: string; name: string; path: string; domain: string; running: boolean; }> { const sites = loadLocalSitesConfig(); const runDir = getLocalRunDirectory(); return Object.entries(sites).map(([id, site]) => { const socketPath = path.join(runDir, id, 'mysql/mysqld.sock'); return { id, name: site.name, path: normalizeSitePath(site.path), domain: site.domain, running: fs.existsSync(socketPath), }; }); } - src/local-detector.ts:221-227 (helper)Helper function loadLocalSitesConfig() - reads and parses Local's sites.json configuration file used by listAvailableSites.
export function loadLocalSitesConfig(): LocalSitesConfig { const sitesJsonPath = getSitesJsonPath(); debugLog(`Loading sites.json from: ${sitesJsonPath}`); const content = fs.readFileSync(sitesJsonPath, 'utf8'); return JSON.parse(content) as LocalSitesConfig; } - src/local-detector.ts:149-178 (helper)Helper function getLocalRunDirectory() - determines the Local by Flywheel run directory path (platform-specific) used to find MySQL socket files for checking site running status.
function getLocalRunDirectory(): string { const customPath = process.env.LOCAL_RUN_DIR; if (customPath && fs.existsSync(customPath)) { return customPath; } const candidates: string[] = []; const home = os.homedir(); if (process.platform === 'darwin') { candidates.push(path.join(home, 'Library/Application Support/Local/run')); } else if (process.platform === 'win32') { if (process.env.LOCALAPPDATA) { candidates.push(path.join(process.env.LOCALAPPDATA, 'Local', 'run')); } if (process.env.APPDATA) { candidates.push(path.join(process.env.APPDATA, 'Local', 'run')); } } else { candidates.push(path.join(home, '.config', 'Local', 'run')); candidates.push(path.join(home, '.local', 'share', 'Local', 'run')); } for (const candidate of candidates) { if (fs.existsSync(candidate)) { return candidate; } } throw new Error('Local run directory not found. Set LOCAL_RUN_DIR to override.');