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
43 changes: 43 additions & 0 deletions lib/core/mcp/mcp_access_store.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'dart:convert';

import 'package:querya_desktop/core/storage/local_db.dart';

/// Which connections MCP clients may read. Opt-in per connection: a
/// connection that was never enabled is invisible to every MCP tool.
abstract class McpAccessPolicy {
Future<bool> canRead(ConnectionRow row);
}

/// [McpAccessPolicy] stored in `app_settings` as a JSON list of connection ids.
class McpAccessStore implements McpAccessPolicy {
McpAccessStore._();

static final McpAccessStore instance = McpAccessStore._();

static const settingsKey = 'mcp_read_connection_ids';

Future<Set<int>> readableIds() async {
final raw = await LocalDb.instance.getAppSetting(settingsKey);
if (raw == null || raw.isEmpty) return {};
try {
final decoded = jsonDecode(raw);
if (decoded is List) return {for (final v in decoded) if (v is int) v};
} catch (_) {}
return {};
}

Future<void> setReadable(int connectionId, bool readable) async {
final ids = await readableIds();
if (readable) {
ids.add(connectionId);
} else {
ids.remove(connectionId);
}
await LocalDb.instance
.setAppSetting(settingsKey, jsonEncode(ids.toList()..sort()));
}

@override
Future<bool> canRead(ConnectionRow row) async =>
row.id != null && (await readableIds()).contains(row.id);
}
Loading
Loading