Add an MCP full-access permission that runs every action without local confirmation
CI / verify (push) Canceled after 0s
CI / verify (push) Canceled after 0s
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
432c0e01b8
commit
08f375621a
6 files changed
+42
-13
No files matched your search
+10
-4
@@ -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),
|
||||
|
||||
+21
-2
@@ -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 () => {
|
||||
|
||||
+1
-1
@@ -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 }) {
|
||||
|
||||
+4
-2
@@ -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 });
|
||||
|
||||
Reference in new issue
Block a user