How do you control which parameters are included in a tool's request schema? #578
-
Pre-submission Checklist
Question Category
Your QuestionI have the following types: public abstract record ToolRequest {
[JsonPropertyName("reason")]
[Description("A **SHORT** (1-2 sentences max.) plain text explanation for why the agent is calling the tool.")]
public required string Reason { get; init; }
}
public sealed record CurrentTimeGetRequest : ToolRequest { }
[McpServerToolType]
public static class MyTools {
[McpServerTool(Name = "get_current_time")]
[Description("Gets the current UTC date and time.")]
public static DateTimeOffset GetCurrentTime(CurrentTimeGetRequest request, TimeProvider timeProvider) => timeProvider.GetUtcNow();
}The {
"name": "get_current_time",
"title": null,
"description": "Gets the current UTC date and time.",
"inputSchema": {
"type": "object",
"properties": {
"request": {
"type": "object",
"properties": {
"reason": {
"description": "A **SHORT** (1-2 sentences max.) plain text explanation for why the agent is calling the tool.",
"type": "string"
}
},
"required": [
"reason"
]
},
"timeProvider": {
"type": "object",
"properties": {
"localTimeZone": {
"type": [
"object",
"null"
],
"properties": {
"id": {
"type": [
"string",
"null"
]
},
"hasIanaId": {
"type": "boolean"
},
"displayName": {
"type": [
"string",
"null"
]
},
"standardName": {
"type": [
"string",
"null"
]
},
"daylightName": {
"type": [
"string",
"null"
]
},
"baseUtcOffset": {
"$comment": "Represents a System.TimeSpan value.",
"type": "string"
},
"supportsDaylightSavingTime": {
"type": "boolean"
}
}
},
"timestampFrequency": {
"type": "integer"
}
}
}
},
"required": [
"request",
"timeProvider"
]
},
"outputSchema": null,
"annotations": null,
"_meta": null
}How does the SDK decide which parameters to include in the schema? Is there any way that I can make it ignore parameters that come from DI without switching from attribute-based tool registration to manual tool registration? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
I believe the best way to do this is by accepting |
Beta Was this translation helpful? Give feedback.
-
|
Okay, I've figured out the answer. I had assumed that var builder = WebApplication.CreateBuilder();
builder.Services.AddAuthentication();
await using var app = builder.Build();
var isRegistered = app.Services.GetRequiredService<IServiceProviderIsService>().IsService(typeof(TimeProvider));
Console.WriteLine(isRegistered); // truevar builder = WebApplication.CreateBuilder();
//builder.Services.AddAuthentication();
await using var app = builder.Build();
var isRegistered = app.Services.GetRequiredService<IServiceProviderIsService>().IsService(typeof(TimeProvider));
Console.WriteLine(isRegistered); // falseIn my server app I have not implemented authentication yet, so |
Beta Was this translation helpful? Give feedback.
Okay, I've figured out the answer. I had assumed that
TimeProviderwas added to the service collection by default when creating the web application builder, but is actually only registered when you add authentication services to the builder: