Skip to content

Conversation

@pedro-inf-custodio
Copy link

Description

This PR fixes an openai.BadRequestError that occurs when an MCP tool provides an inputSchema with "type": "object" but omits the required "properties" key.

Problem

When using langchain-mcp-adapter with 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-server tool aws_knowledge_aws___list_regions provides this schema:

"parameters": {
  "type": "object"
}

This causes the OpenAI API to return a 400 error, as it strictly requires a properties key for any object schema:

openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid schema for function 'ecs_mcp_server_aws_knowledge_aws___list_regions': In context=(), object schema missing properties.", 'type': 'invalid_request_error', 'param': 'tools[4].function.parameters', 'code': 'invalid_function_parameters'}}

Solution

This patch updates the tool conversion logic within the adapter. It checks if an inputSchema's parameters are 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 BadRequestError and allows tools with no arguments to be used successfully with OpenAI models.

@pedro-inf-custodio pedro-inf-custodio changed the title fix: ensure inputSchema has properties key for object type tools Fix: Default empty object schema parameters to include properties: {} for OpenAI compatibility Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant