(input: McpServerInput)
| 856 | ); |
| 857 | |
| 858 | const addServer = (input: McpServerInput) => |
| 859 | Effect.gen(function* () { |
| 860 | const slug = normalizeSlug(input); |
| 861 | const config = toIntegrationConfig(input); |
| 862 | |
| 863 | // Block re-adding an existing slug. The core `integrations.register` |
| 864 | // primitive upserts (so boot re-registration is idempotent), but an |
| 865 | // explicit add must NOT silently clobber an existing integration's |
| 866 | // tools, connections, and policies. To add more auth, update the |
| 867 | // existing integration instead. |
| 868 | const existing = yield* ctx.core.integrations.get(slugFrom(slug)); |
| 869 | if (existing) { |
| 870 | return yield* new IntegrationAlreadyExistsError({ slug: slugFrom(slug) }); |
| 871 | } |
| 872 | |
| 873 | yield* ctx.core.integrations |
| 874 | .register({ |
| 875 | slug: slugFrom(slug), |
| 876 | name: input.name, |
| 877 | description: input.description?.trim() || input.name, |
| 878 | config, |
| 879 | canRemove: true, |
| 880 | canRefresh: true, |
| 881 | }) |
| 882 | .pipe( |
| 883 | Effect.withSpan("mcp.plugin.register_integration", { |
| 884 | attributes: { "mcp.integration.slug": slug }, |
| 885 | }), |
| 886 | ); |
| 887 | |
| 888 | // Auto-create the stdio server's default connection so its tools are |
| 889 | // discovered immediately (without it the integration lands with zero |
| 890 | // connections and therefore zero tools — the fresh-install "no tools |
| 891 | // detected" report). Two cases connect on add: |
| 892 | // • one-shot `env` VALUES were supplied (agent path) → bind them as |
| 893 | // the connection's secrets. |
| 894 | // • the server needs NO secret env at all → a no-auth connection. |
| 895 | // When the server only DECLARES env var names (the UI path), the |
| 896 | // secrets are still missing, so we leave the connection to the connect |
| 897 | // step where the user enters one masked value per declared var. |
| 898 | if (input.transport === "stdio") { |
| 899 | const hasValues = input.env != null && Object.keys(input.env).length > 0; |
| 900 | const declaresSecrets = stdioEnvVarNames(input).length > 0; |
| 901 | if (hasValues || !declaresSecrets) { |
| 902 | yield* ctx.connections |
| 903 | .create({ |
| 904 | owner: "org", |
| 905 | name: ConnectionName.make("default"), |
| 906 | integration: slugFrom(slug), |
| 907 | template: AuthTemplateSlug.make(hasValues ? STDIO_ENV_TEMPLATE : "none"), |
| 908 | values: hasValues ? { ...input.env } : {}, |
| 909 | }) |
| 910 | .pipe( |
| 911 | // These can't arise right after a successful register with |
| 912 | // valid inputs, but the channel must stay within |
| 913 | // McpExtensionFailure; surface them as a connection error |
| 914 | // rather than swallow a real failure. |
| 915 | Effect.catchTags({ |
nothing calls this directly
no test coverage detected