{"record":{"id":"c3e85b98d6c81ee0","repo":"microsoft/semantic-kernel","slug":"server-url-is-not-defined-for-operation-this-id","errorCode":null,"errorMessage":"Server url is not defined for operation {this.Id}","messagePattern":"Server url is not defined for operation (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Functions/Functions.OpenApi/Model/RestApiOperation.cs","lineNumber":429,"sourceCode":"                    serverUrlString = serverUrlString.Replace($\"{{{variableName}}}\", Uri.EscapeDataString(strValue));\n                }\n                // Use the default value if no argument is provided.\n                else if (variable.Value.Default is not null)\n                {\n                    serverUrlString = serverUrlString.Replace($\"{{{variableName}}}\", variable.Value.Default);\n                }\n                // Throw an exception if there's no value for the variable.\n                else\n                {\n                    throw new KernelException($\"No argument '{variable.Value.ArgumentName ?? variableName}' provided for the '{variableName}' server variable of the operation - '{this.Id}'.\");\n                }\n            }\n        }\n        else\n        {\n            serverUrlString =\n                apiHostUrl?.AbsoluteUri ??\n                throw new InvalidOperationException($\"Server url is not defined for operation {this.Id}\");\n        }\n\n        // Make sure base url ends with trailing slash\n        if (!serverUrlString.EndsWith(\"/\", StringComparison.OrdinalIgnoreCase))\n        {\n            serverUrlString += \"/\";\n        }\n\n        return new Uri(serverUrlString);\n    }\n\n    private static readonly Dictionary<RestApiParameterStyle, Func<RestApiParameter, JsonNode, string>> s_parameterSerializers = new()\n    {\n        { RestApiParameterStyle.Simple, SimpleStyleParameterSerializer.Serialize },\n        { RestApiParameterStyle.Form, FormStyleParameterSerializer.Serialize },\n        { RestApiParameterStyle.SpaceDelimited, SpaceDelimitedStyleParameterSerializer.Serialize },\n        { RestApiParameterStyle.PipeDelimited, PipeDelimitedStyleParameterSerializer.Serialize }\n    };","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Functions/Functions.OpenApi/Model/RestApiOperation.cs#L411-L447","documentation":"Thrown by GetServerUrl when there is no serverUrlOverride, the operation's Servers collection is empty (or its first entry has no Url), and no apiHostUrl is available (i.e. the document was not loaded from a URI). With no source of a base URL, the operation's absolute request URL cannot be determined.","triggerScenarios":"Importing an OpenAPI document that has no 'servers' field and was loaded from a local stream (so there is no document host to fall back on), and no ServerUrlOverride provided in OpenApiFunctionExecutionParameters. The first Servers entry having a null Url also triggers this.","commonSituations":"A local OpenAPI file missing the top-level 'servers' array (common in hand-authored or older 2.0 specs); loading from a Stream/byte[] rather than a URL so SK cannot infer a host; a spec where servers[0].url is blank.","solutions":["Add a top-level servers array to the OpenAPI document with at least one valid URL entry.","Provide OpenApiFunctionExecutionParameters.ServerUrlOverride with the base URL when importing.","Load the document from a URL (kernel.ImportPluginFromOpenApiAsync with a URI) so the host is inferred as a fallback.","Verify servers[0].url is non-empty in the spec."],"exampleFix":"// before - no servers in spec, no override, loaded from a stream\nvar plugin = await kernel.CreatePluginFromOpenApiAsync(\"p\", stream);\n\n// after - supply a server URL override\nvar exec = new OpenApiFunctionExecutionParameters { ServerUrlOverride = new Uri(\"https://api.example.com\") };\nvar plugin = await OpenApiKernelPluginFactory.CreateFromOpenApiAsync(\"p\", stream, exec);","handlingStrategy":"validation","validationCode":"var hasServer = doc.Servers.Count > 0 && !string.IsNullOrWhiteSpace(doc.Servers[0].Url);\nvar hasOverride = execParams?.ServerUrlOverride is not null;\nvar hasHost = documentUri is not null;\nif (!hasServer && !hasOverride && !hasHost)\n    throw new InvalidOperationException(\"No server URL available; add a servers entry or set ServerUrlOverride.\");","typeGuard":"static bool HasResolvableServer(OpenApiDocument doc, Uri? overrideUrl, Uri? hostUri)\n    => overrideUrl is not null\n       || (doc.Servers.Count > 0 && !string.IsNullOrWhiteSpace(doc.Servers[0].Url))\n       || hostUri is not null;","tryCatchPattern":"try { var url = operation.BuildOperationUrl(arguments, execParams?.ServerUrlOverride, apiHostUrl); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Server url is not defined\"))\n{ logger.LogError(ex, \"No server configured; set ServerUrlOverride.\"); throw; }","preventionTips":["Always declare a top-level servers array in the spec.","Pass OpenApiFunctionExecutionParameters.ServerUrlOverride for local/missing-server specs.","Load from a URL so the host is inferred as a fallback."],"tags":["openapi","rest-operation","server-url","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}