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

Function removeServer

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

Source from the content-addressed store, hash-verified

1019 }).pipe(Effect.withSpan("mcp.plugin.reconcile_stdio_connections"));
1020
1021 const removeServer = (slug: string) =>
1022 Effect.gen(function* () {
1023 const integration = slugFrom(slug);
1024 const record = yield* ctx.core.integrations.get(integration);
1025 const config = record ? parseMcpIntegrationConfig(record.config) : null;
1026 const legacyCandidates = legacyOAuthClientSlugCandidates(slug, record);
1027 const connections = yield* ctx.connections.list({ integration });
1028 const allConnections = yield* ctx.connections.list();
1029 const oauthClientSummaries = yield* ctx.oauth.listClients();
1030 const usedElsewhere = new Set(
1031 allConnections
1032 .filter((connection) => String(connection.integration) !== String(integration))
1033 .flatMap((connection) =>
1034 connection.oauthClient == null
1035 ? []
1036 : [
1037 oauthClientKey(
1038 connection.oauthClientOwner ?? connection.owner,
1039 connection.oauthClient,
1040 ),
1041 ],
1042 ),
1043 );
1044 const oauthClientsByKey = new Map(
1045 oauthClientSummaries.map((client) => [
1046 oauthClientKey(client.owner, client.slug),
1047 client,
1048 ]),
1049 );
1050 const clientsToRemove = new Map<
1051 string,
1052 { readonly owner: Owner; readonly slug: OAuthClientSlug }
1053 >();
1054
1055 for (const connection of connections) {
1056 if (connection.oauthClient == null) continue;
1057 const owner = connection.oauthClientOwner ?? connection.owner;
1058 const key = oauthClientKey(owner, connection.oauthClient);
1059 const client = oauthClientsByKey.get(key);
1060 if (client?.origin.kind !== "dynamic_client_registration") continue;
1061 clientsToRemove.set(key, {
1062 owner,
1063 slug: connection.oauthClient,
1064 });
1065 }
1066 for (const client of oauthClientSummaries) {
1067 const key = oauthClientKey(client.owner, client.slug);
1068 if (usedElsewhere.has(key)) continue;
1069 if (
1070 client.origin.kind === "dynamic_client_registration" &&
1071 (client.origin.integration == null || String(client.origin.integration) === slug)
1072 ) {
1073 clientsToRemove.set(key, { owner: client.owner, slug: client.slug });
1074 continue;
1075 }
1076 if (legacyMcpClientMatches(client, legacyCandidates, config)) {
1077 clientsToRemove.set(key, { owner: client.owner, slug: client.slug });
1078 }

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected