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

Function removeServer

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

Source from the content-addressed store, hash-verified

1218 }).pipe(Effect.withSpan("mcp.plugin.reconcile_stdio_connections"));
1219
1220 const removeServer = (slug: string) =>
1221 Effect.gen(function* () {
1222 const integration = slugFrom(slug);
1223 const record = yield* ctx.core.integrations.get(integration);
1224 const config = record ? parseMcpIntegrationConfig(record.config) : null;
1225 const legacyCandidates = legacyOAuthClientSlugCandidates(slug, record);
1226 const connections = yield* ctx.connections.list({ integration });
1227 const allConnections = yield* ctx.connections.list();
1228 const oauthClientSummaries = yield* ctx.oauth.listClients();
1229 const usedElsewhere = new Set(
1230 allConnections
1231 .filter((connection) => String(connection.integration) !== String(integration))
1232 .flatMap((connection) =>
1233 connection.oauthClient == null
1234 ? []
1235 : [
1236 oauthClientKey(
1237 connection.oauthClientOwner ?? connection.owner,
1238 connection.oauthClient,
1239 ),
1240 ],
1241 ),
1242 );
1243 const oauthClientsByKey = new Map(
1244 oauthClientSummaries.map((client) => [
1245 oauthClientKey(client.owner, client.slug),
1246 client,
1247 ]),
1248 );
1249 const clientsToRemove = new Map<
1250 string,
1251 { readonly owner: Owner; readonly slug: OAuthClientSlug }
1252 >();
1253
1254 for (const connection of connections) {
1255 if (connection.oauthClient == null) continue;
1256 const owner = connection.oauthClientOwner ?? connection.owner;
1257 const key = oauthClientKey(owner, connection.oauthClient);
1258 const client = oauthClientsByKey.get(key);
1259 if (client?.origin.kind !== "dynamic_client_registration") continue;
1260 clientsToRemove.set(key, {
1261 owner,
1262 slug: connection.oauthClient,
1263 });
1264 }
1265 for (const client of oauthClientSummaries) {
1266 const key = oauthClientKey(client.owner, client.slug);
1267 if (usedElsewhere.has(key)) continue;
1268 if (
1269 client.origin.kind === "dynamic_client_registration" &&
1270 (client.origin.integration == null || String(client.origin.integration) === slug)
1271 ) {
1272 clientsToRemove.set(key, { owner: client.owner, slug: client.slug });
1273 continue;
1274 }
1275 if (legacyMcpClientMatches(client, legacyCandidates, config)) {
1276 clientsToRemove.set(key, { owner: client.owner, slug: client.slug });
1277 }

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