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

Function removeServer

packages/plugins/mcp/src/sdk/plugin.ts:1303–1376  ·  view source on GitHub ↗
(slug: string)

Source from the content-addressed store, hash-verified

1301 }).pipe(Effect.withSpan("mcp.plugin.reconcile_stdio_connections"));
1302
1303 const removeServer = (slug: string) =>
1304 Effect.gen(function* () {
1305 const integration = slugFrom(slug);
1306 const record = yield* ctx.core.integrations.get(integration);
1307 const config = record ? parseMcpIntegrationConfig(record.config) : null;
1308 const legacyCandidates = legacyOAuthClientSlugCandidates(slug, record);
1309 const connections = yield* ctx.connections.list({ integration });
1310 const allConnections = yield* ctx.connections.list();
1311 const oauthClientSummaries = yield* ctx.oauth.listClients();
1312 const usedElsewhere = new Set(
1313 allConnections
1314 .filter((connection) => String(connection.integration) !== String(integration))
1315 .flatMap((connection) =>
1316 connection.oauthClient == null
1317 ? []
1318 : [
1319 oauthClientKey(
1320 connection.oauthClientOwner ?? connection.owner,
1321 connection.oauthClient,
1322 ),
1323 ],
1324 ),
1325 );
1326 const oauthClientsByKey = new Map(
1327 oauthClientSummaries.map((client) => [
1328 oauthClientKey(client.owner, client.slug),
1329 client,
1330 ]),
1331 );
1332 const clientsToRemove = new Map<
1333 string,
1334 { readonly owner: Owner; readonly slug: OAuthClientSlug }
1335 >();
1336
1337 for (const connection of connections) {
1338 if (connection.oauthClient == null) continue;
1339 const owner = connection.oauthClientOwner ?? connection.owner;
1340 const key = oauthClientKey(owner, connection.oauthClient);
1341 const client = oauthClientsByKey.get(key);
1342 if (client?.origin.kind !== "dynamic_client_registration") continue;
1343 clientsToRemove.set(key, {
1344 owner,
1345 slug: connection.oauthClient,
1346 });
1347 }
1348 for (const client of oauthClientSummaries) {
1349 const key = oauthClientKey(client.owner, client.slug);
1350 if (usedElsewhere.has(key)) continue;
1351 if (
1352 client.origin.kind === "dynamic_client_registration" &&
1353 (client.origin.integration == null || String(client.origin.integration) === slug)
1354 ) {
1355 clientsToRemove.set(key, { owner: client.owner, slug: client.slug });
1356 continue;
1357 }
1358 if (legacyMcpClientMatches(client, legacyCandidates, config)) {
1359 clientsToRemove.set(key, { owner: client.owner, slug: client.slug });
1360 }

Callers

nothing calls this directly

Calls 10

slugFromFunction · 0.85
oauthClientKeyFunction · 0.85
legacyMcpClientMatchesFunction · 0.85
valuesMethod · 0.80
getMethod · 0.65
listMethod · 0.65
setMethod · 0.65
removeMethod · 0.65

Tested by

no test coverage detected