@stdiobus/workers-registry 1.4.9 → 1.4.11
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/out/dist/workers-registry/acp-registry/index.js +1 -1
- package/out/dist/workers-registry/acp-registry/index.js.map +2 -2
- package/out/dist/workers-registry/acp-worker/index.js +1 -1
- package/out/dist/workers-registry/acp-worker/index.js.map +2 -2
- package/out/dist/workers-registry/mcp-to-acp-proxy/proxy.js +1 -1
- package/out/dist/workers-registry/mcp-to-acp-proxy/proxy.js.map +2 -2
- package/out/tsc/workers-registry/acp-worker/src/registry-launcher/router/message-router.d.ts +37 -0
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import net from"net";import{createInterface}from"readline";var ACP_HOST=process.env.ACP_HOST||"127.0.0.1";var ACP_PORT=process.env.ACP_PORT||9e3;var AGENT_ID=process.env.AGENT_ID||"default-agent";console.error(`[MCP-APC][proxy] Starting proxy...`);console.error(`[MCP-APC][proxy] Target: ${ACP_HOST}:${ACP_PORT}`);console.error(`[MCP-APC][proxy] Agent ID: ${AGENT_ID}`);var acpSocket=net.connect(ACP_PORT,ACP_HOST);var acpConnected=false;var proxySessionId=null;var acpSessionId=null;var pendingRequests=new Map;var accumulatedText=new Map;acpSocket.on("connect",()=>{console.error("[MCP-APC][proxy] Connected to ACP stdio Bus");acpConnected=true});acpSocket.on("error",err=>{console.error(`[MCP-APC][proxy] ACP connection error: ${err.message}`);process.exit(1)});var acpBuffer="";acpSocket.on("data",data=>{acpBuffer+=data.toString();let newlineIndex;while((newlineIndex=acpBuffer.indexOf("\n"))!==-1){const line=acpBuffer.slice(0,newlineIndex);acpBuffer=acpBuffer.slice(newlineIndex+1);if(line.trim()){try{const acpMsg=JSON.parse(line);console.error(`[MCP-APC][proxy] \u2190 ACP: ${JSON.stringify(acpMsg)}`);if(acpMsg.id===void 0||acpMsg.id===null){console.error(`[MCP-APC][proxy] Processing notification: ${acpMsg.method}`);handleACPNotification(acpMsg)}else{console.error(`[MCP-APC][proxy] Processing response id=${acpMsg.id}`);console.error(`[MCP-APC][proxy] Pending: ${JSON.stringify([...pendingRequests.keys()])}`);const mcpResponse=convertACPtoMCP(acpMsg);if(mcpResponse){console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(mcpResponse)}`);process.stdout.write(JSON.stringify(mcpResponse)+"\n")}else{console.error(`[MCP-APC][proxy] WARNING: No MCP response for id=${acpMsg.id}`)}}}catch(err){console.error(`[MCP-APC][proxy] Error parsing ACP: ${err.message}`)}}}});var rl=createInterface({input:process.stdin,terminal:false});rl.on("line",line=>{if(!line.trim())return;try{const mcpReq=JSON.parse(line);console.error(`[MCP-APC][proxy] \u2190 MCP: ${JSON.stringify(mcpReq)}`);const acpReq=convertMCPtoACP(mcpReq);if(acpReq){console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(acpReq)}`);if(acpConnected){acpSocket.write(JSON.stringify(acpReq)+"\n")}}}catch(err){console.error(`[MCP-APC][proxy] Error parsing MCP: ${err.message}`)}});function handleACPNotification(msg){const{method,params}=msg;if(method==="session/update"&¶ms?.update){const update=params.update;for(const[reqId,pending]of pendingRequests.entries()){if(pending.method==="session/prompt"){if(update.sessionUpdate==="agent_message_chunk"&&update.content?.text){if(!accumulatedText.has(reqId)){accumulatedText.set(reqId,"")}accumulatedText.set(reqId,accumulatedText.get(reqId)+update.content.text)}break}}}}function convertMCPtoACP(mcpReq){const{id,method,params}=mcpReq;if(id===void 0||id===null){return null}pendingRequests.set(id,{method,params});if(!proxySessionId){proxySessionId=`proxy-${Date.now()}`}switch(method){case"initialize":return{jsonrpc:"2.0",id,method:"initialize",agentId:AGENT_ID,sessionId:proxySessionId,params:{protocolVersion:1,clientCapabilities:params?.capabilities||{},clientInfo:params?.clientInfo||{name:"mcp-proxy",version:"1.0.0"}}};case"tools/list":sendMCP({jsonrpc:"2.0",id,result:{tools:[{name:"acp_prompt",description:`Send prompt to ${AGENT_ID}`,inputSchema:{type:"object",properties:{prompt:{type:"string",description:"Prompt text"}},required:["prompt"]}}]}});pendingRequests.delete(id);return null;case"tools/call":const promptText=params?.arguments?.prompt||"";if(!acpSessionId){const sessionReqId=`sess-${id}`;pendingRequests.set(sessionReqId,{method:"session/new",originalId:id,promptText});return{jsonrpc:"2.0",id:sessionReqId,method:"session/new",agentId:AGENT_ID,sessionId:proxySessionId,params:{cwd:process.cwd(),mcpServers:[]}}}pendingRequests.set(id,{method:"session/prompt",params});return{jsonrpc:"2.0",id,method:"session/prompt",agentId:AGENT_ID,sessionId:proxySessionId,params:{sessionId:acpSessionId,prompt:[{type:"text",text:promptText}]}};case"resources/list":sendMCP({jsonrpc:"2.0",id,result:{resources:[]}});pendingRequests.delete(id);return null;case"resources/templates/list":sendMCP({jsonrpc:"2.0",id,result:{resourceTemplates:[]}});pendingRequests.delete(id);return null;case"prompts/list":sendMCP({jsonrpc:"2.0",id,result:{prompts:[]}});pendingRequests.delete(id);return null;default:sendMCP({jsonrpc:"2.0",id,error:{code:-32601,message:`Unknown method: ${method}`}});pendingRequests.delete(id);return null}}function convertACPtoMCP(acpResp){const{id,result,error}=acpResp;const pending=pendingRequests.get(id);if(!pending){console.error(`[MCP-APC][proxy] ERROR: No pending request for id=${id}`);return null}console.error(`[MCP-APC][proxy] Converting ACP->MCP for method: ${pending.method}`);pendingRequests.delete(id);if(error){accumulatedText.delete(id);return{jsonrpc:"2.0",id,error:{code:error.code||-32603,message:error.message||"ACP error"}}}switch(pending.method){case"initialize":return{jsonrpc:"2.0",id,result:{protocolVersion:"2024-11-05",capabilities:{tools:{},resources:{}},serverInfo:result?.agentInfo||{name:"acp-agent",version:"1.0.0"}}};case"session/new":acpSessionId=result?.sessionId;console.error(`[MCP-APC][proxy] ACP session: ${acpSessionId}`);if(pending.originalId&&pending.promptText){const promptReq={jsonrpc:"2.0",id:pending.originalId,method:"session/prompt",agentId:AGENT_ID,sessionId:proxySessionId,params:{sessionId:acpSessionId,prompt:[{type:"text",text:pending.promptText}]}};pendingRequests.set(pending.originalId,{method:"session/prompt"});console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(promptReq)}`);if(acpConnected){acpSocket.write(JSON.stringify(promptReq)+"\n")}}return null;case"session/prompt":const text=accumulatedText.get(id)||"";accumulatedText.delete(id);console.error(`[MCP-APC][proxy] Returning accumulated text (${text.length} chars): "${text.substring(0,50)}..."`);return{jsonrpc:"2.0",id,result:{content:[{type:"text",text:text||"No response"}]}};default:console.error(`[MCP-APC][proxy] WARNING: Unhandled method ${pending.method}, returning raw result`);return{jsonrpc:"2.0",id,result:result||{}}}}function sendMCP(msg){console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(msg)}`);process.stdout.write(JSON.stringify(msg)+"\n")}process.on("SIGTERM",()=>{acpSocket.end();process.exit(0)});process.on("SIGINT",()=>{acpSocket.end();process.exit(0)});
|
|
2
|
+
import net from"net";import{createInterface}from"readline";var ACP_HOST=process.env.ACP_HOST||"127.0.0.1";var ACP_PORT=process.env.ACP_PORT||9e3;var AGENT_ID=process.env.AGENT_ID||"default-agent";console.error(`[MCP-APC][proxy] Starting proxy...`);console.error(`[MCP-APC][proxy] Target: ${ACP_HOST}:${ACP_PORT}`);console.error(`[MCP-APC][proxy] Agent ID: ${AGENT_ID}`);var acpSocket=net.connect(ACP_PORT,ACP_HOST);var acpConnected=false;var proxySessionId=null;var acpSessionId=null;var pendingRequests=new Map;var accumulatedText=new Map;acpSocket.on("connect",()=>{console.error("[MCP-APC][proxy] Connected to ACP stdio Bus");acpConnected=true});acpSocket.on("error",err=>{console.error(`[MCP-APC][proxy] ACP connection error: ${err.message}`);process.exit(1)});var acpBuffer="";acpSocket.on("data",data=>{acpBuffer+=data.toString();let newlineIndex;while((newlineIndex=acpBuffer.indexOf("\n"))!==-1){const line=acpBuffer.slice(0,newlineIndex);acpBuffer=acpBuffer.slice(newlineIndex+1);if(line.trim()){try{const acpMsg=JSON.parse(line);console.error(`[MCP-APC][proxy] \u2190 ACP: ${JSON.stringify(acpMsg)}`);if(acpMsg.id===void 0||acpMsg.id===null){console.error(`[MCP-APC][proxy] Processing notification: ${acpMsg.method}`);handleACPNotification(acpMsg)}else{console.error(`[MCP-APC][proxy] Processing response id=${acpMsg.id}`);console.error(`[MCP-APC][proxy] Pending: ${JSON.stringify([...pendingRequests.keys()])}`);const mcpResponse=convertACPtoMCP(acpMsg);if(mcpResponse){console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(mcpResponse)}`);process.stdout.write(JSON.stringify(mcpResponse)+"\n")}else{console.error(`[MCP-APC][proxy] WARNING: No MCP response for id=${acpMsg.id}`)}}}catch(err){console.error(`[MCP-APC][proxy] Error parsing ACP: ${err.message}`)}}}});var rl=createInterface({input:process.stdin,terminal:false});rl.on("line",line=>{if(!line.trim())return;try{const mcpReq=JSON.parse(line);console.error(`[MCP-APC][proxy] \u2190 MCP: ${JSON.stringify(mcpReq)}`);const acpReq=convertMCPtoACP(mcpReq);if(acpReq){console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(acpReq)}`);if(acpConnected){acpSocket.write(JSON.stringify(acpReq)+"\n")}}}catch(err){console.error(`[MCP-APC][proxy] Error parsing MCP: ${err.message}`)}});function handleACPNotification(msg){const{method,params}=msg;if(method==="session/update"&¶ms?.update){const update=params.update;for(const[reqId,pending]of pendingRequests.entries()){if(pending.method==="session/prompt"){if(update.sessionUpdate==="agent_message_chunk"&&update.content?.text){if(!accumulatedText.has(reqId)){accumulatedText.set(reqId,"")}accumulatedText.set(reqId,accumulatedText.get(reqId)+update.content.text)}break}}}}function convertMCPtoACP(mcpReq){const{id,method,params}=mcpReq;if(id===void 0||id===null){return null}pendingRequests.set(id,{method,params});if(!proxySessionId){proxySessionId=`proxy-${Date.now()}`}switch(method){case"initialize":return{jsonrpc:"2.0",id,method:"initialize",agentId:AGENT_ID,sessionId:proxySessionId,params:{protocolVersion:1,clientCapabilities:params?.capabilities||{},clientInfo:params?.clientInfo||{name:"mcp-proxy",version:"1.0.0"}}};case"tools/list":sendMCP({jsonrpc:"2.0",id,result:{tools:[{name:"acp_prompt",description:`Send prompt to ${AGENT_ID}`,inputSchema:{type:"object",properties:{prompt:{type:"string",description:"Prompt text"}},required:["prompt"]}}]}});pendingRequests.delete(id);return null;case"tools/call":const promptText=params?.arguments?.prompt||"";if(!acpSessionId){const sessionReqId=`sess-${id}`;pendingRequests.set(sessionReqId,{method:"session/new",originalId:id,promptText});return{jsonrpc:"2.0",id:sessionReqId,method:"session/new",agentId:AGENT_ID,sessionId:proxySessionId,params:{cwd:process.cwd(),mcpServers:[]}}}pendingRequests.set(id,{method:"session/prompt",params});return{jsonrpc:"2.0",id,method:"session/prompt",agentId:AGENT_ID,sessionId:proxySessionId,params:{sessionId:acpSessionId,prompt:[{type:"text",text:promptText}]}};case"resources/list":sendMCP({jsonrpc:"2.0",id,result:{resources:[]}});pendingRequests.delete(id);return null;case"resources/templates/list":sendMCP({jsonrpc:"2.0",id,result:{resourceTemplates:[]}});pendingRequests.delete(id);return null;case"prompts/list":sendMCP({jsonrpc:"2.0",id,result:{prompts:[]}});pendingRequests.delete(id);return null;default:sendMCP({jsonrpc:"2.0",id,error:{code:-32601,message:`Unknown method: ${method}`}});pendingRequests.delete(id);return null}}function convertACPtoMCP(acpResp){const{id,result,error}=acpResp;const pending=pendingRequests.get(id);if(!pending){console.error(`[MCP-APC][proxy] ERROR: No pending request for id=${id}`);return null}console.error(`[MCP-APC][proxy] Converting ACP->MCP for method: ${pending.method}`);pendingRequests.delete(id);if(error){if(pending.method==="session/prompt"){const text=accumulatedText.get(id)||"";accumulatedText.delete(id);if(text.length>0){console.error(`[MCP-APC][proxy] Agent error after streaming, returning accumulated text (${text.length} chars) instead of error`);return{jsonrpc:"2.0",id,result:{content:[{type:"text",text}]}}}}accumulatedText.delete(id);return{jsonrpc:"2.0",id,error:{code:error.code||-32603,message:error.message||"ACP error"}}}switch(pending.method){case"initialize":return{jsonrpc:"2.0",id,result:{protocolVersion:"2024-11-05",capabilities:{tools:{},resources:{}},serverInfo:result?.agentInfo||{name:"acp-agent",version:"1.0.0"}}};case"session/new":acpSessionId=result?.sessionId;console.error(`[MCP-APC][proxy] ACP session: ${acpSessionId}`);if(pending.originalId&&pending.promptText){const promptReq={jsonrpc:"2.0",id:pending.originalId,method:"session/prompt",agentId:AGENT_ID,sessionId:proxySessionId,params:{sessionId:acpSessionId,prompt:[{type:"text",text:pending.promptText}]}};pendingRequests.set(pending.originalId,{method:"session/prompt"});console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(promptReq)}`);if(acpConnected){acpSocket.write(JSON.stringify(promptReq)+"\n")}}return null;case"session/prompt":const text=accumulatedText.get(id)||"";accumulatedText.delete(id);console.error(`[MCP-APC][proxy] Returning accumulated text (${text.length} chars): "${text.substring(0,50)}..."`);return{jsonrpc:"2.0",id,result:{content:[{type:"text",text:text||"No response"}]}};default:console.error(`[MCP-APC][proxy] WARNING: Unhandled method ${pending.method}, returning raw result`);return{jsonrpc:"2.0",id,result:result||{}}}}function sendMCP(msg){console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(msg)}`);process.stdout.write(JSON.stringify(msg)+"\n")}process.on("SIGTERM",()=>{acpSocket.end();process.exit(0)});process.on("SIGINT",()=>{acpSocket.end();process.exit(0)});
|
|
3
3
|
//# sourceMappingURL=proxy.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../workers-registry/mcp-to-acp-proxy/proxy.js"],
|
|
4
|
-
"sourcesContent": ["#!/usr/bin/env node\n\n/*\n * Apache License 2.0\n * Copyright (c) 2025\u2013present Raman Marozau, Target Insight Function.\n * Contact: raman@worktif.com\n *\n * This file is part of the stdio bus protocol reference implementation:\n * stdio_bus_kernel_workers (target: <target_stdio_bus_kernel_workers>).\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * MCP-to-ACP Protocol Proxy\n *\n * Converts MCP protocol (from Kiro) to ACP protocol (for stdio Bus)\n * Runs as MCP server for Kiro, forwards to ACP via TCP\n */\n\nimport net from 'net';\nimport { createInterface } from 'readline';\n\nconst ACP_HOST = process.env.ACP_HOST || '127.0.0.1';\nconst ACP_PORT = process.env.ACP_PORT || 9000;\nconst AGENT_ID = process.env.AGENT_ID || 'default-agent';\n\nconsole.error(`[MCP-APC][proxy] Starting proxy...`);\nconsole.error(`[MCP-APC][proxy] Target: ${ACP_HOST}:${ACP_PORT}`);\nconsole.error(`[MCP-APC][proxy] Agent ID: ${AGENT_ID}`);\n\n// State\nconst acpSocket = net.connect(ACP_PORT, ACP_HOST);\nlet acpConnected = false;\nlet proxySessionId = null; // For stdio Bus routing\nlet acpSessionId = null; // From ACP agent\nlet pendingRequests = new Map(); // id -> {method, params, ...}\nlet accumulatedText = new Map(); // requestId -> accumulated text\n\nacpSocket.on('connect', () => {\n console.error('[MCP-APC][proxy] Connected to ACP stdio Bus');\n acpConnected = true;\n});\n\nacpSocket.on('error', (err) => {\n console.error(`[MCP-APC][proxy] ACP connection error: ${err.message}`);\n process.exit(1);\n});\n\n// Handle ACP messages\nlet acpBuffer = '';\nacpSocket.on('data', (data) => {\n acpBuffer += data.toString();\n\n let newlineIndex;\n while ((newlineIndex = acpBuffer.indexOf('\\n')) !== -1) {\n const line = acpBuffer.slice(0, newlineIndex);\n acpBuffer = acpBuffer.slice(newlineIndex + 1);\n\n if (line.trim()) {\n try {\n const acpMsg = JSON.parse(line);\n console.error(`[MCP-APC][proxy] \u2190 ACP: ${JSON.stringify(acpMsg)}`);\n\n // Check if notification or response\n if (acpMsg.id === undefined || acpMsg.id === null) {\n // Notification from ACP worker - rewrite sessionId and send back to stdio Bus\n console.error(`[MCP-APC][proxy] Processing notification: ${acpMsg.method}`);\n handleACPNotification(acpMsg);\n } else {\n // Response\n console.error(`[MCP-APC][proxy] Processing response id=${acpMsg.id}`);\n console.error(`[MCP-APC][proxy] Pending: ${JSON.stringify([...pendingRequests.keys()])}`);\n const mcpResponse = convertACPtoMCP(acpMsg);\n if (mcpResponse) {\n console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(mcpResponse)}`);\n process.stdout.write(JSON.stringify(mcpResponse) + '\\n');\n } else {\n console.error(`[MCP-APC][proxy] WARNING: No MCP response for id=${acpMsg.id}`);\n }\n }\n } catch (err) {\n console.error(`[MCP-APC][proxy] Error parsing ACP: ${err.message}`);\n }\n }\n }\n});\n\n// Handle MCP requests\nconst rl = createInterface({\n input: process.stdin,\n terminal: false\n});\n\nrl.on('line', (line) => {\n if (!line.trim()) return;\n\n try {\n const mcpReq = JSON.parse(line);\n console.error(`[MCP-APC][proxy] \u2190 MCP: ${JSON.stringify(mcpReq)}`);\n\n const acpReq = convertMCPtoACP(mcpReq);\n if (acpReq) {\n console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(acpReq)}`);\n if (acpConnected) {\n acpSocket.write(JSON.stringify(acpReq) + '\\n');\n }\n }\n } catch (err) {\n console.error(`[MCP-APC][proxy] Error parsing MCP: ${err.message}`);\n }\n});\n\nfunction handleACPNotification(msg) {\n const { method, params } = msg;\n\n if (method === 'session/update' && params?.update) {\n const update = params.update;\n\n // Find pending session/prompt request\n for (const [reqId, pending] of pendingRequests.entries()) {\n if (pending.method === 'session/prompt') {\n if (update.sessionUpdate === 'agent_message_chunk' && update.content?.text) {\n if (!accumulatedText.has(reqId)) {\n accumulatedText.set(reqId, '');\n }\n accumulatedText.set(reqId, accumulatedText.get(reqId) + update.content.text);\n }\n break;\n }\n }\n }\n // Note: Notifications are processed internally, not forwarded\n // They accumulate text for the final response\n}\n\nfunction convertMCPtoACP(mcpReq) {\n const { id, method, params } = mcpReq;\n\n if (id === undefined || id === null) {\n return null; // Ignore notifications\n }\n\n pendingRequests.set(id, { method, params });\n\n if (!proxySessionId) {\n proxySessionId = `proxy-${Date.now()}`;\n }\n\n switch (method) {\n case 'initialize':\n return {\n jsonrpc: '2.0',\n id,\n method: 'initialize',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n protocolVersion: 1,\n clientCapabilities: params?.capabilities || {},\n clientInfo: params?.clientInfo || { name: 'mcp-proxy', version: '1.0.0' }\n }\n };\n\n case 'tools/list':\n sendMCP({\n jsonrpc: '2.0',\n id,\n result: {\n tools: [{\n name: 'acp_prompt',\n description: `Send prompt to ${AGENT_ID}`,\n inputSchema: {\n type: 'object',\n properties: {\n prompt: { type: 'string', description: 'Prompt text' }\n },\n required: ['prompt']\n }\n }]\n }\n });\n pendingRequests.delete(id);\n return null;\n\n case 'tools/call':\n const promptText = params?.arguments?.prompt || '';\n\n if (!acpSessionId) {\n // Need to create session first\n const sessionReqId = `sess-${id}`;\n pendingRequests.set(sessionReqId, {\n method: 'session/new',\n originalId: id,\n promptText\n });\n return {\n jsonrpc: '2.0',\n id: sessionReqId,\n method: 'session/new',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: { cwd: process.cwd(), mcpServers: [] }\n };\n }\n\n // Session exists, send prompt\n // IMPORTANT: Update pending to session/prompt since that's what we're sending\n pendingRequests.set(id, { method: 'session/prompt', params });\n return {\n jsonrpc: '2.0',\n id,\n method: 'session/prompt',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n sessionId: acpSessionId,\n prompt: [{ type: 'text', text: promptText }]\n }\n };\n\n case 'resources/list':\n sendMCP({ jsonrpc: '2.0', id, result: { resources: [] } });\n pendingRequests.delete(id);\n return null;\n\n case 'resources/templates/list':\n sendMCP({ jsonrpc: '2.0', id, result: { resourceTemplates: [] } });\n pendingRequests.delete(id);\n return null;\n\n case 'prompts/list':\n sendMCP({ jsonrpc: '2.0', id, result: { prompts: [] } });\n pendingRequests.delete(id);\n return null;\n\n default:\n sendMCP({ jsonrpc: '2.0', id, error: { code: -32601, message: `Unknown method: ${method}` } });\n pendingRequests.delete(id);\n return null;\n }\n}\n\nfunction convertACPtoMCP(acpResp) {\n const { id, result, error } = acpResp;\n\n const pending = pendingRequests.get(id);\n if (!pending) {\n console.error(`[MCP-APC][proxy] ERROR: No pending request for id=${id}`);\n return null;\n }\n\n console.error(`[MCP-APC][proxy] Converting ACP->MCP for method: ${pending.method}`);\n pendingRequests.delete(id);\n\n if (error) {\n accumulatedText.delete(id);\n return {\n jsonrpc: '2.0',\n id,\n error: { code: error.code || -32603, message: error.message || 'ACP error' }\n };\n }\n\n switch (pending.method) {\n case 'initialize':\n return {\n jsonrpc: '2.0',\n id,\n result: {\n protocolVersion: '2024-11-05',\n capabilities: { tools: {}, resources: {} },\n serverInfo: result?.agentInfo || { name: 'acp-agent', version: '1.0.0' }\n }\n };\n\n case 'session/new':\n acpSessionId = result?.sessionId;\n console.error(`[MCP-APC][proxy] ACP session: ${acpSessionId}`);\n\n if (pending.originalId && pending.promptText) {\n // Send queued prompt\n const promptReq = {\n jsonrpc: '2.0',\n id: pending.originalId,\n method: 'session/prompt',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n sessionId: acpSessionId,\n prompt: [{ type: 'text', text: pending.promptText }]\n }\n };\n\n pendingRequests.set(pending.originalId, { method: 'session/prompt' });\n\n console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(promptReq)}`);\n if (acpConnected) {\n acpSocket.write(JSON.stringify(promptReq) + '\\n');\n }\n }\n return null;\n\n case 'session/prompt':\n const text = accumulatedText.get(id) || '';\n accumulatedText.delete(id);\n console.error(`[MCP-APC][proxy] Returning accumulated text (${text.length} chars): \"${text.substring(0, 50)}...\"`);\n return {\n jsonrpc: '2.0',\n id,\n result: {\n content: [{ type: 'text', text: text || 'No response' }]\n }\n };\n\n default:\n console.error(`[MCP-APC][proxy] WARNING: Unhandled method ${pending.method}, returning raw result`);\n return { jsonrpc: '2.0', id, result: result || {} };\n }\n}\n\nfunction sendMCP(msg) {\n console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(msg)}`);\n process.stdout.write(JSON.stringify(msg) + '\\n');\n}\n\nprocess.on('SIGTERM', () => {\n acpSocket.end();\n process.exit(0);\n});\n\nprocess.on('SIGINT', () => {\n acpSocket.end();\n process.exit(0);\n});\n"],
|
|
5
|
-
"mappings": ";AAgCA,OAAO,QAAS,MAChB,OAAS,oBAAuB,WAEhC,IAAM,SAAW,QAAQ,IAAI,UAAY,YACzC,IAAM,SAAW,QAAQ,IAAI,UAAY,IACzC,IAAM,SAAW,QAAQ,IAAI,UAAY,gBAEzC,QAAQ,MAAM,oCAAoC,EAClD,QAAQ,MAAM,4BAA4B,QAAQ,IAAI,QAAQ,EAAE,EAChE,QAAQ,MAAM,8BAA8B,QAAQ,EAAE,EAGtD,IAAM,UAAY,IAAI,QAAQ,SAAU,QAAQ,EAChD,IAAI,aAAe,MACnB,IAAI,eAAiB,KACrB,IAAI,aAAe,KACnB,IAAI,gBAAkB,IAAI,IAC1B,IAAI,gBAAkB,IAAI,IAE1B,UAAU,GAAG,UAAW,IAAM,CAC5B,QAAQ,MAAM,6CAA6C,EAC3D,aAAe,IACjB,CAAC,EAED,UAAU,GAAG,QAAU,KAAQ,CAC7B,QAAQ,MAAM,0CAA0C,IAAI,OAAO,EAAE,EACrE,QAAQ,KAAK,CAAC,CAChB,CAAC,EAGD,IAAI,UAAY,GAChB,UAAU,GAAG,OAAS,MAAS,CAC7B,WAAa,KAAK,SAAS,EAE3B,IAAI,aACJ,OAAQ,aAAe,UAAU,QAAQ,IAAI,KAAO,GAAI,CACtD,MAAM,KAAO,UAAU,MAAM,EAAG,YAAY,EAC5C,UAAY,UAAU,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qD,EAAE,EAAE,EACvE,OAAO,IACT,CAEA,QAAQ,MAAM,oDAAoD,QAAQ,MAAM,EAAE,EAClF,gBAAgB,OAAO,EAAE,EAEzB,GAAI,MAAO,
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\n\n/*\n * Apache License 2.0\n * Copyright (c) 2025\u2013present Raman Marozau, Target Insight Function.\n * Contact: raman@worktif.com\n *\n * This file is part of the stdio bus protocol reference implementation:\n * stdio_bus_kernel_workers (target: <target_stdio_bus_kernel_workers>).\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * MCP-to-ACP Protocol Proxy\n *\n * Converts MCP protocol (from Kiro) to ACP protocol (for stdio Bus)\n * Runs as MCP server for Kiro, forwards to ACP via TCP\n */\n\nimport net from 'net';\nimport { createInterface } from 'readline';\n\nconst ACP_HOST = process.env.ACP_HOST || '127.0.0.1';\nconst ACP_PORT = process.env.ACP_PORT || 9000;\nconst AGENT_ID = process.env.AGENT_ID || 'default-agent';\n\nconsole.error(`[MCP-APC][proxy] Starting proxy...`);\nconsole.error(`[MCP-APC][proxy] Target: ${ACP_HOST}:${ACP_PORT}`);\nconsole.error(`[MCP-APC][proxy] Agent ID: ${AGENT_ID}`);\n\n// State\nconst acpSocket = net.connect(ACP_PORT, ACP_HOST);\nlet acpConnected = false;\nlet proxySessionId = null; // For stdio Bus routing\nlet acpSessionId = null; // From ACP agent\nlet pendingRequests = new Map(); // id -> {method, params, ...}\nlet accumulatedText = new Map(); // requestId -> accumulated text\n\nacpSocket.on('connect', () => {\n console.error('[MCP-APC][proxy] Connected to ACP stdio Bus');\n acpConnected = true;\n});\n\nacpSocket.on('error', (err) => {\n console.error(`[MCP-APC][proxy] ACP connection error: ${err.message}`);\n process.exit(1);\n});\n\n// Handle ACP messages\nlet acpBuffer = '';\nacpSocket.on('data', (data) => {\n acpBuffer += data.toString();\n\n let newlineIndex;\n while ((newlineIndex = acpBuffer.indexOf('\\n')) !== -1) {\n const line = acpBuffer.slice(0, newlineIndex);\n acpBuffer = acpBuffer.slice(newlineIndex + 1);\n\n if (line.trim()) {\n try {\n const acpMsg = JSON.parse(line);\n console.error(`[MCP-APC][proxy] \u2190 ACP: ${JSON.stringify(acpMsg)}`);\n\n // Check if notification or response\n if (acpMsg.id === undefined || acpMsg.id === null) {\n // Notification from ACP worker - rewrite sessionId and send back to stdio Bus\n console.error(`[MCP-APC][proxy] Processing notification: ${acpMsg.method}`);\n handleACPNotification(acpMsg);\n } else {\n // Response\n console.error(`[MCP-APC][proxy] Processing response id=${acpMsg.id}`);\n console.error(`[MCP-APC][proxy] Pending: ${JSON.stringify([...pendingRequests.keys()])}`);\n const mcpResponse = convertACPtoMCP(acpMsg);\n if (mcpResponse) {\n console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(mcpResponse)}`);\n process.stdout.write(JSON.stringify(mcpResponse) + '\\n');\n } else {\n console.error(`[MCP-APC][proxy] WARNING: No MCP response for id=${acpMsg.id}`);\n }\n }\n } catch (err) {\n console.error(`[MCP-APC][proxy] Error parsing ACP: ${err.message}`);\n }\n }\n }\n});\n\n// Handle MCP requests\nconst rl = createInterface({\n input: process.stdin,\n terminal: false\n});\n\nrl.on('line', (line) => {\n if (!line.trim()) return;\n\n try {\n const mcpReq = JSON.parse(line);\n console.error(`[MCP-APC][proxy] \u2190 MCP: ${JSON.stringify(mcpReq)}`);\n\n const acpReq = convertMCPtoACP(mcpReq);\n if (acpReq) {\n console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(acpReq)}`);\n if (acpConnected) {\n acpSocket.write(JSON.stringify(acpReq) + '\\n');\n }\n }\n } catch (err) {\n console.error(`[MCP-APC][proxy] Error parsing MCP: ${err.message}`);\n }\n});\n\nfunction handleACPNotification(msg) {\n const { method, params } = msg;\n\n if (method === 'session/update' && params?.update) {\n const update = params.update;\n\n // Find pending session/prompt request\n for (const [reqId, pending] of pendingRequests.entries()) {\n if (pending.method === 'session/prompt') {\n if (update.sessionUpdate === 'agent_message_chunk' && update.content?.text) {\n if (!accumulatedText.has(reqId)) {\n accumulatedText.set(reqId, '');\n }\n accumulatedText.set(reqId, accumulatedText.get(reqId) + update.content.text);\n }\n break;\n }\n }\n }\n // Note: Notifications are processed internally, not forwarded\n // They accumulate text for the final response\n}\n\nfunction convertMCPtoACP(mcpReq) {\n const { id, method, params } = mcpReq;\n\n if (id === undefined || id === null) {\n return null; // Ignore notifications\n }\n\n pendingRequests.set(id, { method, params });\n\n if (!proxySessionId) {\n proxySessionId = `proxy-${Date.now()}`;\n }\n\n switch (method) {\n case 'initialize':\n return {\n jsonrpc: '2.0',\n id,\n method: 'initialize',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n protocolVersion: 1,\n clientCapabilities: params?.capabilities || {},\n clientInfo: params?.clientInfo || { name: 'mcp-proxy', version: '1.0.0' }\n }\n };\n\n case 'tools/list':\n sendMCP({\n jsonrpc: '2.0',\n id,\n result: {\n tools: [{\n name: 'acp_prompt',\n description: `Send prompt to ${AGENT_ID}`,\n inputSchema: {\n type: 'object',\n properties: {\n prompt: { type: 'string', description: 'Prompt text' }\n },\n required: ['prompt']\n }\n }]\n }\n });\n pendingRequests.delete(id);\n return null;\n\n case 'tools/call':\n const promptText = params?.arguments?.prompt || '';\n\n if (!acpSessionId) {\n // Need to create session first\n const sessionReqId = `sess-${id}`;\n pendingRequests.set(sessionReqId, {\n method: 'session/new',\n originalId: id,\n promptText\n });\n return {\n jsonrpc: '2.0',\n id: sessionReqId,\n method: 'session/new',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: { cwd: process.cwd(), mcpServers: [] }\n };\n }\n\n // Session exists, send prompt\n // IMPORTANT: Update pending to session/prompt since that's what we're sending\n pendingRequests.set(id, { method: 'session/prompt', params });\n return {\n jsonrpc: '2.0',\n id,\n method: 'session/prompt',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n sessionId: acpSessionId,\n prompt: [{ type: 'text', text: promptText }]\n }\n };\n\n case 'resources/list':\n sendMCP({ jsonrpc: '2.0', id, result: { resources: [] } });\n pendingRequests.delete(id);\n return null;\n\n case 'resources/templates/list':\n sendMCP({ jsonrpc: '2.0', id, result: { resourceTemplates: [] } });\n pendingRequests.delete(id);\n return null;\n\n case 'prompts/list':\n sendMCP({ jsonrpc: '2.0', id, result: { prompts: [] } });\n pendingRequests.delete(id);\n return null;\n\n default:\n sendMCP({ jsonrpc: '2.0', id, error: { code: -32601, message: `Unknown method: ${method}` } });\n pendingRequests.delete(id);\n return null;\n }\n}\n\nfunction convertACPtoMCP(acpResp) {\n const { id, result, error } = acpResp;\n\n const pending = pendingRequests.get(id);\n if (!pending) {\n console.error(`[MCP-APC][proxy] ERROR: No pending request for id=${id}`);\n return null;\n }\n\n console.error(`[MCP-APC][proxy] Converting ACP->MCP for method: ${pending.method}`);\n pendingRequests.delete(id);\n\n if (error) {\n // For session/prompt errors: if we already accumulated text from streaming,\n // return the accumulated text as a successful response instead of the error.\n // This handles the case where the agent streams the full response via\n // session/update notifications but then fails to serialize the final response.\n if (pending.method === 'session/prompt') {\n const text = accumulatedText.get(id) || '';\n accumulatedText.delete(id);\n if (text.length > 0) {\n console.error(`[MCP-APC][proxy] Agent error after streaming, returning accumulated text (${text.length} chars) instead of error`);\n return {\n jsonrpc: '2.0',\n id,\n result: {\n content: [{ type: 'text', text }]\n }\n };\n }\n }\n accumulatedText.delete(id);\n return {\n jsonrpc: '2.0',\n id,\n error: { code: error.code || -32603, message: error.message || 'ACP error' }\n };\n }\n\n switch (pending.method) {\n case 'initialize':\n return {\n jsonrpc: '2.0',\n id,\n result: {\n protocolVersion: '2024-11-05',\n capabilities: { tools: {}, resources: {} },\n serverInfo: result?.agentInfo || { name: 'acp-agent', version: '1.0.0' }\n }\n };\n\n case 'session/new':\n acpSessionId = result?.sessionId;\n console.error(`[MCP-APC][proxy] ACP session: ${acpSessionId}`);\n\n if (pending.originalId && pending.promptText) {\n // Send queued prompt\n const promptReq = {\n jsonrpc: '2.0',\n id: pending.originalId,\n method: 'session/prompt',\n agentId: AGENT_ID,\n sessionId: proxySessionId,\n params: {\n sessionId: acpSessionId,\n prompt: [{ type: 'text', text: pending.promptText }]\n }\n };\n\n pendingRequests.set(pending.originalId, { method: 'session/prompt' });\n\n console.error(`[MCP-APC][proxy] \u2192 ACP: ${JSON.stringify(promptReq)}`);\n if (acpConnected) {\n acpSocket.write(JSON.stringify(promptReq) + '\\n');\n }\n }\n return null;\n\n case 'session/prompt':\n const text = accumulatedText.get(id) || '';\n accumulatedText.delete(id);\n console.error(`[MCP-APC][proxy] Returning accumulated text (${text.length} chars): \"${text.substring(0, 50)}...\"`);\n return {\n jsonrpc: '2.0',\n id,\n result: {\n content: [{ type: 'text', text: text || 'No response' }]\n }\n };\n\n default:\n console.error(`[MCP-APC][proxy] WARNING: Unhandled method ${pending.method}, returning raw result`);\n return { jsonrpc: '2.0', id, result: result || {} };\n }\n}\n\nfunction sendMCP(msg) {\n console.error(`[MCP-APC][proxy] \u2192 MCP: ${JSON.stringify(msg)}`);\n process.stdout.write(JSON.stringify(msg) + '\\n');\n}\n\nprocess.on('SIGTERM', () => {\n acpSocket.end();\n process.exit(0);\n});\n\nprocess.on('SIGINT', () => {\n acpSocket.end();\n process.exit(0);\n});\n"],
|
|
5
|
+
"mappings": ";AAgCA,OAAO,QAAS,MAChB,OAAS,oBAAuB,WAEhC,IAAM,SAAW,QAAQ,IAAI,UAAY,YACzC,IAAM,SAAW,QAAQ,IAAI,UAAY,IACzC,IAAM,SAAW,QAAQ,IAAI,UAAY,gBAEzC,QAAQ,MAAM,oC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AEA,QAAQ,GAAG,UAAW,IAAM,CAC1B,UAAU,IAAI,EACd,QAAQ,KAAK,CAAC,CAChB,CAAC,EAED,QAAQ,GAAG,SAAU,IAAM,CACzB,UAAU,IAAI,EACd,QAAQ,KAAK,CAAC,CAChB,CAAC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/out/tsc/workers-registry/acp-worker/src/registry-launcher/router/message-router.d.ts
CHANGED
|
@@ -113,6 +113,8 @@ export declare class MessageRouter {
|
|
|
113
113
|
* Handle a response from an agent process.
|
|
114
114
|
*
|
|
115
115
|
* Intercepts initialize responses to trigger automatic authentication.
|
|
116
|
+
* Handles agent-to-client requests (like session/request_permission) by
|
|
117
|
+
* auto-responding when they cannot be forwarded to the client.
|
|
116
118
|
* Tracks sessionId mapping for proper notification routing.
|
|
117
119
|
* Forwards all responses to stdout.
|
|
118
120
|
*
|
|
@@ -120,6 +122,41 @@ export declare class MessageRouter {
|
|
|
120
122
|
* @param response - The response object from the agent
|
|
121
123
|
*/
|
|
122
124
|
handleAgentResponse(agentId: string, response: object): void;
|
|
125
|
+
/**
|
|
126
|
+
* Handle a request from an agent to the client.
|
|
127
|
+
*
|
|
128
|
+
* Agent-to-client requests (JSON-RPC messages with both `id` and `method`)
|
|
129
|
+
* require a response. Since the Registry Launcher is headless and cannot
|
|
130
|
+
* forward these to a human, we auto-respond to keep the agent unblocked.
|
|
131
|
+
*
|
|
132
|
+
* Known methods:
|
|
133
|
+
* - session/request_permission: Auto-approve with the first "allow" option
|
|
134
|
+
*
|
|
135
|
+
* Unknown methods get a generic success response so the agent continues.
|
|
136
|
+
*
|
|
137
|
+
* @param agentId - The agent that sent the request
|
|
138
|
+
* @param id - The JSON-RPC request id
|
|
139
|
+
* @param method - The JSON-RPC method name
|
|
140
|
+
* @param msg - The full message object
|
|
141
|
+
*/
|
|
142
|
+
private handleAgentRequest;
|
|
143
|
+
/**
|
|
144
|
+
* Build an auto-approve result for session/request_permission.
|
|
145
|
+
*
|
|
146
|
+
* Picks the first "allow" option from the request, preferring
|
|
147
|
+
* allow_always > allow_once > first option as fallback.
|
|
148
|
+
*
|
|
149
|
+
* @param msg - The request_permission message
|
|
150
|
+
* @returns The result object for the response
|
|
151
|
+
*/
|
|
152
|
+
private buildPermissionResponse;
|
|
153
|
+
/**
|
|
154
|
+
* Send a JSON-RPC message directly to an agent process.
|
|
155
|
+
*
|
|
156
|
+
* @param agentId - The agent to send to
|
|
157
|
+
* @param message - The message to send
|
|
158
|
+
*/
|
|
159
|
+
private sendToAgent;
|
|
123
160
|
/**
|
|
124
161
|
* Attempt automatic authentication for an agent.
|
|
125
162
|
*
|
package/package.json
CHANGED