(input: McpServerInput)
| 901 | ); |
| 902 | |
| 903 | const addServer = (input: McpServerInput) => |
| 904 | Effect.gen(function* () { |
| 905 | const slug = normalizeSlug(input); |
| 906 | const config = toIntegrationConfig(input); |
| 907 | |
| 908 | // Block re-adding an existing slug. The core `integrations.register` |
| 909 | // primitive upserts (so boot re-registration is idempotent), but an |
| 910 | // explicit add must NOT silently clobber an existing integration's |
| 911 | // tools, connections, and policies. To add more auth, update the |
| 912 | // existing integration instead. |
| 913 | const existing = yield* ctx.core.integrations.get(slugFrom(slug)); |
| 914 | if (existing) { |
| 915 | return yield* new IntegrationAlreadyExistsError({ slug: slugFrom(slug) }); |
| 916 | } |
| 917 | |
| 918 | yield* ctx.core.integrations |
| 919 | .register({ |
| 920 | slug: slugFrom(slug), |
| 921 | name: input.name, |
| 922 | description: input.description?.trim() || input.name, |
| 923 | config, |
| 924 | canRemove: true, |
| 925 | canRefresh: true, |
| 926 | }) |
| 927 | .pipe( |
| 928 | Effect.withSpan("mcp.plugin.register_integration", { |
| 929 | attributes: { "mcp.integration.slug": slug }, |
| 930 | }), |
| 931 | ); |
| 932 | |
| 933 | // Auto-create the stdio server's default connection so its tools are |
| 934 | // discovered immediately (without it the integration lands with zero |
| 935 | // connections and therefore zero tools — the fresh-install "no tools |
| 936 | // detected" report). Two cases connect on add: |
| 937 | // • one-shot `env` VALUES were supplied (agent path) → bind them as |
| 938 | // the connection's secrets. |
| 939 | // • the server needs NO secret env at all → a no-auth connection. |
| 940 | // When the server only DECLARES env var names (the UI path), the |
| 941 | // secrets are still missing, so we leave the connection to the connect |
| 942 | // step where the user enters one masked value per declared var. |
| 943 | if (input.transport === "stdio") { |
| 944 | const hasValues = input.env != null && Object.keys(input.env).length > 0; |
| 945 | const declaresSecrets = stdioEnvVarNames(input).length > 0; |
| 946 | if (hasValues || !declaresSecrets) { |
| 947 | yield* ctx.connections |
| 948 | .create({ |
| 949 | owner: "org", |
| 950 | name: ConnectionName.make("default"), |
| 951 | integration: slugFrom(slug), |
| 952 | template: AuthTemplateSlug.make(hasValues ? STDIO_ENV_TEMPLATE : "none"), |
| 953 | values: hasValues ? { ...input.env } : {}, |
| 954 | }) |
| 955 | .pipe( |
| 956 | // These can't arise right after a successful register with |
| 957 | // valid inputs, but the channel must stay within |
| 958 | // McpExtensionFailure; surface them as a connection error |
| 959 | // rather than swallow a real failure. |
| 960 | Effect.catchTags({ |
nothing calls this directly
no test coverage detected