(input: McpServerInput)
| 968 | ); |
| 969 | |
| 970 | const addServer = (input: McpServerInput) => |
| 971 | Effect.gen(function* () { |
| 972 | const slug = normalizeSlug(input); |
| 973 | const config = toIntegrationConfig(input); |
| 974 | |
| 975 | // Block re-adding an existing slug. The core `integrations.register` |
| 976 | // primitive upserts (so boot re-registration is idempotent), but an |
| 977 | // explicit add must NOT silently clobber an existing integration's |
| 978 | // tools, connections, and policies. To add more auth, update the |
| 979 | // existing integration instead. |
| 980 | const existing = yield* ctx.core.integrations.get(slugFrom(slug)); |
| 981 | if (existing) { |
| 982 | return yield* new IntegrationAlreadyExistsError({ slug: slugFrom(slug) }); |
| 983 | } |
| 984 | |
| 985 | yield* ctx.core.integrations |
| 986 | .register({ |
| 987 | slug: slugFrom(slug), |
| 988 | name: input.name, |
| 989 | description: input.description?.trim() || input.name, |
| 990 | config, |
| 991 | canRemove: true, |
| 992 | canRefresh: true, |
| 993 | }) |
| 994 | .pipe( |
| 995 | Effect.withSpan("mcp.plugin.register_integration", { |
| 996 | attributes: { "mcp.integration.slug": slug }, |
| 997 | }), |
| 998 | ); |
| 999 | |
| 1000 | // Auto-create the stdio server's default connection so its tools are |
| 1001 | // discovered immediately (without it the integration lands with zero |
| 1002 | // connections and therefore zero tools — the fresh-install "no tools |
| 1003 | // detected" report). Two cases connect on add: |
| 1004 | // • one-shot `env` VALUES were supplied (agent path) → bind them as |
| 1005 | // the connection's secrets. |
| 1006 | // • the server needs NO secret env at all → a no-auth connection. |
| 1007 | // When the server only DECLARES env var names (the UI path), the |
| 1008 | // secrets are still missing, so we leave the connection to the connect |
| 1009 | // step where the user enters one masked value per declared var. |
| 1010 | if (input.transport === "stdio") { |
| 1011 | const hasValues = input.env != null && Object.keys(input.env).length > 0; |
| 1012 | const declaresSecrets = stdioEnvVarNames(input).length > 0; |
| 1013 | if (hasValues || !declaresSecrets) { |
| 1014 | yield* ctx.connections |
| 1015 | .create({ |
| 1016 | owner: "org", |
| 1017 | name: ConnectionName.make("default"), |
| 1018 | integration: slugFrom(slug), |
| 1019 | template: AuthTemplateSlug.make(hasValues ? STDIO_ENV_TEMPLATE : "none"), |
| 1020 | values: hasValues ? { ...input.env } : {}, |
| 1021 | }) |
| 1022 | .pipe( |
| 1023 | // These can't arise right after a successful register with |
| 1024 | // valid inputs, but the channel must stay within |
| 1025 | // McpExtensionFailure; surface them as a connection error |
| 1026 | // rather than swallow a real failure. |
| 1027 | Effect.catchTags({ |
nothing calls this directly
no test coverage detected