Fix: Default empty object schema parameters to include properties: {} for OpenAI compatibility
#343
+40
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an
openai.BadRequestErrorthat occurs when an MCP tool provides aninputSchemawith"type": "object"but omits the required"properties"key.Problem
When using
langchain-mcp-adapterwith an OpenAI model (like Azure OpenAI) in LangGraph, any MCP tool that takes no arguments but defines its schema as just"type": "object"will fail validation.For example, the
ecs-mcp-servertoolaws_knowledge_aws___list_regionsprovides this schema:This causes the OpenAI API to return a 400 error, as it strictly requires a
propertieskey for any object schema:Solution
This patch updates the tool conversion logic within the adapter. It checks if an
inputSchema'sparametersare of"type": "object"and lack a"properties"key. If so, it automatically adds an empty"properties": {}field.This ensures that a schema like:
"parameters": { "type": "object" }Is correctly converted to the OpenAI-compliant schema:
"parameters": { "type": "object", "properties": {} }This change resolves the
BadRequestErrorand allows tools with no arguments to be used successfully with OpenAI models.