MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / createMcpConnector

Function createMcpConnector

packages/plugins/mcp/src/sdk/connection.ts:272–353  ·  view source on GitHub ↗
(input: ConnectorInput)

Source from the content-addressed store, hash-verified

270// ---------------------------------------------------------------------------
271
272export const createMcpConnector = (input: ConnectorInput): McpConnector => {
273 if (input.transport === "stdio") {
274 const command = input.command.trim();
275 if (!command) {
276 return Effect.fail(
277 new McpConnectionError({
278 transport: "stdio",
279 message: "MCP stdio transport requires a command",
280 }),
281 );
282 }
283
284 return Effect.gen(function* () {
285 // Dynamic import so the underlying module (which evaluates
286 // `node:child_process`) is only loaded when stdio is actually used.
287 const { createStdioTransport } = yield* Effect.tryPromise({
288 try: () => import("./stdio-connector"),
289 catch: () =>
290 new McpConnectionError({
291 transport: "stdio",
292 message: "Failed to load stdio transport module",
293 }),
294 });
295
296 return yield* connectClient({
297 transport: "stdio",
298 createTransport: () =>
299 createStdioTransport({
300 command,
301 args: input.args,
302 env: input.env,
303 cwd: input.cwd?.trim().length ? input.cwd.trim() : undefined,
304 }),
305 });
306 });
307 }
308
309 // Remote transport
310 const headers = input.headers ?? {};
311 const remoteTransport = input.remoteTransport ?? "auto";
312 const requestInit = Object.keys(headers).length > 0 ? { headers } : undefined;
313 const fetch = input.httpClientLayer ? fetchFromHttpClientLayer(input.httpClientLayer) : undefined;
314
315 const endpoint = buildEndpointUrl(input.endpoint, input.queryParams ?? {});
316
317 const connectStreamableHttp = connectClient({
318 transport: "streamable-http",
319 createTransport: () =>
320 new StreamableHTTPClientTransport(endpoint, {
321 requestInit,
322 authProvider: input.authProvider,
323 fetch,
324 }),
325 });
326
327 const connectSse = connectClient({
328 transport: "sse",
329 createTransport: () =>

Callers 6

probeEndpointFunction · 0.90
plugin.tsFile · 0.90
invoke.test.tsFile · 0.90
plugin.test.tsFile · 0.90
invokeFunction · 0.90

Calls 4

createStdioTransportFunction · 0.85
fetchFromHttpClientLayerFunction · 0.85
buildEndpointUrlFunction · 0.85
connectClientFunction · 0.70

Tested by 1

invokeFunction · 0.72