Skip to content

Empty object {} parameters fails InputValidator with "input is not of type object" #116

@Middelthon

Description

@Middelthon

Description

When calling an ability via MCP Adapter with an empty object {} as parameters, the InputValidator incorrectly rejects it with the error message "input er ikke av typen object" (Norwegian: "input is not of type object").

This happens despite {} being a valid JSON object that should pass validation for abilities with optional properties.

Steps to Reproduce

  1. Register an ability with optional properties in input_schema:
wp_register_ability( 'example/get-info', array(
    'input_schema' => array(
        'type'       => 'object',
        'properties' => array(
            'fields' => array(
                'type'  => 'array',
                'items' => array( 'type' => 'string' ),
            ),
        ),
    ),
    // ... other config
) );
  1. Call the ability with empty parameters:
{
    "ability_name": "example/get-info",
    "parameters": {}
}
  1. Expected: Ability executes successfully (no required properties)
  2. Actual: Error: Ability "example/get-info" has invalid input. Reason: input is not of type object.

Workaround

Passing any property value (even empty) works:

{
    "ability_name": "example/get-info",
    "parameters": {"fields": []}
}

Environment

  • MCP Adapter version: 0.4.1
  • WordPress version: 6.9
  • PHP version: 8.x
  • MCP Client: Claude Desktop (via claude.ai MCP integration)

Analysis

The issue appears to be in the InputValidator logic that checks if the input is of type "object". An empty object {} should be considered a valid object, but the validator seems to be treating it as invalid (possibly checking for non-empty or using empty() which returns true for {}).

Related Issues

Suggested Fix

The InputValidator should accept empty objects {} as valid when:

  1. The schema type is "object"
  2. There are no required properties
  3. The input is actually an object (even if empty)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions