{"record":{"id":"a0cf30d7cc1e7442","repo":"microsoft/aspire","slug":"existing-mcp-server-configuration-builder-resource-name-is-a0cf30","errorCode":null,"errorMessage":"Existing MCP server configuration '{builder.Resource.Name}' is read-only.","messagePattern":"Existing MCP server configuration '(.+?)' is read-only\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs","lineNumber":590,"sourceCode":"    /// are connector-specific and should be verified against the connector operation metadata. The current\n    /// Connector Namespace preview supports one connector per managed MCP server configuration.\n    /// </remarks>\n    /// <ats-returns>The resource builder.</ats-returns>\n    [AspireExport]\n    public static IResourceBuilder<AzureConnectorNamespaceMcpServerConfigResource> WithConnector(\n        this IResourceBuilder<AzureConnectorNamespaceMcpServerConfigResource> builder,\n        string connectorName,\n        IResourceBuilder<AzureConnectorNamespaceConnectionResource> connection,\n        AzureConnectorNamespaceMcpConnectorOptions options)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrWhiteSpace(connectorName);\n        ArgumentNullException.ThrowIfNull(connection);\n        ArgumentNullException.ThrowIfNull(options);\n\n        if (builder.Resource.IsExisting)\n        {\n            throw new InvalidOperationException(\n                $\"Existing MCP server configuration '{builder.Resource.Name}' is read-only.\");\n        }\n\n        if (!ReferenceEquals(builder.Resource.Parent, connection.Resource.Parent))\n        {\n            throw new InvalidOperationException(\n                $\"Connector connection '{connection.Resource.Name}' belongs to a different Connector Namespace.\");\n        }\n\n        if (builder.Resource.Connectors.Count > 0)\n        {\n            throw new InvalidOperationException(\n                $\"MCP server configuration '{builder.Resource.Name}' already has a connector. \" +\n                \"The current Connector Namespace preview supports one connector per MCP server configuration.\");\n        }\n\n        if (options.Operations is null || options.Operations.Length == 0)\n        {","sourceCodeStart":572,"sourceCodeEnd":608,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs#L572-L608","documentation":"WithConnector attaches a connector route to an MCP server configuration, but existing (AsExisting) configurations are read-only references: adding a connector would imply deployment changes Aspire cannot make. The method checks IsExisting first and throws immediately.","triggerScenarios":"Calling WithConnector(connectorName, connection, options) on an MCP server configuration builder whose Resource.IsExisting is true.","commonSituations":"Wiring an imported MCP server configuration to a connector; shared helper methods that always call WithConnector regardless of create/existing mode.","solutions":["Remove the WithConnector call and associate the connector with the existing configuration in Azure directly.","Model the MCP server configuration as Aspire-created when connector routes must be declared.","Guard the call with if (!builder.Resource.IsExisting)."],"exampleFix":"// before\nvar mcp = ns.AddMcpServerConfig(\"tools\", options).AsExisting();\nmcp.WithConnector(\"db-conn\", connection, connectorOptions); // throws\n\n// after\nvar mcp = ns.AddMcpServerConfig(\"tools\", options).AsExisting();\n// Associate connectors on the existing configuration outside Aspire.","handlingStrategy":"validation","validationCode":"if (!mcp.Resource.IsExisting)\n{\n    mcp.WithConnector(\"db-conn\", connection, connectorOptions);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    mcp.WithConnector(\"db-conn\", connection, connectorOptions);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"is read-only\"))\n{\n    // associate connectors on the existing configuration outside Aspire\n}","preventionTips":["Add connectors only to create-mode MCP server configurations.","Call AsExisting last (or never) when connectors must be modeled.","Audit generic WithConnector helper calls against the resource mode."],"tags":["azure","aspire-hosting","mcp","connector"],"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"}