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
7 changes: 5 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ function jsonSchemaToTypebox(
function discoverToolsSync(host: string, port: number): McpToolDef[] {
const script = `
const net = require('net');
const client = net.createConnection(${port}, ${JSON.stringify(host)}, () => {
const host = process.env.MCP_HOST;
const port = parseInt(process.env.MCP_PORT, 10);
const client = net.createConnection(port, host, () => {
client.write(JSON.stringify({jsonrpc:'2.0',id:1,method:'initialize',params:{protocolVersion:'2024-11-05',capabilities:{},clientInfo:{name:'openclaw-dimos',version:'0.0.1'}}})+'\\n');
});
let buf='';
Expand All @@ -85,7 +87,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 @@ -99,6 +101,7 @@ client.on('error',e=>{process.stderr.write(e.message);process.exit(1);});
const result = execFileSync("node", ["-e", script], {
timeout: 10_000,
encoding: "utf-8",
env: { ...process.env, MCP_HOST: host, MCP_PORT: String(port) },
});
return JSON.parse(result);
}
Expand Down