@stdiobus/workers-registry 1.3.7
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/LICENSE +201 -0
- package/README.md +932 -0
- package/out/dist/workers/acp-registry/registry-launcher-client.js +52 -0
- package/out/dist/workers/acp-registry/registry-launcher-client.js.map +7 -0
- package/out/dist/workers/acp-registry/registry-launcher-config.json +31 -0
- package/out/dist/workers/acp-worker/index.js +5 -0
- package/out/dist/workers/acp-worker/index.js.map +7 -0
- package/out/dist/workers/echo-worker/echo-worker-config.json +21 -0
- package/out/dist/workers/echo-worker/echo-worker.js +3 -0
- package/out/dist/workers/echo-worker/echo-worker.js.map +7 -0
- package/out/dist/workers/index.d.ts +15 -0
- package/out/dist/workers/index.js +33 -0
- package/out/dist/workers/mcp-echo-server/index.js +3 -0
- package/out/dist/workers/mcp-echo-server/index.js.map +7 -0
- package/out/dist/workers/mcp-echo-server/mcp-echo-server-config.json +21 -0
- package/out/dist/workers/mcp-to-acp-proxy/proxy.js +3 -0
- package/out/dist/workers/mcp-to-acp-proxy/proxy.js.map +7 -0
- package/out/tsc/workers/acp-worker/src/acp/client-capabilities.d.ts +131 -0
- package/out/tsc/workers/acp-worker/src/acp/content-mapper.d.ts +95 -0
- package/out/tsc/workers/acp-worker/src/acp/index.d.ts +13 -0
- package/out/tsc/workers/acp-worker/src/acp/tools.d.ts +119 -0
- package/out/tsc/workers/acp-worker/src/agent.d.ts +113 -0
- package/out/tsc/workers/acp-worker/src/index.d.ts +1 -0
- package/out/tsc/workers/acp-worker/src/mcp/connection.d.ts +54 -0
- package/out/tsc/workers/acp-worker/src/mcp/index.d.ts +10 -0
- package/out/tsc/workers/acp-worker/src/mcp/manager.d.ts +178 -0
- package/out/tsc/workers/acp-worker/src/mcp/types.d.ts +114 -0
- package/out/tsc/workers/acp-worker/src/mcp-proxy/connection.d.ts +80 -0
- package/out/tsc/workers/acp-worker/src/mcp-proxy/converter.d.ts +156 -0
- package/out/tsc/workers/acp-worker/src/mcp-proxy/index.d.ts +2 -0
- package/out/tsc/workers/acp-worker/src/mcp-proxy/state.d.ts +165 -0
- package/out/tsc/workers/acp-worker/src/mcp-proxy/types.d.ts +163 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/config/api-keys.d.ts +41 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/config/config.d.ts +17 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/config/index.d.ts +10 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/config/types.d.ts +15 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/index.d.ts +2 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/log.d.ts +77 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/registry/index.d.ts +109 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/registry/resolver.d.ts +67 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/registry/types.d.ts +105 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/router/index.d.ts +8 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/router/message-router.d.ts +150 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/runtime/agent-runtime.d.ts +58 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/runtime/index.d.ts +11 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/runtime/manager.d.ts +82 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/runtime/types.d.ts +20 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/stream/index.d.ts +8 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/stream/ndjson-handler.d.ts +119 -0
- package/out/tsc/workers/acp-worker/src/registry-launcher/test-utils/index.d.ts +234 -0
- package/out/tsc/workers/acp-worker/src/session/index.d.ts +12 -0
- package/out/tsc/workers/acp-worker/src/session/manager.d.ts +63 -0
- package/out/tsc/workers/acp-worker/src/session/session.d.ts +86 -0
- package/out/tsc/workers/acp-worker/src/session/types.d.ts +33 -0
- package/out/tsc/workers/acp-worker/src/test-utils/test-harness.d.ts +80 -0
- package/out/tsc/workers/mcp-echo-server/mcp-echo-server.d.ts +2 -0
- package/package.json +77 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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\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}\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,UAA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UAAU,SAAS,CAAC,EAAE,EACpE,GAAI,aAAc,CAChB,UAAU,MAAM,KAAK,UAAU,SAAS,EAAI,IAAI,CAClD,CACF,CACA,OAAO,KAET,IAAK,iBACH,MAAM,KAAO,gBAAgB,IAAI,EAAE,GAAK,GACxC,gBAAgB,OAAO,EAAE,EACzB,QAAQ,MAAM,gDAAgD,KAAK,MAAM,aAAa,KAAK,UAAU,EAAG,EAAE,CAAC,MAAM,EACjH,MAAO,CACL,QAAS,MACT,GACA,OAAQ,CACN,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,MAAQ,aAAc,CAAC,CACzD,CACF,EAEF,QACE,QAAQ,MAAM,8CAA8C,QAAQ,MAAM,wBAAwB,EAClG,MAAO,CAAE,QAAS,MAAO,GAAI,OAAQ,QAAU,CAAC,CAAE,CACtD,CACF,CAEA,SAAS,QAAQ,IAAK,CACpB,QAAQ,MAAM,gCAA2B,KAAK,UAAU,GAAG,CAAC,EAAE,EAC9D,QAAQ,OAAO,MAAM,KAAK,UAAU,GAAG,EAAI,IAAI,CACjD,CAEA,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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP Client Capabilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for accessing client capabilities like file system
|
|
5
|
+
* and terminal operations via the ACP SDK.
|
|
6
|
+
*
|
|
7
|
+
* @module acp/client-capabilities
|
|
8
|
+
*/
|
|
9
|
+
import type { AgentSideConnection, ClientCapabilities, TerminalHandle } from '@agentclientprotocol/sdk';
|
|
10
|
+
/**
|
|
11
|
+
* Result of a file read operation.
|
|
12
|
+
*/
|
|
13
|
+
export interface FileReadResult {
|
|
14
|
+
/** The file content */
|
|
15
|
+
content: string;
|
|
16
|
+
/** Whether the operation was successful */
|
|
17
|
+
success: boolean;
|
|
18
|
+
/** Error message if the operation failed */
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Result of a file write operation.
|
|
23
|
+
*/
|
|
24
|
+
export interface FileWriteResult {
|
|
25
|
+
/** Whether the operation was successful */
|
|
26
|
+
success: boolean;
|
|
27
|
+
/** Error message if the operation failed */
|
|
28
|
+
error?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Result of a terminal command execution.
|
|
32
|
+
*/
|
|
33
|
+
export interface TerminalResult {
|
|
34
|
+
/** The terminal output */
|
|
35
|
+
output: string;
|
|
36
|
+
/** The exit code (null if terminated by signal) */
|
|
37
|
+
exitCode: number | null;
|
|
38
|
+
/** The signal that terminated the process (null if exited normally) */
|
|
39
|
+
signal: string | null;
|
|
40
|
+
/** Whether the output was truncated */
|
|
41
|
+
truncated: boolean;
|
|
42
|
+
/** Whether the operation was successful */
|
|
43
|
+
success: boolean;
|
|
44
|
+
/** Error message if the operation failed */
|
|
45
|
+
error?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if the client supports file system read operations.
|
|
49
|
+
*
|
|
50
|
+
* @param capabilities - The client capabilities
|
|
51
|
+
* @returns Whether file read is supported
|
|
52
|
+
*/
|
|
53
|
+
export declare function canReadFile(capabilities: ClientCapabilities | null): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if the client supports file system write operations.
|
|
56
|
+
*
|
|
57
|
+
* @param capabilities - The client capabilities
|
|
58
|
+
* @returns Whether file write is supported
|
|
59
|
+
*/
|
|
60
|
+
export declare function canWriteFile(capabilities: ClientCapabilities | null): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Check if the client supports terminal operations.
|
|
63
|
+
*
|
|
64
|
+
* @param capabilities - The client capabilities
|
|
65
|
+
* @returns Whether terminal is supported
|
|
66
|
+
*/
|
|
67
|
+
export declare function canUseTerminal(capabilities: ClientCapabilities | null): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Read a text file from the client's file system.
|
|
70
|
+
*
|
|
71
|
+
* @param connection - The ACP connection
|
|
72
|
+
* @param sessionId - The session ID
|
|
73
|
+
* @param path - Absolute path to the file
|
|
74
|
+
* @param options - Optional read options (line, limit)
|
|
75
|
+
* @returns The file read result
|
|
76
|
+
*/
|
|
77
|
+
export declare function readFile(connection: AgentSideConnection, sessionId: string, path: string, options?: {
|
|
78
|
+
line?: number;
|
|
79
|
+
limit?: number;
|
|
80
|
+
}): Promise<FileReadResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Write content to a text file in the client's file system.
|
|
83
|
+
*
|
|
84
|
+
* @param connection - The ACP connection
|
|
85
|
+
* @param sessionId - The session ID
|
|
86
|
+
* @param path - Absolute path to the file
|
|
87
|
+
* @param content - The content to write
|
|
88
|
+
* @returns The file write result
|
|
89
|
+
*/
|
|
90
|
+
export declare function writeFile(connection: AgentSideConnection, sessionId: string, path: string, content: string): Promise<FileWriteResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Execute a command in a terminal and wait for completion.
|
|
93
|
+
* - Use SDK terminal methods (create, output, wait, kill, release)
|
|
94
|
+
* - Track terminal IDs for cleanup
|
|
95
|
+
* - Implement command timeouts
|
|
96
|
+
*
|
|
97
|
+
* @param connection - The ACP connection
|
|
98
|
+
* @param sessionId - The session ID
|
|
99
|
+
* @param command - The command to execute
|
|
100
|
+
* @param options - Optional execution options
|
|
101
|
+
* @returns The terminal execution result
|
|
102
|
+
*/
|
|
103
|
+
export declare function executeCommand(connection: AgentSideConnection, sessionId: string, command: string, options?: {
|
|
104
|
+
args?: string[];
|
|
105
|
+
cwd?: string;
|
|
106
|
+
env?: Array<{
|
|
107
|
+
name: string;
|
|
108
|
+
value: string;
|
|
109
|
+
}>;
|
|
110
|
+
timeout?: number;
|
|
111
|
+
outputByteLimit?: number;
|
|
112
|
+
}): Promise<TerminalResult>;
|
|
113
|
+
/**
|
|
114
|
+
* Execute a command in a terminal without waiting for completion.
|
|
115
|
+
* Returns a handle for managing the terminal.
|
|
116
|
+
*
|
|
117
|
+
* @param connection - The ACP connection
|
|
118
|
+
* @param sessionId - The session ID
|
|
119
|
+
* @param command - The command to execute
|
|
120
|
+
* @param options - Optional execution options
|
|
121
|
+
* @returns The terminal handle for managing the process
|
|
122
|
+
*/
|
|
123
|
+
export declare function startCommand(connection: AgentSideConnection, sessionId: string, command: string, options?: {
|
|
124
|
+
args?: string[];
|
|
125
|
+
cwd?: string;
|
|
126
|
+
env?: Array<{
|
|
127
|
+
name: string;
|
|
128
|
+
value: string;
|
|
129
|
+
}>;
|
|
130
|
+
outputByteLimit?: number;
|
|
131
|
+
}): Promise<TerminalHandle>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Mapper
|
|
3
|
+
*
|
|
4
|
+
* Maps MCP tool call results to ACP ToolCallContent format.
|
|
5
|
+
* Handles conversion between MCP content types (TextContent, ImageContent, EmbeddedResource)
|
|
6
|
+
* and ACP ToolCallContent types (Content, Diff, Terminal).
|
|
7
|
+
*
|
|
8
|
+
* Also provides resource_link resolution for ACP prompts.
|
|
9
|
+
*
|
|
10
|
+
* @module acp/content-mapper
|
|
11
|
+
*/
|
|
12
|
+
import type { ContentBlock, ToolCallContent } from '@agentclientprotocol/sdk';
|
|
13
|
+
import type { MCPContent, MCPResourceContents } from '../mcp/types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Maps a single MCP content item to an ACP ContentBlock.
|
|
16
|
+
*
|
|
17
|
+
* MCP content types:
|
|
18
|
+
* - TextContent: { type: 'text', text: string }
|
|
19
|
+
* - ImageContent: { type: 'image', data: string, mimeType: string }
|
|
20
|
+
* - EmbeddedResource: { type: 'resource', resource: { uri, mimeType?, text?, blob? } }
|
|
21
|
+
*
|
|
22
|
+
* ACP ContentBlock types:
|
|
23
|
+
* - TextContent: { type: 'text', text: string }
|
|
24
|
+
* - ImageContent: { type: 'image', data: string, mimeType: string }
|
|
25
|
+
* - EmbeddedResource: { type: 'resource', resource: TextResourceContents | BlobResourceContents }
|
|
26
|
+
*
|
|
27
|
+
* @param mcpContent - The MCP content item to convert
|
|
28
|
+
* @returns The corresponding ACP ContentBlock
|
|
29
|
+
*/
|
|
30
|
+
export declare function mapMCPContentToACPContentBlock(mcpContent: MCPContent): ContentBlock;
|
|
31
|
+
/**
|
|
32
|
+
* Maps an array of MCP content items to ACP ToolCallContent array.
|
|
33
|
+
*
|
|
34
|
+
* Each MCP content item is wrapped in an ACP Content structure with type: 'content'.
|
|
35
|
+
*
|
|
36
|
+
* @param mcpContents - Array of MCP content items
|
|
37
|
+
* @returns Array of ACP ToolCallContent items
|
|
38
|
+
*/
|
|
39
|
+
export declare function mapMCPResultToACPToolCallContent(mcpContents: MCPContent[]): ToolCallContent[];
|
|
40
|
+
/**
|
|
41
|
+
* Creates an error ToolCallContent from an error message.
|
|
42
|
+
*
|
|
43
|
+
* Used when MCP tool execution fails (isError: true) to create
|
|
44
|
+
* appropriate error content for the ACP client.
|
|
45
|
+
*
|
|
46
|
+
* @param errorMessage - The error message to display
|
|
47
|
+
* @returns A ToolCallContent array with the error message
|
|
48
|
+
*/
|
|
49
|
+
export declare function createErrorToolCallContent(errorMessage: string): ToolCallContent[];
|
|
50
|
+
/**
|
|
51
|
+
* Maps MCP tool call result to ACP ToolCallContent array.
|
|
52
|
+
*
|
|
53
|
+
* Handles both successful results and error results.
|
|
54
|
+
* For errors, creates appropriate error content.
|
|
55
|
+
*
|
|
56
|
+
* @param content - Array of MCP content items from tool result
|
|
57
|
+
* @param isError - Whether the tool execution resulted in an error
|
|
58
|
+
* @returns Array of ACP ToolCallContent items
|
|
59
|
+
*/
|
|
60
|
+
export declare function mapToolResultToACPContent(content: MCPContent[], isError?: boolean): ToolCallContent[];
|
|
61
|
+
/**
|
|
62
|
+
* Represents a resource_link from an ACP ContentBlock.
|
|
63
|
+
*/
|
|
64
|
+
export interface ResourceLink {
|
|
65
|
+
type: 'resource_link';
|
|
66
|
+
uri: string;
|
|
67
|
+
name: string;
|
|
68
|
+
title?: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
mimeType?: string;
|
|
71
|
+
size?: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Type guard to check if a ContentBlock is a resource_link.
|
|
75
|
+
*
|
|
76
|
+
* @param block - The content block to check
|
|
77
|
+
* @returns True if the block is a resource_link
|
|
78
|
+
*/
|
|
79
|
+
export declare function isResourceLink(block: ContentBlock): block is ResourceLink;
|
|
80
|
+
/**
|
|
81
|
+
* Maps MCP resource contents to an ACP EmbeddedResource ContentBlock.
|
|
82
|
+
*
|
|
83
|
+
* Converts the result of readResource() to an ACP-compatible format.
|
|
84
|
+
*
|
|
85
|
+
* @param contents - The MCP resource contents from readResource()
|
|
86
|
+
* @returns The ACP embedded resource content block
|
|
87
|
+
*/
|
|
88
|
+
export declare function mapMCPResourceContentsToACPContentBlock(contents: MCPResourceContents): ContentBlock;
|
|
89
|
+
/**
|
|
90
|
+
* Extracts the URI from a resource_link ContentBlock.
|
|
91
|
+
*
|
|
92
|
+
* @param block - The resource_link content block
|
|
93
|
+
* @returns The URI string or null if not a valid resource_link
|
|
94
|
+
*/
|
|
95
|
+
export declare function extractResourceLinkUri(block: ContentBlock): string | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP Module
|
|
3
|
+
*
|
|
4
|
+
* Exports ACP-related utilities and mappers.
|
|
5
|
+
*
|
|
6
|
+
* @module acp
|
|
7
|
+
*/
|
|
8
|
+
export { mapMCPContentToACPContentBlock, mapMCPResultToACPToolCallContent, createErrorToolCallContent, mapToolResultToACPContent, isResourceLink, extractResourceLinkUri, mapMCPResourceContentsToACPContentBlock, } from './content-mapper.js';
|
|
9
|
+
export { generateToolCallId, determineToolKind, sendToolCallInitiation, sendToolCallUpdate, requestToolPermission, executeToolCall, executeToolCallWithPermission, } from './tools.js';
|
|
10
|
+
export { canReadFile, canWriteFile, canUseTerminal, readFile, writeFile, executeCommand, startCommand, } from './client-capabilities.js';
|
|
11
|
+
export type { ToolKind, ToolCallStatus, PermissionResult } from './tools.js';
|
|
12
|
+
export type { ResourceLink } from './content-mapper.js';
|
|
13
|
+
export type { FileReadResult, FileWriteResult, TerminalResult } from './client-capabilities.js';
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Call Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for initiating and managing tool calls in ACP.
|
|
5
|
+
* Handles tool call lifecycle including initiation, permission requests,
|
|
6
|
+
* execution, and result reporting.
|
|
7
|
+
*
|
|
8
|
+
* @module acp/tools
|
|
9
|
+
*/
|
|
10
|
+
import type { AgentSideConnection, PermissionOption, ToolCallContent } from '@agentclientprotocol/sdk';
|
|
11
|
+
import type { MCPManager } from '../mcp/manager.js';
|
|
12
|
+
/**
|
|
13
|
+
* Permission request result.
|
|
14
|
+
*/
|
|
15
|
+
export interface PermissionResult {
|
|
16
|
+
/** Whether permission was granted */
|
|
17
|
+
granted: boolean;
|
|
18
|
+
/** The option ID that was selected (if granted) */
|
|
19
|
+
optionId?: string;
|
|
20
|
+
/** Whether the request was cancelled */
|
|
21
|
+
cancelled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Tool kind categories for ACP tool calls.
|
|
25
|
+
* Helps clients choose appropriate icons and UI treatment.
|
|
26
|
+
*/
|
|
27
|
+
export type ToolKind = 'read' | 'edit' | 'delete' | 'move' | 'search' | 'execute' | 'think' | 'fetch' | 'switch_mode' | 'other';
|
|
28
|
+
/**
|
|
29
|
+
* Tool call status values.
|
|
30
|
+
*/
|
|
31
|
+
export type ToolCallStatus = 'pending' | 'in_progress' | 'completed' | 'failed';
|
|
32
|
+
/**
|
|
33
|
+
* Generate a unique tool call ID.
|
|
34
|
+
*
|
|
35
|
+
* @returns A unique tool call ID string
|
|
36
|
+
*/
|
|
37
|
+
export declare function generateToolCallId(): string;
|
|
38
|
+
/**
|
|
39
|
+
* Determine the tool kind based on tool name and description.
|
|
40
|
+
*
|
|
41
|
+
* @param toolName - The name of the tool
|
|
42
|
+
* @param description - Optional tool description
|
|
43
|
+
* @returns The appropriate ToolKind
|
|
44
|
+
*/
|
|
45
|
+
export declare function determineToolKind(toolName: string, description?: string): ToolKind;
|
|
46
|
+
/**
|
|
47
|
+
* Send a tool_call session update to initiate a tool call.
|
|
48
|
+
*
|
|
49
|
+
* @param connection - The ACP connection
|
|
50
|
+
* @param sessionId - The session ID
|
|
51
|
+
* @param toolCallId - The unique tool call ID
|
|
52
|
+
* @param title - Human-readable title for the tool call
|
|
53
|
+
* @param kind - The tool kind category
|
|
54
|
+
* @param status - Initial status (usually 'pending')
|
|
55
|
+
*/
|
|
56
|
+
export declare function sendToolCallInitiation(connection: AgentSideConnection, sessionId: string, toolCallId: string, title: string, kind?: ToolKind, status?: ToolCallStatus): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Send a tool_call_update to report progress or results.
|
|
59
|
+
*
|
|
60
|
+
* @param connection - The ACP connection
|
|
61
|
+
* @param sessionId - The session ID
|
|
62
|
+
* @param toolCallId - The tool call ID to update
|
|
63
|
+
* @param status - The new status
|
|
64
|
+
* @param content - Optional content to include
|
|
65
|
+
* @param title - Optional updated title
|
|
66
|
+
*/
|
|
67
|
+
export declare function sendToolCallUpdate(connection: AgentSideConnection, sessionId: string, toolCallId: string, status: ToolCallStatus, content?: ToolCallContent[], title?: string): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Request permission from the user before executing a tool.
|
|
70
|
+
*
|
|
71
|
+
* @param connection - The ACP connection
|
|
72
|
+
* @param sessionId - The session ID
|
|
73
|
+
* @param toolCallId - The tool call ID
|
|
74
|
+
* @param title - Human-readable title for the tool call
|
|
75
|
+
* @param kind - The tool kind category
|
|
76
|
+
* @param options - Permission options to present to the user
|
|
77
|
+
* @returns The permission result with granted/cancelled status
|
|
78
|
+
*/
|
|
79
|
+
export declare function requestToolPermission(connection: AgentSideConnection, sessionId: string, toolCallId: string, title: string, kind?: ToolKind, options?: PermissionOption[]): Promise<PermissionResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Execute a tool call with full lifecycle management.
|
|
82
|
+
*
|
|
83
|
+
* This function handles the complete tool call flow:
|
|
84
|
+
* 1. Sends tool_call initiation with pending status
|
|
85
|
+
* 2. Updates to in_progress when execution starts
|
|
86
|
+
* 3. Executes the tool via MCP
|
|
87
|
+
* 4. Updates with completed/failed status and results
|
|
88
|
+
*
|
|
89
|
+
* @param connection - The ACP connection
|
|
90
|
+
* @param sessionId - The session ID
|
|
91
|
+
* @param mcpManager - The MCP manager for tool execution
|
|
92
|
+
* @param toolName - The name of the tool to execute
|
|
93
|
+
* @param args - Arguments to pass to the tool
|
|
94
|
+
* @param description - Optional tool description for kind detection
|
|
95
|
+
* @returns The tool call result content
|
|
96
|
+
*/
|
|
97
|
+
export declare function executeToolCall(connection: AgentSideConnection, sessionId: string, mcpManager: MCPManager, toolName: string, args: Record<string, unknown>, description?: string): Promise<ToolCallContent[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Execute a tool call with permission request.
|
|
100
|
+
*
|
|
101
|
+
* This function handles the complete tool call flow with permission:
|
|
102
|
+
* 1. Sends tool_call initiation with pending status
|
|
103
|
+
* 2. Requests permission from the user
|
|
104
|
+
* 3. If granted, executes the tool via MCP
|
|
105
|
+
* 4. Updates with completed/failed status and results
|
|
106
|
+
*
|
|
107
|
+
* @param connection - The ACP connection
|
|
108
|
+
* @param sessionId - The session ID
|
|
109
|
+
* @param mcpManager - The MCP manager for tool execution
|
|
110
|
+
* @param toolName - The name of the tool to execute
|
|
111
|
+
* @param args - Arguments to pass to the tool
|
|
112
|
+
* @param description - Optional tool description for kind detection
|
|
113
|
+
* @param requirePermission - Whether to request permission before execution
|
|
114
|
+
* @returns The tool call result content and permission result
|
|
115
|
+
*/
|
|
116
|
+
export declare function executeToolCallWithPermission(connection: AgentSideConnection, sessionId: string, mcpManager: MCPManager, toolName: string, args: Record<string, unknown>, description?: string, requirePermission?: boolean): Promise<{
|
|
117
|
+
content: ToolCallContent[];
|
|
118
|
+
permissionResult?: PermissionResult;
|
|
119
|
+
}>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Implementation
|
|
3
|
+
*
|
|
4
|
+
* This module implements the ACP Agent interface using @agentclientprotocol/sdk.
|
|
5
|
+
* The Agent handles all ACP protocol methods including initialization,
|
|
6
|
+
* session management, and prompt processing.
|
|
7
|
+
*
|
|
8
|
+
* @module agent
|
|
9
|
+
*/
|
|
10
|
+
import type { Agent, AgentSideConnection, AuthenticateRequest, AuthenticateResponse, CancelNotification, ClientCapabilities, InitializeRequest, InitializeResponse, LoadSessionRequest, LoadSessionResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse } from '@agentclientprotocol/sdk';
|
|
11
|
+
import { SessionManager } from './session/manager.js';
|
|
12
|
+
/**
|
|
13
|
+
* ACP Agent implementation for stdio Bus kernel worker.
|
|
14
|
+
*
|
|
15
|
+
* This class implements the Agent interface from the ACP SDK,
|
|
16
|
+
* handling all protocol methods and coordinating with MCP servers
|
|
17
|
+
* for tool execution.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ACPAgent implements Agent {
|
|
20
|
+
/**
|
|
21
|
+
* Reference to the AgentSideConnection for sending notifications.
|
|
22
|
+
* Used by prompt processing to send session updates.
|
|
23
|
+
*/
|
|
24
|
+
private readonly _connection;
|
|
25
|
+
/**
|
|
26
|
+
* Session manager for handling session lifecycle.
|
|
27
|
+
* Manages session creation, lookup, cancellation, and cleanup.
|
|
28
|
+
*/
|
|
29
|
+
private readonly _sessionManager;
|
|
30
|
+
/**
|
|
31
|
+
* Client capabilities received during initialization.
|
|
32
|
+
* Used to determine what features the client supports.
|
|
33
|
+
*/
|
|
34
|
+
private _clientCapabilities;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new ACP Agent instance.
|
|
37
|
+
*
|
|
38
|
+
* @param connection - The AgentSideConnection for communicating with the client
|
|
39
|
+
*/
|
|
40
|
+
constructor(connection: AgentSideConnection);
|
|
41
|
+
/**
|
|
42
|
+
* Get the connection for sending notifications.
|
|
43
|
+
* Used by prompt processing to send session updates.
|
|
44
|
+
*/
|
|
45
|
+
get connection(): AgentSideConnection;
|
|
46
|
+
/**
|
|
47
|
+
* Get the session manager for session operations.
|
|
48
|
+
*/
|
|
49
|
+
get sessionManager(): SessionManager;
|
|
50
|
+
/**
|
|
51
|
+
* Get the client capabilities received during initialization.
|
|
52
|
+
* Returns null if initialize() has not been called yet.
|
|
53
|
+
*/
|
|
54
|
+
get clientCapabilities(): ClientCapabilities | null;
|
|
55
|
+
/**
|
|
56
|
+
* Handle ACP initialize request.
|
|
57
|
+
* Returns agent capabilities and info.
|
|
58
|
+
*
|
|
59
|
+
* Stores client capabilities for later use and returns InitializeResponse
|
|
60
|
+
* with agent info and capabilities including promptCapabilities.embeddedContext: true.
|
|
61
|
+
*
|
|
62
|
+
* @param params - The initialization request parameters
|
|
63
|
+
* @returns Promise resolving to InitializeResponse with agent capabilities
|
|
64
|
+
*/
|
|
65
|
+
initialize(params: InitializeRequest): Promise<InitializeResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Handle ACP session/new request.
|
|
68
|
+
* Creates a new session with MCP server connections.
|
|
69
|
+
*
|
|
70
|
+
* Generates a unique sessionId using crypto.randomUUID(), stores session state,
|
|
71
|
+
* initializes MCP connections from the request params, and returns NewSessionResponse.
|
|
72
|
+
*
|
|
73
|
+
* @param params - The new session request parameters containing cwd and optional mcpServers
|
|
74
|
+
* @returns Promise resolving to NewSessionResponse with session ID
|
|
75
|
+
*/
|
|
76
|
+
newSession(params: NewSessionRequest): Promise<NewSessionResponse>;
|
|
77
|
+
/**
|
|
78
|
+
* Handle ACP session/load request.
|
|
79
|
+
* Loads an existing session (optional capability).
|
|
80
|
+
*
|
|
81
|
+
* @param params - The load session request parameters
|
|
82
|
+
* @returns Promise resolving to LoadSessionResponse
|
|
83
|
+
*/
|
|
84
|
+
loadSession(_params: LoadSessionRequest): Promise<LoadSessionResponse>;
|
|
85
|
+
/**
|
|
86
|
+
* Handle ACP authenticate request.
|
|
87
|
+
* Processes authentication (if required).
|
|
88
|
+
*
|
|
89
|
+
* @param params - The authentication request parameters
|
|
90
|
+
* @returns Promise resolving to AuthenticateResponse or void
|
|
91
|
+
*/
|
|
92
|
+
authenticate(_params: AuthenticateRequest): Promise<AuthenticateResponse | void>;
|
|
93
|
+
/**
|
|
94
|
+
* Handle ACP session/prompt request.
|
|
95
|
+
* Processes user prompts and streams responses.
|
|
96
|
+
*
|
|
97
|
+
* Currently implements echo mode for testing - echoes user prompt as agent response.
|
|
98
|
+
*
|
|
99
|
+
* @param params - The prompt request parameters
|
|
100
|
+
* @returns Promise resolving to PromptResponse with stop reason
|
|
101
|
+
*/
|
|
102
|
+
prompt(params: PromptRequest): Promise<PromptResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Handle ACP session/cancel notification.
|
|
105
|
+
* Cancels ongoing operations for a session.
|
|
106
|
+
*
|
|
107
|
+
* Looks up the session by sessionId and calls session.cancel() to set
|
|
108
|
+
* the cancellation flag and abort pending MCP operations.
|
|
109
|
+
*
|
|
110
|
+
* @param params - The cancel notification parameters containing sessionId
|
|
111
|
+
*/
|
|
112
|
+
cancel(params: CancelNotification): Promise<void>;
|
|
113
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Connection
|
|
3
|
+
*
|
|
4
|
+
* Represents a single connection to an MCP server.
|
|
5
|
+
* Uses @modelcontextprotocol/sdk for protocol handling.
|
|
6
|
+
*
|
|
7
|
+
* @module mcp/connection
|
|
8
|
+
*/
|
|
9
|
+
import type { MCPResource, MCPServerConfig, MCPTool } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Represents a connection to a single MCP server.
|
|
12
|
+
*/
|
|
13
|
+
export declare class MCPConnection {
|
|
14
|
+
private _config;
|
|
15
|
+
private connected;
|
|
16
|
+
constructor(config: MCPServerConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Get the server configuration.
|
|
19
|
+
*/
|
|
20
|
+
get config(): MCPServerConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Establish connection to the MCP server.
|
|
23
|
+
*/
|
|
24
|
+
connect(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if the connection is active.
|
|
27
|
+
*/
|
|
28
|
+
isConnected(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Get tools available from this server.
|
|
31
|
+
*/
|
|
32
|
+
listTools(): Promise<MCPTool[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Invoke a tool on this server.
|
|
35
|
+
*/
|
|
36
|
+
callTool(_name: string, _args: Record<string, unknown>): Promise<unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* Get resources available from this server.
|
|
39
|
+
*/
|
|
40
|
+
listResources(): Promise<MCPResource[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Read a resource from this server.
|
|
43
|
+
*/
|
|
44
|
+
readResource(_uri: string): Promise<unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* Close the connection to the MCP server.
|
|
47
|
+
*/
|
|
48
|
+
close(): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Abort all pending operations on this connection.
|
|
51
|
+
* Called when a session is cancelled to stop in-flight requests.
|
|
52
|
+
*/
|
|
53
|
+
abortPendingOperations(): void;
|
|
54
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Client Management
|
|
3
|
+
*
|
|
4
|
+
* This module provides MCP client functionality using @modelcontextprotocol/sdk.
|
|
5
|
+
* It handles connections to MCP servers, tool discovery, and tool invocation.
|
|
6
|
+
*
|
|
7
|
+
* @module mcp
|
|
8
|
+
*/
|
|
9
|
+
export { MCPManager, type MCPConnection } from './manager.js';
|
|
10
|
+
export type { MCPServerConfig, MCPTool, MCPResource } from './types.js';
|