Open
Description
Describe the bug
When invoking the test-getPetById function(OpenApi PetStoreV2 ) in Semantic Kernel, the execution fails with an ArgumentOutOfRangeException. The error indicates that the argument type System.Text.Json.JsonElement is not convertible to the expected parameter type integer for the petId parameter. The actual value passed was 4.
To Reproduce
Steps to reproduce the behavior:
- Set up a Semantic Kernel instance with the OpenAPI plugin and expose To MCP Server Plugin.
- Define a function test-getPetById that expects an integer parameter petId.
- Invoke the function with a valid integer value (e.g., 4).
- Observe the error in the logs.
Expected behavior
The function should correctly convert the System.Text.Json.JsonElement to the expected integer type and execute without errors.
Screenshots
If applicable, add screenshots to help explain your problem.
Platform
- Language: C#
- Source: main
- AI model: OpenAI:GPT-4o-mini
- IDE: VS Code
- OS: Mac
Additional context
fail: Microsoft.SemanticKernel.OpenApiKernelExtensions[0]
RestAPI function test.getPetById execution failed with error Argument type 'System.Text.Json.JsonElement' is not convertible to parameter type 'integer'. (Parameter 'petId')
Actual value was 4. (Parameter 'petId')
Actual value was 4.
System.ArgumentOutOfRangeException: Argument type 'System.Text.Json.JsonElement' is not convertible to parameter type 'integer'. (Parameter 'petId')
Actual value was 4. (Parameter 'petId')
Actual value was 4.
at Microsoft.SemanticKernel.Plugins.OpenApi.OpenApiTypeConverter.Convert(String name, String type, Object argument, KernelJsonSchema schema)
at Microsoft.SemanticKernel.Plugins.OpenApi.RestApiOperation.BuildPath(String pathTemplate, IDictionary`2 arguments)
at Microsoft.SemanticKernel.Plugins.OpenApi.RestApiOperation.BuildOperationUrl(IDictionary`2 arguments, Uri serverUrlOverride, Uri apiHostUrl)
at Microsoft.SemanticKernel.Plugins.OpenApi.RestApiOperationRunner.BuildsOperationUrl(RestApiOperation operation, IDictionary`2 arguments, Uri serverUrlOverride, Uri apiHostUrl)
at Microsoft.SemanticKernel.Plugins.OpenApi.RestApiOperationRunner.RunAsync(RestApiOperation operation, KernelArguments arguments, RestApiOperationRunOptions options, CancellationToken cancellationToken)
at Microsoft.SemanticKernel.Plugins.OpenApi.OpenApiKernelPluginFactory.<>c__DisplayClass6_0.<<CreateRestApiFunction>g__ExecuteAsync|0>d.MoveNext()
/pet/{petId}:
get:
tags:
- "pet"
summary: "Find pet by ID"
description: "Returns a single pet"
operationId: "getPetById"
produces:
- "application/xml"
- "application/json"
parameters:
- name: "petId"
in: "path"
description: "ID of pet to return"
required: true
type: "integer"
format: "int64"
responses:
"200":
description: "successful operation"
schema:
$ref: "#/definitions/Pet"
"400":
description: "Invalid ID supplied"
"404":
description: "Pet not found"
security:
- api_key: []