getAppSchemas
Retrieve all registered app schema details from the current device’s environment to manage and monitor app interactions effectively.
Instructions
获取当前设备所有注册唤醒的 App Schema 信息
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:163-171 (registration)Registration of the 'getAppSchemas' tool in the list of tools returned by ListToolsRequest handler, including its name, description, and empty input schema.{ name: "getAppSchemas", description: "获取当前设备所有注册唤醒的 App Schema 信息", inputSchema: { type: "object", properties: {}, required: [] } },
- src/index.ts:540-599 (handler)The main handler logic for the 'getAppSchemas' tool within the handleCallToolRequest switch statement. It platform-specifically scans for registered URL schemes (App Schemas) in applications using system commands and file parsing (mdfind/plist on macOS, .desktop on Linux, registry on Windows).case "getAppSchemas": { let appSchemas: Record<string, string[]> = {}; try { if (os.platform() === 'darwin') { // macOS 使用 mdfind 命令查找所有 .app 包 const appPaths = execSync('mdfind "kMDItemContentType == com.apple.application-bundle"').toString().split('\n'); for (const appPath of appPaths) { if (appPath) { try { // 读取 Info.plist 文件 const plistPath = `${appPath}/Contents/Info.plist`; if (fs.existsSync(plistPath)) { const plistContent = fs.readFileSync(plistPath, 'utf8'); const plistData: any = plist.parse(plistContent); if (plistData.CFBundleURLTypes) { const schemes = plistData.CFBundleURLTypes .flatMap((type: any) => type.CFBundleURLSchemes || []) .filter((scheme: string) => scheme); if (schemes.length > 0) { appSchemas[plistData.CFBundleName || appPath] = schemes; } } } } catch (error) { console.warn(`无法读取 ${appPath} 的 Info.plist 文件:`, error); continue; // 跳过无法读取的 .app 包 } } } } else if (os.platform() === 'linux') { // Linux 通过检查 .desktop 文件获取 URL Scheme 信息 const desktopFiles = execSync('find /usr/share/applications /~/.local/share/applications -name "*.desktop"').toString().split('\n'); desktopFiles.forEach(file => { if (file) { const content = execSync(`cat ${file}`).toString(); const schemes = content.match(/MimeType=(.+)/)?.[1].split(';').filter(s => s.startsWith('x-scheme-handler/')).map(s => s.replace('x-scheme-handler/', '')); if (schemes && schemes.length > 0) { appSchemas[file] = schemes; } } }); } else if (os.platform() === 'win32') { // Windows 通过注册表获取 URL Scheme 信息 const regOutput = execSync('reg query HKEY_CLASSES_ROOT /f "URL Protocol" /s').toString(); const schemes = regOutput.split('\n').filter(line => line.trim().startsWith('HKEY_CLASSES_ROOT\\')).map(line => line.split('\\')[1]); schemes.forEach(scheme => { appSchemas[scheme] = [scheme]; }); } } catch (error) { console.error("获取 App Schema 信息失败:", error); } return { content: [{ type: "text", text: JSON.stringify(appSchemas, null, 2) }] }; }