fix(tools): normalize truly empty MCP tool schemas for OpenAI#60176
Conversation
Greptile SummaryAdds a missing normalization branch in Confidence Score: 5/5Safe to merge — the fix is minimal, correctly guarded, and covered by a new test. The new condition fires only after confirming neither No files require special attention. Reviews (1): Last reviewed commit: "fix(tools): normalize truly empty MCP to..." | Re-trigger Greptile |
Fixes openclaw#60158 MCP tools with parameter-free schemas may return truly empty objects `{}` without a `type` field. The existing normalization handled `{ type: "object" }` → `{ type: "object", properties: {} }` but missed the truly empty case. OpenAI gpt-5.4 rejects tool schemas without `type: "object"` and `properties`, causing HTTP 400 errors: ``` Invalid schema for function 'flux-mcp__get_flux_instance': In context=(), object schema missing properties. ``` This change catches empty schemas (no type, no properties, no unions) before the final pass-through and converts them to the required format. Added test case for parameter-free MCP tool schemas.
751773a to
90633d8
Compare
|
Related work from PRtags group Title: Open PR duplicate: MCP schema properties + auto-reset override self-heal composite
|
|
Thank you @steipete for landing it! Glad the fix was clean — the truly-empty |
…o OpenAI (openclaw#75362) MCP servers may return inputSchema as { type: "object" } without a properties field, or with properties set to undefined/null. The hasTopLevelObjectSchema guard only checked 'properties' in schemaRecord (key existence) without verifying the value is a real object. This caused such schemas to pass through unnormalized, resulting in OpenAI rejecting them with 'object schema missing properties'. Fix: tighten hasTopLevelObjectSchema to require properties to be a non-null object, and broaden isTypedSchemaMissingProperties to catch properties keys with undefined/null values. Regression of openclaw#60158 (originally fixed by openclaw#60176).
…o OpenAI (#75362) MCP servers may return inputSchema as { type: "object" } without a properties field, or with properties set to undefined/null. The hasTopLevelObjectSchema guard only checked 'properties' in schemaRecord (key existence) without verifying the value is a real object. This caused such schemas to pass through unnormalized, resulting in OpenAI rejecting them with 'object schema missing properties'. Fix: tighten hasTopLevelObjectSchema to require properties to be a non-null object, and broaden isTypedSchemaMissingProperties to catch properties keys with undefined/null values. Regression of #60158 (originally fixed by #60176).
…o OpenAI (openclaw#75362) MCP servers may return inputSchema as { type: "object" } without a properties field, or with properties set to undefined/null. The hasTopLevelObjectSchema guard only checked 'properties' in schemaRecord (key existence) without verifying the value is a real object. This caused such schemas to pass through unnormalized, resulting in OpenAI rejecting them with 'object schema missing properties'. Fix: tighten hasTopLevelObjectSchema to require properties to be a non-null object, and broaden isTypedSchemaMissingProperties to catch properties keys with undefined/null values. Regression of openclaw#60158 (originally fixed by openclaw#60176).
…o OpenAI (openclaw#75362) MCP servers may return inputSchema as { type: "object" } without a properties field, or with properties set to undefined/null. The hasTopLevelObjectSchema guard only checked 'properties' in schemaRecord (key existence) without verifying the value is a real object. This caused such schemas to pass through unnormalized, resulting in OpenAI rejecting them with 'object schema missing properties'. Fix: tighten hasTopLevelObjectSchema to require properties to be a non-null object, and broaden isTypedSchemaMissingProperties to catch properties keys with undefined/null values. Regression of openclaw#60158 (originally fixed by openclaw#60176).
…o OpenAI (openclaw#75362) MCP servers may return inputSchema as { type: "object" } without a properties field, or with properties set to undefined/null. The hasTopLevelObjectSchema guard only checked 'properties' in schemaRecord (key existence) without verifying the value is a real object. This caused such schemas to pass through unnormalized, resulting in OpenAI rejecting them with 'object schema missing properties'. Fix: tighten hasTopLevelObjectSchema to require properties to be a non-null object, and broaden isTypedSchemaMissingProperties to catch properties keys with undefined/null values. Regression of openclaw#60158 (originally fixed by openclaw#60176).
…o OpenAI (openclaw#75362) MCP servers may return inputSchema as { type: "object" } without a properties field, or with properties set to undefined/null. The hasTopLevelObjectSchema guard only checked 'properties' in schemaRecord (key existence) without verifying the value is a real object. This caused such schemas to pass through unnormalized, resulting in OpenAI rejecting them with 'object schema missing properties'. Fix: tighten hasTopLevelObjectSchema to require properties to be a non-null object, and broaden isTypedSchemaMissingProperties to catch properties keys with undefined/null values. Regression of openclaw#60158 (originally fixed by openclaw#60176).
…o OpenAI (openclaw#75362) MCP servers may return inputSchema as { type: "object" } without a properties field, or with properties set to undefined/null. The hasTopLevelObjectSchema guard only checked 'properties' in schemaRecord (key existence) without verifying the value is a real object. This caused such schemas to pass through unnormalized, resulting in OpenAI rejecting them with 'object schema missing properties'. Fix: tighten hasTopLevelObjectSchema to require properties to be a non-null object, and broaden isTypedSchemaMissingProperties to catch properties keys with undefined/null values. Regression of openclaw#60158 (originally fixed by openclaw#60176).
Summary
Fixes #60158
MCP tools with parameter-free schemas may return truly empty objects
{}without atypefield. The existing normalization handled{ type: "object" }→{ type: "object", properties: {} }but missed the truly empty case.Problem
OpenAI gpt-5.4 rejects tool schemas without
type: "object"andproperties, causing HTTP 400 errors:This was happening for MCP tools like
flux-operator-mcpthat expose parameter-free tool schemas.Root Cause
The
normalizeToolParameterSchemafunction inpi-tools.schema.tshandled three cases:typeandproperties→ pass throughtypebut withpropertiesorrequired→ addtype: "object"typebut noproperties→ addproperties: {}But it did not handle truly empty schemas
{}that have neithertypenorproperties. These fell through to the finalreturn schemawithout normalization.Fix
Added a condition before the final pass-through to catch empty schemas (no type, no properties, no unions) and normalize them to
{ type: "object", properties: {} }.Testing