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

Function withConnection

packages/plugins/mcp/src/sdk/connection-pool.ts:101–120  ·  view source on GitHub ↗
(key, connector, use)

Source from the content-addressed store, hash-verified

99 });
100
101 const withConnection: McpConnectionPool["withConnection"] = (key, connector, use) => {
102 let reused = false;
103 const run = (forceFresh: boolean) =>
104 Effect.acquireUseRelease(
105 acquire(key, connector, forceFresh),
106 (lease) => {
107 if (!forceFresh) reused = lease.reused;
108 return use(lease.connection);
109 },
110 (lease, exit) => release(key, lease, exit),
111 );
112
113 return run(false).pipe(
114 Effect.catch((error) =>
115 reused && isMcpInvocationError(error) && error.status === 404
116 ? run(true)
117 : Effect.fail(error),
118 ),
119 );
120 };
121
122 const close = () =>
123 Effect.gen(function* () {

Callers

nothing calls this directly

Calls 2

isMcpInvocationErrorFunction · 0.85
runFunction · 0.70

Tested by

no test coverage detected