@genkit-ai/mcp 1.14.1-rc.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/LICENSE +203 -0
- package/README.md +205 -0
- package/examples/client/index.js +36 -0
- package/examples/client/package.json +25 -0
- package/examples/server/index.js +46 -0
- package/examples/server/package.json +18 -0
- package/examples/server/prompts/port_code.prompt +13 -0
- package/lib/client/client.d.mts +177 -0
- package/lib/client/client.d.ts +177 -0
- package/lib/client/client.js +282 -0
- package/lib/client/client.js.map +1 -0
- package/lib/client/client.mjs +267 -0
- package/lib/client/client.mjs.map +1 -0
- package/lib/client/host.d.mts +202 -0
- package/lib/client/host.d.ts +202 -0
- package/lib/client/host.js +392 -0
- package/lib/client/host.js.map +1 -0
- package/lib/client/host.mjs +368 -0
- package/lib/client/host.mjs.map +1 -0
- package/lib/client/index.d.mts +9 -0
- package/lib/client/index.d.ts +9 -0
- package/lib/client/index.js +32 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/index.mjs +7 -0
- package/lib/client/index.mjs.map +1 -0
- package/lib/index.d.mts +12 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +48 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +22 -0
- package/lib/index.mjs.map +1 -0
- package/lib/server.d.mts +188 -0
- package/lib/server.d.ts +188 -0
- package/lib/server.js +280 -0
- package/lib/server.js.map +1 -0
- package/lib/server.mjs +249 -0
- package/lib/server.mjs.map +1 -0
- package/lib/util/index.d.mts +11 -0
- package/lib/util/index.d.ts +11 -0
- package/lib/util/index.js +29 -0
- package/lib/util/index.js.map +1 -0
- package/lib/util/index.mjs +5 -0
- package/lib/util/index.mjs.map +1 -0
- package/lib/util/message.d.mts +43 -0
- package/lib/util/message.d.ts +43 -0
- package/lib/util/message.js +61 -0
- package/lib/util/message.js.map +1 -0
- package/lib/util/message.mjs +36 -0
- package/lib/util/message.mjs.map +1 -0
- package/lib/util/prompts.d.mts +45 -0
- package/lib/util/prompts.d.ts +45 -0
- package/lib/util/prompts.js +147 -0
- package/lib/util/prompts.js.map +1 -0
- package/lib/util/prompts.mjs +123 -0
- package/lib/util/prompts.mjs.map +1 -0
- package/lib/util/resource.d.mts +28 -0
- package/lib/util/resource.d.ts +28 -0
- package/lib/util/resource.js +116 -0
- package/lib/util/resource.js.map +1 -0
- package/lib/util/resource.mjs +95 -0
- package/lib/util/resource.mjs.map +1 -0
- package/lib/util/tools.d.mts +37 -0
- package/lib/util/tools.d.ts +37 -0
- package/lib/util/tools.js +120 -0
- package/lib/util/tools.js.map +1 -0
- package/lib/util/tools.mjs +95 -0
- package/lib/util/tools.mjs.map +1 -0
- package/lib/util/transport.d.mts +39 -0
- package/lib/util/transport.d.ts +39 -0
- package/lib/util/transport.js +63 -0
- package/lib/util/transport.js.map +1 -0
- package/lib/util/transport.mjs +29 -0
- package/lib/util/transport.mjs.map +1 -0
- package/package.json +57 -0
- package/src/client/client.ts +414 -0
- package/src/client/host.ts +485 -0
- package/src/client/index.ts +29 -0
- package/src/index.ts +114 -0
- package/src/server.ts +330 -0
- package/src/util/index.ts +20 -0
- package/src/util/message.ts +72 -0
- package/src/util/prompts.ts +223 -0
- package/src/util/resource.ts +141 -0
- package/src/util/tools.ts +164 -0
- package/src/util/transport.ts +67 -0
- package/tests/fakes.ts +221 -0
- package/tests/host_test.ts +609 -0
- package/tests/server_test.ts +165 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
+
import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
3
|
+
import { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
4
|
+
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
5
|
+
import { Root } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
import { Genkit, ToolAction, DynamicResourceAction, PromptGenerateOptions, ExecutablePrompt } from 'genkit';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Copyright 2025 Google LLC
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
interface McpServerRef {
|
|
25
|
+
client: Client;
|
|
26
|
+
transport: Transport;
|
|
27
|
+
error?: string;
|
|
28
|
+
}
|
|
29
|
+
interface McpServerControls {
|
|
30
|
+
/** when true, the server will be stopped and its registered components will
|
|
31
|
+
* not appear in lists/plugins/etc */
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
roots?: Root[];
|
|
34
|
+
}
|
|
35
|
+
type McpStdioServerConfig = StdioServerParameters & {
|
|
36
|
+
url?: never;
|
|
37
|
+
transport?: never;
|
|
38
|
+
};
|
|
39
|
+
type McpStreamableHttpConfig = {
|
|
40
|
+
url: string;
|
|
41
|
+
command?: never;
|
|
42
|
+
transport?: never;
|
|
43
|
+
} & Omit<StreamableHTTPClientTransportOptions, 'sessionId'>;
|
|
44
|
+
type McpTransportServerConfig = {
|
|
45
|
+
transport: Transport;
|
|
46
|
+
command?: never;
|
|
47
|
+
url?: never;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Configuration for an individual MCP server. The interface should be familiar
|
|
51
|
+
* and compatible with existing tool configurations e.g. Cursor or Claude
|
|
52
|
+
* Desktop.
|
|
53
|
+
*
|
|
54
|
+
* In addition to stdio servers, remote servers are supported via URL and
|
|
55
|
+
* custom/arbitary transports are supported as well.
|
|
56
|
+
*/
|
|
57
|
+
type McpServerConfig = (McpStdioServerConfig | McpStreamableHttpConfig | McpTransportServerConfig) & McpServerControls;
|
|
58
|
+
/**
|
|
59
|
+
* Configuration options for an individual `GenkitMcpClient` instance.
|
|
60
|
+
* This defines how the client connects to a single MCP server and how it behaves.
|
|
61
|
+
*/
|
|
62
|
+
type McpClientOptions = {
|
|
63
|
+
/** Client name to advertise to the server. */
|
|
64
|
+
name: string;
|
|
65
|
+
/** Name for the server, defaults to the server's advertised name. */
|
|
66
|
+
serverName?: string;
|
|
67
|
+
/**
|
|
68
|
+
* An optional version number for this client. This is primarily for logging
|
|
69
|
+
* and identification purposes. Defaults to '1.0.0'.
|
|
70
|
+
*/
|
|
71
|
+
version?: string;
|
|
72
|
+
/**
|
|
73
|
+
* If true, tool responses from the MCP server will be returned in their raw
|
|
74
|
+
* MCP format. Otherwise (default), they are processed and potentially
|
|
75
|
+
* simplified for better compatibility with Genkit's typical data structures.
|
|
76
|
+
*/
|
|
77
|
+
rawToolResponses?: boolean;
|
|
78
|
+
/** The server configuration to connect. */
|
|
79
|
+
mcpServer: McpServerConfig;
|
|
80
|
+
/** Manually supply a session id for HTTP streaming clients if desired. */
|
|
81
|
+
sessionId?: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Represents a client connection to a single MCP (Model Context Protocol) server.
|
|
85
|
+
* It handles the lifecycle of the connection (connect, disconnect, disable, re-enable, reconnect)
|
|
86
|
+
* and provides methods to fetch tools from the connected server.
|
|
87
|
+
*
|
|
88
|
+
* An instance of `GenkitMcpClient` is typically managed by a `GenkitMcpHost`
|
|
89
|
+
* when dealing with multiple MCP server connections.
|
|
90
|
+
*/
|
|
91
|
+
declare class GenkitMcpClient {
|
|
92
|
+
_server?: McpServerRef;
|
|
93
|
+
sessionId?: string;
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly suppliedServerName?: string;
|
|
96
|
+
private version;
|
|
97
|
+
private serverConfig;
|
|
98
|
+
private rawToolResponses?;
|
|
99
|
+
private disabled;
|
|
100
|
+
private roots?;
|
|
101
|
+
private _readyListeners;
|
|
102
|
+
private _ready;
|
|
103
|
+
constructor(options: McpClientOptions);
|
|
104
|
+
get serverName(): string;
|
|
105
|
+
updateRoots(roots: Root[]): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Sets up a connection based on a provided map of server configurations.
|
|
108
|
+
* - Reconnects existing servers if their configuration appears to have
|
|
109
|
+
* changed (implicitly handled by `connectServer`).
|
|
110
|
+
* - Sets the client's ready state once all connection attempts are complete.
|
|
111
|
+
* @param mcpServers A record mapping server names to their configurations.
|
|
112
|
+
*/
|
|
113
|
+
private _initializeConnection;
|
|
114
|
+
/**
|
|
115
|
+
* Returns a Promise that resolves when the client has attempted to connect
|
|
116
|
+
* to all configured servers, or rejects if a critical error occurs during
|
|
117
|
+
* the initial connection phase.
|
|
118
|
+
*/
|
|
119
|
+
ready(): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Connects to a single MCP server defined by the provided configuration.
|
|
122
|
+
* @param config The configuration object for the server.
|
|
123
|
+
*/
|
|
124
|
+
private _connect;
|
|
125
|
+
/**
|
|
126
|
+
* Disconnects the MCP server and removes its registration
|
|
127
|
+
* from this client instance.
|
|
128
|
+
*/
|
|
129
|
+
_disconnect(): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Disables a server. Closes the underlying transport and server's configuration. Does nothing if the server is
|
|
132
|
+
* already disabled.
|
|
133
|
+
*/
|
|
134
|
+
disable(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Whether this client-server connection is enabled or not.
|
|
137
|
+
*/
|
|
138
|
+
isEnabled(): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Enables a server connection, including previously disabled ones. Does nothing if the
|
|
141
|
+
* server is not disabled.
|
|
142
|
+
*/
|
|
143
|
+
enable(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Closes and then restarts the transport connection for the specified server.
|
|
146
|
+
* Useful for attempting to recover from connection issues without full
|
|
147
|
+
* reconfiguration.
|
|
148
|
+
*/
|
|
149
|
+
restart(): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Fetches all tools available through this client, if the server
|
|
152
|
+
* configuration is not disabled.
|
|
153
|
+
*/
|
|
154
|
+
getActiveTools(ai: Genkit): Promise<ToolAction[]>;
|
|
155
|
+
/**
|
|
156
|
+
* Fetches all resources available through this client, if the server
|
|
157
|
+
* configuration is not disabled.
|
|
158
|
+
*/
|
|
159
|
+
getActiveResources(ai: Genkit): Promise<DynamicResourceAction[]>;
|
|
160
|
+
/**
|
|
161
|
+
* Fetches all active prompts available through this client, if the server
|
|
162
|
+
* configuration supports prompts.
|
|
163
|
+
* @param ai The Genkit instance.
|
|
164
|
+
* @param options Optional prompt generation options.
|
|
165
|
+
* @returns A promise that resolves to an array of ExecutablePrompt.
|
|
166
|
+
*/
|
|
167
|
+
getActivePrompts(ai: Genkit, options?: PromptGenerateOptions): Promise<ExecutablePrompt[]>;
|
|
168
|
+
/**
|
|
169
|
+
* Get the specified prompt as an `ExecutablePrompt` available through this
|
|
170
|
+
* client. If no such prompt is found, return undefined.
|
|
171
|
+
*/
|
|
172
|
+
getPrompt(ai: Genkit, promptName: string, opts?: PromptGenerateOptions): Promise<ExecutablePrompt | undefined>;
|
|
173
|
+
/** Returns the underlying MCP SDK client if one has been initialized. */
|
|
174
|
+
get mcpClient(): Client | undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export { GenkitMcpClient, type McpClientOptions, type McpServerConfig, type McpServerControls, type McpStdioServerConfig, type McpStreamableHttpConfig, type McpTransportServerConfig };
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
+
import { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
3
|
+
import { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
4
|
+
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
5
|
+
import { Root } from '@modelcontextprotocol/sdk/types.js';
|
|
6
|
+
import { Genkit, ToolAction, DynamicResourceAction, PromptGenerateOptions, ExecutablePrompt } from 'genkit';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Copyright 2025 Google LLC
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License.
|
|
13
|
+
* You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
interface McpServerRef {
|
|
25
|
+
client: Client;
|
|
26
|
+
transport: Transport;
|
|
27
|
+
error?: string;
|
|
28
|
+
}
|
|
29
|
+
interface McpServerControls {
|
|
30
|
+
/** when true, the server will be stopped and its registered components will
|
|
31
|
+
* not appear in lists/plugins/etc */
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
roots?: Root[];
|
|
34
|
+
}
|
|
35
|
+
type McpStdioServerConfig = StdioServerParameters & {
|
|
36
|
+
url?: never;
|
|
37
|
+
transport?: never;
|
|
38
|
+
};
|
|
39
|
+
type McpStreamableHttpConfig = {
|
|
40
|
+
url: string;
|
|
41
|
+
command?: never;
|
|
42
|
+
transport?: never;
|
|
43
|
+
} & Omit<StreamableHTTPClientTransportOptions, 'sessionId'>;
|
|
44
|
+
type McpTransportServerConfig = {
|
|
45
|
+
transport: Transport;
|
|
46
|
+
command?: never;
|
|
47
|
+
url?: never;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Configuration for an individual MCP server. The interface should be familiar
|
|
51
|
+
* and compatible with existing tool configurations e.g. Cursor or Claude
|
|
52
|
+
* Desktop.
|
|
53
|
+
*
|
|
54
|
+
* In addition to stdio servers, remote servers are supported via URL and
|
|
55
|
+
* custom/arbitary transports are supported as well.
|
|
56
|
+
*/
|
|
57
|
+
type McpServerConfig = (McpStdioServerConfig | McpStreamableHttpConfig | McpTransportServerConfig) & McpServerControls;
|
|
58
|
+
/**
|
|
59
|
+
* Configuration options for an individual `GenkitMcpClient` instance.
|
|
60
|
+
* This defines how the client connects to a single MCP server and how it behaves.
|
|
61
|
+
*/
|
|
62
|
+
type McpClientOptions = {
|
|
63
|
+
/** Client name to advertise to the server. */
|
|
64
|
+
name: string;
|
|
65
|
+
/** Name for the server, defaults to the server's advertised name. */
|
|
66
|
+
serverName?: string;
|
|
67
|
+
/**
|
|
68
|
+
* An optional version number for this client. This is primarily for logging
|
|
69
|
+
* and identification purposes. Defaults to '1.0.0'.
|
|
70
|
+
*/
|
|
71
|
+
version?: string;
|
|
72
|
+
/**
|
|
73
|
+
* If true, tool responses from the MCP server will be returned in their raw
|
|
74
|
+
* MCP format. Otherwise (default), they are processed and potentially
|
|
75
|
+
* simplified for better compatibility with Genkit's typical data structures.
|
|
76
|
+
*/
|
|
77
|
+
rawToolResponses?: boolean;
|
|
78
|
+
/** The server configuration to connect. */
|
|
79
|
+
mcpServer: McpServerConfig;
|
|
80
|
+
/** Manually supply a session id for HTTP streaming clients if desired. */
|
|
81
|
+
sessionId?: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Represents a client connection to a single MCP (Model Context Protocol) server.
|
|
85
|
+
* It handles the lifecycle of the connection (connect, disconnect, disable, re-enable, reconnect)
|
|
86
|
+
* and provides methods to fetch tools from the connected server.
|
|
87
|
+
*
|
|
88
|
+
* An instance of `GenkitMcpClient` is typically managed by a `GenkitMcpHost`
|
|
89
|
+
* when dealing with multiple MCP server connections.
|
|
90
|
+
*/
|
|
91
|
+
declare class GenkitMcpClient {
|
|
92
|
+
_server?: McpServerRef;
|
|
93
|
+
sessionId?: string;
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly suppliedServerName?: string;
|
|
96
|
+
private version;
|
|
97
|
+
private serverConfig;
|
|
98
|
+
private rawToolResponses?;
|
|
99
|
+
private disabled;
|
|
100
|
+
private roots?;
|
|
101
|
+
private _readyListeners;
|
|
102
|
+
private _ready;
|
|
103
|
+
constructor(options: McpClientOptions);
|
|
104
|
+
get serverName(): string;
|
|
105
|
+
updateRoots(roots: Root[]): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Sets up a connection based on a provided map of server configurations.
|
|
108
|
+
* - Reconnects existing servers if their configuration appears to have
|
|
109
|
+
* changed (implicitly handled by `connectServer`).
|
|
110
|
+
* - Sets the client's ready state once all connection attempts are complete.
|
|
111
|
+
* @param mcpServers A record mapping server names to their configurations.
|
|
112
|
+
*/
|
|
113
|
+
private _initializeConnection;
|
|
114
|
+
/**
|
|
115
|
+
* Returns a Promise that resolves when the client has attempted to connect
|
|
116
|
+
* to all configured servers, or rejects if a critical error occurs during
|
|
117
|
+
* the initial connection phase.
|
|
118
|
+
*/
|
|
119
|
+
ready(): Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Connects to a single MCP server defined by the provided configuration.
|
|
122
|
+
* @param config The configuration object for the server.
|
|
123
|
+
*/
|
|
124
|
+
private _connect;
|
|
125
|
+
/**
|
|
126
|
+
* Disconnects the MCP server and removes its registration
|
|
127
|
+
* from this client instance.
|
|
128
|
+
*/
|
|
129
|
+
_disconnect(): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Disables a server. Closes the underlying transport and server's configuration. Does nothing if the server is
|
|
132
|
+
* already disabled.
|
|
133
|
+
*/
|
|
134
|
+
disable(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Whether this client-server connection is enabled or not.
|
|
137
|
+
*/
|
|
138
|
+
isEnabled(): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Enables a server connection, including previously disabled ones. Does nothing if the
|
|
141
|
+
* server is not disabled.
|
|
142
|
+
*/
|
|
143
|
+
enable(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Closes and then restarts the transport connection for the specified server.
|
|
146
|
+
* Useful for attempting to recover from connection issues without full
|
|
147
|
+
* reconfiguration.
|
|
148
|
+
*/
|
|
149
|
+
restart(): Promise<void>;
|
|
150
|
+
/**
|
|
151
|
+
* Fetches all tools available through this client, if the server
|
|
152
|
+
* configuration is not disabled.
|
|
153
|
+
*/
|
|
154
|
+
getActiveTools(ai: Genkit): Promise<ToolAction[]>;
|
|
155
|
+
/**
|
|
156
|
+
* Fetches all resources available through this client, if the server
|
|
157
|
+
* configuration is not disabled.
|
|
158
|
+
*/
|
|
159
|
+
getActiveResources(ai: Genkit): Promise<DynamicResourceAction[]>;
|
|
160
|
+
/**
|
|
161
|
+
* Fetches all active prompts available through this client, if the server
|
|
162
|
+
* configuration supports prompts.
|
|
163
|
+
* @param ai The Genkit instance.
|
|
164
|
+
* @param options Optional prompt generation options.
|
|
165
|
+
* @returns A promise that resolves to an array of ExecutablePrompt.
|
|
166
|
+
*/
|
|
167
|
+
getActivePrompts(ai: Genkit, options?: PromptGenerateOptions): Promise<ExecutablePrompt[]>;
|
|
168
|
+
/**
|
|
169
|
+
* Get the specified prompt as an `ExecutablePrompt` available through this
|
|
170
|
+
* client. If no such prompt is found, return undefined.
|
|
171
|
+
*/
|
|
172
|
+
getPrompt(ai: Genkit, promptName: string, opts?: PromptGenerateOptions): Promise<ExecutablePrompt | undefined>;
|
|
173
|
+
/** Returns the underlying MCP SDK client if one has been initialized. */
|
|
174
|
+
get mcpClient(): Client | undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export { GenkitMcpClient, type McpClientOptions, type McpServerConfig, type McpServerControls, type McpStdioServerConfig, type McpStreamableHttpConfig, type McpTransportServerConfig };
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var client_exports = {};
|
|
20
|
+
__export(client_exports, {
|
|
21
|
+
GenkitMcpClient: () => GenkitMcpClient
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(client_exports);
|
|
24
|
+
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
|
25
|
+
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
26
|
+
var import_genkit = require("genkit");
|
|
27
|
+
var import_logging = require("genkit/logging");
|
|
28
|
+
var import_util = require("../util");
|
|
29
|
+
var import_resource = require("../util/resource");
|
|
30
|
+
class GenkitMcpClient {
|
|
31
|
+
_server;
|
|
32
|
+
sessionId;
|
|
33
|
+
name;
|
|
34
|
+
suppliedServerName;
|
|
35
|
+
version;
|
|
36
|
+
serverConfig;
|
|
37
|
+
rawToolResponses;
|
|
38
|
+
disabled;
|
|
39
|
+
roots;
|
|
40
|
+
_readyListeners = [];
|
|
41
|
+
_ready = false;
|
|
42
|
+
constructor(options) {
|
|
43
|
+
this.name = options.name;
|
|
44
|
+
this.suppliedServerName = options.serverName;
|
|
45
|
+
this.version = options.version || "1.0.0";
|
|
46
|
+
this.serverConfig = options.mcpServer;
|
|
47
|
+
this.rawToolResponses = !!options.rawToolResponses;
|
|
48
|
+
this.disabled = !!options.mcpServer.disabled;
|
|
49
|
+
this.roots = options.mcpServer.roots;
|
|
50
|
+
this.sessionId = options.sessionId;
|
|
51
|
+
this._initializeConnection();
|
|
52
|
+
}
|
|
53
|
+
get serverName() {
|
|
54
|
+
return this.suppliedServerName ?? this._server?.client.getServerVersion()?.name ?? "unknown-server";
|
|
55
|
+
}
|
|
56
|
+
async updateRoots(roots) {
|
|
57
|
+
this.roots = roots;
|
|
58
|
+
await this._server?.client.sendRootsListChanged();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sets up a connection based on a provided map of server configurations.
|
|
62
|
+
* - Reconnects existing servers if their configuration appears to have
|
|
63
|
+
* changed (implicitly handled by `connectServer`).
|
|
64
|
+
* - Sets the client's ready state once all connection attempts are complete.
|
|
65
|
+
* @param mcpServers A record mapping server names to their configurations.
|
|
66
|
+
*/
|
|
67
|
+
async _initializeConnection() {
|
|
68
|
+
this._ready = false;
|
|
69
|
+
try {
|
|
70
|
+
await this._connect();
|
|
71
|
+
this._ready = true;
|
|
72
|
+
while (this._readyListeners.length) {
|
|
73
|
+
this._readyListeners.pop()?.resolve();
|
|
74
|
+
}
|
|
75
|
+
} catch (err) {
|
|
76
|
+
while (this._readyListeners.length) {
|
|
77
|
+
this._readyListeners.pop()?.reject(err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (this.roots) {
|
|
81
|
+
await this.updateRoots(this.roots);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Returns a Promise that resolves when the client has attempted to connect
|
|
86
|
+
* to all configured servers, or rejects if a critical error occurs during
|
|
87
|
+
* the initial connection phase.
|
|
88
|
+
*/
|
|
89
|
+
async ready() {
|
|
90
|
+
if (this._ready) return;
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
this._readyListeners.push({ resolve, reject });
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Connects to a single MCP server defined by the provided configuration.
|
|
97
|
+
* @param config The configuration object for the server.
|
|
98
|
+
*/
|
|
99
|
+
async _connect() {
|
|
100
|
+
if (this._server) await this._server.transport.close();
|
|
101
|
+
import_logging.logger.debug(
|
|
102
|
+
`[MCP Client] Connecting MCP server '${this.serverName}' in client '${this.name}'.`
|
|
103
|
+
);
|
|
104
|
+
const { transport, type: transportType } = await (0, import_util.transportFrom)(
|
|
105
|
+
this.serverConfig,
|
|
106
|
+
this.sessionId
|
|
107
|
+
);
|
|
108
|
+
if (!transport) {
|
|
109
|
+
throw new import_genkit.GenkitError({
|
|
110
|
+
status: "INVALID_ARGUMENT",
|
|
111
|
+
message: `[MCP Client] Could not determine valid transport config from supplied options.`
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
let error;
|
|
115
|
+
const client = new import_client.Client(
|
|
116
|
+
{ name: this.name, version: this.version },
|
|
117
|
+
{ capabilities: { roots: { listChanged: true } } }
|
|
118
|
+
);
|
|
119
|
+
client.setRequestHandler(import_types.ListRootsRequestSchema, () => {
|
|
120
|
+
import_logging.logger.debug(`[MCP Client] fetching roots for ${this.name}`);
|
|
121
|
+
return { roots: this.roots || [] };
|
|
122
|
+
});
|
|
123
|
+
try {
|
|
124
|
+
await client.connect(transport);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
import_logging.logger.warn(
|
|
127
|
+
`[MCP Client] Error connecting server via ${transportType} transport: ${e}`
|
|
128
|
+
);
|
|
129
|
+
this.disabled = true;
|
|
130
|
+
error = e.toString();
|
|
131
|
+
}
|
|
132
|
+
this._server = {
|
|
133
|
+
client,
|
|
134
|
+
transport,
|
|
135
|
+
error
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Disconnects the MCP server and removes its registration
|
|
140
|
+
* from this client instance.
|
|
141
|
+
*/
|
|
142
|
+
async _disconnect() {
|
|
143
|
+
if (this._server) {
|
|
144
|
+
import_logging.logger.debug(
|
|
145
|
+
`[MCP Client] Disconnecting MCP server in client '${this.name}'.`
|
|
146
|
+
);
|
|
147
|
+
await this._server.client.close();
|
|
148
|
+
this._server = void 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Disables a server. Closes the underlying transport and server's configuration. Does nothing if the server is
|
|
153
|
+
* already disabled.
|
|
154
|
+
*/
|
|
155
|
+
async disable() {
|
|
156
|
+
if (!this.isEnabled()) return;
|
|
157
|
+
if (this._server) {
|
|
158
|
+
import_logging.logger.debug(
|
|
159
|
+
`[MCP Client] Disabling MCP server in client '${this.name}'`
|
|
160
|
+
);
|
|
161
|
+
await this._disconnect();
|
|
162
|
+
this.disabled = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Whether this client-server connection is enabled or not.
|
|
167
|
+
*/
|
|
168
|
+
isEnabled() {
|
|
169
|
+
return !this.disabled;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Enables a server connection, including previously disabled ones. Does nothing if the
|
|
173
|
+
* server is not disabled.
|
|
174
|
+
*/
|
|
175
|
+
async enable() {
|
|
176
|
+
if (this.isEnabled()) return;
|
|
177
|
+
import_logging.logger.debug(`[MCP Client] Reenabling MCP server in client '${this.name}'`);
|
|
178
|
+
await this._initializeConnection();
|
|
179
|
+
this.disabled = !!this._server.error;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Closes and then restarts the transport connection for the specified server.
|
|
183
|
+
* Useful for attempting to recover from connection issues without full
|
|
184
|
+
* reconfiguration.
|
|
185
|
+
*/
|
|
186
|
+
async restart() {
|
|
187
|
+
if (this._server) {
|
|
188
|
+
import_logging.logger.debug(
|
|
189
|
+
`[MCP Client] Restarting connection to MCP server in client '${this.name}'`
|
|
190
|
+
);
|
|
191
|
+
await this._disconnect();
|
|
192
|
+
await this._initializeConnection();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Fetches all tools available through this client, if the server
|
|
197
|
+
* configuration is not disabled.
|
|
198
|
+
*/
|
|
199
|
+
async getActiveTools(ai) {
|
|
200
|
+
await this.ready();
|
|
201
|
+
let tools = [];
|
|
202
|
+
if (this._server) {
|
|
203
|
+
const capabilities = this._server.client.getServerCapabilities();
|
|
204
|
+
if (capabilities?.tools)
|
|
205
|
+
tools.push(
|
|
206
|
+
...await (0, import_util.fetchDynamicTools)(ai, this._server.client, {
|
|
207
|
+
rawToolResponses: this.rawToolResponses,
|
|
208
|
+
serverName: this.serverName,
|
|
209
|
+
name: this.name
|
|
210
|
+
})
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return tools;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Fetches all resources available through this client, if the server
|
|
217
|
+
* configuration is not disabled.
|
|
218
|
+
*/
|
|
219
|
+
async getActiveResources(ai) {
|
|
220
|
+
await this.ready();
|
|
221
|
+
let resources = [];
|
|
222
|
+
if (this._server) {
|
|
223
|
+
const capabilities = this._server.client.getServerCapabilities();
|
|
224
|
+
if (capabilities?.resources)
|
|
225
|
+
resources.push(
|
|
226
|
+
...await (0, import_resource.fetchDynamicResources)(ai, this._server.client, {
|
|
227
|
+
serverName: this.serverName,
|
|
228
|
+
name: this.name
|
|
229
|
+
})
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
return resources;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Fetches all active prompts available through this client, if the server
|
|
236
|
+
* configuration supports prompts.
|
|
237
|
+
* @param ai The Genkit instance.
|
|
238
|
+
* @param options Optional prompt generation options.
|
|
239
|
+
* @returns A promise that resolves to an array of ExecutablePrompt.
|
|
240
|
+
*/
|
|
241
|
+
async getActivePrompts(ai, options) {
|
|
242
|
+
if (this._server?.client.getServerCapabilities()?.prompts) {
|
|
243
|
+
return (0, import_util.fetchAllPrompts)(this._server.client, {
|
|
244
|
+
ai,
|
|
245
|
+
serverName: this.serverName,
|
|
246
|
+
name: this.name,
|
|
247
|
+
options
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Get the specified prompt as an `ExecutablePrompt` available through this
|
|
254
|
+
* client. If no such prompt is found, return undefined.
|
|
255
|
+
*/
|
|
256
|
+
async getPrompt(ai, promptName, opts) {
|
|
257
|
+
await this.ready();
|
|
258
|
+
if (this._server) {
|
|
259
|
+
const capabilities = await this._server.client.getServerCapabilities();
|
|
260
|
+
if (capabilities?.prompts) {
|
|
261
|
+
return await (0, import_util.getExecutablePrompt)(this._server.client, {
|
|
262
|
+
ai,
|
|
263
|
+
serverName: this.name,
|
|
264
|
+
promptName,
|
|
265
|
+
name: this.name,
|
|
266
|
+
options: opts
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
import_logging.logger.debug(`[MCP Client] No prompts are found in this MCP server.`);
|
|
270
|
+
}
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
/** Returns the underlying MCP SDK client if one has been initialized. */
|
|
274
|
+
get mcpClient() {
|
|
275
|
+
return this._server?.client;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
279
|
+
0 && (module.exports = {
|
|
280
|
+
GenkitMcpClient
|
|
281
|
+
});
|
|
282
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/client.ts"],"sourcesContent":["/**\n * Copyright 2025 Google LLC\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\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport type { StdioServerParameters } from '@modelcontextprotocol/sdk/client/stdio.js';\nimport type { StreamableHTTPClientTransportOptions } from '@modelcontextprotocol/sdk/client/streamableHttp.js';\nimport { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';\nimport {\n ListRootsRequestSchema,\n Root,\n} from '@modelcontextprotocol/sdk/types.js';\nimport {\n DynamicResourceAction,\n ExecutablePrompt,\n Genkit,\n GenkitError,\n PromptGenerateOptions,\n ToolAction,\n} from 'genkit';\nimport { logger } from 'genkit/logging';\nimport {\n fetchAllPrompts,\n fetchDynamicTools,\n getExecutablePrompt,\n transportFrom,\n} from '../util';\nimport { fetchDynamicResources } from '../util/resource';\n\ninterface McpServerRef {\n client: Client;\n transport: Transport;\n error?: string;\n}\n\nexport interface McpServerControls {\n /** when true, the server will be stopped and its registered components will\n * not appear in lists/plugins/etc */\n disabled?: boolean;\n\n // MCP roots configuration. See: https://modelcontextprotocol.io/docs/concepts/roots\n roots?: Root[];\n}\n\nexport type McpStdioServerConfig = StdioServerParameters & {\n url?: never;\n transport?: never;\n};\n\nexport type McpStreamableHttpConfig = {\n url: string;\n command?: never;\n transport?: never;\n} & Omit<StreamableHTTPClientTransportOptions, 'sessionId'>;\n\nexport type McpTransportServerConfig = {\n transport: Transport;\n command?: never;\n url?: never;\n};\n\n/**\n * Configuration for an individual MCP server. The interface should be familiar\n * and compatible with existing tool configurations e.g. Cursor or Claude\n * Desktop.\n *\n * In addition to stdio servers, remote servers are supported via URL and\n * custom/arbitary transports are supported as well.\n */\nexport type McpServerConfig = (\n | McpStdioServerConfig\n | McpStreamableHttpConfig\n | McpTransportServerConfig\n) &\n McpServerControls;\n\n/**\n * Configuration options for an individual `GenkitMcpClient` instance.\n * This defines how the client connects to a single MCP server and how it behaves.\n */\nexport type McpClientOptions = {\n /** Client name to advertise to the server. */\n name: string;\n /** Name for the server, defaults to the server's advertised name. */\n serverName?: string;\n\n /**\n * An optional version number for this client. This is primarily for logging\n * and identification purposes. Defaults to '1.0.0'.\n */\n version?: string;\n /**\n * If true, tool responses from the MCP server will be returned in their raw\n * MCP format. Otherwise (default), they are processed and potentially\n * simplified for better compatibility with Genkit's typical data structures.\n */\n rawToolResponses?: boolean;\n /** The server configuration to connect. */\n mcpServer: McpServerConfig;\n /** Manually supply a session id for HTTP streaming clients if desired. */\n sessionId?: string;\n};\n\n/**\n * Represents a client connection to a single MCP (Model Context Protocol) server.\n * It handles the lifecycle of the connection (connect, disconnect, disable, re-enable, reconnect)\n * and provides methods to fetch tools from the connected server.\n *\n * An instance of `GenkitMcpClient` is typically managed by a `GenkitMcpHost`\n * when dealing with multiple MCP server connections.\n */\nexport class GenkitMcpClient {\n _server?: McpServerRef;\n\n sessionId?: string;\n readonly name: string;\n readonly suppliedServerName?: string;\n private version: string;\n private serverConfig: McpServerConfig;\n private rawToolResponses?: boolean;\n private disabled: boolean;\n private roots?: Root[];\n\n private _readyListeners: {\n resolve: () => void;\n reject: (err: Error) => void;\n }[] = [];\n private _ready = false;\n\n constructor(options: McpClientOptions) {\n this.name = options.name;\n this.suppliedServerName = options.serverName;\n this.version = options.version || '1.0.0';\n this.serverConfig = options.mcpServer;\n this.rawToolResponses = !!options.rawToolResponses;\n this.disabled = !!options.mcpServer.disabled;\n this.roots = options.mcpServer.roots;\n this.sessionId = options.sessionId;\n\n this._initializeConnection();\n }\n\n get serverName(): string {\n return (\n this.suppliedServerName ??\n this._server?.client.getServerVersion()?.name ??\n 'unknown-server'\n );\n }\n\n async updateRoots(roots: Root[]) {\n this.roots = roots;\n await this._server?.client.sendRootsListChanged();\n }\n\n /**\n * Sets up a connection based on a provided map of server configurations.\n * - Reconnects existing servers if their configuration appears to have\n * changed (implicitly handled by `connectServer`).\n * - Sets the client's ready state once all connection attempts are complete.\n * @param mcpServers A record mapping server names to their configurations.\n */\n private async _initializeConnection() {\n this._ready = false;\n try {\n await this._connect();\n this._ready = true;\n while (this._readyListeners.length) {\n this._readyListeners.pop()?.resolve();\n }\n } catch (err) {\n while (this._readyListeners.length) {\n this._readyListeners.pop()?.reject(err as Error);\n }\n }\n if (this.roots) {\n await this.updateRoots(this.roots);\n }\n }\n\n /**\n * Returns a Promise that resolves when the client has attempted to connect\n * to all configured servers, or rejects if a critical error occurs during\n * the initial connection phase.\n */\n async ready() {\n if (this._ready) return;\n return new Promise<void>((resolve, reject) => {\n this._readyListeners.push({ resolve, reject });\n });\n }\n\n /**\n * Connects to a single MCP server defined by the provided configuration.\n * @param config The configuration object for the server.\n */\n private async _connect() {\n if (this._server) await this._server.transport.close();\n logger.debug(\n `[MCP Client] Connecting MCP server '${this.serverName}' in client '${this.name}'.`\n );\n\n const { transport, type: transportType } = await transportFrom(\n this.serverConfig,\n this.sessionId\n );\n if (!transport) {\n throw new GenkitError({\n status: 'INVALID_ARGUMENT',\n message: `[MCP Client] Could not determine valid transport config from supplied options.`,\n });\n }\n\n let error: string | undefined;\n\n const client = new Client(\n { name: this.name, version: this.version },\n { capabilities: { roots: { listChanged: true } } }\n );\n client.setRequestHandler(ListRootsRequestSchema, () => {\n logger.debug(`[MCP Client] fetching roots for ${this.name}`);\n return { roots: this.roots || [] };\n });\n\n try {\n await client.connect(transport);\n } catch (e) {\n logger.warn(\n `[MCP Client] Error connecting server via ${transportType} transport: ${e}`\n );\n this.disabled = true;\n error = (e as Error).toString();\n }\n\n this._server = {\n client,\n transport,\n error,\n } as McpServerRef;\n }\n\n /**\n * Disconnects the MCP server and removes its registration\n * from this client instance.\n */\n async _disconnect() {\n if (this._server) {\n logger.debug(\n `[MCP Client] Disconnecting MCP server in client '${this.name}'.`\n );\n await this._server.client.close();\n this._server = undefined;\n }\n }\n\n /**\n * Disables a server. Closes the underlying transport and server's configuration. Does nothing if the server is\n * already disabled.\n */\n async disable() {\n if (!this.isEnabled()) return;\n if (this._server) {\n logger.debug(\n `[MCP Client] Disabling MCP server in client '${this.name}'`\n );\n await this._disconnect();\n this.disabled = true;\n }\n }\n\n /**\n * Whether this client-server connection is enabled or not.\n */\n isEnabled() {\n return !this.disabled;\n }\n\n /**\n * Enables a server connection, including previously disabled ones. Does nothing if the\n * server is not disabled.\n */\n async enable() {\n if (this.isEnabled()) return;\n logger.debug(`[MCP Client] Reenabling MCP server in client '${this.name}'`);\n await this._initializeConnection();\n this.disabled = !!this._server!.error;\n }\n\n /**\n * Closes and then restarts the transport connection for the specified server.\n * Useful for attempting to recover from connection issues without full\n * reconfiguration.\n */\n async restart() {\n if (this._server) {\n logger.debug(\n `[MCP Client] Restarting connection to MCP server in client '${this.name}'`\n );\n await this._disconnect();\n await this._initializeConnection();\n }\n }\n\n /**\n * Fetches all tools available through this client, if the server\n * configuration is not disabled.\n */\n async getActiveTools(ai: Genkit): Promise<ToolAction[]> {\n await this.ready();\n let tools: ToolAction[] = [];\n\n if (this._server) {\n const capabilities = this._server.client.getServerCapabilities();\n if (capabilities?.tools)\n tools.push(\n ...(await fetchDynamicTools(ai, this._server.client, {\n rawToolResponses: this.rawToolResponses,\n serverName: this.serverName,\n name: this.name,\n }))\n );\n }\n\n return tools;\n }\n\n /**\n * Fetches all resources available through this client, if the server\n * configuration is not disabled.\n */\n async getActiveResources(ai: Genkit): Promise<DynamicResourceAction[]> {\n await this.ready();\n let resources: DynamicResourceAction[] = [];\n\n if (this._server) {\n const capabilities = this._server.client.getServerCapabilities();\n if (capabilities?.resources)\n resources.push(\n ...(await fetchDynamicResources(ai, this._server.client, {\n serverName: this.serverName,\n name: this.name,\n }))\n );\n }\n\n return resources;\n }\n\n /**\n * Fetches all active prompts available through this client, if the server\n * configuration supports prompts.\n * @param ai The Genkit instance.\n * @param options Optional prompt generation options.\n * @returns A promise that resolves to an array of ExecutablePrompt.\n */\n async getActivePrompts(\n ai: Genkit,\n options?: PromptGenerateOptions\n ): Promise<ExecutablePrompt[]> {\n if (this._server?.client.getServerCapabilities()?.prompts) {\n return fetchAllPrompts(this._server.client, {\n ai,\n serverName: this.serverName,\n name: this.name,\n options,\n });\n }\n return [];\n }\n\n /**\n * Get the specified prompt as an `ExecutablePrompt` available through this\n * client. If no such prompt is found, return undefined.\n */\n async getPrompt(\n ai: Genkit,\n promptName: string,\n opts?: PromptGenerateOptions\n ): Promise<ExecutablePrompt | undefined> {\n await this.ready();\n\n if (this._server) {\n const capabilities = await this._server.client.getServerCapabilities();\n if (capabilities?.prompts) {\n return await getExecutablePrompt(this._server.client, {\n ai,\n serverName: this.name,\n promptName,\n name: this.name,\n options: opts,\n });\n }\n logger.debug(`[MCP Client] No prompts are found in this MCP server.`);\n }\n return;\n }\n\n /** Returns the underlying MCP SDK client if one has been initialized. */\n get mcpClient(): Client | undefined {\n return this._server?.client;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,oBAAuB;AAIvB,mBAGO;AACP,oBAOO;AACP,qBAAuB;AACvB,kBAKO;AACP,sBAAsC;AAoF/B,MAAM,gBAAgB;AAAA,EAC3B;AAAA,EAEA;AAAA,EACS;AAAA,EACA;AAAA,EACD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,kBAGF,CAAC;AAAA,EACC,SAAS;AAAA,EAEjB,YAAY,SAA2B;AACrC,SAAK,OAAO,QAAQ;AACpB,SAAK,qBAAqB,QAAQ;AAClC,SAAK,UAAU,QAAQ,WAAW;AAClC,SAAK,eAAe,QAAQ;AAC5B,SAAK,mBAAmB,CAAC,CAAC,QAAQ;AAClC,SAAK,WAAW,CAAC,CAAC,QAAQ,UAAU;AACpC,SAAK,QAAQ,QAAQ,UAAU;AAC/B,SAAK,YAAY,QAAQ;AAEzB,SAAK,sBAAsB;AAAA,EAC7B;AAAA,EAEA,IAAI,aAA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