@abraca/mcp 2.6.0 → 2.7.0
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.
- package/dist/abracadabra-mcp.cjs +10134 -10006
- package/dist/abracadabra-mcp.cjs.map +1 -1
- package/dist/abracadabra-mcp.esm.js +10206 -10078
- package/dist/abracadabra-mcp.esm.js.map +1 -1
- package/dist/index.d.ts +29 -2
- package/package.json +2 -2
- package/src/hook-bridge.ts +305 -197
- package/src/index.ts +150 -136
- package/src/server.ts +1160 -940
- package/src/tools/channel.ts +138 -98
- package/src/tools/hooks.ts +44 -35
package/src/index.ts
CHANGED
|
@@ -24,84 +24,94 @@
|
|
|
24
24
|
* schema before forwarding to the server.
|
|
25
25
|
* When unset, behaviour is unchanged.
|
|
26
26
|
*/
|
|
27
|
-
import { McpServer } from
|
|
28
|
-
import { StdioServerTransport } from
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import { registerHookTools } from
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import
|
|
27
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
28
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
29
|
+
import { HookBridge } from "./hook-bridge.ts";
|
|
30
|
+
import { registerAgentGuide } from "./resources/agent-guide.ts";
|
|
31
|
+
import { registerServerInfoResource } from "./resources/server-info.ts";
|
|
32
|
+
import { registerTreeResource } from "./resources/tree-resource.ts";
|
|
33
|
+
import { loadSchemaBundle, SchemaBundleLoadError } from "./schema/loader.ts";
|
|
34
|
+
import type { SchemaBundleValidator } from "./schema/validator.ts";
|
|
35
|
+
import { AbracadabraMCPServer, type TriggerMode } from "./server.ts";
|
|
36
|
+
import { registerAwarenessTools } from "./tools/awareness.ts";
|
|
37
|
+
import { registerChannelTools } from "./tools/channel.ts";
|
|
38
|
+
import { registerContentTools } from "./tools/content.ts";
|
|
39
|
+
import { registerFileTools } from "./tools/files.ts";
|
|
40
|
+
import { registerHookTools } from "./tools/hooks.ts";
|
|
41
|
+
import { registerMetaTools } from "./tools/meta.ts";
|
|
42
|
+
import { registerSvgTools } from "./tools/svg.ts";
|
|
43
|
+
import { registerTreeTools } from "./tools/tree.ts";
|
|
44
44
|
|
|
45
45
|
async function main() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
46
|
+
const url = process.env.ABRA_URL;
|
|
47
|
+
|
|
48
|
+
if (!url) {
|
|
49
|
+
console.error("Missing required environment variable: ABRA_URL");
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Parse trigger mode (defaults to mention+task)
|
|
54
|
+
const rawMode = (process.env.ABRA_AGENT_TRIGGER_MODE ?? "mention+task")
|
|
55
|
+
.trim()
|
|
56
|
+
.toLowerCase();
|
|
57
|
+
const validModes: TriggerMode[] = ["all", "mention", "task", "mention+task"];
|
|
58
|
+
const triggerMode = (validModes as string[]).includes(rawMode)
|
|
59
|
+
? (rawMode as TriggerMode)
|
|
60
|
+
: "mention+task";
|
|
61
|
+
if (rawMode && !(validModes as string[]).includes(rawMode)) {
|
|
62
|
+
console.error(
|
|
63
|
+
`[abracadabra-mcp] Invalid ABRA_AGENT_TRIGGER_MODE="${rawMode}", falling back to "mention+task"`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const aliasEnv = process.env.ABRA_AGENT_MENTION_ALIASES;
|
|
68
|
+
const mentionAliases: string[] | undefined = aliasEnv
|
|
69
|
+
? aliasEnv
|
|
70
|
+
.split(",")
|
|
71
|
+
.map((a: string) => a.trim())
|
|
72
|
+
.filter((a: string) => a.length > 0)
|
|
73
|
+
: undefined;
|
|
74
|
+
|
|
75
|
+
// Create the Abracadabra connection manager
|
|
76
|
+
const server = new AbracadabraMCPServer({
|
|
77
|
+
url,
|
|
78
|
+
agentName: process.env.ABRA_AGENT_NAME,
|
|
79
|
+
agentColor: process.env.ABRA_AGENT_COLOR,
|
|
80
|
+
inviteCode: process.env.ABRA_INVITE_CODE,
|
|
81
|
+
keyFile: process.env.ABRA_KEY_FILE,
|
|
82
|
+
triggerMode,
|
|
83
|
+
mentionAliases,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
console.error(
|
|
87
|
+
`[abracadabra-mcp] Trigger mode: ${triggerMode}; aliases: ${server.mentionAliases.join(", ")}`,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// Optional schema bundle. When set, update_metadata + create_document validate
|
|
91
|
+
// `meta` against the resolved doc-type's schema before forwarding. When unset,
|
|
92
|
+
// behaviour is identical to today (Rules 2 + 4 in feedback_schema_free_core.md).
|
|
93
|
+
let schemaValidator: SchemaBundleValidator | null = null;
|
|
94
|
+
const schemaBundlePath = process.env.ABRA_MCP_SCHEMA_BUNDLE;
|
|
95
|
+
if (schemaBundlePath && schemaBundlePath.trim().length > 0) {
|
|
96
|
+
try {
|
|
97
|
+
schemaValidator = loadSchemaBundle(schemaBundlePath);
|
|
98
|
+
console.error(
|
|
99
|
+
`[abracadabra-mcp] Loaded schema bundle from ${schemaBundlePath}; known doc-types: ${schemaValidator.knownTypes.join(", ")}`,
|
|
100
|
+
);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
const msg =
|
|
103
|
+
err instanceof SchemaBundleLoadError ? err.message : String(err);
|
|
104
|
+
console.error(`[abracadabra-mcp] ${msg}`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Create MCP server with channel capability
|
|
110
|
+
const mcp = new McpServer(
|
|
111
|
+
{ name: "abracadabra", version: "1.0.0" },
|
|
112
|
+
{
|
|
113
|
+
capabilities: { experimental: { "claude/channel": {} } },
|
|
114
|
+
instructions: `Abracadabra is a CRDT collaboration platform where everything is a document in a tree.
|
|
105
115
|
|
|
106
116
|
## CRITICAL: Responding to Channel Events
|
|
107
117
|
The user CANNOT see your plain text output — they only see messages sent via MCP tools. When you receive a channel event:
|
|
@@ -136,68 +146,72 @@ The user CANNOT see your plain text output — they only see messages sent via M
|
|
|
136
146
|
|
|
137
147
|
## Full Reference
|
|
138
148
|
Read the resource at abracadabra://agent-guide for the complete guide covering page type schemas, metadata reference, awareness/presence, content structure, and detailed examples.`,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// Register tools
|
|
153
|
+
registerTreeTools(mcp, server, schemaValidator);
|
|
154
|
+
registerContentTools(mcp, server);
|
|
155
|
+
registerMetaTools(mcp, server, schemaValidator);
|
|
156
|
+
registerFileTools(mcp, server);
|
|
157
|
+
registerAwarenessTools(mcp, server);
|
|
158
|
+
registerChannelTools(mcp, server);
|
|
159
|
+
registerSvgTools(mcp, server);
|
|
160
|
+
|
|
161
|
+
// Register resources
|
|
162
|
+
registerAgentGuide(mcp);
|
|
163
|
+
registerTreeResource(mcp, server);
|
|
164
|
+
registerServerInfoResource(mcp, server);
|
|
165
|
+
|
|
166
|
+
// Connect to Abracadabra server
|
|
167
|
+
try {
|
|
168
|
+
await server.connect();
|
|
169
|
+
} catch (error: any) {
|
|
170
|
+
console.error(`[abracadabra-mcp] Failed to connect: ${error.message}`);
|
|
171
|
+
process.exit(1);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Start Claude Code hook bridge (HTTP server for activity events)
|
|
175
|
+
const hookBridge = new HookBridge(server);
|
|
176
|
+
try {
|
|
177
|
+
const hookPort = await hookBridge.start();
|
|
178
|
+
console.error(
|
|
179
|
+
`[abracadabra-mcp] Hook bridge listening on port ${hookPort}`,
|
|
180
|
+
);
|
|
181
|
+
} catch (error: any) {
|
|
182
|
+
console.error(
|
|
183
|
+
`[abracadabra-mcp] Hook bridge failed to start: ${error.message}`,
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Register hook config tool (must be after bridge starts so port is available)
|
|
188
|
+
registerHookTools(mcp, hookBridge);
|
|
189
|
+
|
|
190
|
+
// Start MCP stdio transport
|
|
191
|
+
const transport = new StdioServerTransport();
|
|
192
|
+
await mcp.connect(transport);
|
|
193
|
+
|
|
194
|
+
// Wire up real-time channel notifications (awareness → channel dispatch)
|
|
195
|
+
server.startChannelNotifications(mcp);
|
|
196
|
+
console.error("[abracadabra-mcp] MCP server running on stdio");
|
|
197
|
+
|
|
198
|
+
// Graceful shutdown
|
|
199
|
+
const shutdown = async () => {
|
|
200
|
+
console.error("[abracadabra-mcp] Shutting down...");
|
|
201
|
+
await hookBridge.destroy();
|
|
202
|
+
await server.destroy();
|
|
203
|
+
process.exit(0);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
process.on("SIGINT", shutdown);
|
|
207
|
+
process.on("SIGTERM", shutdown);
|
|
194
208
|
}
|
|
195
209
|
|
|
196
210
|
main().catch((error) => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
})
|
|
211
|
+
console.error("[abracadabra-mcp] Fatal error:", error);
|
|
212
|
+
process.exit(1);
|
|
213
|
+
});
|
|
200
214
|
|
|
215
|
+
export type { MCPServerConfig } from "./server.ts";
|
|
201
216
|
// Re-export for library usage
|
|
202
|
-
export { AbracadabraMCPServer } from
|
|
203
|
-
export type { MCPServerConfig } from './server.ts'
|
|
217
|
+
export { AbracadabraMCPServer } from "./server.ts";
|