Skip to content

Non-static classes and methods are not picked up by WithTools() #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GerbenAxendo opened this issue Mar 24, 2025 · 4 comments · Fixed by #89
Closed

Non-static classes and methods are not picked up by WithTools() #79

GerbenAxendo opened this issue Mar 24, 2025 · 4 comments · Fixed by #89
Assignees
Labels
enhancement New feature or request

Comments

@GerbenAxendo
Copy link

GerbenAxendo commented Mar 24, 2025

Non-static classes and methods that are correctly decortated with the [McpToolType] and [McpTool] attribute classes are not picked up. The sample in AspNetCoreSseServer\Tools\SampleLlmTool doesn't seem to work because of this issue. The comment in this class noted "This tool uses depenency injection and async method" - suggesting support for non-static classes and methods.

To Reproduce
Steps to reproduce the behavior:

  1. Run AspNetCoreSseServer\Program.cs
  2. Use MCP Inspector (v0.6.0) against the localhost (transport type SSE)
  3. The tool "SampleLlmTool" is not display in the Tool list, even when Echo (the other sample) is.

Expected behavior
You would expect the tool SampleLLM to appear.

Additional context
Add any other context about the problem here.

@GerbenAxendo GerbenAxendo added the bug Something isn't working label Mar 24, 2025
@GerbenAxendo GerbenAxendo changed the title Non-static classes and methods are not picked up by WithTools Non-static classes and methods are not picked up by WithTools() Mar 24, 2025
@stephentoub
Copy link
Contributor

stephentoub commented Mar 24, 2025

Thanks. We'll fix the sample.

The scenario will soon be supported, once a new build of Microsoft.Extensions.AI is picked up.

At that point, [McpTool]s will be able to specify tool arguments like IServerProvider, IMcpServer, etc., and they'll be supplied from DI / the surrounding context.

We currently do not plan to enable to enable [McpTool] to work with instance methods. Whatever the receiver type would have been can instead be fetched from DI via an argument.

@stephentoub stephentoub added enhancement New feature or request and removed bug Something isn't working labels Mar 24, 2025
@stephentoub stephentoub self-assigned this Mar 24, 2025
@GerbenAxendo
Copy link
Author

@stephentoub I like the speed of this. Let me know if/when I can do some checking.

@stephentoub
Copy link
Contributor

Based on multiple folks asking for it, instance support has now been added. It'll be in the next build (should be published to nuget this week), but you can also build from source to get it immediately. Feedback welcome.

@GerbenAxendo
Copy link
Author

@stephentoub Yes, builded from source yesterday and this works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants