Skip to content
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

Add [McpServerTool] support for instance methods #100

Merged

Conversation

stephentoub
Copy link
Contributor

By popular demand, enables [McpServerTool] on instance methods. The instance is constructed per invocation, using ActivatorUtilities.CreateInstance when possible so that constructor arguments are satisfied from DI.

Ports dotnet/extensions#6193 to the temporary AIFunctionFactory polyfill.

By popular demand, enables [McpServerTool] on instance methods. The instance is constructed per invocation, using ActivatorUtilities.CreateInstance when possible so that constructor arguments are satisfied from DI.
Copy link
Contributor

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It might be worth adding tests around tool lifecycle to verify that it's created and disposed per-invocation, but I understand that we're moving quickly.

Edit: I see Can_Call_Registered_Tool_With_Instance_Method would fail if it did not create an instance per-invocation, but verifying it gets disposed would be nice. And possibly verify that we don't try to resolve the tool directly from the container.

@stephentoub
Copy link
Contributor Author

@halter73, can you also review dotnet/extensions#6193 ? I'd like to hold off on merging this until I know that's going in.

@stephentoub stephentoub merged commit b61cdef into modelcontextprotocol:main Mar 26, 2025
8 checks passed
@stephentoub stephentoub deleted the mcpservertoolinstance branch March 26, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants