@mebular/mcp 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,91 @@
1
+ // Adapter registry (W1).
2
+ //
3
+ // Host adapters are data + methods; adding a host means adding a descriptor
4
+ // module and one registration line. DSH and Hermes are implemented in their
5
+ // own modules; MCP-only hosts stay explicit `unsupported` descriptors.
6
+
7
+ import { dshAdapter } from './dsh.mjs';
8
+ import { hermesAdapter } from './hermes.mjs';
9
+ import { openChamberAdapter, openCodeAdapter } from './opencode.mjs';
10
+
11
+ const registry = new Map();
12
+
13
+ const MCP_ONLY_HOSTS = [
14
+ { hostId: 'claude-code', displayName: 'Claude Code' },
15
+ { hostId: 'claude-desktop', displayName: 'Claude Desktop' },
16
+ { hostId: 'cursor', displayName: 'Cursor' },
17
+ { hostId: 'generic', displayName: 'Generic MCP client' },
18
+ ];
19
+
20
+ /**
21
+ * MCP-only / pending descriptor. Every provisioning call fails with a stable
22
+ * code; nothing is written to the host.
23
+ */
24
+ export function createUnsupportedAdapter({
25
+ hostId,
26
+ displayName = hostId,
27
+ status = 'unsupported',
28
+ code = 'ADAPTER_UNSUPPORTED',
29
+ reason = 'mcp_only',
30
+ } = {}) {
31
+ const fail = async () => ({ ok: false, code, reason });
32
+ return {
33
+ hostId,
34
+ displayName,
35
+ status,
36
+ reason,
37
+ package: { name: null, version: null, source: 'manual' },
38
+ detect: async () => ({ detected: false, signals: [{ kind: 'unsupported', source: reason, hit: false }] }),
39
+ ensurePackage: fail,
40
+ configure: fail,
41
+ activate: async () => ({ ok: true, activation: 'next-start' }),
42
+ verify: async () => ({ ok: false, code, checks: [] }),
43
+ rollback: async () => ({ ok: true, removed: false, restoredFrom: null }),
44
+ };
45
+ }
46
+
47
+ const DESCRIPTOR_METHODS = ['detect', 'ensurePackage', 'configure', 'activate', 'verify', 'rollback'];
48
+
49
+ /** Extensible registration (tests / future host modules). */
50
+ export function registerAdapter(adapter) {
51
+ if (!adapter || typeof adapter.hostId !== 'string' || !/^[a-z0-9][a-z0-9-]*$/.test(adapter.hostId)) {
52
+ throw new Error('adapter.hostId must be lower-case kebab-case');
53
+ }
54
+ for (const method of DESCRIPTOR_METHODS) {
55
+ if (typeof adapter[method] !== 'function') throw new Error(`adapter ${adapter.hostId} missing ${method}()`);
56
+ }
57
+ registry.set(adapter.hostId, adapter);
58
+ return adapter;
59
+ }
60
+
61
+ /** Resolve a descriptor, or null for an unknown host. */
62
+ export function getAdapter(hostId) {
63
+ return registry.get(hostId) ?? null;
64
+ }
65
+
66
+ export function listAdapters() {
67
+ return [...registry.values()];
68
+ }
69
+
70
+ export const ADAPTER_HOST_IDS = Object.freeze([
71
+ 'opencode',
72
+ 'openchamber',
73
+ 'dsh',
74
+ 'hermes',
75
+ ...MCP_ONLY_HOSTS.map((host) => host.hostId),
76
+ ]);
77
+
78
+ registerAdapter(openCodeAdapter);
79
+ registerAdapter(openChamberAdapter);
80
+ registerAdapter(dshAdapter);
81
+ registerAdapter(hermesAdapter);
82
+
83
+ for (const host of MCP_ONLY_HOSTS) {
84
+ registerAdapter(createUnsupportedAdapter({
85
+ hostId: host.hostId,
86
+ displayName: host.displayName,
87
+ status: 'unsupported',
88
+ code: 'ADAPTER_UNSUPPORTED',
89
+ reason: 'mcp_only',
90
+ }));
91
+ }