Skip to content

[BUG] McpToolFilter.Serialization.cs does not deserialize MCP tool allowed_tools of type array #880

@sakoll

Description

@sakoll

Describe the bug

Based on OpenAI API Reference for Responses API here, the allowed_tools can be an array or object. However the SDK is not deserializing array type and ending up with this error

System.InvalidOperationException: The requested operation requires an element of type 'Object', but the target element has type 'Array'.
at System.Text.Json.ThrowHelper.ThrowJsonElementWrongTypeException(JsonTokenType expectedType, JsonTokenType actualType)
at System.Text.Json.JsonElement.EnumerateObject()
at OpenAI.Responses.McpToolFilter.DeserializeMcpToolFilter(JsonElement element, ModelReaderWriterOptions options)
at OpenAI.Responses.McpTool.DeserializeMcpTool(JsonElement element, ModelReaderWriterOptions options)
at OpenAI.Responses.ResponseTool.DeserializeResponseTool(JsonElement element, ModelReaderWriterOptions options)
at OpenAI.Responses.InternalUnknownTool.PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
at OpenAI.Responses.InternalUnknownTool.System.ClientModel.Primitives.IPersistableModel<OpenAI.Responses.ResponseTool>.Create(BinaryData data, ModelReaderWriterOptions options)

Steps to reproduce

As described in description, create a model response with MCP tool allowed_tools of array type and use SDK to retrieve it

Code snippets

OS

Windows

.NET version

8

Library version

2.5

Metadata

Metadata

Assignees

Labels

area: responsesThis item is related to ResponsesbugCategory: Something isn't working and appears to be a defect in the client library.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions