@mcp-abap-adt/llm-agent-mcp 12.0.2 → 12.0.4
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/dist/adapter.d.ts +16 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +95 -0
- package/dist/adapter.js.map +1 -0
- package/dist/client.d.ts +133 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +314 -0
- package/dist/client.js.map +1 -0
- package/dist/factory.d.ts +3 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +21 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/strategies/index.d.ts +4 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +4 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/lazy-connection-strategy.d.ts +14 -0
- package/dist/strategies/lazy-connection-strategy.d.ts.map +1 -0
- package/dist/strategies/lazy-connection-strategy.js +82 -0
- package/dist/strategies/lazy-connection-strategy.js.map +1 -0
- package/dist/strategies/noop-connection-strategy.d.ts +5 -0
- package/dist/strategies/noop-connection-strategy.d.ts.map +1 -0
- package/dist/strategies/noop-connection-strategy.js +6 -0
- package/dist/strategies/noop-connection-strategy.js.map +1 -0
- package/dist/strategies/periodic-connection-strategy.d.ts +12 -0
- package/dist/strategies/periodic-connection-strategy.d.ts.map +1 -0
- package/dist/strategies/periodic-connection-strategy.js +40 -0
- package/dist/strategies/periodic-connection-strategy.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* McpClientAdapter — wraps MCPClientWrapper as IMcpClient.
|
|
3
|
+
*/
|
|
4
|
+
import type { IMcpClient } from '@mcp-abap-adt/llm-agent';
|
|
5
|
+
import { type CallOptions, McpError, type McpTool, type McpToolResult, type Result } from '@mcp-abap-adt/llm-agent';
|
|
6
|
+
import type { MCPClientWrapper } from './client.js';
|
|
7
|
+
export declare class McpClientAdapter implements IMcpClient {
|
|
8
|
+
private readonly client;
|
|
9
|
+
private toolsCache;
|
|
10
|
+
private lastHealthy;
|
|
11
|
+
constructor(client: MCPClientWrapper);
|
|
12
|
+
listTools(options?: CallOptions): Promise<Result<McpTool[], McpError>>;
|
|
13
|
+
healthCheck(options?: CallOptions): Promise<Result<boolean, McpError>>;
|
|
14
|
+
callTool(name: string, args: Record<string, unknown>, options?: CallOptions): Promise<Result<McpToolResult, McpError>>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,KAAK,WAAW,EAChB,QAAQ,EACR,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,MAAM,EAEZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA2BpD,qBAAa,gBAAiB,YAAW,UAAU;IAIrC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAHnC,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,WAAW,CAAQ;gBAEE,MAAM,EAAE,gBAAgB;IAE/C,SAAS,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;IAyBtE,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAqBtE,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;CA8B5C"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* McpClientAdapter — wraps MCPClientWrapper as IMcpClient.
|
|
3
|
+
*/
|
|
4
|
+
import { McpError, } from '@mcp-abap-adt/llm-agent';
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Module-private helper
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
function withAbort(promise, signal, makeError) {
|
|
9
|
+
if (!signal)
|
|
10
|
+
return promise;
|
|
11
|
+
if (signal.aborted)
|
|
12
|
+
return Promise.reject(makeError());
|
|
13
|
+
return Promise.race([
|
|
14
|
+
promise,
|
|
15
|
+
new Promise((_, reject) => {
|
|
16
|
+
signal.addEventListener('abort', () => reject(makeError()), {
|
|
17
|
+
once: true,
|
|
18
|
+
});
|
|
19
|
+
}),
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// McpClientAdapter
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
export class McpClientAdapter {
|
|
26
|
+
client;
|
|
27
|
+
toolsCache;
|
|
28
|
+
lastHealthy = true;
|
|
29
|
+
constructor(client) {
|
|
30
|
+
this.client = client;
|
|
31
|
+
}
|
|
32
|
+
async listTools(options) {
|
|
33
|
+
if (this.toolsCache) {
|
|
34
|
+
return { ok: true, value: this.toolsCache };
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const raw = await withAbort(this.client.listTools(), options?.signal, () => new McpError('Aborted', 'ABORTED'));
|
|
38
|
+
const tools = raw.map((t) => ({
|
|
39
|
+
name: t.name,
|
|
40
|
+
description: t.description ?? '',
|
|
41
|
+
inputSchema: t.inputSchema ?? {},
|
|
42
|
+
}));
|
|
43
|
+
this.toolsCache = tools;
|
|
44
|
+
return { ok: true, value: tools };
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (err instanceof McpError)
|
|
48
|
+
return { ok: false, error: err };
|
|
49
|
+
return { ok: false, error: new McpError(String(err)) };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async healthCheck(options) {
|
|
53
|
+
try {
|
|
54
|
+
await withAbort(this.client.ping(), options?.signal, () => new McpError('Aborted', 'ABORTED'));
|
|
55
|
+
// Reconnect detection: unhealthy → healthy means the server restarted
|
|
56
|
+
// and may expose a different tool catalog.
|
|
57
|
+
if (!this.lastHealthy) {
|
|
58
|
+
this.toolsCache = undefined;
|
|
59
|
+
}
|
|
60
|
+
this.lastHealthy = true;
|
|
61
|
+
return { ok: true, value: true };
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
this.lastHealthy = false;
|
|
65
|
+
if (err instanceof McpError)
|
|
66
|
+
return { ok: false, error: err };
|
|
67
|
+
return { ok: false, error: new McpError(String(err)) };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async callTool(name, args, options) {
|
|
71
|
+
try {
|
|
72
|
+
const result = await withAbort(this.client.callTool({
|
|
73
|
+
id: crypto.randomUUID(),
|
|
74
|
+
name,
|
|
75
|
+
arguments: args,
|
|
76
|
+
}), options?.signal, () => new McpError('Aborted', 'ABORTED'));
|
|
77
|
+
return {
|
|
78
|
+
ok: true,
|
|
79
|
+
value: {
|
|
80
|
+
content: typeof (result.error ?? result.result) === 'string' ||
|
|
81
|
+
typeof (result.error ?? result.result) === 'object'
|
|
82
|
+
? (result.error ?? result.result)
|
|
83
|
+
: String(result.error ?? result.result),
|
|
84
|
+
isError: !!result.error,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
if (err instanceof McpError)
|
|
90
|
+
return { ok: false, error: err };
|
|
91
|
+
return { ok: false, error: new McpError(String(err)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AAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;YAC9D,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QACzD,CAAC;IACH,CAAC;CACF"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Client Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps the MCP SDK client to provide a simpler interface for the agent
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolCall, ToolResult } from '@mcp-abap-adt/llm-agent';
|
|
7
|
+
type McpToolDef = {
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
inputSchema?: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
type EmbeddedServerInstance = {
|
|
13
|
+
server?: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type TransportType = 'stdio' | 'sse' | 'stream-http' | 'auto' | 'embedded';
|
|
16
|
+
export interface MCPClientConfig {
|
|
17
|
+
/**
|
|
18
|
+
* Transport type:
|
|
19
|
+
* - 'stdio': Standard input/output (for local processes)
|
|
20
|
+
* - 'sse': Server-Sent Events (GET endpoint)
|
|
21
|
+
* - 'stream-http': Streamable HTTP (POST endpoint, bidirectional NDJSON)
|
|
22
|
+
* - 'auto': Automatically detect from URL (defaults to 'stream-http' for HTTP URLs)
|
|
23
|
+
* - 'embedded': Direct MCP server instance (same process, no transport)
|
|
24
|
+
*
|
|
25
|
+
* If URL is provided and transport is 'auto', it will be detected automatically:
|
|
26
|
+
* - URLs containing '/sse' or ending with '/sse' -> 'sse'
|
|
27
|
+
* - URLs containing '/stream/http' or '/http' -> 'stream-http'
|
|
28
|
+
* - Otherwise defaults to 'stream-http'
|
|
29
|
+
*/
|
|
30
|
+
transport?: TransportType;
|
|
31
|
+
/**
|
|
32
|
+
* For embedded mode: Direct MCP server instance
|
|
33
|
+
* Use this when MCP server runs in the same process (e.g., imported as submodule)
|
|
34
|
+
* The server instance must have:
|
|
35
|
+
* - server.setRequestHandler() method for ListToolsRequestSchema and CallToolRequestSchema
|
|
36
|
+
* - Or provide tools list and tool call handler directly
|
|
37
|
+
*/
|
|
38
|
+
serverInstance?: EmbeddedServerInstance;
|
|
39
|
+
/**
|
|
40
|
+
* For embedded mode: Direct access to tools registry
|
|
41
|
+
* If provided, listTools() will use this instead of calling server
|
|
42
|
+
*/
|
|
43
|
+
toolsRegistry?: {
|
|
44
|
+
getAllTools: () => McpToolDef[];
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* For embedded mode: Direct tool call handler
|
|
48
|
+
* If provided, callTool() will use this instead of calling server
|
|
49
|
+
*/
|
|
50
|
+
toolCallHandler?: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* Direct tools list provider (DI)
|
|
53
|
+
* Use this to supply tools without relying on MCP transport details.
|
|
54
|
+
*/
|
|
55
|
+
listToolsHandler?: () => Promise<McpToolDef[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Direct tool call provider (DI)
|
|
58
|
+
* Use this to supply tool execution without relying on MCP transport details.
|
|
59
|
+
*/
|
|
60
|
+
callToolHandler?: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
61
|
+
/**
|
|
62
|
+
* For stdio: command and args to execute
|
|
63
|
+
*/
|
|
64
|
+
command?: string;
|
|
65
|
+
args?: string[];
|
|
66
|
+
/**
|
|
67
|
+
* For HTTP transports: URL endpoint
|
|
68
|
+
* Examples:
|
|
69
|
+
* - 'http://localhost:4004/mcp/stream/sse' -> SSE transport
|
|
70
|
+
* - 'http://localhost:4004/mcp/stream/http' -> Streamable HTTP transport
|
|
71
|
+
*/
|
|
72
|
+
url?: string;
|
|
73
|
+
/**
|
|
74
|
+
* Session ID for HTTP transports (optional, will be generated if not provided)
|
|
75
|
+
* For Streamable HTTP: first request should omit this, subsequent requests should include it
|
|
76
|
+
*/
|
|
77
|
+
sessionId?: string;
|
|
78
|
+
/**
|
|
79
|
+
* HTTP headers for authentication and configuration
|
|
80
|
+
*/
|
|
81
|
+
headers?: Record<string, string>;
|
|
82
|
+
/**
|
|
83
|
+
* Timeout in milliseconds (default: 30000)
|
|
84
|
+
*/
|
|
85
|
+
timeout?: number;
|
|
86
|
+
}
|
|
87
|
+
export declare class MCPClientWrapper {
|
|
88
|
+
private client;
|
|
89
|
+
private config;
|
|
90
|
+
private tools;
|
|
91
|
+
private detectedTransport;
|
|
92
|
+
private sessionId?;
|
|
93
|
+
constructor(config: MCPClientConfig);
|
|
94
|
+
/**
|
|
95
|
+
* Detect transport type from config
|
|
96
|
+
*/
|
|
97
|
+
private detectTransport;
|
|
98
|
+
/**
|
|
99
|
+
* Initialize MCP client connection
|
|
100
|
+
*/
|
|
101
|
+
connect(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Get detected transport type
|
|
104
|
+
*/
|
|
105
|
+
getTransport(): TransportType;
|
|
106
|
+
/**
|
|
107
|
+
* Get current session ID (for HTTP transports)
|
|
108
|
+
*/
|
|
109
|
+
getSessionId(): string | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Get list of available tools
|
|
112
|
+
*/
|
|
113
|
+
listTools(): Promise<McpToolDef[]>;
|
|
114
|
+
/**
|
|
115
|
+
* Execute a tool call
|
|
116
|
+
*/
|
|
117
|
+
callTool(toolCall: ToolCall): Promise<ToolResult>;
|
|
118
|
+
/**
|
|
119
|
+
* Execute multiple tool calls
|
|
120
|
+
*/
|
|
121
|
+
callTools(toolCalls: ToolCall[]): Promise<ToolResult[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Lightweight ping — verifies the MCP server is reachable
|
|
124
|
+
* without triggering a full tools/list request.
|
|
125
|
+
*/
|
|
126
|
+
ping(): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Disconnect from MCP server
|
|
129
|
+
*/
|
|
130
|
+
disconnect(): Promise<void>;
|
|
131
|
+
}
|
|
132
|
+
export {};
|
|
133
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAKpE,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,aAAa,GACrB,OAAO,GACP,KAAK,GACL,aAAa,GACb,MAAM,GACN,UAAU,CAAC;AAEf,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,aAAa,CAAC;IAE1B;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC;IAExC;;;OAGG;IACH,aAAa,CAAC,EAAE;QACd,WAAW,EAAE,MAAM,UAAU,EAAE,CAAC;KACjC,CAAC;IAEF;;;OAGG;IACH,eAAe,CAAC,EAAE,CAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAE/C;;;OAGG;IACH,eAAe,CAAC,EAAE,CAChB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,iBAAiB,CAAgB;IACzC,OAAO,CAAC,SAAS,CAAC,CAAS;gBAEf,MAAM,EAAE,eAAe;IAKnC;;OAEG;IACH,OAAO,CAAC,eAAe;IA6CvB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgH9B;;OAEG;IACH,YAAY,IAAI,aAAa;IAI7B;;OAEG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IAIlC;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAoCxC;;OAEG;IACG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC;IA4FvD;;OAEG;IACG,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAO7D;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAWlC"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Client Wrapper
|
|
3
|
+
*
|
|
4
|
+
* Wraps the MCP SDK client to provide a simpler interface for the agent
|
|
5
|
+
*/
|
|
6
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
7
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
8
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
9
|
+
export class MCPClientWrapper {
|
|
10
|
+
client = null;
|
|
11
|
+
config;
|
|
12
|
+
tools = [];
|
|
13
|
+
detectedTransport;
|
|
14
|
+
sessionId;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.detectedTransport = this.detectTransport();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detect transport type from config
|
|
21
|
+
*/
|
|
22
|
+
detectTransport() {
|
|
23
|
+
// If transport is explicitly set and not 'auto', use it
|
|
24
|
+
if (this.config.transport && this.config.transport !== 'auto') {
|
|
25
|
+
return this.config.transport;
|
|
26
|
+
}
|
|
27
|
+
// If direct handlers or server instance are provided, use embedded mode
|
|
28
|
+
if (this.config.listToolsHandler ||
|
|
29
|
+
this.config.callToolHandler ||
|
|
30
|
+
this.config.serverInstance) {
|
|
31
|
+
return 'embedded';
|
|
32
|
+
}
|
|
33
|
+
// If URL is provided, try to detect from URL
|
|
34
|
+
if (this.config.url) {
|
|
35
|
+
const url = this.config.url.toLowerCase();
|
|
36
|
+
if (url.includes('/sse') || url.endsWith('/sse')) {
|
|
37
|
+
return 'sse';
|
|
38
|
+
}
|
|
39
|
+
if (url.includes('/stream/http') || url.includes('/http')) {
|
|
40
|
+
return 'stream-http';
|
|
41
|
+
}
|
|
42
|
+
// Default for HTTP URLs
|
|
43
|
+
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
44
|
+
return 'stream-http';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// If command is provided, assume stdio
|
|
48
|
+
if (this.config.command) {
|
|
49
|
+
return 'stdio';
|
|
50
|
+
}
|
|
51
|
+
// Default fallback
|
|
52
|
+
throw new Error('Cannot determine transport type. Please provide either:\n' +
|
|
53
|
+
' - transport: "embedded" with serverInstance\n' +
|
|
54
|
+
' - transport: "stdio" with command\n' +
|
|
55
|
+
' - transport: "sse" or "stream-http" with url\n' +
|
|
56
|
+
' - url (will auto-detect transport)');
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Initialize MCP client connection
|
|
60
|
+
*/
|
|
61
|
+
async connect() {
|
|
62
|
+
const transport = this.detectedTransport;
|
|
63
|
+
if (transport === 'embedded') {
|
|
64
|
+
const hasDirectTools = this.config.listToolsHandler || this.config.toolsRegistry;
|
|
65
|
+
// Embedded mode - allow direct handlers without serverInstance
|
|
66
|
+
if (!this.config.serverInstance && !hasDirectTools) {
|
|
67
|
+
throw new Error('serverInstance or toolsRegistry/listToolsHandler is required for embedded transport');
|
|
68
|
+
}
|
|
69
|
+
// If tools registry is provided, use it directly
|
|
70
|
+
if (this.config.listToolsHandler) {
|
|
71
|
+
this.tools = await this.config.listToolsHandler();
|
|
72
|
+
}
|
|
73
|
+
else if (this.config.toolsRegistry) {
|
|
74
|
+
this.tools = this.config.toolsRegistry.getAllTools();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Fallback: try to get from server instance if it has a method
|
|
78
|
+
if (this.config.serverInstance?.server) {
|
|
79
|
+
// Try to simulate ListToolsRequest
|
|
80
|
+
try {
|
|
81
|
+
// MCP Server has request handlers, but we need to call them directly
|
|
82
|
+
throw new Error('Direct server.listTools() not supported, use toolsRegistry');
|
|
83
|
+
}
|
|
84
|
+
catch (_err) {
|
|
85
|
+
throw new Error('Cannot get tools list in embedded mode. Provide toolsRegistry.');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new Error('Cannot get tools list in embedded mode. Provide toolsRegistry.');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// No need to connect in embedded mode - server is already in process
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
else if (transport === 'stdio') {
|
|
96
|
+
if (!this.config.command) {
|
|
97
|
+
throw new Error('Command is required for stdio transport');
|
|
98
|
+
}
|
|
99
|
+
const stdioTransport = new StdioClientTransport({
|
|
100
|
+
command: this.config.command,
|
|
101
|
+
args: this.config.args || [],
|
|
102
|
+
});
|
|
103
|
+
this.client = new Client({
|
|
104
|
+
name: 'llm-agent',
|
|
105
|
+
version: '0.1.0',
|
|
106
|
+
}, {
|
|
107
|
+
capabilities: {},
|
|
108
|
+
});
|
|
109
|
+
await this.client.connect(stdioTransport);
|
|
110
|
+
// List available tools
|
|
111
|
+
const toolsResponse = await this.client.listTools();
|
|
112
|
+
this.tools = toolsResponse.tools || [];
|
|
113
|
+
}
|
|
114
|
+
else if (transport === 'sse' || transport === 'stream-http') {
|
|
115
|
+
if (!this.config.url) {
|
|
116
|
+
throw new Error('URL is required for HTTP transports');
|
|
117
|
+
}
|
|
118
|
+
// Use StreamableHTTPClientTransport for both SSE and stream-http
|
|
119
|
+
// The SDK handles the protocol differences internally
|
|
120
|
+
const httpTransport = new StreamableHTTPClientTransport(new URL(this.config.url), {
|
|
121
|
+
sessionId: this.config.sessionId,
|
|
122
|
+
requestInit: {
|
|
123
|
+
headers: {
|
|
124
|
+
Accept: 'application/json, text/event-stream',
|
|
125
|
+
...this.config.headers,
|
|
126
|
+
},
|
|
127
|
+
signal: AbortSignal.timeout(this.config.timeout || 30000),
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
this.client = new Client({
|
|
131
|
+
name: 'llm-agent',
|
|
132
|
+
version: '0.1.0',
|
|
133
|
+
}, {
|
|
134
|
+
capabilities: {},
|
|
135
|
+
});
|
|
136
|
+
await this.client.connect(httpTransport);
|
|
137
|
+
// Store session ID if provided by transport
|
|
138
|
+
if (httpTransport.sessionId) {
|
|
139
|
+
this.sessionId = httpTransport.sessionId;
|
|
140
|
+
}
|
|
141
|
+
// List available tools
|
|
142
|
+
const toolsResponse = await this.client.listTools();
|
|
143
|
+
this.tools = toolsResponse.tools || [];
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
throw new Error(`Unsupported transport type: ${transport}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get detected transport type
|
|
151
|
+
*/
|
|
152
|
+
getTransport() {
|
|
153
|
+
return this.detectedTransport;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get current session ID (for HTTP transports)
|
|
157
|
+
*/
|
|
158
|
+
getSessionId() {
|
|
159
|
+
return this.sessionId || this.config.sessionId;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get list of available tools
|
|
163
|
+
*/
|
|
164
|
+
async listTools() {
|
|
165
|
+
// For embedded mode, tools are already loaded in connect()
|
|
166
|
+
if (this.detectedTransport === 'embedded') {
|
|
167
|
+
return this.tools;
|
|
168
|
+
}
|
|
169
|
+
const performList = async () => {
|
|
170
|
+
if (!this.client) {
|
|
171
|
+
await this.connect();
|
|
172
|
+
}
|
|
173
|
+
const response = await this.client?.listTools();
|
|
174
|
+
if (!response) {
|
|
175
|
+
throw new Error('MCP listTools returned no response');
|
|
176
|
+
}
|
|
177
|
+
this.tools = response.tools || [];
|
|
178
|
+
return this.tools;
|
|
179
|
+
};
|
|
180
|
+
try {
|
|
181
|
+
return await performList();
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
185
|
+
try {
|
|
186
|
+
console.warn(`MCP listTools failed, attempting reconnect: ${errorMessage}`);
|
|
187
|
+
await this.disconnect();
|
|
188
|
+
await this.connect();
|
|
189
|
+
return await performList();
|
|
190
|
+
}
|
|
191
|
+
catch (_retryError) {
|
|
192
|
+
return this.tools; // Return cached tools if reconnect fails
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Execute a tool call
|
|
198
|
+
*/
|
|
199
|
+
async callTool(toolCall) {
|
|
200
|
+
// For embedded mode, use direct handler or server instance
|
|
201
|
+
if (this.detectedTransport === 'embedded') {
|
|
202
|
+
try {
|
|
203
|
+
let result;
|
|
204
|
+
if (this.config.callToolHandler) {
|
|
205
|
+
result = await this.config.callToolHandler(toolCall.name, toolCall.arguments);
|
|
206
|
+
}
|
|
207
|
+
else if (this.config.toolCallHandler) {
|
|
208
|
+
// Use provided handler
|
|
209
|
+
result = await this.config.toolCallHandler(toolCall.name, toolCall.arguments);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
throw new Error('No tool call handler available in embedded mode. Provide toolCallHandler in mcpConfig.');
|
|
213
|
+
}
|
|
214
|
+
const normalizedResult = typeof result === 'object' && result !== null && 'content' in result
|
|
215
|
+
? result.content
|
|
216
|
+
: result;
|
|
217
|
+
return {
|
|
218
|
+
toolCallId: toolCall.id,
|
|
219
|
+
name: toolCall.name,
|
|
220
|
+
result: normalizedResult,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
225
|
+
return {
|
|
226
|
+
toolCallId: toolCall.id,
|
|
227
|
+
name: toolCall.name,
|
|
228
|
+
result: null,
|
|
229
|
+
error: errorMessage || 'Tool execution failed',
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const performCall = async () => {
|
|
234
|
+
if (!this.client) {
|
|
235
|
+
await this.connect();
|
|
236
|
+
}
|
|
237
|
+
const response = await this.client?.callTool({
|
|
238
|
+
name: toolCall.name,
|
|
239
|
+
arguments: toolCall.arguments,
|
|
240
|
+
});
|
|
241
|
+
if (!response) {
|
|
242
|
+
throw new Error('MCP callTool returned no response');
|
|
243
|
+
}
|
|
244
|
+
return response;
|
|
245
|
+
};
|
|
246
|
+
try {
|
|
247
|
+
const response = await performCall();
|
|
248
|
+
return {
|
|
249
|
+
toolCallId: toolCall.id,
|
|
250
|
+
name: toolCall.name,
|
|
251
|
+
result: response.content,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
256
|
+
// Auto-reconnect logic: if it fails, try to connect again and retry once
|
|
257
|
+
try {
|
|
258
|
+
console.warn(`MCP call failed, attempting reconnect: ${errorMessage}`);
|
|
259
|
+
await this.disconnect();
|
|
260
|
+
await this.connect();
|
|
261
|
+
const response = await performCall();
|
|
262
|
+
return {
|
|
263
|
+
toolCallId: toolCall.id,
|
|
264
|
+
name: toolCall.name,
|
|
265
|
+
result: response.content,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
catch (retryError) {
|
|
269
|
+
const retryErrorMessage = retryError instanceof Error ? retryError.message : String(retryError);
|
|
270
|
+
return {
|
|
271
|
+
toolCallId: toolCall.id,
|
|
272
|
+
name: toolCall.name,
|
|
273
|
+
result: null,
|
|
274
|
+
error: retryErrorMessage || 'Tool execution failed after reconnect',
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Execute multiple tool calls
|
|
281
|
+
*/
|
|
282
|
+
async callTools(toolCalls) {
|
|
283
|
+
const results = await Promise.all(toolCalls.map((toolCall) => this.callTool(toolCall)));
|
|
284
|
+
return results;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Lightweight ping — verifies the MCP server is reachable
|
|
288
|
+
* without triggering a full tools/list request.
|
|
289
|
+
*/
|
|
290
|
+
async ping() {
|
|
291
|
+
if (this.detectedTransport === 'embedded') {
|
|
292
|
+
// Embedded mode: server is in-process, always reachable
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (!this.client) {
|
|
296
|
+
await this.connect();
|
|
297
|
+
}
|
|
298
|
+
await this.client?.ping();
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Disconnect from MCP server
|
|
302
|
+
*/
|
|
303
|
+
async disconnect() {
|
|
304
|
+
// For embedded mode, no need to disconnect
|
|
305
|
+
if (this.detectedTransport === 'embedded') {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (this.client) {
|
|
309
|
+
await this.client.close();
|
|
310
|
+
this.client = null;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AA2GnG,MAAM,OAAO,gBAAgB;IACnB,MAAM,GAAkB,IAAI,CAAC;IAC7B,MAAM,CAAkB;IACxB,KAAK,GAAiB,EAAE,CAAC;IACzB,iBAAiB,CAAgB;IACjC,SAAS,CAAU;IAE3B,YAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;IAClD,CAAC;IAED;;OAEG;IACK,eAAe;QACrB,wDAAwD;QACxD,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,KAAK,MAAM,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;QAC/B,CAAC;QAED,wEAAwE;QACxE,IACE,IAAI,CAAC,MAAM,CAAC,gBAAgB;YAC5B,IAAI,CAAC,MAAM,CAAC,eAAe;YAC3B,IAAI,CAAC,MAAM,CAAC,cAAc,EAC1B,CAAC;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,6CAA6C;QAC7C,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YACpB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM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U,EAAE,CAAC;YAC1C,OAAO;QACT,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAIjC,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,sBAAsB,CAAC,CAoBjC"}
|
package/dist/factory.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { McpClientAdapter } from './adapter.js';
|
|
2
|
+
import { MCPClientWrapper } from './client.js';
|
|
3
|
+
export async function createDefaultMcpClient(config) {
|
|
4
|
+
const wrapper = config.type === 'stdio'
|
|
5
|
+
? new MCPClientWrapper({
|
|
6
|
+
transport: 'stdio',
|
|
7
|
+
command: config.command,
|
|
8
|
+
args: config.args ?? [],
|
|
9
|
+
})
|
|
10
|
+
: new MCPClientWrapper({
|
|
11
|
+
transport: 'auto',
|
|
12
|
+
url: config.url,
|
|
13
|
+
});
|
|
14
|
+
await wrapper.connect();
|
|
15
|
+
const client = new McpClientAdapter(wrapper);
|
|
16
|
+
return {
|
|
17
|
+
client,
|
|
18
|
+
close: () => wrapper.disconnect?.() ?? Promise.resolve(),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAA2B;IAE3B,MAAM,OAAO,GACX,MAAM,CAAC,IAAI,KAAK,OAAO;QACrB,CAAC,CAAC,IAAI,gBAAgB,CAAC;YACnB,SAAS,EAAE,OAAO;YAClB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;SACxB,CAAC;QACJ,CAAC,CAAC,IAAI,gBAAgB,CAAC;YACnB,SAAS,EAAE,MAAM;YACjB,GAAG,EAAE,MAAM,CAAC,GAAG;SAChB,CAAC,CAAC;IAET,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;IACxB,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE7C,OAAO;QACL,MAAM;QACN,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE;KACzD,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { McpClientAdapter } from './adapter.js';
|
|
2
|
+
export { type MCPClientConfig, MCPClientWrapper, type TransportType, } from './client.js';
|
|
3
|
+
export { createDefaultMcpClient } from './factory.js';
|
|
4
|
+
export { LazyConnectionStrategy, NoopConnectionStrategy, PeriodicConnectionStrategy, } from './strategies/index.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EACL,KAAK,eAAe,EACpB,gBAAgB,EAChB,KAAK,aAAa,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { McpClientAdapter } from './adapter.js';
|
|
2
|
+
export { MCPClientWrapper, } from './client.js';
|
|
3
|
+
export { createDefaultMcpClient } from './factory.js';
|
|
4
|
+
export { LazyConnectionStrategy, NoopConnectionStrategy, PeriodicConnectionStrategy, } from './strategies/index.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAEL,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/strategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/strategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ConnectionStrategyOptions, IMcpClient, IMcpConnectionStrategy, McpClientFactory, McpConnectionConfig, McpConnectionResult } from '@mcp-abap-adt/llm-agent';
|
|
2
|
+
export declare class LazyConnectionStrategy implements IMcpConnectionStrategy {
|
|
3
|
+
private readonly _slots;
|
|
4
|
+
private readonly _skipRevectorize;
|
|
5
|
+
private readonly _cooldownMs;
|
|
6
|
+
private readonly _factory;
|
|
7
|
+
private _resolving;
|
|
8
|
+
constructor(configs: McpConnectionConfig[], options?: ConnectionStrategyOptions, factory?: McpClientFactory);
|
|
9
|
+
resolve(_currentClients?: IMcpClient[]): Promise<McpConnectionResult>;
|
|
10
|
+
private _doResolve;
|
|
11
|
+
private _checkHealth;
|
|
12
|
+
dispose(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=lazy-connection-strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-connection-strategy.d.ts","sourceRoot":"","sources":["../../src/strategies/lazy-connection-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,UAAU,EACV,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAWjC,qBAAa,sBAAuB,YAAW,sBAAsB;IACnE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,UAAU,CAA6C;gBAG7D,OAAO,EAAE,mBAAmB,EAAE,EAC9B,OAAO,CAAC,EAAE,yBAAyB,EACnC,OAAO,CAAC,EAAE,gBAAgB;IAY5B,OAAO,CAAC,eAAe,CAAC,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAYvD,UAAU;YAyCV,YAAY;IAapB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAO/B"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createDefaultMcpClient } from '../factory.js';
|
|
2
|
+
export class LazyConnectionStrategy {
|
|
3
|
+
_slots;
|
|
4
|
+
_skipRevectorize;
|
|
5
|
+
_cooldownMs;
|
|
6
|
+
_factory;
|
|
7
|
+
_resolving = null;
|
|
8
|
+
constructor(configs, options, factory) {
|
|
9
|
+
this._skipRevectorize = options?.skipRevectorize ?? false;
|
|
10
|
+
this._cooldownMs = options?.cooldownMs ?? 30000;
|
|
11
|
+
this._factory = factory ?? createDefaultMcpClient;
|
|
12
|
+
this._slots = configs.map((config) => ({
|
|
13
|
+
config,
|
|
14
|
+
lastAttempt: 0,
|
|
15
|
+
healthy: false,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
resolve(_currentClients) {
|
|
19
|
+
if (this._resolving !== null) {
|
|
20
|
+
return this._resolving;
|
|
21
|
+
}
|
|
22
|
+
this._resolving = this._doResolve().finally(() => {
|
|
23
|
+
this._resolving = null;
|
|
24
|
+
});
|
|
25
|
+
return this._resolving;
|
|
26
|
+
}
|
|
27
|
+
async _doResolve() {
|
|
28
|
+
let anyNewlyHealthy = false;
|
|
29
|
+
for (const slot of this._slots) {
|
|
30
|
+
if (slot.client !== undefined) {
|
|
31
|
+
const healthy = await this._checkHealth(slot.client);
|
|
32
|
+
if (healthy) {
|
|
33
|
+
slot.healthy = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// Client is unhealthy — clear it and attempt reconnect
|
|
37
|
+
slot.client = undefined;
|
|
38
|
+
slot.closeHandle = undefined;
|
|
39
|
+
slot.healthy = false;
|
|
40
|
+
}
|
|
41
|
+
// No client or just cleared — try reconnect if cooldown expired
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
if (now - slot.lastAttempt >= this._cooldownMs) {
|
|
44
|
+
slot.lastAttempt = now;
|
|
45
|
+
try {
|
|
46
|
+
const result = await this._factory(slot.config);
|
|
47
|
+
slot.client = result.client;
|
|
48
|
+
slot.closeHandle = result.close;
|
|
49
|
+
slot.healthy = true;
|
|
50
|
+
anyNewlyHealthy = true;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
slot.healthy = false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const clients = this._slots
|
|
58
|
+
.filter((s) => s.healthy && s.client !== undefined)
|
|
59
|
+
.map((s) => s.client);
|
|
60
|
+
const toolsChanged = anyNewlyHealthy && !this._skipRevectorize;
|
|
61
|
+
return { clients, toolsChanged };
|
|
62
|
+
}
|
|
63
|
+
async _checkHealth(client) {
|
|
64
|
+
try {
|
|
65
|
+
if (typeof client.healthCheck === 'function') {
|
|
66
|
+
const result = await client.healthCheck();
|
|
67
|
+
return result.ok;
|
|
68
|
+
}
|
|
69
|
+
const result = await client.listTools();
|
|
70
|
+
return result.ok;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async dispose() {
|
|
77
|
+
await Promise.all(this._slots
|
|
78
|
+
.filter((s) => s.closeHandle !== undefined)
|
|
79
|
+
.map((s) => Promise.resolve(s.closeHandle?.())));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=lazy-connection-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-connection-strategy.js","sourceRoot":"","sources":["../../src/strategies/lazy-connection-strategy.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAUvD,MAAM,OAAO,sBAAsB;IAChB,MAAM,CAAS;IACf,gBAAgB,CAAU;IAC1B,WAAW,CAAS;IACpB,QAAQ,CAAmB;IACpC,UAAU,GAAwC,IAAI,CAAC;IAE/D,YACE,OAA8B,EAC9B,OAAmC,EACnC,OAA0B;QAE1B,IAA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AAM,CAAC,EAAE,CAAC;QACnB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,OAAO,CAAC,GAAG,CACf,IAAI,CAAC,MAAM;aACR,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,KAAK,SAAS,CAAC;aAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAClD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CallOptions, IMcpClient, IMcpConnectionStrategy, McpConnectionResult } from '@mcp-abap-adt/llm-agent';
|
|
2
|
+
export declare class NoopConnectionStrategy implements IMcpConnectionStrategy {
|
|
3
|
+
resolve(currentClients: IMcpClient[], _options?: CallOptions): Promise<McpConnectionResult>;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=noop-connection-strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noop-connection-strategy.d.ts","sourceRoot":"","sources":["../../src/strategies/noop-connection-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAEjC,qBAAa,sBAAuB,YAAW,sBAAsB;IAC7D,OAAO,CACX,cAAc,EAAE,UAAU,EAAE,EAC5B,QAAQ,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,mBAAmB,CAAC;CAGhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noop-connection-strategy.js","sourceRoot":"","sources":["../../src/strategies/noop-connection-strategy.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,sBAAsB;IACjC,KAAK,CAAC,OAAO,CACX,cAA4B,EAC5B,QAAsB;QAEtB,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IAC1D,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ConnectionStrategyOptions, IMcpClient, IMcpConnectionStrategy, McpClientFactory, McpConnectionConfig, McpConnectionResult } from '@mcp-abap-adt/llm-agent';
|
|
2
|
+
export declare class PeriodicConnectionStrategy implements IMcpConnectionStrategy {
|
|
3
|
+
private readonly _lazy;
|
|
4
|
+
private _cachedResult;
|
|
5
|
+
private _changed;
|
|
6
|
+
private readonly _interval;
|
|
7
|
+
constructor(configs: McpConnectionConfig[], intervalMs: number, options?: ConnectionStrategyOptions, factory?: McpClientFactory);
|
|
8
|
+
private _probe;
|
|
9
|
+
resolve(_currentClients?: IMcpClient[]): Promise<McpConnectionResult>;
|
|
10
|
+
dispose(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=periodic-connection-strategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"periodic-connection-strategy.d.ts","sourceRoot":"","sources":["../../src/strategies/periodic-connection-strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,UAAU,EACV,sBAAsB,EACtB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAGjC,qBAAa,0BAA2B,YAAW,sBAAsB;IACvE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAC/C,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiC;gBAGzD,OAAO,EAAE,mBAAmB,EAAE,EAC9B,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,yBAAyB,EACnC,OAAO,CAAC,EAAE,gBAAgB;YAmBd,MAAM;IAQd,OAAO,CAAC,eAAe,CAAC,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAWrE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAI/B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LazyConnectionStrategy } from './lazy-connection-strategy.js';
|
|
2
|
+
export class PeriodicConnectionStrategy {
|
|
3
|
+
_lazy;
|
|
4
|
+
_cachedResult;
|
|
5
|
+
_changed;
|
|
6
|
+
_interval;
|
|
7
|
+
constructor(configs, intervalMs, options, factory) {
|
|
8
|
+
// cooldownMs = 0 because the interval itself is the rate limiter
|
|
9
|
+
this._lazy = new LazyConnectionStrategy(configs, { ...options, cooldownMs: 0 }, factory);
|
|
10
|
+
this._cachedResult = { clients: [], toolsChanged: false };
|
|
11
|
+
this._changed = false;
|
|
12
|
+
this._interval = setInterval(() => {
|
|
13
|
+
void this._probe();
|
|
14
|
+
}, intervalMs);
|
|
15
|
+
// Run first probe immediately
|
|
16
|
+
void this._probe();
|
|
17
|
+
}
|
|
18
|
+
async _probe() {
|
|
19
|
+
const result = await this._lazy.resolve(this._cachedResult.clients);
|
|
20
|
+
if (result.clients !== this._cachedResult.clients) {
|
|
21
|
+
this._cachedResult = result;
|
|
22
|
+
this._changed = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async resolve(_currentClients) {
|
|
26
|
+
if (this._changed) {
|
|
27
|
+
this._changed = false;
|
|
28
|
+
return {
|
|
29
|
+
clients: this._cachedResult.clients,
|
|
30
|
+
toolsChanged: this._cachedResult.toolsChanged,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return { clients: this._cachedResult.clients, toolsChanged: false };
|
|
34
|
+
}
|
|
35
|
+
async dispose() {
|
|
36
|
+
clearInterval(this._interval);
|
|
37
|
+
await this._lazy.dispose();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=periodic-connection-strategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"periodic-connection-strategy.js","sourceRoot":"","sources":["../../src/strategies/periodic-connection-strategy.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,MAAM,OAAO,0BAA0B;IACpB,KAAK,CAAyB;IACvC,aAAa,CAAsB;IACnC,QAAQ,CAAU;IACT,SAAS,CAAiC;IAE3D,YACE,OAA8B,EAC9B,UAAkB,EAClB,OAAmC,EACnC,OAA0B;QAE1B,iEAAiE;QACjE,IAAI,CAAC,KAAK,GAAG,IAAI,sBAAsB,CACrC,OAAO,EACP,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,EAC7B,OAAO,CACR,CAAC;QACF,IAAI,CAAC,aAAa,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;QAC1D,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAEtB,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE;YAChC,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;QACrB,CAAC,EAAE,UAAU,CAAC,CAAC;QAEf,8BAA8B;QAC9B,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;IACrB,CAAC;IAEO,KAAK,CAAC,MAAM;QAClB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACpE,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;YAClD,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;YAC5B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,eAA8B;QAC1C,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;YACtB,OAAO;gBACL,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,OAAO;gBACnC,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC,YAAY;aAC9C,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACtE,CAAC;IAED,KAAK,CAAC,OAAO;QACX,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC9B,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-abap-adt/llm-agent-mcp",
|
|
3
|
-
"version": "12.0.
|
|
3
|
+
"version": "12.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
|
-
"import": "./dist/index.js"
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
11
12
|
}
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
"test": "node --import tsx/esm --test --test-reporter=spec 'src/**/*.test.ts'"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@mcp-abap-adt/llm-agent": "
|
|
24
|
+
"@mcp-abap-adt/llm-agent": "^12.0.4",
|
|
24
25
|
"@modelcontextprotocol/sdk": "^1.28.0"
|
|
25
26
|
},
|
|
26
27
|
"publishConfig": {
|