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

Function addServer

packages/plugins/mcp/src/sdk/plugin.ts:1095–1184  ·  view source on GitHub ↗
(input: McpServerInput)

Source from the content-addressed store, hash-verified

1093 );
1094
1095 const addServer = (input: McpServerInput) =>
1096 Effect.gen(function* () {
1097 const slug = normalizeSlug(input);
1098 const config = toIntegrationConfig(input);
1099
1100 // Block re-adding an existing slug. The core `integrations.register`
1101 // primitive upserts (so boot re-registration is idempotent), but an
1102 // explicit add must NOT silently clobber an existing integration's
1103 // tools, connections, and policies. To add more auth, update the
1104 // existing integration instead.
1105 const existing = yield* ctx.core.integrations.get(slugFrom(slug));
1106 if (existing) {
1107 return yield* new IntegrationAlreadyExistsError({ slug: slugFrom(slug) });
1108 }
1109
1110 yield* ctx.core.integrations
1111 .register({
1112 slug: slugFrom(slug),
1113 name: input.name,
1114 description: input.description?.trim() || input.name,
1115 config,
1116 canRemove: true,
1117 canRefresh: true,
1118 })
1119 .pipe(
1120 Effect.withSpan("mcp.plugin.register_integration", {
1121 attributes: { "mcp.integration.slug": slug },
1122 }),
1123 );
1124
1125 // Auto-create the stdio server's default connection so its tools are
1126 // discovered immediately (without it the integration lands with zero
1127 // connections and therefore zero tools — the fresh-install "no tools
1128 // detected" report). Two cases connect on add:
1129 // • one-shot `env` VALUES were supplied (agent path) → bind them as
1130 // the connection's secrets.
1131 // • the server needs NO secret env at all → a no-auth connection.
1132 // When the server only DECLARES env var names (the UI path), the
1133 // secrets are still missing, so we leave the connection to the connect
1134 // step where the user enters one masked value per declared var.
1135 if (input.transport === "stdio") {
1136 const hasValues = input.env != null && Object.keys(input.env).length > 0;
1137 const declaresSecrets = stdioEnvVarNames(input).length > 0;
1138 if (hasValues || !declaresSecrets) {
1139 yield* ctx.connections
1140 .create({
1141 owner: "org",
1142 name: ConnectionName.make("default"),
1143 integration: slugFrom(slug),
1144 template: AuthTemplateSlug.make(hasValues ? STDIO_ENV_TEMPLATE : "none"),
1145 values: hasValues ? { ...input.env } : {},
1146 })
1147 .pipe(
1148 // These can't arise right after a successful register with
1149 // valid inputs, but the channel must stay within
1150 // McpExtensionFailure; surface them as a connection error
1151 // rather than swallow a real failure.
1152 Effect.catchTags({

Callers

nothing calls this directly

Calls 5

normalizeSlugFunction · 0.85
toIntegrationConfigFunction · 0.85
slugFromFunction · 0.85
stdioEnvVarNamesFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected