-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprobe.ts
More file actions
32 lines (28 loc) · 1.4 KB
/
Copy pathprobe.ts
File metadata and controls
32 lines (28 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const API_KEY = process.env.SNIPPET_API_KEY ?? '';
const base = process.env.AGENT_URL_BASE;
if (!base) throw new Error('AGENT_URL_BASE is required');
const url = `${base}/mcp-${Date.now()}`;
const expected = 'eniratco';
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
for (let attempt = 0; attempt < 15; attempt += 1) {
const response = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json', 'x-api-key': API_KEY }, body: JSON.stringify({ kind: 'user', body: JSON.stringify({ text: 'octarine' }) }) });
if (response.status === 202 || response.status === 200) break;
if (attempt === 14) throw new Error(`expected 202, got ${response.status}`);
await sleep(4000);
}
const deadline = Date.now() + 120_000;
while (Date.now() < deadline) {
const response = await fetch(url);
if (response.ok) {
const snapshot = (await response.json()) as { messages?: Array<{ role: string; parts?: Array<{ type: string; text?: string }> }> };
const text = (snapshot.messages ?? []).filter((message) => message.role === 'assistant').flatMap((message) => message.parts ?? []).filter((part) => part.type === 'text').map((part) => part.text ?? '').join('\n');
if (text.toLowerCase().includes(expected)) {
console.log(`MCP reverse result: ${text}`);
process.exit(0);
}
}
await sleep(2000);
}
throw new Error('timed out waiting for MCP result');