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

Function createMcpConnector

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

Source from the content-addressed store, hash-verified

223// ---------------------------------------------------------------------------
224
225export const createMcpConnector = (input: ConnectorInput): McpConnector => {
226 if (input.transport === "stdio") {
227 const command = input.command.trim();
228 if (!command) {
229 return Effect.fail(
230 new McpConnectionError({
231 transport: "stdio",
232 message: "MCP stdio transport requires a command",
233 }),
234 );
235 }
236
237 return Effect.gen(function* () {
238 // Dynamic import so the underlying module (which evaluates
239 // `node:child_process`) is only loaded when stdio is actually used.
240 const { createStdioTransport } = yield* Effect.tryPromise({
241 try: () => import("./stdio-connector"),
242 catch: () =>
243 new McpConnectionError({
244 transport: "stdio",
245 message: "Failed to load stdio transport module",
246 }),
247 });
248
249 return yield* connectClient({
250 transport: "stdio",
251 createTransport: () =>
252 createStdioTransport({
253 command,
254 args: input.args,
255 env: input.env,
256 cwd: input.cwd?.trim().length ? input.cwd.trim() : undefined,
257 }),
258 });
259 });
260 }
261
262 // Remote transport
263 const headers = input.headers ?? {};
264 const remoteTransport = input.remoteTransport ?? "auto";
265 const requestInit = Object.keys(headers).length > 0 ? { headers } : undefined;
266 const fetch = input.httpClientLayer ? fetchFromHttpClientLayer(input.httpClientLayer) : undefined;
267
268 const endpoint = buildEndpointUrl(input.endpoint, input.queryParams ?? {});
269
270 const connectStreamableHttp = connectClient({
271 transport: "streamable-http",
272 createTransport: () =>
273 new StreamableHTTPClientTransport(endpoint, {
274 requestInit,
275 authProvider: input.authProvider,
276 fetch,
277 }),
278 });
279
280 const connectSse = connectClient({
281 transport: "sse",
282 createTransport: () =>

Callers 5

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

Calls 4

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

Tested by

no test coverage detected