Skip to content

Support discovery of tools that use DI with McpTool attribute #80

Closed
@erinnmclaughlin

Description

@erinnmclaughlin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions