From 08f375621a7882b85bf100084382bb4c1a99b0db Mon Sep 17 00:00:00 2001 From: Sucukdeluxe <259325684+Sucukdeluxe@users.noreply.github.com> Date: Wed, 21 Oct 2026 23:02:18 +0200 Subject: [PATCH] Add an MCP full-access permission that runs every action without local confirmation With full access the installation grants every capability, destructive and conditionally confirmed actions (queue retry/remove with source deletion, history clear, app restart, ...) run without the local dialog, and the new mhu_files_grant tool can add or widen directory grants. Narrowing or removing grants and changing permissions stay local. Enabling full access in the settings asks for local confirmation once. Co-Authored-By: Claude Opus 5.5 --- lib/mcp-app.js | 14 ++++++++++---- lib/mcp-service.js | 23 +++++++++++++++++++++-- lib/mcp-store.js | 2 +- lib/mcp-tools.js | 6 ++++-- main.js | 3 ++- renderer/mcp.js | 7 ++++--- 6 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lib/mcp-app.js b/lib/mcp-app.js index f98300d..55381e8 100644 --- a/lib/mcp-app.js +++ b/lib/mcp-app.js @@ -16,7 +16,7 @@ function page(items, args) { } function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel, ...args) => invoke(channel, ...args), renderer, collectors, getGrants, trashFile, canWrite, - getCapabilities, getProtectedPaths, getInstallationId, getDiagnosticSources, getRuntimeDiagnostics = () => null, getPerformance = () => null, getSystemMetrics = () => null, profile, updates }) { + getCapabilities, getProtectedPaths, getInstallationId, getDiagnosticSources, getRuntimeDiagnostics = () => null, getPerformance = () => null, getSystemMetrics = () => null, profile, updates, grantDirectory }) { const transfers = createMcpTransfers({ getGrants, getCapabilities, getProtectedPaths, getInstallationId }); const sanitize = createMcpSanitizer(loadConfig); const guard = context => { @@ -67,15 +67,21 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel, ...createMcpFiles({ getGrants, trashFile }), ...transfers.handlers, ...createMcpDiagnostics({ getSources: getDiagnosticSources, redact: text => sanitize(redactLogText(text, collectSecretValues(loadConfig()))) }), + mhu_files_grant: async ({ path: directory, readOnly, allowTransfer }, context) => { + canWrite(); guard(context); + if (typeof grantDirectory !== 'function') throw new McpAccessError('ACTION_UNAVAILABLE'); + return grantDirectory(directory, { readOnly: readOnly !== false, allowTransfer: allowTransfer === true }); + }, mhu_app_info: () => invoke('get-app-info'), mhu_capabilities: () => { const permissions = getCapabilities?.() || []; const settings = loadConfig().globalSettings; - return { permissions, tools: MCP_TOOLS.filter(tool => tool.requiredScopes.every(scope => permissions.includes(scope))).map(tool => ({ + const fullAccess = permissions.includes('full_access'); + return { permissions, tools: MCP_TOOLS.filter(tool => fullAccess || tool.requiredScopes.every(scope => permissions.includes(scope))).map(tool => ({ name: tool.name, readOnly: tool.annotations.readOnlyHint, requiredScopes: tool.requiredScopes, - localConfirmation: tool.destructive || requiresMcpConfirmation(tool.name, {}, settings), + localConfirmation: !fullAccess && (tool.destructive || requiresMcpConfirmation(tool.name, {}, settings)), conditionalConfirmation: tool.name === 'mhu_settings_update' - })), boundaries: ['Permissions and directory grants can only be changed locally.', 'Destructive actions require an exact local confirmation; MCP cannot approve it.', 'No arbitrary shell, SQL, mouse/keyboard or screen control.', 'Paused automation is resumed with mhu_automation_resume. A disabled monitor requires mhu_automation_start.'] }; + })), boundaries: [fullAccess ? 'Full access: actions run without local confirmation. Permissions, and narrowing or removing directory grants, can only be changed locally.' : 'Permissions and directory grants can only be changed locally.', fullAccess ? 'mhu_files_grant can add or widen directory grants.' : 'Destructive actions require an exact local confirmation; MCP cannot approve it.', 'No arbitrary shell, SQL, mouse/keyboard or screen control.', 'Paused automation is resumed with mhu_automation_resume. A disabled monitor requires mhu_automation_start.'] }; }, mhu_performance_get: () => getPerformance(), mhu_profile_start: args => profile.start(args.seconds), diff --git a/lib/mcp-service.js b/lib/mcp-service.js index 72c8c1d..26f19fa 100644 --- a/lib/mcp-service.js +++ b/lib/mcp-service.js @@ -25,7 +25,10 @@ class McpService { this.protocol = null; this.generation = 0; } - capabilities() { return this.active ? this.store.value.capabilities : []; } + capabilities() { + if (!this.active) return []; + return this.store.value.capabilities.includes('full_access') ? [...CAPABILITIES] : this.store.value.capabilities; + } state() { const { name, capabilities, grants, enabled, identity, revocations } = this.store.value; return { name, capabilities, grants, enabled: this.active && enabled, connection: this.connection, installationId: identity?.installationId || null, @@ -86,7 +89,7 @@ class McpService { } configure(args) { validateInput(args, { type: 'object', additionalProperties: false, required: ['enabled', 'name', 'capabilities'], properties: { - enabled: { type: 'boolean' }, name: { type: 'string', minLength: 1, maxLength: 100 }, capabilities: { type: 'array', maxItems: 5, items: { type: 'string', enum: CAPABILITIES } } + enabled: { type: 'boolean' }, name: { type: 'string', minLength: 1, maxLength: 100 }, capabilities: { type: 'array', maxItems: CAPABILITIES.length, items: { type: 'string', enum: CAPABILITIES } } } }); if (!args.name.trim()) throw new McpAccessError('INVALID_ARGUMENTS'); this.active = false; @@ -143,6 +146,22 @@ class McpService { this.publish(); return this.state(); }); } + grantDirectory(directory, { readOnly = true, allowTransfer = false } = {}) { + return this.serialize(async () => { + if (!this.ready) throw new McpAccessError('ACCESS_STORE_UNAVAILABLE'); + if (typeof directory !== 'string' || !path.isAbsolute(directory)) throw new McpAccessError('PATH_NOT_GRANTED'); + const resolved = await fs.realpath(directory).catch(() => { throw new McpAccessError('PATH_NOT_GRANTED'); }); + const stat = await fs.stat(resolved); + if (!stat.isDirectory() || path.parse(resolved).root === resolved) throw new McpAccessError('PATH_NOT_GRANTED'); + const existing = this.store.value.grants.find(grant => grant.path === resolved); + if (existing && ((existing.readOnly === false && readOnly) || (existing.allowTransfer === true && !allowTransfer))) throw new McpAccessError('GRANT_NARROWING_LOCAL_ONLY'); + if (!existing && this.store.value.grants.length >= 30) throw new McpAccessError('GRANT_LIMIT'); + const grant = existing ? { ...existing, readOnly, allowTransfer } : { id: randomUUID(), label: path.basename(resolved), path: resolved, readOnly, allowTransfer }; + await this.store.save({ ...this.store.value, grants: existing ? this.store.value.grants.map(item => item.id === existing.id ? grant : item) : [...this.store.value.grants, grant] }); + this.publish(); + return { id: grant.id, label: grant.label, readOnly: grant.readOnly, allowTransfer: grant.allowTransfer }; + }); + } updateGrant(id, remove, readOnly = true, allowTransfer) { const generation = this.generation; return this.serialize(async () => { diff --git a/lib/mcp-store.js b/lib/mcp-store.js index 95d90c8..5313234 100644 --- a/lib/mcp-store.js +++ b/lib/mcp-store.js @@ -4,7 +4,7 @@ const { randomUUID, randomBytes } = require('node:crypto'); const { McpAccessError } = require('./mcp-access'); const RELAY_URL = 'https://downloader.24-music.de/mcp-relay'; -const CAPABILITIES = ['read', 'control', 'files', 'secrets', 'updates']; +const CAPABILITIES = ['read', 'control', 'files', 'secrets', 'updates', 'full_access']; class McpStore { constructor({ directory, encrypt, decrypt }) { diff --git a/lib/mcp-tools.js b/lib/mcp-tools.js index f15a8bd..e998b8c 100644 --- a/lib/mcp-tools.js +++ b/lib/mcp-tools.js @@ -98,6 +98,7 @@ const definitions = [ { transferId: id, offset: integer(0, 32 * 1024 ** 3), length: integer(1, 1024 * 1024) }, ['transferId', 'offset']], ['files_transfer_close', 'Close an owned temporary transfer handle without modifying its source file.', 'files', { transferId: id }, ['transferId']], ['files_delete', 'Delete a specifically selected file inside a writable grant.', 'files.write', file, ['rootId', 'relativePath'], true], + ['files_grant', 'Grant or widen access to an absolute local directory. Requires full access; narrowing or removing a grant stays local.', 'full_access', { path: text(), readOnly: boolean, allowTransfer: boolean }, ['path']], ['cloud_status', 'Read CloudDrop log synchronization state.', 'read', {}, []], ['cloud_configure', 'Enable or disable CloudDrop log sync with the saved or supplied key.', 'settings', { enabled: boolean, apiKey: text(200) }, ['enabled']], ['cloud_backfill', 'Queue missing entries from the current local upload log.', 'control', {}, []], @@ -131,7 +132,8 @@ function createMcpToolAdapter({ handlers, authorizeConfirmation, sanitize, audit const tool = byName.get(name); if (!tool || typeof handlers[name] !== 'function') throw new McpAccessError('TOOL_UNAVAILABLE'); const allowed = () => getCapabilities ? getCapabilities() : context?.scopes; - const permitted = () => Array.isArray(allowed()) && tool.requiredScopes.every(scope => allowed().includes(scope)); + const fullAccess = () => Array.isArray(allowed()) && allowed().includes('full_access'); + const permitted = () => Array.isArray(allowed()) && (fullAccess() || tool.requiredScopes.every(scope => allowed().includes(scope))); if (!permitted()) throw new McpAccessError('SCOPE_DENIED'); validateInput(args, tool.inputSchema); if (context.signal?.aborted || !Number.isFinite(context.deadline) || context.deadline <= Date.now()) throw new McpAccessError('REQUEST_EXPIRED'); @@ -150,7 +152,7 @@ function createMcpToolAdapter({ handlers, authorizeConfirmation, sanitize, audit const startedAt = Date.now(); if (context.signal?.aborted || Date.now() >= context.deadline) throw new McpAccessError('REQUEST_EXPIRED'); if (!permitted()) throw new McpAccessError('SCOPE_DENIED'); - if ((tool.destructive || requiresConfirmation(name, args)) && (!authorizeConfirmation || !await authorizeConfirmation({ tool: name, digest, args, context }))) throw new McpAccessError('CONFIRMATION_REQUIRED'); + if (!fullAccess() && (tool.destructive || requiresConfirmation(name, args)) && (!authorizeConfirmation || !await authorizeConfirmation({ tool: name, digest, args, context }))) throw new McpAccessError('CONFIRMATION_REQUIRED'); if (context.signal?.aborted || Date.now() >= context.deadline) throw new McpAccessError('REQUEST_EXPIRED'); if (!permitted()) throw new McpAccessError('SCOPE_DENIED'); audit({ tool: name, event: 'started', requestId: context.requestId, durationMs: 0 }); diff --git a/main.js b/main.js index 7ae5bbd..0e8e4e2 100644 --- a/main.js +++ b/main.js @@ -4270,6 +4270,7 @@ async function startMcpService() { getSystemMetrics: args => systemMetrics.snapshot(args), getGrants: () => mcpService?.store.value.grants || [], trashFile: file => require('electron').shell.trashItem(file), canWrite: assertConfigWriteAllowed, getCapabilities: () => mcpService?.capabilities() || [], + grantDirectory: (directory, options) => mcpService.grantDirectory(directory, options), getProtectedPaths: () => [app.getPath('userData'), configStore.filePath, configStore.historyPath, configStore.automationCompletionPath], getInstallationId: () => mcpService?.store.value.identity?.installationId, getRuntimeDiagnostics: () => ({ @@ -4307,7 +4308,7 @@ ipcMain.on('mcp:reply', (event, payload) => { }); ipcMain.handle('mcp:configure', async (event, args) => { if (!isTrustedOnlineBackupIpcEvent(event) || !mcpService) throw new Error('MCP_ACCESS_DENIED'); - if (args?.enabled && (args.capabilities?.includes('secrets') || (args.capabilities?.includes('updates') && !mcpService.capabilities().includes('updates')) || !mcpService.active)) { + if (args?.enabled && (args.capabilities?.includes('secrets') || (args.capabilities?.includes('full_access') && !mcpService.capabilities().includes('full_access')) || (args.capabilities?.includes('updates') && !mcpService.capabilities().includes('updates')) || !mcpService.active)) { const result = await dialog.showMessageBox(mainWindow, { type: 'warning', title: 'MCP-Zugriff / MCP access', message: 'MCP-Zugriff mit diesen Berechtigungen aktivieren? / Enable MCP with these capabilities?', detail: String(args.capabilities?.join(', ') || '').slice(0, 100), buttons: ['Abbrechen / Cancel', 'Aktivieren / Enable'], defaultId: 0, cancelId: 0, noLink: true }); if (result.response !== 1) return mcpService.state(); diff --git a/renderer/mcp.js b/renderer/mcp.js index 3752cbf..6c1ee26 100644 --- a/renderer/mcp.js +++ b/renderer/mcp.js @@ -222,8 +222,9 @@ ['control','App steuern','Control app','Uploads und Konten verwalten. Kritische Aktionen lokal bestätigen.','Manage uploads and accounts. Confirm critical actions locally.'], ['files','Freigegebene Ordner','Granted directories','Auf ausgewählte Ordner zugreifen. Dateiinhalte separat freigeben.','Access selected directories. Allow file contents separately.'], ['updates','App-Updates installieren','Install app updates','Geprüfte Updates ohne erneute Bestätigung installieren. Uploads abschließen und danach fortsetzen. Keine Portable-Versionen.','Install verified updates without another confirmation. Finish uploads and resume afterwards. No portable versions.'], - ['secrets','Zugangsdaten auslesen','Reveal credentials','Gespeicherte Zugangsdaten ausdrücklich freigeben. Zusätzliche lokale Bestätigung erforderlich.','Explicitly allow saved credentials to be read. Additional local confirmation required.'] - ].map(([value,de,en,description,englishDescription])=>``).join('')} + ['secrets','Zugangsdaten auslesen','Reveal credentials','Gespeicherte Zugangsdaten ausdrücklich freigeben. Zusätzliche lokale Bestätigung erforderlich.','Explicitly allow saved credentials to be read. Additional local confirmation required.'], + ['full_access','Vollzugriff ohne Bestätigung','Full access without confirmation','Alle Aktionen ohne lokale Bestätigung ausführen, auch Löschen, Wiederholen mit Quelldatei-Löschung, Ordnerfreigaben und Zugangsdaten.','Run every action without local confirmation, including deletions, retries with source deletion, directory grants and credentials.'] + ].map(([value,de,en,description,englishDescription])=>``).join('')}

${text('Erst speichern und aktivieren, dann den Verbindungscode kopieren.', 'Save and enable first, then copy the connection code.')}

@@ -233,7 +234,7 @@

${text('Zugang verwalten', 'Manage access')}

-

${text('Der Verbindungscode ist ein Zugangsschlüssel. Er wird weder im Backup gespeichert noch auf andere Installationen übertragen. Löschungen und andere gefährliche Aktionen verlangen eine lokale Bestätigung.', 'The connection code is a credential. It is not stored in backups or transferred to other installations. Deletions and other dangerous actions require local confirmation.')}

+

${text('Der Verbindungscode ist ein Zugangsschlüssel. Er wird weder im Backup gespeichert noch auf andere Installationen übertragen. Löschungen und andere gefährliche Aktionen verlangen eine lokale Bestätigung, außer bei Vollzugriff.', 'The connection code is a credential. It is not stored in backups or transferred to other installations. Deletions and other dangerous actions require local confirmation unless full access is granted.')}

${text('Zugang erneuern macht den bisherigen Code ungültig. Deaktivieren beendet den Fernzugriff und widerruft den Zugang.', 'Rotating access invalidates the previous code. Disabling remote access revokes access.')}