{"record":{"id":"294a37311b9e3bec","repo":"microsoft/aspire","slug":"mcp-server-configuration-builder-resource-name-has-connector","errorCode":null,"errorMessage":"MCP server configuration '{builder.Resource.Name}' has connector routes and cannot be marked as existing.","messagePattern":"MCP server configuration '(.+?)' has connector routes and cannot be marked as existing\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs","lineNumber":501,"sourceCode":"        config.Annotations.Add(ManifestPublishingCallbackAnnotation.Ignore);\n        builder.Resource.McpServerConfigs.Add(config);\n        return builder.ApplicationBuilder.AddResource(config);\n    }\n\n    /// <summary>\n    /// Marks a managed MCP server configuration as an existing Azure resource.\n    /// </summary>\n    /// <param name=\"builder\">The MCP server configuration resource builder.</param>\n    /// <returns>The resource builder.</returns>\n    /// <ats-returns>The resource builder.</ats-returns>\n    [AspireExport(\"asExistingConnectorNamespaceMcpServerConfig\", MethodName = \"asExisting\")]\n    public static IResourceBuilder<AzureConnectorNamespaceMcpServerConfigResource> AsExisting(\n        this IResourceBuilder<AzureConnectorNamespaceMcpServerConfigResource> builder)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        if (builder.Resource.Connectors.Count > 0)\n        {\n            throw new InvalidOperationException(\n                $\"MCP server configuration '{builder.Resource.Name}' has connector routes and cannot be marked as existing.\");\n        }\n\n        if (!string.IsNullOrWhiteSpace(builder.Resource.Description))\n        {\n            throw new InvalidOperationException(\n                $\"MCP server configuration '{builder.Resource.Name}' configures a description and cannot be marked as existing.\");\n        }\n\n        if (builder.Resource.AccessPolicies.Count > 0)\n        {\n            throw new InvalidOperationException(\n                $\"MCP server configuration '{builder.Resource.Name}' configures access policies and cannot be marked as existing.\");\n        }\n\n        builder.Resource.IsExisting = true;\n        return builder;\n    }","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs#L483-L519","documentation":"AsExisting marks an MCP server configuration resource as a read-only reference to pre-existing infrastructure. A configuration that already declares connector routes cannot be converted, because existing references must not carry modeled child connectors that would never be deployed. The library validates this invariant and throws before mutating IsExisting.","triggerScenarios":"Calling builder.AsExisting() on an AzureConnectorNamespaceMcpServerConfigResource after one or more WithConnector calls have populated Resource.Connectors.","commonSituations":"Flipping a fully-modeled MCP config to existing mode to avoid deployment, e.g. pointing at an already-provisioned config while keeping its WithConnector wiring.","solutions":["Remove the WithConnector call(s) before calling AsExisting.","Create a separate, unconfigured builder (e.g. re-add the config) and mark that one AsExisting.","If connectors must be modeled, keep the config in create mode instead of existing mode."],"exampleFix":"// before\nvar mcp = ns.AddMcpServerConfig(\"tools\", options).WithConnector(\"conn\", connection, connectorOptions);\nmcp.AsExisting(); // throws\n\n// after\nvar mcp = ns.AddMcpServerConfig(\"tools\", options); // no connectors\nmcp.AsExisting();","handlingStrategy":"validation","validationCode":"if (mcp.Resource.Connectors.Count == 0)\n{\n    mcp.AsExisting();\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    mcp.AsExisting();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"has connector routes\"))\n{\n    // strip WithConnector calls or keep the config in create mode\n}","preventionTips":["Call AsExisting immediately after creating the builder, before any WithConnector calls.","Do not flip fully-modeled configs to existing mode; model existing references minimally.","Audit helpers that conditionally switch between create and existing mode."],"tags":["azure","aspire-hosting","mcp","existing-resource"],"backgroundTag":"invalid-state-transition","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}