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

Function removeServer

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

Source from the content-addressed store, hash-verified

1064 }).pipe(Effect.withSpan("mcp.plugin.reconcile_stdio_connections"));
1065
1066 const removeServer = (slug: string) =>
1067 Effect.gen(function* () {
1068 const integration = slugFrom(slug);
1069 const record = yield* ctx.core.integrations.get(integration);
1070 const config = record ? parseMcpIntegrationConfig(record.config) : null;
1071 const legacyCandidates = legacyOAuthClientSlugCandidates(slug, record);
1072 const connections = yield* ctx.connections.list({ integration });
1073 const allConnections = yield* ctx.connections.list();
1074 const oauthClientSummaries = yield* ctx.oauth.listClients();
1075 const usedElsewhere = new Set(
1076 allConnections
1077 .filter((connection) => String(connection.integration) !== String(integration))
1078 .flatMap((connection) =>
1079 connection.oauthClient == null
1080 ? []
1081 : [
1082 oauthClientKey(
1083 connection.oauthClientOwner ?? connection.owner,
1084 connection.oauthClient,
1085 ),
1086 ],
1087 ),
1088 );
1089 const oauthClientsByKey = new Map(
1090 oauthClientSummaries.map((client) => [
1091 oauthClientKey(client.owner, client.slug),
1092 client,
1093 ]),
1094 );
1095 const clientsToRemove = new Map<
1096 string,
1097 { readonly owner: Owner; readonly slug: OAuthClientSlug }
1098 >();
1099
1100 for (const connection of connections) {
1101 if (connection.oauthClient == null) continue;
1102 const owner = connection.oauthClientOwner ?? connection.owner;
1103 const key = oauthClientKey(owner, connection.oauthClient);
1104 const client = oauthClientsByKey.get(key);
1105 if (client?.origin.kind !== "dynamic_client_registration") continue;
1106 clientsToRemove.set(key, {
1107 owner,
1108 slug: connection.oauthClient,
1109 });
1110 }
1111 for (const client of oauthClientSummaries) {
1112 const key = oauthClientKey(client.owner, client.slug);
1113 if (usedElsewhere.has(key)) continue;
1114 if (
1115 client.origin.kind === "dynamic_client_registration" &&
1116 (client.origin.integration == null || String(client.origin.integration) === slug)
1117 ) {
1118 clientsToRemove.set(key, { owner: client.owner, slug: client.slug });
1119 continue;
1120 }
1121 if (legacyMcpClientMatches(client, legacyCandidates, config)) {
1122 clientsToRemove.set(key, { owner: client.owner, slug: client.slug });
1123 }

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