Closed
Description
Is your feature request related to a problem? Please describe.
Currently, discovery of tools using [McpToolType]
and [McpTool]
is only supported for public static methods (ref). It would be useful to also support instance methods when the class is registered in DI.
Describe the solution you'd like
Program.cs
var builder = Host.CreateApplicationBuilder(args);
builder.AddHttpClient<TodoApi>(c => c.BaseAddress = new Uri("...")); // for example
builder.AddMcpServer().WithStdioServerTransport().WithTools();
await builder.Build().RunAsync();
TodoApi.cs
// it'd be nice to this was automatically added to the MCP tool list.
[McpToolType]
public class TodoApi(HttpClient httpClient)
{
[McpTool("getTodoList")]
[Description("Gets the user's todo list.")]
public async Task<TodoList[]> GetTodoListAsync(CancellationToken ct)
{
var todos = await httpClient.GetFromJsonAsync<TodoList[]>("todos", ct);
return todos ?? [];
}
}
Describe alternatives you've considered
There is currently an option to manually configure the ServerCapabilities.Tools
, so this is a workaround.