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

Function addServer

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

Source from the content-addressed store, hash-verified

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