inspector icon indicating copy to clipboard operation
inspector copied to clipboard

fix: Restore JSONForm array when all items are simple items

Open max-stytch opened this issue 7 months ago • 1 comments

Motivation and Context

Partially resolves of #332 - this PR restores the array logic that was removed in #284, but only when all nested objects are also "simple" objects.

How Has This Been Tested?

Validated against the JSON schema in this comment - nested items are rendered appropriately image

Breaking Changes

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Documentation update

Checklist

  • [ ] I have read the MCP Documentation
  • [ ] My code follows the repository's style guidelines
  • [ ] New and existing tests pass locally
  • [ ] I have added appropriate error handling
  • [ ] I have added or updated documentation as needed

Additional context

max-stytch avatar May 24 '25 21:05 max-stytch

Hi @max-stytch I tried testing with a schema based on the shape you linked to but when I click the Add Item button, it doesn't show a field like it does in your screenshot. Have I got the schema wrong?

Screenshot 2025-05-27 at 10 50 47 AM

https://github.com/user-attachments/assets/986f465f-c40c-4c5e-a375-f9edfd85d6d9

cliffhall avatar May 27 '25 14:05 cliffhall

Hi @max-stytch we merged a larger set of changes here which I think will have addressed both this and the required issue that you pointed out: https://github.com/modelcontextprotocol/inspector/pull/480

olaservo avatar Jun 28 '25 04:06 olaservo

Amazing!

On Fri, Jun 27, 2025 at 9:09 PM Ola Hungerford @.***> wrote:

olaservo left a comment (modelcontextprotocol/inspector#434) https://github.com/modelcontextprotocol/inspector/pull/434#issuecomment-3014926777

Hi @max-stytch https://github.com/max-stytch we merged a larger set of changes here which I think will have addressed both this and the required issue that you pointed out: #480 https://github.com/modelcontextprotocol/inspector/pull/480

— Reply to this email directly, view it on GitHub https://github.com/modelcontextprotocol/inspector/pull/434#issuecomment-3014926777, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVOFOTYI3PQRH5FISY2MZO33FYIRDAVCNFSM6AAAAAB526K32CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMJUHEZDMNZXG4 . You are receiving this because you were mentioned.Message ID: @.***>

max-stytch avatar Jun 28 '25 13:06 max-stytch

@max-stytch I think there were some crossed wires here. @olaservo's comment that led you to close this I think was mistaken. This was about the form handling and #480 was about fixing a problem where we had the required field as a boolean rather than an array. I think we still need this. We also need a tool in the everything server that has a complex inputSchema to test with.

cliffhall avatar Aug 07 '25 20:08 cliffhall

I was doing unrelated inputSchema investigation with a testing server and tool, and had taken note of this issue, so I checked the form rendering. I think the form for arrays is fixed.

There is a slight quirk, that objects with typed properties do not initialize default values the same as primitive fields. Skimming the code, I think this is because in the object case getArrayItemDefault() is not called for the default values of the types of the object properties. Also, the typed_objects object case might be sorted out by inspecting additionalProperties, not properties. All of this is in isSimpleObject().

Here's the tool schema, and a screenshot of the form. (I added alternating bounding boxes in the screenshot just to make the form layout clearer. I think the layout can be improved.)

I can add such a tool to the Everything Server.

{
  "tools": [
    {
      "name": "complex_input_schema_tool",
      "description": "Tool that handles complex input schemas with mixed-type arrays.",
      "inputSchema": {
        "type": "object",
        "properties": {
          "numbers": {
            "description": "An array of numbers",
            "items": {
              "type": "number"
            },
            "title": "Numbers",
            "type": "array"
          },
          "strings": {
            "description": "An array of strings",
            "items": {
              "type": "string"
            },
            "title": "Strings",
            "type": "array"
          },
          "objects": {
            "description": "An array of objects (dicts)",
            "items": {
              "additionalProperties": true,
              "type": "object"
            },
            "title": "Objects",
            "type": "array"
          },
          "typed_objects": {
            "description": "An array of objects with 'word' (str) and 'length' (int) properties",
            "items": {
              "additionalProperties": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "integer"
                  }
                ]
              },
              "type": "object"
            },
            "title": "Typed Objects",
            "type": "array"
          },
          "structured_objects": {
            "description": "An array of structured objects with defined word and length properties",
            "items": {
              "properties": {
                "word": {
                  "title": "Word",
                  "type": "string"
                },
                "length": {
                  "title": "Length",
                  "type": "integer"
                }
              },
              "required": [
                "word",
                "length"
              ],
              "title": "WordItem",
              "type": "object"
            },
            "title": "Structured Objects",
            "type": "array"
          },
          "mixed": {
            "description": "An array of non-uniform types (int, str, bool, dict, etc.)",
            "items": {},
            "title": "Mixed",
            "type": "array"
          },
          "str_and_int": {
            "description": "An array containing only strings and integers",
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "title": "Str And Int",
            "type": "array"
          }
        },
        "required": [
          "numbers",
          "strings",
          "objects",
          "typed_objects",
          "structured_objects",
          "mixed",
          "str_and_int"
        ]
      },
      "outputSchema": {
        "type": "object",
        "properties": {
          "result": {
            "title": "Result",
            "type": "string"
          }
        },
        "required": [
          "result"
        ],
      },
      "_meta": {
        "_fastmcp": {
          "tags": []
        }
      }
    }
  ]
}
Screenshot 2025-08-15 at 00 31 45

richardkmichael avatar Aug 15 '25 07:08 richardkmichael

I was doing unrelated inputSchema investigation with a testing server and tool, and had taken note of this issue, so I checked the form rendering. I think the form for arrays is fixed

@richardkmichael Fixed in the existing Inspector or with this PR?

I can add such a tool to the Everything Server.

This would be nice.

cliffhall avatar Aug 18 '25 18:08 cliffhall

I was doing unrelated inputSchema investigation with a testing server and tool, and had taken note of this issue, so I checked the form rendering. I think the form for arrays is fixed

@richardkmichael Fixed in the existing Inspector or with this PR?

On main, without this PR. (Sorry, I had realized my comment was ambiguous and meant to come back and edit it.)

I can add such a tool to the Everything Server.

This would be nice.

Will do.

richardkmichael avatar Aug 18 '25 19:08 richardkmichael