Skip to content

DataAnnotations on tools arguments ignored #796

@6bee

Description

@6bee

Describe the bug
While data model properties within tools arguments allow DataAnnotations which are reflected in json schema, annotations on tools arguments are ignored.

To Reproduce
Steps to reproduce the behavior:

  1. add McpServerTool with and without annotated parameter

mcp server tool

[McpServerToolType]
public sealed class TestTool
{
    [McpServerTool]
    public string Echo1([MinLength(3), RegularExpression(@"[a-z]*")] string input) => input;

    [McpServerTool]
    public string Echo2(Message input) => input.value;
}

public readonly record struct Message([property: MinLength(3), RegularExpression(@"[a-z]*")] string value);

json schema returned by tools/list

{
  "tools": [
    {
      "name": "echo2",
      "description": "",
      "inputSchema": {
        "type": "object",
        "properties": {
          "input": {
            "type": "object",
            "properties": {
              "value": {
                "type": "string",
                "pattern": "[a-z]*",
                "minLength": 3
              }
            }
          }
        },
        "required": [
          "input"
        ]
      }
    },
    {
      "name": "echo1",
      "description": "",
      "inputSchema": {
        "type": "object",
        "properties": {
          "input": {
            "type": "string"
          }
        },
        "required": [
          "input"
        ]
      }
    }
  ]
}

Expected behavior
Data annotations on tools arguments should be applied the same way they are on the rest of the data model.

Logs
none

Additional context
n/a

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