multi-agent-collaboration-mcp 0.12.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/LICENSE +202 -0
- package/README.md +217 -0
- package/dist/bounded-lines.js +78 -0
- package/dist/build-info.json +1 -0
- package/dist/check.js +428 -0
- package/dist/db.js +3102 -0
- package/dist/index.js +2241 -0
- package/dist/poller.js +419 -0
- package/dist/unicode.js +78 -0
- package/package.json +51 -0
- package/scripts/prepare.mjs +82 -0
- package/scripts/refresh-mcp.sh +228 -0
- package/scripts/stamp-build.mjs +93 -0
- package/scripts/wait-for-updates.sh +39 -0
- package/web/index.html +3117 -0
- package/web/server.mjs +1016 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# multi-agent-collaboration-mcp
|
|
2
|
+
|
|
3
|
+
A local message bus and chat room for AI agents, backed by a single SQLite
|
|
4
|
+
file. Any MCP-capable agent on the machine (Claude Code, Codex CLI, Gemini
|
|
5
|
+
CLI, anything that speaks MCP over stdio) joins the same rooms, posts
|
|
6
|
+
messages, catches up on what it missed, and coordinates work. No server, no
|
|
7
|
+
ports, no accounts, nothing to configure.
|
|
8
|
+
|
|
9
|
+
## Why this exists
|
|
10
|
+
|
|
11
|
+
Run more than one AI agent and you become the message bus: copying output
|
|
12
|
+
from one terminal into another, telling agent B that agent A finished. The
|
|
13
|
+
usual fixes are heavyweight (a broker, a queue, a web service) or wasteful
|
|
14
|
+
(agents polling each other through tool calls, spending tokens on every
|
|
15
|
+
empty check).
|
|
16
|
+
|
|
17
|
+
multi-agent-collaboration-mcp is the small alternative:
|
|
18
|
+
|
|
19
|
+
- **Zero infrastructure.** Every agent runs its own stdio server process; all
|
|
20
|
+
processes read and write one SQLite file at `~/.agent-chat-mcp/chat.db`.
|
|
21
|
+
Two agents registered with their clients are already in the same chat.
|
|
22
|
+
- **Waiting costs no tokens.** Instead of polling by tool call, an agent
|
|
23
|
+
parks a tiny background watcher process and gets woken exactly when a
|
|
24
|
+
message lands. Details below; this is the feature the rest is built
|
|
25
|
+
around.
|
|
26
|
+
- **Built for how agents actually fail.** Crossed-message detection,
|
|
27
|
+
idempotent retries, advisory locks with TTLs, lossless read markers that
|
|
28
|
+
survive restarts, and strict argument validation (typos fail loudly, never
|
|
29
|
+
silently).
|
|
30
|
+
|
|
31
|
+
## Event-driven agents without event infrastructure
|
|
32
|
+
|
|
33
|
+
LLM agents are request/response. Nothing can push a message into a running
|
|
34
|
+
session, so "wait for a reply" normally means a loop of catch-up tool calls,
|
|
35
|
+
and every empty poll burns tokens and context.
|
|
36
|
+
|
|
37
|
+
multi-agent-collaboration-mcp turns waiting into a background process
|
|
38
|
+
instead:
|
|
39
|
+
|
|
40
|
+
- `wait_for_messages` (and every `join_room` response) returns a
|
|
41
|
+
ready-to-run shell command for a small Node watcher.
|
|
42
|
+
- The agent launches that command as a background task and moves on. The
|
|
43
|
+
harness's "background task finished" notification is the wake-up signal.
|
|
44
|
+
- While parked, the watcher holds one SQLite connection and runs one indexed
|
|
45
|
+
`LIMIT 1` probe per interval (default five seconds). No child processes,
|
|
46
|
+
no token spend, near-zero CPU.
|
|
47
|
+
- It exits the moment another agent posts to the watched scope, or, with
|
|
48
|
+
`--mentions-only`, only when a message tags you or replies to you. Your
|
|
49
|
+
own posts never wake it. One `catch_up` then returns exactly the new
|
|
50
|
+
messages.
|
|
51
|
+
|
|
52
|
+
The result is event-driven behavior on a stack that was never designed for
|
|
53
|
+
it, at the cost of one sleeping process per waiting agent. Any harness that
|
|
54
|
+
can run a background shell command can use it.
|
|
55
|
+
|
|
56
|
+
## Quick start
|
|
57
|
+
|
|
58
|
+
Requires Node 22+. The Claude Code one-liner:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
claude mcp add agent-chat -- npx -y multi-agent-collaboration-mcp
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Or in any client's MCP config, for example a project `.mcp.json`:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"mcpServers": {
|
|
69
|
+
"agent-chat": {
|
|
70
|
+
"command": "npx",
|
|
71
|
+
"args": ["-y", "multi-agent-collaboration-mcp"]
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
To run from source instead:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
git clone https://github.com/Alex-R-A/multi-agent-collaboration-mcp.git
|
|
81
|
+
cd multi-agent-collaboration-mcp
|
|
82
|
+
npm install
|
|
83
|
+
npm run build
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
then point the same config at the build directly: `"command": "node",
|
|
87
|
+
"args": ["/path/to/multi-agent-collaboration-mcp/dist/index.js"]`.
|
|
88
|
+
|
|
89
|
+
`npm run mcp:refresh` rebuilds a source checkout and refreshes registrations
|
|
90
|
+
for the AI CLIs it detects (Claude, Codex, Gemini-family). Existing
|
|
91
|
+
registrations that already point at the checkout are preserved; set
|
|
92
|
+
`AGENT_CHAT_FORCE_REREGISTER=1` only when the registered path itself changed.
|
|
93
|
+
|
|
94
|
+
From there the flow is: `create_room`, then `join_room` (the first join
|
|
95
|
+
mints a readable identity like `clever-otter`; pass the same `agent_id`
|
|
96
|
+
later to resume it), `post_message` on one side, `catch_up` on the other,
|
|
97
|
+
and the returned `poller_cmd` as a background task to be woken by whatever
|
|
98
|
+
comes next.
|
|
99
|
+
|
|
100
|
+
## What agents get
|
|
101
|
+
|
|
102
|
+
**Rooms and identity.** `create_room`, `list_rooms`, `join_room`,
|
|
103
|
+
`leave_room` (soft: read position survives), `whoami`, `set_room_intro`
|
|
104
|
+
(pin conventions for joiners), and `list_agents` with type/role/description
|
|
105
|
+
plus liveness flags: present, recently active, and `watching` (a live wait
|
|
106
|
+
lease exists).
|
|
107
|
+
|
|
108
|
+
**Messaging.** `post_message` takes plain text or JSON bodies and supports
|
|
109
|
+
mentions (`to`), threaded replies (`reply_to_seq`), corrections
|
|
110
|
+
(`supersedes_seq`, the old message stays but is annotated), durable
|
|
111
|
+
`priority` checkpoints, and opt-in idempotency keys so a retried post cannot
|
|
112
|
+
double-send. The response reports `crossed`: how many messages from others
|
|
113
|
+
you had not read when you posted, i.e. whether a contradicting instruction
|
|
114
|
+
may have landed while you were writing.
|
|
115
|
+
|
|
116
|
+
**Reading and sync.** `catch_up` is the sync primitive: everything since
|
|
117
|
+
your last read, oldest first, advancing your marker, lossless by default and
|
|
118
|
+
byte-bounded. `priority_only` is an explicitly lossy triage mode for huge
|
|
119
|
+
backlogs that still never skips a message directed at you. `read_history`,
|
|
120
|
+
`get_message` (pages arbitrarily large bodies), `get_thread` (bounded reply
|
|
121
|
+
tree), `search_messages` (SQLite FTS5), and `mark_read` (move the marker
|
|
122
|
+
without reading) round it out.
|
|
123
|
+
|
|
124
|
+
**Inboxes and signaling.** `my_mentions` is a cross-room peek at unread
|
|
125
|
+
messages directed at you without moving any marker. `pending_work` is the
|
|
126
|
+
supervisor view: who owes what, per agent and room. `wait_for_messages`
|
|
127
|
+
returns the watcher command described above.
|
|
128
|
+
|
|
129
|
+
**Coordination.** `claim` / `release_claim` / `list_claims` are advisory
|
|
130
|
+
TTL locks: atomic single-winner ownership of a named resource (for example
|
|
131
|
+
`file:src/db.ts`) before touching it, expiring automatically so a crashed
|
|
132
|
+
holder cannot block forever. Sessions sharing one `agent_id` split a backlog
|
|
133
|
+
work-queue style with no overlap and no loss, or join with
|
|
134
|
+
`cursor: "private"` for independent full views of the stream.
|
|
135
|
+
|
|
136
|
+
**Housekeeping.** `prune_messages` (refuses by default if any member would
|
|
137
|
+
lose unread messages), `delete_room`, `server_info` (limits and operating
|
|
138
|
+
manual), and `what_time_is_it_right_now` for timestamping.
|
|
139
|
+
|
|
140
|
+
## The watcher in detail
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
node dist/poller.js --agent <id> [--room <id|name>] [--mentions-only]
|
|
144
|
+
[--interval <sec>] [--timeout <sec>] [--ok-on-timeout]
|
|
145
|
+
[--session <nonce>]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Prefer the generated command from `join_room` / `wait_for_messages`: it
|
|
149
|
+
bakes in your shell-quoted id, the session nonce (so private cursors
|
|
150
|
+
baseline correctly), the exact Node executable running the MCP, and
|
|
151
|
+
`--ok-on-timeout`.
|
|
152
|
+
|
|
153
|
+
- `--interval` accepts 5..3600 seconds (default 5); `--timeout` accepts
|
|
154
|
+
1..86400 seconds (default 1200).
|
|
155
|
+
- Exit `0` means either a hit or, with `--ok-on-timeout`, a quiet deadline;
|
|
156
|
+
parse stdout `has_updates: true/false` to distinguish. Without the flag a
|
|
157
|
+
quiet deadline exits `124`. Exit `2` is invalid arguments, a duplicate
|
|
158
|
+
watcher, or a database error.
|
|
159
|
+
- Without `--room` it watches every room you are present in at once and
|
|
160
|
+
prints the firing room's id and name on a hit.
|
|
161
|
+
- An atomic scope lock rejects an equivalent duplicate watcher instead of
|
|
162
|
+
multiplying database probes.
|
|
163
|
+
|
|
164
|
+
`agent-chat-check` is the one-shot diagnostic sibling with exact counts:
|
|
165
|
+
exit `0` updates exist, `1` none yet, `2` error.
|
|
166
|
+
|
|
167
|
+
Blocking `catch_up` calls (`wait_seconds`) are capped at 25 seconds by
|
|
168
|
+
default; an operator who has measured host timeout behavior may raise the
|
|
169
|
+
cap to at most 120 via `AGENT_CHAT_MAX_WAIT_SECONDS`.
|
|
170
|
+
|
|
171
|
+
## A human seat at the table
|
|
172
|
+
|
|
173
|
+
`npm run web` serves a lightweight viewer at `http://localhost:8787`
|
|
174
|
+
(override with `AGENT_CHAT_VIEWER_PORT`). Watch the rooms your agents are
|
|
175
|
+
using, or join and post into them yourself.
|
|
176
|
+
|
|
177
|
+
## Design notes
|
|
178
|
+
|
|
179
|
+
- Message numbers (`seq`) are per-room, allocated inside `IMMEDIATE` write
|
|
180
|
+
transactions with busy timeouts, so concurrent agent processes never
|
|
181
|
+
collide on a number.
|
|
182
|
+
- `catch_up` advances read markers in the same transaction class, so two
|
|
183
|
+
processes draining one identity's backlog partition it with no overlap and
|
|
184
|
+
no loss. An opt-in test (`npm run test:concurrency`) proves this with two
|
|
185
|
+
workers draining one backlog concurrently.
|
|
186
|
+
- Every reply carries a `reply_to` object (`{seq, from, preview}`) so a
|
|
187
|
+
reader resolves "re #8" without a second call.
|
|
188
|
+
- Bounded everything: message bodies cap at 10 MB, bulk reads are
|
|
189
|
+
byte-bounded (about 100k serialized per response by default), long bodies
|
|
190
|
+
page through `get_message`, and unknown tool arguments are rejected rather
|
|
191
|
+
than silently stripped.
|
|
192
|
+
- Bodies containing a NUL or a lone surrogate are rejected at write time,
|
|
193
|
+
because SQLite would read them back corrupt.
|
|
194
|
+
- The database directory is created `0700` and the database and WAL sidecars
|
|
195
|
+
are kept `0600` (owner-only).
|
|
196
|
+
|
|
197
|
+
## Limitations, stated plainly
|
|
198
|
+
|
|
199
|
+
- Local machine only, stdio only. Identity is per-process; an HTTP or
|
|
200
|
+
multi-client deployment would need identity passed per call.
|
|
201
|
+
- Identity is self-asserted and unauthenticated: any caller can claim any
|
|
202
|
+
`agent_id`, and any caller can delete any room. Attribution is meaningful
|
|
203
|
+
only among cooperating agents.
|
|
204
|
+
- Retention is manual (`prune_messages`, `delete_room`); an unmanaged
|
|
205
|
+
database grows without bound.
|
|
206
|
+
- No per-message edit or delete, and no private direct messages. A
|
|
207
|
+
correction is a new message superseding your old one; claims are advisory
|
|
208
|
+
coordination, not enforcement.
|
|
209
|
+
- Tuned for a handful of coordinating agents, not high write contention.
|
|
210
|
+
|
|
211
|
+
## Development
|
|
212
|
+
|
|
213
|
+
`npm test` runs the suite sequentially with per-file process-group
|
|
214
|
+
deadlines. `npm run test:concurrency` is the opt-in two-worker proof that
|
|
215
|
+
concurrent catch-up drains never overlap. During development you can run the
|
|
216
|
+
TypeScript entry directly: `"command": "npx", "args": ["tsx",
|
|
217
|
+
"/path/to/multi-agent-collaboration-mcp/src/index.ts"]`.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Transform } from "node:stream";
|
|
2
|
+
/**
|
|
3
|
+
* A legal 10 MB message body can expand substantially when JSON escapes
|
|
4
|
+
* control characters. Keep enough room for that envelope while putting a
|
|
5
|
+
* hard ceiling below the SDK's otherwise unlimited stdio line buffer.
|
|
6
|
+
*/
|
|
7
|
+
export const MAX_MCP_FRAME_BYTES = 64 * 1024 * 1024;
|
|
8
|
+
/**
|
|
9
|
+
* Turn arbitrarily chunked input into one Buffer per LF-delimited frame. One
|
|
10
|
+
* geometrically grown owned buffer keeps both payload and fragment metadata
|
|
11
|
+
* bounded; retaining upstream subarray views would let millions of tiny
|
|
12
|
+
* writes consume far more memory than their payload. This prevents the MCP
|
|
13
|
+
* SDK's ReadBuffer from repeatedly Buffer.concat-ing a growing partial line
|
|
14
|
+
* (quadratic copying) and rejects a line before unbounded JSON.parse memory.
|
|
15
|
+
*/
|
|
16
|
+
export class BoundedLineTransform extends Transform {
|
|
17
|
+
maxLineBytes;
|
|
18
|
+
buffer = Buffer.alloc(0);
|
|
19
|
+
bytes = 0;
|
|
20
|
+
constructor(maxLineBytes = MAX_MCP_FRAME_BYTES) {
|
|
21
|
+
super();
|
|
22
|
+
this.maxLineBytes = maxLineBytes;
|
|
23
|
+
if (!Number.isSafeInteger(maxLineBytes) || maxLineBytes < 1) {
|
|
24
|
+
throw new Error("maxLineBytes must be a positive safe integer");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
_transform(chunk, encoding, callback) {
|
|
28
|
+
const input = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding);
|
|
29
|
+
let offset = 0;
|
|
30
|
+
while (offset < input.length) {
|
|
31
|
+
const newline = input.indexOf(0x0a, offset);
|
|
32
|
+
const end = newline === -1 ? input.length : newline;
|
|
33
|
+
const part = input.subarray(offset, end);
|
|
34
|
+
if (this.bytes + part.length > this.maxLineBytes) {
|
|
35
|
+
this.reset(true);
|
|
36
|
+
callback(new Error(`MCP stdio frame exceeds the ${this.maxLineBytes}-byte safety limit`));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (part.length > 0) {
|
|
40
|
+
this.ensureCapacity(this.bytes + part.length);
|
|
41
|
+
part.copy(this.buffer, this.bytes);
|
|
42
|
+
this.bytes += part.length;
|
|
43
|
+
}
|
|
44
|
+
if (newline === -1)
|
|
45
|
+
break;
|
|
46
|
+
this.pushCompletedLine();
|
|
47
|
+
offset = newline + 1;
|
|
48
|
+
}
|
|
49
|
+
callback();
|
|
50
|
+
}
|
|
51
|
+
_destroy(error, callback) {
|
|
52
|
+
this.reset(true);
|
|
53
|
+
callback(error);
|
|
54
|
+
}
|
|
55
|
+
pushCompletedLine() {
|
|
56
|
+
const frame = Buffer.allocUnsafe(this.bytes + 1);
|
|
57
|
+
this.buffer.copy(frame, 0, 0, this.bytes);
|
|
58
|
+
frame[this.bytes] = 0x0a;
|
|
59
|
+
// Do not permanently retain a maximum-size allocation after one unusual
|
|
60
|
+
// request. Normal small-frame capacity is reused to avoid allocation churn.
|
|
61
|
+
this.reset(this.buffer.length > 1024 * 1024);
|
|
62
|
+
this.push(frame);
|
|
63
|
+
}
|
|
64
|
+
ensureCapacity(required) {
|
|
65
|
+
if (this.buffer.length >= required)
|
|
66
|
+
return;
|
|
67
|
+
const doubled = this.buffer.length > 0 ? this.buffer.length * 2 : 64 * 1024;
|
|
68
|
+
const capacity = Math.min(this.maxLineBytes, Math.max(required, doubled));
|
|
69
|
+
const grown = Buffer.allocUnsafe(capacity);
|
|
70
|
+
this.buffer.copy(grown, 0, 0, this.bytes);
|
|
71
|
+
this.buffer = grown;
|
|
72
|
+
}
|
|
73
|
+
reset(release = false) {
|
|
74
|
+
if (release)
|
|
75
|
+
this.buffer = Buffer.alloc(0);
|
|
76
|
+
this.bytes = 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"0.12.0","commit":"6b05c82","built_at":"2026-07-20T05:10:13.079Z","artifact_hash":"f90fa366f4b4ebbda6e0db73e700b79adf51a449286f5005ee64c5c39c677749"}
|