Description
Tagging experts here! @halter73 @stephentoub
Hello! I have such a tool
public CallToolResponse testTool(Foo foo)
{
return new CallToolResponse()
{
Content = [new Content { Text = "hello") }],
IsError = false
};
}
Note that Foo class is NOT my source code, it lies in a third-party package, which I can't control at all. It's a complex class having nested classes as childs and also inherits from other class, like
class ParentOfFoo
{
string myStr;
}
class Foo : ParentOfFoo
{
Bar bar;
}
class Bar
{
Baz baz;
}
class Baz
{
int myInt;
}
For sure, there isn't any [Description]
attribute in the third-party code, by default, the InputSchema
generated by sdk will be like.
{
"name": "test_tool",
"description": "A test tool that accepts a Foo object and returns a hello world string",
"inputSchema": {
"title": "test_tool",
"description": "A test tool that accepts a Foo object and returns a hello world string",
"type": "object",
"properties": {
"foo": {
"description": "The Foo object containing nested Bar and Baz objects",
"type": "object",
"properties": {
"bar": {
"type": "object",
"properties": {
"baz": {
"type": "object",
"properties": {
"myInt": {
"type": "integer"
}
}
}
}
},
"myStr": {
"type": "string"
}
}
}
},
"required": [
"foo"
]
}
}
My requirement: add [Description]
on each field of the third-party classes, similar like(note: I can't modify their source code, just for illustration here). I need add descriptions for AI to understand schema for each single field.
class ParentOfFoo
{
[Description("XXX")]
string myStr;
}
class Foo : ParentOfFoo
{
[Description("XXX")]
Bar bar;
}
class Bar
{
[Description("XXX")]
Baz baz;
}
class Baz
{
[Description("XXX")]
int myInt;
}
I expect to see inputschema is like
{
"name": "test_tool",
"description": "A test tool that accepts a Foo object and returns a hello world string",
"inputSchema": {
"title": "test_tool",
"description": "A test tool that accepts a Foo object and returns a hello world string",
"type": "object",
"properties": {
"foo": {
"description": "The Foo object containing nested Bar and Baz objects",
"type": "object",
"properties": {
"bar": {
"type": "object",
"description": "XXX",
"properties": {
"baz": {
"type": "object",
"description": "XXX"
"properties": {
"myInt": {
"type": "integer",
"description": "XXX"
}
}
}
}
},
"myStr": {
"type": "string",
"description": "XXX"
}
}
}
},
"required": [
"foo"
]
}
}
Is there an elegant way to achieve? I have some hacky and bad ideas, like creating my own facade class (adding description) based on the third party class, and use it as tool input. I would have hunderds of tools in one mcp server, need an elegant and efficient way .