@modelprofile.com/mcp-crossharness 5.0.0 → 5.2.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_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/classes.codexappserverclient.d.ts +71 -0
- package/dist_ts/classes.codexappserverclient.js +298 -0
- package/dist_ts/classes.connection.codex.d.ts +1 -9
- package/dist_ts/classes.connection.codex.js +22 -246
- package/dist_ts/classes.mcpserver.d.ts +4 -4
- package/dist_ts/classes.mcpserver.js +63 -215
- package/dist_ts/classes.mcptoolregistrar.d.ts +26 -0
- package/dist_ts/classes.mcptoolregistrar.js +257 -0
- package/dist_ts/index.d.ts +2 -0
- package/dist_ts/index.js +3 -1
- package/dist_ts/plugins.d.ts +2 -0
- package/dist_ts/plugins.js +1 -1
- package/package.json +2 -2
- package/readme.md +109 -3
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.codexappserverclient.ts +331 -0
- package/ts/classes.connection.codex.ts +22 -256
- package/ts/classes.mcpserver.ts +67 -297
- package/ts/classes.mcptoolregistrar.ts +345 -0
- package/ts/index.ts +2 -0
- package/ts/plugins.ts +2 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import type * as interfaces from './interfaces.js';
|
|
3
|
+
import { ConnectionRegistry } from './classes.connectionregistry.js';
|
|
4
|
+
import { DispatchRegistry } from './classes.dispatchregistry.js';
|
|
5
|
+
|
|
6
|
+
const harnessNameSchema = plugins.z.enum(['claudecode', 'opencode', 'codex']);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers the Crossharness tool surface on an externally owned MCP server and
|
|
10
|
+
* owns only the resources used by those tools.
|
|
11
|
+
*/
|
|
12
|
+
export class CrossHarnessMcpToolRegistrar {
|
|
13
|
+
public readonly connections: ConnectionRegistry;
|
|
14
|
+
public readonly dispatches: DispatchRegistry;
|
|
15
|
+
private registeredTools: plugins.RegisteredTool[] = [];
|
|
16
|
+
private registeredServer: InstanceType<typeof plugins.McpServer> | undefined;
|
|
17
|
+
private registered = false;
|
|
18
|
+
private closeStarted = false;
|
|
19
|
+
private closePromise: Promise<void> | undefined;
|
|
20
|
+
private resourceShutdownPromise: Promise<void> | undefined;
|
|
21
|
+
|
|
22
|
+
constructor(connectionsArg = new ConnectionRegistry(), dispatchesArg = new DispatchRegistry()) {
|
|
23
|
+
this.connections = connectionsArg;
|
|
24
|
+
this.dispatches = dispatchesArg;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Register the tool surface before the externally owned MCP server connects. */
|
|
28
|
+
public register(serverArg: InstanceType<typeof plugins.McpServer>): void {
|
|
29
|
+
if (this.closeStarted) {
|
|
30
|
+
throw new Error('Crossharness MCP tool registrar is closed');
|
|
31
|
+
}
|
|
32
|
+
if (this.registered) {
|
|
33
|
+
throw new Error('Crossharness MCP tools are already registered');
|
|
34
|
+
}
|
|
35
|
+
if (serverArg.isConnected()) {
|
|
36
|
+
throw new Error('Crossharness MCP tools must be registered before the MCP server connects');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const registeredTools: plugins.RegisteredTool[] = [];
|
|
40
|
+
try {
|
|
41
|
+
registeredTools.push(serverArg.registerTool(
|
|
42
|
+
'connect_harness',
|
|
43
|
+
{
|
|
44
|
+
title: 'Connect to harness server',
|
|
45
|
+
description:
|
|
46
|
+
'Establish an explicit connection to an allowlisted harness web server. The exact origin must be listed in CROSSHARNESS_ALLOWED_SERVER_URLS. OpenCode uses http(s), Codex uses ws(s), and Claude Code is rejected because it exposes no URL-addressable session server. Returns a connectionId required by every connection-scoped operation; list_connections remains global.',
|
|
47
|
+
inputSchema: {
|
|
48
|
+
harness: harnessNameSchema,
|
|
49
|
+
serverUrl: plugins.z.string().max(2048).url().describe('Allowlisted harness server origin'),
|
|
50
|
+
directory: plugins.z
|
|
51
|
+
.string()
|
|
52
|
+
.max(4096)
|
|
53
|
+
.startsWith('/')
|
|
54
|
+
.describe('Absolute project directory on the harness server'),
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
async (args, extra) =>
|
|
58
|
+
this.wrapToolCall(async () => {
|
|
59
|
+
const info = await this.connections.connect(
|
|
60
|
+
args.harness as interfaces.THarnessName,
|
|
61
|
+
args.serverUrl,
|
|
62
|
+
args.directory,
|
|
63
|
+
extra.signal,
|
|
64
|
+
);
|
|
65
|
+
return this.describeConnection(info);
|
|
66
|
+
}),
|
|
67
|
+
));
|
|
68
|
+
|
|
69
|
+
registeredTools.push(serverArg.registerTool(
|
|
70
|
+
'disconnect_harness',
|
|
71
|
+
{
|
|
72
|
+
title: 'Disconnect harness server',
|
|
73
|
+
description:
|
|
74
|
+
'Close and remove an established harness connection. In-flight requests fail; async dispatch records remain inspectable with check_reply.',
|
|
75
|
+
inputSchema: {
|
|
76
|
+
connectionId: plugins.z.string().max(128).describe('Connection id returned by connect_harness'),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
async (args) =>
|
|
80
|
+
this.wrapToolCall(async () =>
|
|
81
|
+
this.describeConnection(await this.connections.disconnect(args.connectionId)),
|
|
82
|
+
),
|
|
83
|
+
));
|
|
84
|
+
|
|
85
|
+
registeredTools.push(serverArg.registerTool(
|
|
86
|
+
'list_connections',
|
|
87
|
+
{
|
|
88
|
+
title: 'List harness connections',
|
|
89
|
+
description: 'List explicit harness web-server connections established in this MCP process.',
|
|
90
|
+
inputSchema: {},
|
|
91
|
+
},
|
|
92
|
+
async () =>
|
|
93
|
+
this.wrapToolCall(async () => {
|
|
94
|
+
const connections = this.connections.list();
|
|
95
|
+
return connections.length > 0
|
|
96
|
+
? connections.map((connection) => this.describeConnection(connection)).join('\n\n')
|
|
97
|
+
: 'No harness server connections established.';
|
|
98
|
+
}),
|
|
99
|
+
));
|
|
100
|
+
|
|
101
|
+
registeredTools.push(serverArg.registerTool(
|
|
102
|
+
'connection_status',
|
|
103
|
+
{
|
|
104
|
+
title: 'Check harness connection',
|
|
105
|
+
description: 'Run the protocol health check for one explicit harness server connection.',
|
|
106
|
+
inputSchema: {
|
|
107
|
+
connectionId: plugins.z.string().max(128).describe('Connection id returned by connect_harness'),
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
async (args) =>
|
|
111
|
+
this.wrapToolCall(async () => {
|
|
112
|
+
const status = await this.connections.get(args.connectionId).getStatus();
|
|
113
|
+
return `${this.describeConnection(status)}\nhealthy: ${status.healthy ? 'yes' : 'no'}\ndetail: ${status.detail}`;
|
|
114
|
+
}),
|
|
115
|
+
));
|
|
116
|
+
|
|
117
|
+
registeredTools.push(serverArg.registerTool(
|
|
118
|
+
'list_chats',
|
|
119
|
+
{
|
|
120
|
+
title: 'List harness chats',
|
|
121
|
+
description:
|
|
122
|
+
'List chats from the server and directory bound to an explicit connection. No local session stores are read.',
|
|
123
|
+
inputSchema: {
|
|
124
|
+
connectionId: plugins.z.string().max(128).describe('Connection id returned by connect_harness'),
|
|
125
|
+
limit: plugins.z.number().int().min(1).max(100).optional(),
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
async (args) =>
|
|
129
|
+
this.wrapToolCall(async () => {
|
|
130
|
+
const chats = await this.connections.get(args.connectionId).listChats(args.limit ?? 10);
|
|
131
|
+
if (chats.length === 0) return 'No chats found for this connection.';
|
|
132
|
+
return [
|
|
133
|
+
'harness\tchatId\tupdatedAt\tactivity\ttitle',
|
|
134
|
+
...chats.map(
|
|
135
|
+
(chat) =>
|
|
136
|
+
`${chat.harness}\t${chat.chatId}\t${chat.updatedAt}\t${chat.isActive ? 'active' : 'idle'}\t${chat.title.replace(/\s+/g, ' ').slice(0, 120)}`,
|
|
137
|
+
),
|
|
138
|
+
].join('\n');
|
|
139
|
+
}),
|
|
140
|
+
));
|
|
141
|
+
|
|
142
|
+
registeredTools.push(serverArg.registerTool(
|
|
143
|
+
'read_chat',
|
|
144
|
+
{
|
|
145
|
+
title: 'Read harness chat',
|
|
146
|
+
description:
|
|
147
|
+
'Read a chat through the harness web server bound to an explicit connection.',
|
|
148
|
+
inputSchema: {
|
|
149
|
+
connectionId: plugins.z.string().max(128).describe('Connection id returned by connect_harness'),
|
|
150
|
+
chatId: plugins.z.string().min(1).max(1024),
|
|
151
|
+
limit: plugins.z.number().int().min(1).max(500).optional(),
|
|
152
|
+
maxChars: plugins.z.number().int().min(200).max(50000).optional(),
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
async (args) =>
|
|
156
|
+
this.wrapToolCall(async () => {
|
|
157
|
+
const transcript = await this.connections
|
|
158
|
+
.get(args.connectionId)
|
|
159
|
+
.readChat(args.chatId, args.limit ?? 20, args.maxChars ?? 2000);
|
|
160
|
+
const header = [
|
|
161
|
+
`harness: ${transcript.harness}`,
|
|
162
|
+
`chatId: ${transcript.chatId}`,
|
|
163
|
+
`title: ${transcript.title}`,
|
|
164
|
+
`directory: ${transcript.directory}`,
|
|
165
|
+
transcript.totalMessages === undefined
|
|
166
|
+
? `messages: showing ${transcript.messages.length}; server total unavailable`
|
|
167
|
+
: `messages: showing ${transcript.messages.length} of ${transcript.totalMessages}`,
|
|
168
|
+
].join('\n');
|
|
169
|
+
const body = transcript.messages
|
|
170
|
+
.map(
|
|
171
|
+
(message) =>
|
|
172
|
+
`-- [${message.role}]${message.timestamp ? ` ${message.timestamp}` : ''}\n${message.text}`,
|
|
173
|
+
)
|
|
174
|
+
.join('\n');
|
|
175
|
+
return `${header}\n\n${body}`;
|
|
176
|
+
}),
|
|
177
|
+
));
|
|
178
|
+
|
|
179
|
+
registeredTools.push(serverArg.registerTool(
|
|
180
|
+
'send_message',
|
|
181
|
+
{
|
|
182
|
+
title: 'Send message through harness server',
|
|
183
|
+
description:
|
|
184
|
+
'Send a message only through the harness web server bound to an explicit connection and wait for the reply. There is no CLI, process, local-store, discovery, or retry fallback.',
|
|
185
|
+
inputSchema: {
|
|
186
|
+
connectionId: plugins.z.string().max(128).describe('Connection id returned by connect_harness'),
|
|
187
|
+
chatId: plugins.z.string().min(1).max(1024),
|
|
188
|
+
message: plugins.z.string().min(1).max(1024 * 1024),
|
|
189
|
+
timeoutSeconds: plugins.z.number().int().min(1).max(3600).optional(),
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
async (args, extra) =>
|
|
193
|
+
this.wrapToolCall(async () => {
|
|
194
|
+
const result = await this.connections
|
|
195
|
+
.get(args.connectionId)
|
|
196
|
+
.sendMessage(args.chatId, args.message, args.timeoutSeconds ?? 300, extra.signal);
|
|
197
|
+
return `${result.reply}\n\n[crossharness transport: ${result.via}]`;
|
|
198
|
+
}),
|
|
199
|
+
));
|
|
200
|
+
|
|
201
|
+
registeredTools.push(serverArg.registerTool(
|
|
202
|
+
'send_message_async',
|
|
203
|
+
{
|
|
204
|
+
title: 'Send message through harness server asynchronously',
|
|
205
|
+
description:
|
|
206
|
+
'Start a server-only send and return a dispatchId immediately. Both this connectionId and the dispatchId are required by check_reply.',
|
|
207
|
+
inputSchema: {
|
|
208
|
+
connectionId: plugins.z.string().max(128).describe('Connection id returned by connect_harness'),
|
|
209
|
+
chatId: plugins.z.string().min(1).max(1024),
|
|
210
|
+
message: plugins.z.string().min(1).max(1024 * 1024),
|
|
211
|
+
timeoutSeconds: plugins.z.number().int().min(1).max(3600).optional(),
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
async (args) =>
|
|
215
|
+
this.wrapToolCall(async () => {
|
|
216
|
+
const connection = this.connections.get(args.connectionId);
|
|
217
|
+
const record = this.dispatches.track(
|
|
218
|
+
args.connectionId,
|
|
219
|
+
connection.harness,
|
|
220
|
+
args.chatId,
|
|
221
|
+
() => connection.sendMessage(args.chatId, args.message, args.timeoutSeconds ?? 900),
|
|
222
|
+
);
|
|
223
|
+
return [
|
|
224
|
+
`connectionId: ${record.connectionId}`,
|
|
225
|
+
`dispatchId: ${record.dispatchId}`,
|
|
226
|
+
`harness: ${record.harness}`,
|
|
227
|
+
`chatId: ${record.chatId}`,
|
|
228
|
+
`startedAt: ${record.startedAt}`,
|
|
229
|
+
].join('\n');
|
|
230
|
+
}),
|
|
231
|
+
));
|
|
232
|
+
|
|
233
|
+
registeredTools.push(serverArg.registerTool(
|
|
234
|
+
'check_reply',
|
|
235
|
+
{
|
|
236
|
+
title: 'Check async server send',
|
|
237
|
+
description:
|
|
238
|
+
'Check an asynchronous send. The connectionId must own the dispatch. Records remain inspectable after disconnect.',
|
|
239
|
+
inputSchema: {
|
|
240
|
+
connectionId: plugins.z.string().max(128).describe('Connection id used for send_message_async'),
|
|
241
|
+
dispatchId: plugins.z.string().max(128).describe('Dispatch id returned by send_message_async'),
|
|
242
|
+
waitSeconds: plugins.z.number().int().min(0).max(60).optional(),
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
async (args, extra) =>
|
|
246
|
+
this.wrapToolCall(async () => {
|
|
247
|
+
const record = await this.dispatches.waitFor(
|
|
248
|
+
args.connectionId,
|
|
249
|
+
args.dispatchId,
|
|
250
|
+
(args.waitSeconds ?? 0) * 1000,
|
|
251
|
+
extra.signal,
|
|
252
|
+
);
|
|
253
|
+
if (!record) throw new Error('unknown dispatchId for this connectionId');
|
|
254
|
+
const header = [
|
|
255
|
+
`connectionId: ${record.connectionId}`,
|
|
256
|
+
`dispatchId: ${record.dispatchId}`,
|
|
257
|
+
`status: ${record.status}`,
|
|
258
|
+
`harness: ${record.harness}`,
|
|
259
|
+
`chatId: ${record.chatId}`,
|
|
260
|
+
`startedAt: ${record.startedAt}`,
|
|
261
|
+
...(record.completedAt ? [`completedAt: ${record.completedAt}`] : []),
|
|
262
|
+
].join('\n');
|
|
263
|
+
if (record.status === 'working') return `${header}\n\nStill working.`;
|
|
264
|
+
if (record.status === 'failed') return `${header}\n\nError: ${record.error}`;
|
|
265
|
+
return `${header}\n\n${record.reply}\n\n[crossharness transport: ${record.via}]`;
|
|
266
|
+
}),
|
|
267
|
+
));
|
|
268
|
+
} catch (errorArg) {
|
|
269
|
+
for (const registeredTool of registeredTools.reverse()) registeredTool.remove();
|
|
270
|
+
throw errorArg;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
this.registeredTools = registeredTools;
|
|
274
|
+
this.registeredServer = serverArg;
|
|
275
|
+
this.registered = true;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Close the externally owned MCP server before closing this registrar. */
|
|
279
|
+
public async close(): Promise<void> {
|
|
280
|
+
if (this.closePromise) return this.closePromise;
|
|
281
|
+
if (this.registeredServer?.isConnected()) {
|
|
282
|
+
throw new Error(
|
|
283
|
+
'Crossharness MCP tool registrar cannot close while its MCP server is connected; close the shared MCP server first',
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
this.closeStarted = true;
|
|
287
|
+
this.removeRegisteredTools();
|
|
288
|
+
this.registeredServer = undefined;
|
|
289
|
+
this.closePromise = this.ensureResourceShutdown().finally(() => {
|
|
290
|
+
this.closePromise = undefined;
|
|
291
|
+
});
|
|
292
|
+
return this.closePromise;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
private removeRegisteredTools(): void {
|
|
296
|
+
for (const registeredTool of this.registeredTools.reverse()) registeredTool.remove();
|
|
297
|
+
this.registeredTools = [];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
private ensureResourceShutdown(): Promise<void> {
|
|
301
|
+
if (this.resourceShutdownPromise) return this.resourceShutdownPromise;
|
|
302
|
+
let shutdownPromise!: Promise<void>;
|
|
303
|
+
shutdownPromise = this.connections.closeAll().finally(() => {
|
|
304
|
+
this.dispatches.dispose();
|
|
305
|
+
}).catch((errorArg) => {
|
|
306
|
+
if (this.resourceShutdownPromise === shutdownPromise) {
|
|
307
|
+
this.resourceShutdownPromise = undefined;
|
|
308
|
+
}
|
|
309
|
+
throw errorArg;
|
|
310
|
+
});
|
|
311
|
+
this.resourceShutdownPromise = shutdownPromise;
|
|
312
|
+
return shutdownPromise;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private describeConnection(infoArg: interfaces.IConnectionInfo): string {
|
|
316
|
+
return [
|
|
317
|
+
`connectionId: ${infoArg.connectionId}`,
|
|
318
|
+
`harness: ${infoArg.harness}`,
|
|
319
|
+
`serverUrl: ${infoArg.serverUrl}`,
|
|
320
|
+
`directory: ${infoArg.directory}`,
|
|
321
|
+
`state: ${infoArg.state}`,
|
|
322
|
+
`connectedAt: ${infoArg.connectedAt}`,
|
|
323
|
+
...(infoArg.serverVersion ? [`serverVersion: ${infoArg.serverVersion}`] : []),
|
|
324
|
+
].join('\n');
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private async wrapToolCall(
|
|
328
|
+
handlerArg: () => Promise<string>,
|
|
329
|
+
): Promise<{ content: Array<{ type: 'text'; text: string }>; isError?: boolean }> {
|
|
330
|
+
try {
|
|
331
|
+
const text = await handlerArg();
|
|
332
|
+
return { content: [{ type: 'text', text: text.slice(0, 100000) }] };
|
|
333
|
+
} catch (error) {
|
|
334
|
+
return {
|
|
335
|
+
content: [
|
|
336
|
+
{
|
|
337
|
+
type: 'text',
|
|
338
|
+
text: `Error: ${error instanceof Error ? error.message : String(error)}`.slice(0, 100000),
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
isError: true,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
package/ts/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './interfaces.js';
|
|
2
|
+
export * from './classes.codexappserverclient.js';
|
|
2
3
|
export * from './classes.connectionregistry.js';
|
|
3
4
|
export * from './classes.dispatchregistry.js';
|
|
5
|
+
export * from './classes.mcptoolregistrar.js';
|
|
4
6
|
export * from './classes.mcpserver.js';
|
|
5
7
|
|
|
6
8
|
import { CrossHarnessMcpServer } from './classes.mcpserver.js';
|
package/ts/plugins.ts
CHANGED
|
@@ -9,6 +9,7 @@ export type { AddressInfo };
|
|
|
9
9
|
|
|
10
10
|
// Third-party modules
|
|
11
11
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
12
|
+
import type { RegisteredTool } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
12
13
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
13
14
|
import { Client as McpClient } from '@modelcontextprotocol/sdk/client/index.js';
|
|
14
15
|
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
@@ -27,4 +28,5 @@ export {
|
|
|
27
28
|
z,
|
|
28
29
|
};
|
|
29
30
|
export type { RawData };
|
|
31
|
+
export type { RegisteredTool };
|
|
30
32
|
export type { Transport };
|