macro-agent 0.0.13 → 0.0.15

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.
Files changed (143) hide show
  1. package/.claude/settings.local.json +59 -0
  2. package/dist/agent/agent-manager.d.ts.map +1 -1
  3. package/dist/agent/agent-manager.js +10 -4
  4. package/dist/agent/agent-manager.js.map +1 -1
  5. package/dist/cli/acp.d.ts +6 -0
  6. package/dist/cli/acp.d.ts.map +1 -1
  7. package/dist/cli/acp.js +16 -2
  8. package/dist/cli/acp.js.map +1 -1
  9. package/dist/map/adapter/index.d.ts +1 -1
  10. package/dist/map/adapter/index.d.ts.map +1 -1
  11. package/dist/map/adapter/index.js +1 -1
  12. package/dist/map/adapter/index.js.map +1 -1
  13. package/dist/map/utils/address-translation.d.ts +99 -0
  14. package/dist/map/utils/address-translation.d.ts.map +1 -0
  15. package/dist/map/utils/address-translation.js +285 -0
  16. package/dist/map/utils/address-translation.js.map +1 -0
  17. package/dist/map/utils/index.d.ts +7 -0
  18. package/dist/map/utils/index.d.ts.map +1 -0
  19. package/dist/map/utils/index.js +7 -0
  20. package/dist/map/utils/index.js.map +1 -0
  21. package/dist/server/combined-server.d.ts.map +1 -1
  22. package/dist/server/combined-server.js +8 -1
  23. package/dist/server/combined-server.js.map +1 -1
  24. package/dist/store/event-store.js +9 -2
  25. package/dist/store/event-store.js.map +1 -1
  26. package/dist/store/types/agents.d.ts +2 -0
  27. package/dist/store/types/agents.d.ts.map +1 -1
  28. package/package.json +4 -4
  29. package/references/acp-factory-ref/CHANGELOG.md +33 -0
  30. package/references/acp-factory-ref/LICENSE +21 -0
  31. package/references/acp-factory-ref/README.md +341 -0
  32. package/references/acp-factory-ref/package-lock.json +3102 -0
  33. package/references/acp-factory-ref/package.json +96 -0
  34. package/references/acp-factory-ref/python/CHANGELOG.md +33 -0
  35. package/references/acp-factory-ref/python/LICENSE +21 -0
  36. package/references/acp-factory-ref/python/Makefile +57 -0
  37. package/references/acp-factory-ref/python/README.md +253 -0
  38. package/references/acp-factory-ref/python/pyproject.toml +73 -0
  39. package/references/acp-factory-ref/python/tests/__init__.py +0 -0
  40. package/references/acp-factory-ref/python/tests/e2e/__init__.py +1 -0
  41. package/references/acp-factory-ref/python/tests/e2e/test_codex_e2e.py +349 -0
  42. package/references/acp-factory-ref/python/tests/e2e/test_gemini_e2e.py +165 -0
  43. package/references/acp-factory-ref/python/tests/e2e/test_opencode_e2e.py +296 -0
  44. package/references/acp-factory-ref/python/tests/test_client_handler.py +543 -0
  45. package/references/acp-factory-ref/python/tests/test_pushable.py +199 -0
  46. package/references/claude-code-acp/.github/workflows/ci.yml +45 -0
  47. package/references/claude-code-acp/.github/workflows/publish.yml +34 -0
  48. package/references/claude-code-acp/.prettierrc.json +4 -0
  49. package/references/claude-code-acp/CHANGELOG.md +249 -0
  50. package/references/claude-code-acp/LICENSE +222 -0
  51. package/references/claude-code-acp/README.md +53 -0
  52. package/references/claude-code-acp/docs/RELEASES.md +24 -0
  53. package/references/claude-code-acp/eslint.config.js +48 -0
  54. package/references/claude-code-acp/package-lock.json +4570 -0
  55. package/references/claude-code-acp/package.json +88 -0
  56. package/references/claude-code-acp/scripts/release.sh +119 -0
  57. package/references/claude-code-acp/src/acp-agent.ts +2079 -0
  58. package/references/claude-code-acp/src/index.ts +26 -0
  59. package/references/claude-code-acp/src/lib.ts +38 -0
  60. package/references/claude-code-acp/src/mcp-server.ts +911 -0
  61. package/references/claude-code-acp/src/settings.ts +522 -0
  62. package/references/claude-code-acp/src/tests/.claude/commands/quick-math.md +5 -0
  63. package/references/claude-code-acp/src/tests/.claude/commands/say-hello.md +6 -0
  64. package/references/claude-code-acp/src/tests/acp-agent-fork.test.ts +479 -0
  65. package/references/claude-code-acp/src/tests/acp-agent.test.ts +1502 -0
  66. package/references/claude-code-acp/src/tests/extract-lines.test.ts +103 -0
  67. package/references/claude-code-acp/src/tests/fork-session.test.ts +335 -0
  68. package/references/claude-code-acp/src/tests/replace-and-calculate-location.test.ts +334 -0
  69. package/references/claude-code-acp/src/tests/settings.test.ts +617 -0
  70. package/references/claude-code-acp/src/tests/skills-options.test.ts +187 -0
  71. package/references/claude-code-acp/src/tests/tools.test.ts +318 -0
  72. package/references/claude-code-acp/src/tests/typescript-declarations.test.ts +558 -0
  73. package/references/claude-code-acp/src/tools.ts +819 -0
  74. package/references/claude-code-acp/src/utils.ts +171 -0
  75. package/references/claude-code-acp/tsconfig.json +18 -0
  76. package/references/claude-code-acp/vitest.config.ts +19 -0
  77. package/references/multi-agent-protocol/.sudocode/issues.jsonl +111 -0
  78. package/references/multi-agent-protocol/.sudocode/specs.jsonl +13 -0
  79. package/references/multi-agent-protocol/LICENSE +21 -0
  80. package/references/multi-agent-protocol/README.md +113 -0
  81. package/references/multi-agent-protocol/docs/00-design-specification.md +496 -0
  82. package/references/multi-agent-protocol/docs/01-open-questions.md +1050 -0
  83. package/references/multi-agent-protocol/docs/02-wire-protocol.md +296 -0
  84. package/references/multi-agent-protocol/docs/03-streaming-semantics.md +252 -0
  85. package/references/multi-agent-protocol/docs/04-error-handling.md +231 -0
  86. package/references/multi-agent-protocol/docs/05-connection-model.md +244 -0
  87. package/references/multi-agent-protocol/docs/06-visibility-permissions.md +243 -0
  88. package/references/multi-agent-protocol/docs/07-federation.md +259 -0
  89. package/references/multi-agent-protocol/docs/08-macro-agent-migration.md +253 -0
  90. package/references/multi-agent-protocol/docs/09-authentication.md +680 -0
  91. package/references/multi-agent-protocol/docs/10-mail-protocol.md +553 -0
  92. package/references/multi-agent-protocol/docs/agent-iam-integration.md +877 -0
  93. package/references/multi-agent-protocol/docs/agentic-mesh-integration-draft.md +459 -0
  94. package/references/multi-agent-protocol/docs/git-transport-draft.md +251 -0
  95. package/references/multi-agent-protocol/docs-site/Gemfile +22 -0
  96. package/references/multi-agent-protocol/docs-site/README.md +82 -0
  97. package/references/multi-agent-protocol/docs-site/_config.yml +91 -0
  98. package/references/multi-agent-protocol/docs-site/_includes/head_custom.html +20 -0
  99. package/references/multi-agent-protocol/docs-site/_sass/color_schemes/map.scss +42 -0
  100. package/references/multi-agent-protocol/docs-site/_sass/custom/custom.scss +34 -0
  101. package/references/multi-agent-protocol/docs-site/examples/full-integration.md +510 -0
  102. package/references/multi-agent-protocol/docs-site/examples/index.md +138 -0
  103. package/references/multi-agent-protocol/docs-site/examples/simple-chat.md +282 -0
  104. package/references/multi-agent-protocol/docs-site/examples/task-queue.md +399 -0
  105. package/references/multi-agent-protocol/docs-site/getting-started/index.md +98 -0
  106. package/references/multi-agent-protocol/docs-site/getting-started/installation.md +219 -0
  107. package/references/multi-agent-protocol/docs-site/getting-started/overview.md +172 -0
  108. package/references/multi-agent-protocol/docs-site/getting-started/quickstart.md +237 -0
  109. package/references/multi-agent-protocol/docs-site/index.md +136 -0
  110. package/references/multi-agent-protocol/docs-site/protocol/authentication.md +391 -0
  111. package/references/multi-agent-protocol/docs-site/protocol/connection-model.md +376 -0
  112. package/references/multi-agent-protocol/docs-site/protocol/design.md +284 -0
  113. package/references/multi-agent-protocol/docs-site/protocol/error-handling.md +312 -0
  114. package/references/multi-agent-protocol/docs-site/protocol/federation.md +449 -0
  115. package/references/multi-agent-protocol/docs-site/protocol/index.md +129 -0
  116. package/references/multi-agent-protocol/docs-site/protocol/permissions.md +398 -0
  117. package/references/multi-agent-protocol/docs-site/protocol/streaming.md +353 -0
  118. package/references/multi-agent-protocol/docs-site/protocol/wire-protocol.md +369 -0
  119. package/references/multi-agent-protocol/docs-site/sdk/api/agent.md +357 -0
  120. package/references/multi-agent-protocol/docs-site/sdk/api/client.md +380 -0
  121. package/references/multi-agent-protocol/docs-site/sdk/api/index.md +62 -0
  122. package/references/multi-agent-protocol/docs-site/sdk/api/server.md +453 -0
  123. package/references/multi-agent-protocol/docs-site/sdk/api/types.md +468 -0
  124. package/references/multi-agent-protocol/docs-site/sdk/guides/agent.md +375 -0
  125. package/references/multi-agent-protocol/docs-site/sdk/guides/authentication.md +405 -0
  126. package/references/multi-agent-protocol/docs-site/sdk/guides/client.md +352 -0
  127. package/references/multi-agent-protocol/docs-site/sdk/guides/index.md +89 -0
  128. package/references/multi-agent-protocol/docs-site/sdk/guides/server.md +360 -0
  129. package/references/multi-agent-protocol/docs-site/sdk/guides/testing.md +446 -0
  130. package/references/multi-agent-protocol/docs-site/sdk/guides/transports.md +363 -0
  131. package/references/multi-agent-protocol/docs-site/sdk/index.md +206 -0
  132. package/references/multi-agent-protocol/package-lock.json +3886 -0
  133. package/references/multi-agent-protocol/package.json +56 -0
  134. package/references/multi-agent-protocol/schema/meta.json +467 -0
  135. package/references/multi-agent-protocol/schema/schema.json +2558 -0
  136. package/src/agent/__tests__/agent-manager.test.ts +67 -1
  137. package/src/agent/agent-manager.ts +10 -4
  138. package/src/cli/__tests__/stable-instance-id.test.ts +57 -0
  139. package/src/cli/acp.ts +17 -2
  140. package/src/map/adapter/index.ts +3 -0
  141. package/src/server/combined-server.ts +10 -0
  142. package/src/store/event-store.ts +10 -3
  143. package/src/store/types/agents.ts +2 -0
@@ -0,0 +1,363 @@
1
+ ---
2
+ title: Transports
3
+ parent: Guides
4
+ grand_parent: SDK
5
+ nav_order: 4
6
+ description: "WebSocket, stdio, and custom transport adapters"
7
+ ---
8
+
9
+ # Transports
10
+ {: .no_toc }
11
+
12
+ Connect via WebSocket, stdio, or custom transports.
13
+ {: .fs-6 .fw-300 }
14
+
15
+ ## Table of contents
16
+ {: .no_toc .text-delta }
17
+
18
+ 1. TOC
19
+ {:toc}
20
+
21
+ ---
22
+
23
+ ## Overview
24
+
25
+ MAP is transport-agnostic. The SDK provides adapters for common transports and interfaces for building custom ones.
26
+
27
+ ---
28
+
29
+ ## Stream Interface
30
+
31
+ All transports implement the bidirectional stream interface:
32
+
33
+ ```typescript
34
+ interface Stream {
35
+ readable: ReadableStream<JSONRPCMessage>;
36
+ writable: WritableStream<JSONRPCMessage>;
37
+ }
38
+ ```
39
+
40
+ ---
41
+
42
+ ## WebSocket Transport
43
+
44
+ The most common transport for remote connections.
45
+
46
+ ### Server Side
47
+
48
+ ```typescript
49
+ import { MAPServer } from "@multi-agent-protocol/sdk/server";
50
+ import { WebSocketServer } from "ws";
51
+
52
+ const server = new MAPServer({ name: "MyServer" });
53
+ const wss = new WebSocketServer({ port: 8080 });
54
+
55
+ wss.on("connection", (ws) => {
56
+ const stream = websocketToStream(ws);
57
+ server.accept(stream).start();
58
+ });
59
+
60
+ function websocketToStream(ws: WebSocket): Stream {
61
+ return {
62
+ readable: new ReadableStream({
63
+ start(controller) {
64
+ ws.on("message", (data) => {
65
+ controller.enqueue(JSON.parse(data.toString()));
66
+ });
67
+ ws.on("close", () => controller.close());
68
+ ws.on("error", (err) => controller.error(err));
69
+ },
70
+ }),
71
+ writable: new WritableStream({
72
+ write(message) {
73
+ ws.send(JSON.stringify(message));
74
+ },
75
+ close() {
76
+ ws.close();
77
+ },
78
+ }),
79
+ };
80
+ }
81
+ ```
82
+
83
+ ### Client Side
84
+
85
+ ```typescript
86
+ import { ClientConnection } from "@multi-agent-protocol/sdk";
87
+ import WebSocket from "ws";
88
+
89
+ const ws = new WebSocket("ws://localhost:8080");
90
+ await new Promise((resolve) => ws.on("open", resolve));
91
+
92
+ const stream = websocketToStream(ws);
93
+ const client = new ClientConnection(stream, { name: "Dashboard" });
94
+ await client.connect();
95
+ ```
96
+
97
+ ---
98
+
99
+ ## Stdio Transport
100
+
101
+ For subprocess agents (like Claude Code's Task tool pattern).
102
+
103
+ ### Parent Process (Server)
104
+
105
+ ```typescript
106
+ import { spawn } from "child_process";
107
+ import { MAPServer } from "@multi-agent-protocol/sdk/server";
108
+
109
+ const server = new MAPServer({ name: "ParentServer" });
110
+
111
+ // Spawn child agent process
112
+ const child = spawn("node", ["agent.js"], {
113
+ stdio: ["pipe", "pipe", "inherit"],
114
+ });
115
+
116
+ const stream = stdioToStream(child.stdin, child.stdout);
117
+ server.accept(stream).start();
118
+
119
+ function stdioToStream(stdin: Writable, stdout: Readable): Stream {
120
+ let buffer = "";
121
+
122
+ return {
123
+ readable: new ReadableStream({
124
+ start(controller) {
125
+ stdout.on("data", (chunk) => {
126
+ buffer += chunk.toString();
127
+ const lines = buffer.split("\n");
128
+ buffer = lines.pop() || "";
129
+
130
+ for (const line of lines) {
131
+ if (line.trim()) {
132
+ controller.enqueue(JSON.parse(line));
133
+ }
134
+ }
135
+ });
136
+ stdout.on("end", () => controller.close());
137
+ stdout.on("error", (err) => controller.error(err));
138
+ },
139
+ }),
140
+ writable: new WritableStream({
141
+ write(message) {
142
+ stdin.write(JSON.stringify(message) + "\n");
143
+ },
144
+ close() {
145
+ stdin.end();
146
+ },
147
+ }),
148
+ };
149
+ }
150
+ ```
151
+
152
+ ### Child Process (Agent)
153
+
154
+ ```typescript
155
+ // agent.js
156
+ import { AgentConnection } from "@multi-agent-protocol/sdk";
157
+
158
+ const stream = stdioToStream(process.stdin, process.stdout);
159
+ const agent = new AgentConnection(stream, {
160
+ name: "ChildAgent",
161
+ role: "worker",
162
+ });
163
+
164
+ await agent.connect();
165
+
166
+ agent.onMessage((message) => {
167
+ // Process messages from parent
168
+ });
169
+ ```
170
+
171
+ ---
172
+
173
+ ## In-Process Transport
174
+
175
+ For testing or co-located components.
176
+
177
+ ```typescript
178
+ import { createStreamPair } from "@multi-agent-protocol/sdk/stream";
179
+ import { MAPServer } from "@multi-agent-protocol/sdk/server";
180
+ import { ClientConnection } from "@multi-agent-protocol/sdk";
181
+
182
+ // Create a connected pair of streams
183
+ const [clientStream, serverStream] = createStreamPair();
184
+
185
+ // Server uses one end
186
+ const server = new MAPServer({ name: "TestServer" });
187
+ server.accept(serverStream).start();
188
+
189
+ // Client uses the other end
190
+ const client = new ClientConnection(clientStream, { name: "TestClient" });
191
+ await client.connect();
192
+ ```
193
+
194
+ ---
195
+
196
+ ## HTTP + SSE Transport
197
+
198
+ For stateless clients and environments that don't support WebSockets.
199
+
200
+ ### Server Side
201
+
202
+ ```typescript
203
+ import express from "express";
204
+ import { MAPServer } from "@multi-agent-protocol/sdk/server";
205
+
206
+ const app = express();
207
+ const server = new MAPServer({ name: "HTTPServer" });
208
+
209
+ // Store active SSE connections
210
+ const sseConnections = new Map<string, Response>();
211
+
212
+ // RPC endpoint
213
+ app.post("/map/rpc", express.json(), async (req, res) => {
214
+ const sessionId = req.headers["x-session-id"] as string;
215
+ const result = await server.handleRequest(req.body, sessionId);
216
+ res.json(result);
217
+ });
218
+
219
+ // SSE endpoint for events
220
+ app.get("/map/events", (req, res) => {
221
+ const sessionId = req.query.sessionId as string;
222
+
223
+ res.setHeader("Content-Type", "text/event-stream");
224
+ res.setHeader("Cache-Control", "no-cache");
225
+ res.setHeader("Connection", "keep-alive");
226
+
227
+ sseConnections.set(sessionId, res);
228
+
229
+ req.on("close", () => {
230
+ sseConnections.delete(sessionId);
231
+ });
232
+ });
233
+
234
+ // Deliver events via SSE
235
+ server.on("*", (event) => {
236
+ for (const [sessionId, res] of sseConnections) {
237
+ res.write(`event: map.event\n`);
238
+ res.write(`data: ${JSON.stringify(event)}\n\n`);
239
+ }
240
+ });
241
+
242
+ app.listen(8080);
243
+ ```
244
+
245
+ ### Client Side
246
+
247
+ ```typescript
248
+ function httpToStream(baseUrl: string, sessionId: string): Stream {
249
+ const eventSource = new EventSource(
250
+ `${baseUrl}/map/events?sessionId=${sessionId}`
251
+ );
252
+
253
+ return {
254
+ readable: new ReadableStream({
255
+ start(controller) {
256
+ eventSource.addEventListener("map.event", (e) => {
257
+ controller.enqueue(JSON.parse(e.data));
258
+ });
259
+ eventSource.onerror = () => controller.close();
260
+ },
261
+ }),
262
+ writable: new WritableStream({
263
+ async write(message) {
264
+ await fetch(`${baseUrl}/map/rpc`, {
265
+ method: "POST",
266
+ headers: {
267
+ "Content-Type": "application/json",
268
+ "X-Session-Id": sessionId,
269
+ },
270
+ body: JSON.stringify(message),
271
+ });
272
+ },
273
+ }),
274
+ };
275
+ }
276
+ ```
277
+
278
+ ---
279
+
280
+ ## Custom Transports
281
+
282
+ Implement any transport by providing a Stream:
283
+
284
+ ```typescript
285
+ interface CustomTransportOptions {
286
+ // Your transport-specific options
287
+ }
288
+
289
+ function createCustomTransport(options: CustomTransportOptions): Stream {
290
+ return {
291
+ readable: new ReadableStream({
292
+ start(controller) {
293
+ // Set up your transport's incoming message handling
294
+ // Call controller.enqueue(message) for each message
295
+ // Call controller.close() when connection ends
296
+ // Call controller.error(err) on errors
297
+ },
298
+ }),
299
+ writable: new WritableStream({
300
+ write(message) {
301
+ // Send message over your transport
302
+ },
303
+ close() {
304
+ // Clean up your transport
305
+ },
306
+ }),
307
+ };
308
+ }
309
+ ```
310
+
311
+ ### Example: Redis Pub/Sub Transport
312
+
313
+ ```typescript
314
+ import Redis from "ioredis";
315
+
316
+ function redisToStream(channelIn: string, channelOut: string): Stream {
317
+ const subscriber = new Redis();
318
+ const publisher = new Redis();
319
+
320
+ return {
321
+ readable: new ReadableStream({
322
+ async start(controller) {
323
+ await subscriber.subscribe(channelIn);
324
+ subscriber.on("message", (channel, data) => {
325
+ if (channel === channelIn) {
326
+ controller.enqueue(JSON.parse(data));
327
+ }
328
+ });
329
+ },
330
+ cancel() {
331
+ subscriber.unsubscribe(channelIn);
332
+ subscriber.quit();
333
+ },
334
+ }),
335
+ writable: new WritableStream({
336
+ write(message) {
337
+ publisher.publish(channelOut, JSON.stringify(message));
338
+ },
339
+ close() {
340
+ publisher.quit();
341
+ },
342
+ }),
343
+ };
344
+ }
345
+ ```
346
+
347
+ ---
348
+
349
+ ## Transport Selection Guide
350
+
351
+ | Transport | Use Case | Pros | Cons |
352
+ |:----------|:---------|:-----|:-----|
353
+ | **WebSocket** | Remote clients, browsers | Bidirectional, real-time | Requires WS support |
354
+ | **stdio** | Subprocess agents | Simple, no network | Local only |
355
+ | **In-process** | Testing, co-located | Zero latency | Same process only |
356
+ | **HTTP + SSE** | Serverless, restricted envs | Works everywhere | Higher latency |
357
+
358
+ ---
359
+
360
+ ## Next Steps
361
+
362
+ - [Server Setup](./server.html) - Configure your server
363
+ - [Testing](./testing.html) - Use in-process transport for tests
@@ -0,0 +1,206 @@
1
+ ---
2
+ title: SDK
3
+ nav_order: 4
4
+ has_children: true
5
+ description: "MAP TypeScript SDK documentation"
6
+ ---
7
+
8
+ # TypeScript SDK
9
+
10
+ The Multi-Agent Protocol TypeScript SDK provides everything you need to build observable, coordinated multi-agent systems.
11
+ {: .fs-6 .fw-300 }
12
+
13
+ ---
14
+
15
+ ## Who This Is For
16
+
17
+ - **Agent Developers** - Build agents that register with MAP servers, receive messages, and collaborate with other agents
18
+ - **Platform Developers** - Build MAP-compliant servers that orchestrate agents and expose them to clients
19
+ - **Client Developers** - Build applications that observe and interact with multi-agent systems
20
+
21
+ ---
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @multi-agent-protocol/sdk
27
+ ```
28
+
29
+ ---
30
+
31
+ ## Quick Navigation
32
+
33
+ ### Guides
34
+
35
+ | Guide | Description |
36
+ |:------|:------------|
37
+ | [Server Setup](./guides/server.html) | Set up a MAP server with MAPServer |
38
+ | [Client Integration](./guides/client.html) | Connect clients that observe and send messages |
39
+ | [Agent Integration](./guides/agent.html) | Build agents that register and process work |
40
+ | [Transports](./guides/transports.html) | WebSocket, stdio, and custom transports |
41
+ | [Authentication](./guides/authentication.html) | Configure authentication |
42
+ | [Testing](./guides/testing.html) | Test your MAP integrations |
43
+
44
+ ### API Reference
45
+
46
+ | Reference | Description |
47
+ |:----------|:------------|
48
+ | [Server API](./api/server.html) | MAPServer and building blocks |
49
+ | [Client API](./api/client.html) | ClientConnection methods |
50
+ | [Agent API](./api/agent.html) | AgentConnection methods |
51
+ | [Types](./api/types.html) | TypeScript type definitions |
52
+
53
+ ---
54
+
55
+ ## Package Exports
56
+
57
+ ```typescript
58
+ // Main exports (connections)
59
+ import {
60
+ ClientConnection,
61
+ AgentConnection,
62
+ GatewayConnection
63
+ } from "@multi-agent-protocol/sdk";
64
+
65
+ // Server components
66
+ import { MAPServer } from "@multi-agent-protocol/sdk/server";
67
+
68
+ // Building blocks for custom servers
69
+ import {
70
+ EventBusImpl,
71
+ AgentRegistryImpl,
72
+ ScopeManagerImpl,
73
+ SubscriptionManagerImpl,
74
+ } from "@multi-agent-protocol/sdk/server";
75
+
76
+ // Stream utilities
77
+ import { createStreamPair } from "@multi-agent-protocol/sdk/stream";
78
+
79
+ // Type definitions
80
+ import type {
81
+ Agent,
82
+ Message,
83
+ Event,
84
+ Subscription,
85
+ } from "@multi-agent-protocol/sdk";
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Minimal Example
91
+
92
+ **Server:**
93
+ ```typescript
94
+ import { MAPServer } from "@multi-agent-protocol/sdk/server";
95
+ import { WebSocketServer } from "ws";
96
+
97
+ const server = new MAPServer({ name: "MyServer" });
98
+ const wss = new WebSocketServer({ port: 8080 });
99
+
100
+ wss.on("connection", (ws) => {
101
+ const stream = websocketToStream(ws);
102
+ server.accept(stream).start();
103
+ });
104
+ ```
105
+
106
+ **Agent:**
107
+ ```typescript
108
+ import { AgentConnection } from "@multi-agent-protocol/sdk";
109
+
110
+ const agent = new AgentConnection(stream, {
111
+ name: "Worker",
112
+ role: "processor"
113
+ });
114
+
115
+ const { agent: registered } = await agent.connect();
116
+ console.log(`Registered: ${registered.id}`);
117
+
118
+ agent.onMessage((message) => {
119
+ console.log("Received:", message.payload);
120
+ });
121
+ ```
122
+
123
+ **Client:**
124
+ ```typescript
125
+ import { ClientConnection } from "@multi-agent-protocol/sdk";
126
+
127
+ const client = new ClientConnection(stream, { name: "Dashboard" });
128
+ await client.connect();
129
+
130
+ // List all agents
131
+ const { agents } = await client.listAgents();
132
+
133
+ // Subscribe to events
134
+ const subscription = await client.subscribe({
135
+ eventTypes: ["agent.*"]
136
+ });
137
+
138
+ for await (const event of subscription) {
139
+ console.log("Event:", event.type);
140
+ }
141
+ ```
142
+
143
+ ---
144
+
145
+ ## Progressive Disclosure
146
+
147
+ The SDK follows a **progressive disclosure** pattern:
148
+
149
+ ### Level 1: Just Works
150
+
151
+ ```typescript
152
+ const server = new MAPServer();
153
+ ```
154
+
155
+ ### Level 2: Customize Behavior
156
+
157
+ ```typescript
158
+ const server = new MAPServer({
159
+ middleware: [loggingMiddleware, authMiddleware],
160
+ additionalHandlers: { "custom/method": myHandler },
161
+ });
162
+ ```
163
+
164
+ ### Level 3: Full Control
165
+
166
+ ```typescript
167
+ const eventBus = new EventBusImpl({
168
+ store: new RedisEventStore()
169
+ });
170
+ const agents = new AgentRegistryImpl({
171
+ eventBus,
172
+ store: new PostgresAgentStore()
173
+ });
174
+ // ... compose your own server
175
+ ```
176
+
177
+ ---
178
+
179
+ ## Key Concepts
180
+
181
+ ### Three Participant Types
182
+
183
+ | Type | Class | Purpose |
184
+ |:-----|:------|:--------|
185
+ | **Agent** | `AgentConnection` | Worker that processes tasks |
186
+ | **Client** | `ClientConnection` | Observer that monitors and sends messages |
187
+ | **Gateway** | `GatewayConnection` | Bridge between federated systems |
188
+
189
+ ### Server Building Blocks
190
+
191
+ | Component | Purpose |
192
+ |:----------|:--------|
193
+ | **EventBus** | Central event dispatcher |
194
+ | **AgentRegistry** | Tracks registered agents |
195
+ | **ScopeManager** | Manages logical groupings |
196
+ | **SessionManager** | Handles connections |
197
+ | **SubscriptionManager** | Event filtering and delivery |
198
+ | **MessageRouter** | Routes messages |
199
+
200
+ ---
201
+
202
+ ## Next Steps
203
+
204
+ 1. **[Server Setup](./guides/server.html)** - Create your MAP server
205
+ 2. **[Agent Integration](./guides/agent.html)** - Build your first agent
206
+ 3. **[Client Integration](./guides/client.html)** - Build observability tools