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

Function addServer

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

Source from the content-addressed store, hash-verified

1128 );
1129
1130 const addServer = (input: McpServerInput) =>
1131 Effect.gen(function* () {
1132 const slug = normalizeSlug(input);
1133 const config = toIntegrationConfig(input);
1134
1135 // Block re-adding an existing slug. The core `integrations.register`
1136 // primitive upserts (so boot re-registration is idempotent), but an
1137 // explicit add must NOT silently clobber an existing integration's
1138 // tools, connections, and policies. To add more auth, update the
1139 // existing integration instead.
1140 const existing = yield* ctx.core.integrations.get(slugFrom(slug));
1141 if (existing) {
1142 return yield* new IntegrationAlreadyExistsError({ slug: slugFrom(slug) });
1143 }
1144
1145 yield* ctx.core.integrations
1146 .register({
1147 slug: slugFrom(slug),
1148 name: input.name,
1149 description: input.description?.trim() || input.name,
1150 config,
1151 canRemove: true,
1152 canRefresh: true,
1153 })
1154 .pipe(
1155 Effect.withSpan("mcp.plugin.register_integration", {
1156 attributes: { "mcp.integration.slug": slug },
1157 }),
1158 );
1159
1160 // Auto-create the stdio server's default connection so its tools are
1161 // discovered immediately (without it the integration lands with zero
1162 // connections and therefore zero tools — the fresh-install "no tools
1163 // detected" report). Two cases connect on add:
1164 // • one-shot `env` VALUES were supplied (agent path) → bind them as
1165 // the connection's secrets.
1166 // • the server needs NO secret env at all → a no-auth connection.
1167 // When the server only DECLARES env var names (the UI path), the
1168 // secrets are still missing, so we leave the connection to the connect
1169 // step where the user enters one masked value per declared var.
1170 if (input.transport === "stdio") {
1171 const hasValues = input.env != null && Object.keys(input.env).length > 0;
1172 const declaresSecrets = stdioEnvVarNames(input).length > 0;
1173 if (hasValues || !declaresSecrets) {
1174 yield* ctx.connections
1175 .create({
1176 owner: "org",
1177 name: ConnectionName.make("default"),
1178 integration: slugFrom(slug),
1179 template: AuthTemplateSlug.make(hasValues ? STDIO_ENV_TEMPLATE : "none"),
1180 values: hasValues ? { ...input.env } : {},
1181 })
1182 .pipe(
1183 // These can't arise right after a successful register with
1184 // valid inputs, but the channel must stay within
1185 // McpExtensionFailure; surface them as a connection error
1186 // rather than swallow a real failure.
1187 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