Skip to content

How to create tools with optional params #1388

@mukuagar

Description

@mukuagar

Question

I was creating a mcp server that has tools which has multiple params, in which most are optional, how do I represent this
Currently what I was doing is

param1: Optional[str] = Field(default=None, description="desc of param"),
    param2: Optional[str] = Field(default=None, description="desc of param 2")

The way it appears in inspector is:

"param1": {
  "anyOf": [
    {
      "type": "string"
    },
    {
      "type": "null"
    }
  ],
  "default": null,
  "description": "desc of param",
  "title": "param1"
},
"param2": {
  "anyOf": [
    {
      "type": "string"
    },
    {
      "type": "null"
    }
  ],
  "default": null,
  "description": "desc of param 2",
  "title": "param2"
}

Is this the right expectation with the anyOf block, or should that not exist?

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions