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

No one assigned

    Labels

    area: externalThis issue is regarding an external experience, such as a companion service or client.issue-addressedWorkflow: The OpenAI maintainers believe the issue to be addressed and ready to close.questionCategory: The issue is seeking information about the library or its usage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions