mcp-use 0.2.0 → 1.0.0
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/chunk-2HFIPY7C.js +429 -0
- package/dist/chunk-4DEFXVWT.js +680 -0
- package/dist/chunk-JXLQRAW2.js +532 -0
- package/dist/chunk-SHUYVCID.js +6 -0
- package/dist/chunk-YUSC6R6V.js +299 -0
- package/dist/index.cjs +5762 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3767 -22
- package/dist/langfuse-YA2S23SM.js +13 -0
- package/dist/src/agents/remote.d.ts.map +1 -1
- package/dist/src/agents/utils/ai_sdk.d.ts.map +1 -1
- package/dist/src/auth/browser-provider.d.ts +52 -0
- package/dist/src/auth/browser-provider.d.ts.map +1 -0
- package/dist/src/auth/callback.d.ts +6 -0
- package/dist/src/auth/callback.d.ts.map +1 -0
- package/dist/src/auth/index.d.ts +7 -0
- package/dist/src/auth/index.d.ts.map +1 -0
- package/dist/src/auth/types.d.ts +18 -0
- package/dist/src/auth/types.d.ts.map +1 -0
- package/dist/src/browser.cjs +323 -0
- package/dist/src/browser.d.ts +5 -46
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +9 -75
- package/dist/src/oauth-helper.d.ts +2 -12
- package/dist/src/oauth-helper.d.ts.map +1 -1
- package/dist/src/react/index.cjs +986 -0
- package/dist/src/react/index.d.ts +9 -0
- package/dist/src/react/index.d.ts.map +1 -0
- package/dist/src/react/index.js +11 -0
- package/dist/src/react/types.d.ts +139 -0
- package/dist/src/react/types.d.ts.map +1 -0
- package/dist/src/react/useMcp.d.ts +3 -0
- package/dist/src/react/useMcp.d.ts.map +1 -0
- package/dist/src/server/index.cjs +566 -0
- package/dist/src/server/index.d.ts +3 -0
- package/dist/src/server/index.d.ts.map +1 -0
- package/dist/src/server/index.js +9 -0
- package/dist/src/server/logging.d.ts +16 -0
- package/dist/src/server/logging.d.ts.map +1 -0
- package/dist/src/server/mcp-server.d.ts +282 -0
- package/dist/src/server/mcp-server.d.ts.map +1 -0
- package/dist/src/server/types.d.ts +47 -0
- package/dist/src/server/types.d.ts.map +1 -0
- package/dist/src/utils/assert.d.ts +8 -0
- package/dist/src/utils/assert.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +67 -40
- package/dist/src/adapters/base.js +0 -124
- package/dist/src/adapters/index.js +0 -2
- package/dist/src/adapters/langchain_adapter.js +0 -49
- package/dist/src/agents/base.js +0 -9
- package/dist/src/agents/index.js +0 -3
- package/dist/src/agents/mcp_agent.js +0 -1002
- package/dist/src/agents/prompts/system_prompt_builder.js +0 -40
- package/dist/src/agents/prompts/templates.js +0 -39
- package/dist/src/agents/remote.js +0 -264
- package/dist/src/agents/utils/ai_sdk.js +0 -62
- package/dist/src/agents/utils/index.js +0 -1
- package/dist/src/client/base.js +0 -119
- package/dist/src/client.js +0 -50
- package/dist/src/config.js +0 -34
- package/dist/src/connectors/base.js +0 -143
- package/dist/src/connectors/http.js +0 -150
- package/dist/src/connectors/index.js +0 -4
- package/dist/src/connectors/stdio.js +0 -68
- package/dist/src/connectors/websocket.js +0 -157
- package/dist/src/logging.js +0 -232
- package/dist/src/managers/index.js +0 -2
- package/dist/src/managers/server_manager.js +0 -106
- package/dist/src/managers/tools/acquire_active_mcp_server.js +0 -17
- package/dist/src/managers/tools/add_server_from_config.js +0 -40
- package/dist/src/managers/tools/base.js +0 -17
- package/dist/src/managers/tools/connect_mcp_server.js +0 -46
- package/dist/src/managers/tools/index.js +0 -5
- package/dist/src/managers/tools/list_mcp_servers.js +0 -33
- package/dist/src/managers/tools/release_mcp_server_connection.js +0 -19
- package/dist/src/oauth-helper.js +0 -427
- package/dist/src/observability/index.js +0 -12
- package/dist/src/observability/langfuse.js +0 -211
- package/dist/src/observability/manager.js +0 -199
- package/dist/src/observability/types.js +0 -4
- package/dist/src/session.js +0 -23
- package/dist/src/task_managers/base.js +0 -127
- package/dist/src/task_managers/index.js +0 -5
- package/dist/src/task_managers/sse.js +0 -43
- package/dist/src/task_managers/stdio.js +0 -51
- package/dist/src/task_managers/streamable_http.js +0 -50
- package/dist/src/task_managers/websocket.js +0 -67
- package/dist/src/telemetry/events.js +0 -44
- package/dist/src/telemetry/index.js +0 -8
- package/dist/src/telemetry/telemetry.js +0 -324
- package/dist/src/telemetry/utils.js +0 -39
- package/dist/tests/ai_sdk_compatibility.test.js +0 -214
- package/dist/tests/stream_events.test.js +0 -307
- package/dist/tests/stream_events_simple.test.js +0 -179
- package/dist/vitest.config.js +0 -21
@@ -1,199 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Observability callbacks manager for MCP-use.
|
3
|
-
*
|
4
|
-
* This module provides a centralized manager for handling observability callbacks
|
5
|
-
* from various platforms (Langfuse, Laminar, etc.) in a clean and extensible way.
|
6
|
-
*/
|
7
|
-
import { logger } from '../logging.js';
|
8
|
-
export class ObservabilityManager {
|
9
|
-
customCallbacks;
|
10
|
-
availableHandlers = [];
|
11
|
-
handlerNames = [];
|
12
|
-
initialized = false;
|
13
|
-
verbose;
|
14
|
-
observe;
|
15
|
-
agentId;
|
16
|
-
metadata;
|
17
|
-
metadataProvider;
|
18
|
-
tagsProvider;
|
19
|
-
constructor(config = {}) {
|
20
|
-
this.customCallbacks = config.customCallbacks;
|
21
|
-
this.verbose = config.verbose ?? false;
|
22
|
-
this.observe = config.observe ?? true;
|
23
|
-
this.agentId = config.agentId;
|
24
|
-
this.metadata = config.metadata;
|
25
|
-
this.metadataProvider = config.metadataProvider;
|
26
|
-
this.tagsProvider = config.tagsProvider;
|
27
|
-
}
|
28
|
-
/**
|
29
|
-
* Collect all available observability handlers from configured platforms.
|
30
|
-
*/
|
31
|
-
async collectAvailableHandlers() {
|
32
|
-
if (this.initialized) {
|
33
|
-
return;
|
34
|
-
}
|
35
|
-
// Import handlers lazily to avoid circular imports
|
36
|
-
try {
|
37
|
-
const { langfuseHandler, langfuseInitPromise } = await import('./langfuse.js');
|
38
|
-
// If we have an agent ID, metadata, or providers, we need to reinitialize Langfuse
|
39
|
-
if (this.agentId || this.metadata || this.metadataProvider || this.tagsProvider) {
|
40
|
-
// Import the initialization function directly
|
41
|
-
const { initializeLangfuse } = await import('./langfuse.js');
|
42
|
-
await initializeLangfuse(this.agentId, this.metadata, this.metadataProvider, this.tagsProvider);
|
43
|
-
logger.debug(`ObservabilityManager: Reinitialized Langfuse with agent ID: ${this.agentId}, metadata: ${JSON.stringify(this.metadata)}`);
|
44
|
-
}
|
45
|
-
else {
|
46
|
-
// Wait for existing initialization to complete
|
47
|
-
const initPromise = langfuseInitPromise();
|
48
|
-
if (initPromise) {
|
49
|
-
await initPromise;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
const handler = langfuseHandler();
|
53
|
-
if (handler) {
|
54
|
-
this.availableHandlers.push(handler);
|
55
|
-
this.handlerNames.push('Langfuse');
|
56
|
-
logger.debug('ObservabilityManager: Langfuse handler available');
|
57
|
-
}
|
58
|
-
}
|
59
|
-
catch {
|
60
|
-
logger.debug('ObservabilityManager: Langfuse module not available');
|
61
|
-
}
|
62
|
-
// Future: Add more platforms here...
|
63
|
-
this.initialized = true;
|
64
|
-
}
|
65
|
-
/**
|
66
|
-
* Get the list of callbacks to use.
|
67
|
-
* @returns List of callbacks - either custom callbacks if provided, or all available observability handlers.
|
68
|
-
*/
|
69
|
-
async getCallbacks() {
|
70
|
-
// If observability is disabled, return empty array
|
71
|
-
if (!this.observe) {
|
72
|
-
logger.debug('ObservabilityManager: Observability disabled via observe=false');
|
73
|
-
return [];
|
74
|
-
}
|
75
|
-
// If custom callbacks were provided, use those
|
76
|
-
if (this.customCallbacks) {
|
77
|
-
logger.debug(`ObservabilityManager: Using ${this.customCallbacks.length} custom callbacks`);
|
78
|
-
return this.customCallbacks;
|
79
|
-
}
|
80
|
-
// Otherwise, collect and return all available handlers
|
81
|
-
await this.collectAvailableHandlers();
|
82
|
-
if (this.availableHandlers.length > 0) {
|
83
|
-
logger.debug(`ObservabilityManager: Using ${this.availableHandlers.length} handlers`);
|
84
|
-
}
|
85
|
-
else {
|
86
|
-
logger.debug('ObservabilityManager: No callbacks configured');
|
87
|
-
}
|
88
|
-
return this.availableHandlers;
|
89
|
-
}
|
90
|
-
/**
|
91
|
-
* Get the names of available handlers.
|
92
|
-
* @returns List of handler names (e.g., ["Langfuse", "Laminar"])
|
93
|
-
*/
|
94
|
-
async getHandlerNames() {
|
95
|
-
// If observability is disabled, return empty array
|
96
|
-
if (!this.observe) {
|
97
|
-
return [];
|
98
|
-
}
|
99
|
-
if (this.customCallbacks) {
|
100
|
-
// For custom callbacks, try to get their class names
|
101
|
-
return this.customCallbacks.map(cb => cb.constructor.name);
|
102
|
-
}
|
103
|
-
await this.collectAvailableHandlers();
|
104
|
-
return this.handlerNames;
|
105
|
-
}
|
106
|
-
/**
|
107
|
-
* Check if any callbacks are available.
|
108
|
-
* @returns True if callbacks are available, False otherwise.
|
109
|
-
*/
|
110
|
-
async hasCallbacks() {
|
111
|
-
// If observability is disabled, no callbacks are available
|
112
|
-
if (!this.observe) {
|
113
|
-
return false;
|
114
|
-
}
|
115
|
-
const callbacks = await this.getCallbacks();
|
116
|
-
return callbacks.length > 0;
|
117
|
-
}
|
118
|
-
/**
|
119
|
-
* Add a callback to the custom callbacks list.
|
120
|
-
* @param callback The callback to add.
|
121
|
-
*/
|
122
|
-
addCallback(callback) {
|
123
|
-
if (!this.customCallbacks) {
|
124
|
-
this.customCallbacks = [];
|
125
|
-
}
|
126
|
-
this.customCallbacks.push(callback);
|
127
|
-
logger.debug(`ObservabilityManager: Added custom callback: ${callback.constructor.name}`);
|
128
|
-
}
|
129
|
-
/**
|
130
|
-
* Clear all custom callbacks.
|
131
|
-
*/
|
132
|
-
clearCallbacks() {
|
133
|
-
this.customCallbacks = [];
|
134
|
-
logger.debug('ObservabilityManager: Cleared all custom callbacks');
|
135
|
-
}
|
136
|
-
/**
|
137
|
-
* Flush all pending traces to observability platforms.
|
138
|
-
* Important for serverless environments and short-lived processes.
|
139
|
-
*/
|
140
|
-
async flush() {
|
141
|
-
// Flush Langfuse traces
|
142
|
-
const callbacks = await this.getCallbacks();
|
143
|
-
for (const callback of callbacks) {
|
144
|
-
if ('flushAsync' in callback && typeof callback.flushAsync === 'function') {
|
145
|
-
await callback.flushAsync();
|
146
|
-
}
|
147
|
-
}
|
148
|
-
logger.debug('ObservabilityManager: All traces flushed');
|
149
|
-
}
|
150
|
-
/**
|
151
|
-
* Shutdown all handlers gracefully (for serverless environments).
|
152
|
-
*/
|
153
|
-
async shutdown() {
|
154
|
-
// Flush before shutdown
|
155
|
-
await this.flush();
|
156
|
-
// Shutdown other callbacks
|
157
|
-
const callbacks = await this.getCallbacks();
|
158
|
-
for (const callback of callbacks) {
|
159
|
-
// Check if the callback has a shutdown method (like Langfuse)
|
160
|
-
if ('shutdownAsync' in callback && typeof callback.shutdownAsync === 'function') {
|
161
|
-
await callback.shutdownAsync();
|
162
|
-
}
|
163
|
-
else if ('shutdown' in callback && typeof callback.shutdown === 'function') {
|
164
|
-
await callback.shutdown();
|
165
|
-
}
|
166
|
-
}
|
167
|
-
logger.debug('ObservabilityManager: All handlers shutdown');
|
168
|
-
}
|
169
|
-
/**
|
170
|
-
* String representation of the ObservabilityManager.
|
171
|
-
*/
|
172
|
-
toString() {
|
173
|
-
const names = this.handlerNames;
|
174
|
-
if (names.length > 0) {
|
175
|
-
return `ObservabilityManager(handlers=${names.join(', ')})`;
|
176
|
-
}
|
177
|
-
return 'ObservabilityManager(no handlers)';
|
178
|
-
}
|
179
|
-
}
|
180
|
-
// Singleton instance for easy access
|
181
|
-
let defaultManager = null;
|
182
|
-
/**
|
183
|
-
* Get the default ObservabilityManager instance.
|
184
|
-
* @returns The default ObservabilityManager instance (singleton).
|
185
|
-
*/
|
186
|
-
export function getDefaultManager() {
|
187
|
-
if (!defaultManager) {
|
188
|
-
defaultManager = new ObservabilityManager();
|
189
|
-
}
|
190
|
-
return defaultManager;
|
191
|
-
}
|
192
|
-
/**
|
193
|
-
* Create a new ObservabilityManager instance.
|
194
|
-
* @param config Configuration options
|
195
|
-
* @returns A new ObservabilityManager instance.
|
196
|
-
*/
|
197
|
-
export function createManager(config = {}) {
|
198
|
-
return new ObservabilityManager(config);
|
199
|
-
}
|
package/dist/src/session.js
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
export class MCPSession {
|
2
|
-
connector;
|
3
|
-
autoConnect;
|
4
|
-
constructor(connector, autoConnect = true) {
|
5
|
-
this.connector = connector;
|
6
|
-
this.autoConnect = autoConnect;
|
7
|
-
}
|
8
|
-
async connect() {
|
9
|
-
await this.connector.connect();
|
10
|
-
}
|
11
|
-
async disconnect() {
|
12
|
-
await this.connector.disconnect();
|
13
|
-
}
|
14
|
-
async initialize() {
|
15
|
-
if (!this.isConnected && this.autoConnect) {
|
16
|
-
await this.connect();
|
17
|
-
}
|
18
|
-
await this.connector.initialize();
|
19
|
-
}
|
20
|
-
get isConnected() {
|
21
|
-
return this.connector && this.connector.isClientConnected;
|
22
|
-
}
|
23
|
-
}
|
@@ -1,127 +0,0 @@
|
|
1
|
-
import { logger } from '../logging.js';
|
2
|
-
export class ConnectionManager {
|
3
|
-
_readyPromise;
|
4
|
-
_readyResolver;
|
5
|
-
_donePromise;
|
6
|
-
_doneResolver;
|
7
|
-
_exception = null;
|
8
|
-
_connection = null;
|
9
|
-
_task = null;
|
10
|
-
_abortController = null;
|
11
|
-
constructor() {
|
12
|
-
this.reset();
|
13
|
-
}
|
14
|
-
/**
|
15
|
-
* Start the connection manager and establish a connection.
|
16
|
-
*
|
17
|
-
* @returns The established connection.
|
18
|
-
* @throws If the connection cannot be established.
|
19
|
-
*/
|
20
|
-
async start() {
|
21
|
-
// Reset internal state before starting
|
22
|
-
this.reset();
|
23
|
-
logger.debug(`Starting ${this.constructor.name}`);
|
24
|
-
// Kick off the background task that manages the connection
|
25
|
-
this._task = this.connectionTask();
|
26
|
-
// Wait until the connection is ready or an error occurs
|
27
|
-
await this._readyPromise;
|
28
|
-
// If an exception occurred during startup, re‑throw it
|
29
|
-
if (this._exception) {
|
30
|
-
throw this._exception;
|
31
|
-
}
|
32
|
-
if (this._connection === null) {
|
33
|
-
throw new Error('Connection was not established');
|
34
|
-
}
|
35
|
-
return this._connection;
|
36
|
-
}
|
37
|
-
/**
|
38
|
-
* Stop the connection manager and close the connection.
|
39
|
-
*/
|
40
|
-
async stop() {
|
41
|
-
if (this._task && this._abortController) {
|
42
|
-
logger.debug(`Cancelling ${this.constructor.name} task`);
|
43
|
-
this._abortController.abort();
|
44
|
-
try {
|
45
|
-
await this._task;
|
46
|
-
}
|
47
|
-
catch (e) {
|
48
|
-
if (e instanceof Error && e.name === 'AbortError') {
|
49
|
-
logger.debug(`${this.constructor.name} task aborted successfully`);
|
50
|
-
}
|
51
|
-
else {
|
52
|
-
logger.warn(`Error stopping ${this.constructor.name} task: ${e}`);
|
53
|
-
}
|
54
|
-
}
|
55
|
-
}
|
56
|
-
// Wait until the connection cleanup has completed
|
57
|
-
await this._donePromise;
|
58
|
-
logger.debug(`${this.constructor.name} task completed`);
|
59
|
-
}
|
60
|
-
/**
|
61
|
-
* Reset all internal state.
|
62
|
-
*/
|
63
|
-
reset() {
|
64
|
-
this._readyPromise = new Promise(res => (this._readyResolver = res));
|
65
|
-
this._donePromise = new Promise(res => (this._doneResolver = res));
|
66
|
-
this._exception = null;
|
67
|
-
this._connection = null;
|
68
|
-
this._task = null;
|
69
|
-
this._abortController = new AbortController();
|
70
|
-
}
|
71
|
-
/**
|
72
|
-
* The background task responsible for establishing and maintaining the
|
73
|
-
* connection until it is cancelled.
|
74
|
-
*/
|
75
|
-
async connectionTask() {
|
76
|
-
logger.debug(`Running ${this.constructor.name} task`);
|
77
|
-
try {
|
78
|
-
// Establish the connection
|
79
|
-
this._connection = await this.establishConnection();
|
80
|
-
logger.debug(`${this.constructor.name} connected successfully`);
|
81
|
-
// Signal that the connection is ready
|
82
|
-
this._readyResolver();
|
83
|
-
// Keep the task alive until it is cancelled
|
84
|
-
await this.waitForAbort();
|
85
|
-
}
|
86
|
-
catch (err) {
|
87
|
-
this._exception = err;
|
88
|
-
logger.error(`Error in ${this.constructor.name} task: ${err}`);
|
89
|
-
// Ensure the ready promise resolves so that start() can handle the error
|
90
|
-
this._readyResolver();
|
91
|
-
}
|
92
|
-
finally {
|
93
|
-
// Clean up the connection if it was established
|
94
|
-
if (this._connection !== null) {
|
95
|
-
try {
|
96
|
-
await this.closeConnection(this._connection);
|
97
|
-
}
|
98
|
-
catch (closeErr) {
|
99
|
-
logger.warn(`Error closing connection in ${this.constructor.name}: ${closeErr}`);
|
100
|
-
}
|
101
|
-
this._connection = null;
|
102
|
-
}
|
103
|
-
// Signal that cleanup is finished
|
104
|
-
this._doneResolver();
|
105
|
-
}
|
106
|
-
}
|
107
|
-
/**
|
108
|
-
* Helper that returns a promise which resolves when the abort signal fires.
|
109
|
-
*/
|
110
|
-
async waitForAbort() {
|
111
|
-
return new Promise((_resolve, _reject) => {
|
112
|
-
if (!this._abortController) {
|
113
|
-
return;
|
114
|
-
}
|
115
|
-
const signal = this._abortController.signal;
|
116
|
-
if (signal.aborted) {
|
117
|
-
_resolve();
|
118
|
-
return;
|
119
|
-
}
|
120
|
-
const onAbort = () => {
|
121
|
-
signal.removeEventListener('abort', onAbort);
|
122
|
-
_resolve();
|
123
|
-
};
|
124
|
-
signal.addEventListener('abort', onAbort);
|
125
|
-
});
|
126
|
-
}
|
127
|
-
}
|
@@ -1,5 +0,0 @@
|
|
1
|
-
export { ConnectionManager } from './base.js';
|
2
|
-
export { SseConnectionManager } from './sse.js';
|
3
|
-
export { StdioConnectionManager } from './stdio.js';
|
4
|
-
export { StreamableHttpConnectionManager } from './streamable_http.js';
|
5
|
-
export { WebSocketConnectionManager } from './websocket.js';
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
2
|
-
import { logger } from '../logging.js';
|
3
|
-
import { ConnectionManager } from './base.js';
|
4
|
-
export class SseConnectionManager extends ConnectionManager {
|
5
|
-
url;
|
6
|
-
opts;
|
7
|
-
_transport = null;
|
8
|
-
/**
|
9
|
-
* Create an SSE connection manager.
|
10
|
-
*
|
11
|
-
* @param url The SSE endpoint URL.
|
12
|
-
* @param opts Optional transport options (auth, headers, etc.).
|
13
|
-
*/
|
14
|
-
constructor(url, opts) {
|
15
|
-
super();
|
16
|
-
this.url = typeof url === 'string' ? new URL(url) : url;
|
17
|
-
this.opts = opts;
|
18
|
-
}
|
19
|
-
/**
|
20
|
-
* Spawn a new `SSEClientTransport` and start the connection.
|
21
|
-
*/
|
22
|
-
async establishConnection() {
|
23
|
-
this._transport = new SSEClientTransport(this.url, this.opts);
|
24
|
-
logger.debug(`${this.constructor.name} connected successfully`);
|
25
|
-
return this._transport;
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* Close the underlying transport and clean up resources.
|
29
|
-
*/
|
30
|
-
async closeConnection(_connection) {
|
31
|
-
if (this._transport) {
|
32
|
-
try {
|
33
|
-
await this._transport.close();
|
34
|
-
}
|
35
|
-
catch (e) {
|
36
|
-
logger.warn(`Error closing SSE transport: ${e}`);
|
37
|
-
}
|
38
|
-
finally {
|
39
|
-
this._transport = null;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
2
|
-
import { logger } from '../logging.js';
|
3
|
-
import { ConnectionManager } from './base.js';
|
4
|
-
export class StdioConnectionManager extends ConnectionManager {
|
5
|
-
serverParams;
|
6
|
-
errlog;
|
7
|
-
_transport = null;
|
8
|
-
/**
|
9
|
-
* Create a new stdio connection manager.
|
10
|
-
*
|
11
|
-
* @param serverParams Parameters for the stdio server process.
|
12
|
-
* @param errlog Stream to which the server's stderr should be piped.
|
13
|
-
* Defaults to `process.stderr`.
|
14
|
-
*/
|
15
|
-
constructor(serverParams, errlog = process.stderr) {
|
16
|
-
super();
|
17
|
-
this.serverParams = serverParams;
|
18
|
-
this.errlog = errlog;
|
19
|
-
}
|
20
|
-
/**
|
21
|
-
* Establish the stdio connection by spawning the server process and starting
|
22
|
-
* the SDK's transport. Returns the live `StdioClientTransport` instance.
|
23
|
-
*/
|
24
|
-
async establishConnection() {
|
25
|
-
// Instantiate and start the transport
|
26
|
-
this._transport = new StdioClientTransport(this.serverParams);
|
27
|
-
// If stderr was piped, forward it to `errlog` for visibility
|
28
|
-
if (this._transport.stderr && typeof this._transport.stderr.pipe === 'function') {
|
29
|
-
this._transport.stderr.pipe(this.errlog);
|
30
|
-
}
|
31
|
-
logger.debug(`${this.constructor.name} connected successfully`);
|
32
|
-
return this._transport;
|
33
|
-
}
|
34
|
-
/**
|
35
|
-
* Close the stdio connection, making sure the transport cleans up the child
|
36
|
-
* process and associated resources.
|
37
|
-
*/
|
38
|
-
async closeConnection(_connection) {
|
39
|
-
if (this._transport) {
|
40
|
-
try {
|
41
|
-
await this._transport.close();
|
42
|
-
}
|
43
|
-
catch (e) {
|
44
|
-
logger.warn(`Error closing stdio transport: ${e}`);
|
45
|
-
}
|
46
|
-
finally {
|
47
|
-
this._transport = null;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}
|
@@ -1,50 +0,0 @@
|
|
1
|
-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
2
|
-
import { logger } from '../logging.js';
|
3
|
-
import { ConnectionManager } from './base.js';
|
4
|
-
export class StreamableHttpConnectionManager extends ConnectionManager {
|
5
|
-
url;
|
6
|
-
opts;
|
7
|
-
_transport = null;
|
8
|
-
/**
|
9
|
-
* Create a Streamable HTTP connection manager.
|
10
|
-
*
|
11
|
-
* @param url The HTTP endpoint URL.
|
12
|
-
* @param opts Optional transport options (auth, headers, etc.).
|
13
|
-
*/
|
14
|
-
constructor(url, opts) {
|
15
|
-
super();
|
16
|
-
this.url = typeof url === 'string' ? new URL(url) : url;
|
17
|
-
this.opts = opts;
|
18
|
-
}
|
19
|
-
/**
|
20
|
-
* Spawn a new `StreamableHTTPClientTransport` and return it.
|
21
|
-
* The Client.connect() method will handle starting the transport.
|
22
|
-
*/
|
23
|
-
async establishConnection() {
|
24
|
-
this._transport = new StreamableHTTPClientTransport(this.url, this.opts);
|
25
|
-
logger.debug(`${this.constructor.name} created successfully`);
|
26
|
-
return this._transport;
|
27
|
-
}
|
28
|
-
/**
|
29
|
-
* Close the underlying transport and clean up resources.
|
30
|
-
*/
|
31
|
-
async closeConnection(_connection) {
|
32
|
-
if (this._transport) {
|
33
|
-
try {
|
34
|
-
await this._transport.close();
|
35
|
-
}
|
36
|
-
catch (e) {
|
37
|
-
logger.warn(`Error closing Streamable HTTP transport: ${e}`);
|
38
|
-
}
|
39
|
-
finally {
|
40
|
-
this._transport = null;
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
/**
|
45
|
-
* Get the session ID from the transport if available.
|
46
|
-
*/
|
47
|
-
get sessionId() {
|
48
|
-
return this._transport?.sessionId;
|
49
|
-
}
|
50
|
-
}
|
@@ -1,67 +0,0 @@
|
|
1
|
-
import WS from 'ws';
|
2
|
-
import { logger } from '../logging.js';
|
3
|
-
import { ConnectionManager } from './base.js';
|
4
|
-
export class WebSocketConnectionManager extends ConnectionManager {
|
5
|
-
url;
|
6
|
-
headers;
|
7
|
-
_ws = null;
|
8
|
-
/**
|
9
|
-
* @param url The WebSocket URL to connect to.
|
10
|
-
* @param headers Optional headers to include in the connection handshake.
|
11
|
-
*/
|
12
|
-
constructor(url, headers = {}) {
|
13
|
-
super();
|
14
|
-
this.url = url;
|
15
|
-
this.headers = headers;
|
16
|
-
}
|
17
|
-
/** Establish a WebSocket connection and wait until it is open. */
|
18
|
-
async establishConnection() {
|
19
|
-
logger.debug(`Connecting to WebSocket: ${this.url}`);
|
20
|
-
return new Promise((resolve, reject) => {
|
21
|
-
const ws = new WS(this.url, { headers: this.headers });
|
22
|
-
this._ws = ws;
|
23
|
-
const onOpen = () => {
|
24
|
-
// eslint-disable-next-line ts/no-use-before-define
|
25
|
-
cleanup();
|
26
|
-
logger.debug('WebSocket connected successfully');
|
27
|
-
resolve(ws);
|
28
|
-
};
|
29
|
-
const onError = (err) => {
|
30
|
-
// eslint-disable-next-line ts/no-use-before-define
|
31
|
-
cleanup();
|
32
|
-
logger.error(`Failed to connect to WebSocket: ${err}`);
|
33
|
-
reject(err);
|
34
|
-
};
|
35
|
-
const cleanup = () => {
|
36
|
-
ws.off('open', onOpen);
|
37
|
-
ws.off('error', onError);
|
38
|
-
};
|
39
|
-
// Register listeners (browser vs Node API differences handled)
|
40
|
-
ws.on('open', onOpen);
|
41
|
-
ws.on('error', onError);
|
42
|
-
});
|
43
|
-
}
|
44
|
-
/** Cleanly close the WebSocket connection. */
|
45
|
-
async closeConnection(connection) {
|
46
|
-
logger.debug('Closing WebSocket connection');
|
47
|
-
return new Promise((resolve) => {
|
48
|
-
const onClose = () => {
|
49
|
-
connection.off('close', onClose);
|
50
|
-
this._ws = null;
|
51
|
-
resolve();
|
52
|
-
};
|
53
|
-
if (connection.readyState === WS.CLOSED) {
|
54
|
-
onClose();
|
55
|
-
return;
|
56
|
-
}
|
57
|
-
connection.on('close', onClose);
|
58
|
-
try {
|
59
|
-
connection.close();
|
60
|
-
}
|
61
|
-
catch (e) {
|
62
|
-
logger.warn(`Error closing WebSocket connection: ${e}`);
|
63
|
-
onClose();
|
64
|
-
}
|
65
|
-
});
|
66
|
-
}
|
67
|
-
}
|
@@ -1,44 +0,0 @@
|
|
1
|
-
export class BaseTelemetryEvent {
|
2
|
-
}
|
3
|
-
export class MCPAgentExecutionEvent extends BaseTelemetryEvent {
|
4
|
-
data;
|
5
|
-
constructor(data) {
|
6
|
-
super();
|
7
|
-
this.data = data;
|
8
|
-
}
|
9
|
-
get name() {
|
10
|
-
return 'mcp_agent_execution';
|
11
|
-
}
|
12
|
-
get properties() {
|
13
|
-
return {
|
14
|
-
// Core execution info
|
15
|
-
execution_method: this.data.executionMethod,
|
16
|
-
query: this.data.query,
|
17
|
-
query_length: this.data.query.length,
|
18
|
-
success: this.data.success,
|
19
|
-
// Agent configuration
|
20
|
-
model_provider: this.data.modelProvider,
|
21
|
-
model_name: this.data.modelName,
|
22
|
-
server_count: this.data.serverCount,
|
23
|
-
server_identifiers: this.data.serverIdentifiers,
|
24
|
-
total_tools_available: this.data.totalToolsAvailable,
|
25
|
-
tools_available_names: this.data.toolsAvailableNames,
|
26
|
-
max_steps_configured: this.data.maxStepsConfigured,
|
27
|
-
memory_enabled: this.data.memoryEnabled,
|
28
|
-
use_server_manager: this.data.useServerManager,
|
29
|
-
// Execution parameters (always include, even if null)
|
30
|
-
max_steps_used: this.data.maxStepsUsed,
|
31
|
-
manage_connector: this.data.manageConnector,
|
32
|
-
external_history_used: this.data.externalHistoryUsed,
|
33
|
-
// Execution results (always include, even if null)
|
34
|
-
steps_taken: this.data.stepsTaken ?? null,
|
35
|
-
tools_used_count: this.data.toolsUsedCount ?? null,
|
36
|
-
tools_used_names: this.data.toolsUsedNames ?? null,
|
37
|
-
response: this.data.response ?? null,
|
38
|
-
response_length: this.data.response ? this.data.response.length : null,
|
39
|
-
execution_time_ms: this.data.executionTimeMs ?? null,
|
40
|
-
error_type: this.data.errorType ?? null,
|
41
|
-
conversation_history_length: this.data.conversationHistoryLength ?? null,
|
42
|
-
};
|
43
|
-
}
|
44
|
-
}
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import { Telemetry } from './telemetry.js';
|
2
|
-
export { BaseTelemetryEvent, MCPAgentExecutionEvent } from './events.js';
|
3
|
-
export { Telemetry } from './telemetry.js';
|
4
|
-
export { extractModelInfo, getModelName, getModelProvider, getPackageVersion } from './utils.js';
|
5
|
-
// Convenience function to set telemetry source globally
|
6
|
-
export function setTelemetrySource(source) {
|
7
|
-
Telemetry.getInstance().setSource(source);
|
8
|
-
}
|