Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ client.on('data',d=>{
buf=lines.pop()||'';
for(const line of lines){
if(!line.trim())continue;
const msg=JSON.parse(line);
let msg;try{msg=JSON.parse(line);}catch{continue;}
if(msg.id===1){
client.write(JSON.stringify({jsonrpc:'2.0',id:2,method:'tools/list',params:{}})+'\\n');
}else if(msg.id===2){
Expand All @@ -100,7 +100,11 @@ client.on('error',e=>{process.stderr.write(e.message);process.exit(1);});
timeout: 10_000,
encoding: "utf-8",
});
return JSON.parse(result);
try {
return JSON.parse(result);
} catch {
throw new Error(`Failed to parse MCP tool discovery response: ${result.slice(0, 200)}`);
}
}

/** Call an MCP tool via direct TCP connection to the DimOS server. */
Expand Down Expand Up @@ -140,7 +144,12 @@ async function callTool(
buf = lines.pop() || "";
for (const line of lines) {
if (!line.trim()) continue;
const msg = JSON.parse(line);
let msg: { id?: number; result?: { content?: unknown }; error?: { message: string } };
try {
msg = JSON.parse(line);
} catch {
continue; // skip malformed JSON lines
}
if (phase === "init" && msg.id === 1) {
phase = "call";
client.write(
Expand Down