Skip to content

Optional empty fields are sent as empty strings #623

@ln-12

Description

@ln-12

Describe the bug
This might be a follow-up to #480. I noticed that initially the inspector correctly omits values in the request that are optional and not filled out. However, when I change the value to something and then remove the value again (so I have an empty textfield), the inspector sends "" instead of not sending the value at all.

To Reproduce
Steps to reproduce the behavior (simplified):

  1. Using the Go SDK, I have the following argument definition:
Price         uint32   `json:"price,omitempty" jsonschema:"Some description"`
  1. When running List Tools, I get the expected result:
{
  "tools": [
    {
      "name": "search",
      "description": "Something",
      "inputSchema": {
        "type": "object",
        "properties": {
          "price": {
            "type": "integer",
            "description": "Some description"
          }
        },
        "required": [],
        "additionalProperties": {
          "not": {}
        }
      },
    }
  ]
}
  1. Invoking the tool, I see the correct request not containing the argument:
{
  "method": "tools/call",
  "params": {
    "name": "search",
    "arguments": {},
    "_meta": {
      "progressToken": 0
    }
  }
}
  1. Afterwards I write 0 in the price field and delete it again. If I now run the tool again, an empty string is sent for the integer price field.
{
  "method": "tools/call",
  "params": {
    "name": "search",
    "arguments": {
      "price": "",
    },
    "_meta": {
      "progressToken": 1
    }
  }
}

Expected behavior
If I enter anything for an optional field and delete the value again, it should not be sent in the request (like initially).

Additional context
I tested both v0.16.1 and the latest commit from this repository. Both have the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions