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

Function removeServer

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

Source from the content-addressed store, hash-verified

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

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