NewToolFromHandler creates a ServerTool that retrieves ToolDependencies from context at call time. Use this when you have a handler that conforms to mcp.ToolHandler directly. The handler function receives deps extracted from context via MustDepsFromContext. Ensure ContextWithDeps is called to injec
( toolset inventory.ToolsetMetadata, tool mcp.Tool, requiredScopes []scopes.Scope, handler func(ctx context.Context, deps ToolDependencies, req *mcp.CallToolRequest) (*mcp.CallToolResult, error), )
| 248 | // requiredScopes specifies the minimum OAuth scopes needed for this tool. |
| 249 | // AcceptedScopes are automatically derived using the scope hierarchy. |
| 250 | func NewToolFromHandler( |
| 251 | toolset inventory.ToolsetMetadata, |
| 252 | tool mcp.Tool, |
| 253 | requiredScopes []scopes.Scope, |
| 254 | handler func(ctx context.Context, deps ToolDependencies, req *mcp.CallToolRequest) (*mcp.CallToolResult, error), |
| 255 | ) inventory.ServerTool { |
| 256 | st := inventory.NewServerTool(tool, toolset, func(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) { |
| 257 | deps := MustDepsFromContext(ctx) |
| 258 | return handler(ctx, deps, req) |
| 259 | }) |
| 260 | st.RequiredScopes = scopes.ToStringSlice(requiredScopes...) |
| 261 | st.AcceptedScopes = scopes.ExpandScopes(requiredScopes...) |
| 262 | return st |
| 263 | } |
| 264 | |
| 265 | type RequestDeps struct { |
| 266 | // Static dependencies |
nothing calls this directly
no test coverage detected