Implement Dynamic Tool Filtering by Query String
mainTo expose different tool sets based on URL query parameters, implement the DynamicToolResolverInterface.
declaredTools(McpEndpointDefinition $endpoint): Returns the full catalog of tools available to this endpoint.resolve(McpEndpointDefinition $endpoint, ToolResolutionContext $context): Returns the specific subset of tools visible for the current request based on$context->queryParameters.consumedQueryParameters(): (Optional convention) List query keys that should be used for filtering but not forwarded as tool arguments. If omitted, these keys are forwarded as arguments.
Register the resolver using ->dynamicTools(YourResolver::class) on the route.
use OPGG\LaravelMcpServer\Data\ToolResolutionContext;
use OPGG\LaravelMcpServer\Routing\McpEndpointDefinition;
use OPGG\LaravelMcpServer\Services\ToolService\DynamicToolResolverInterface;
final class LolPhaseToolResolver implements DynamicToolResolverInterface
{
public function declaredTools(McpEndpointDefinition $endpoint): array
{
return [
\App\MCP\Tools\LolSearchChampionMetaTool::class,
\App\MCP\Tools\LolGetChampionAnalysisTool::class,
\App\MCP\Tools\LolGetLiveItemRecommendationsTool::class,
];
}
public function resolve(
McpEndpointDefinition $endpoint,
ToolResolutionContext $context,
): array {
return match ($context->queryParameters['phase'] ?? null) {
'lobby' => [
\App\MCP\Tools\LolSearchChampionMetaTool::class,
\App\MCP\Tools\LolGetChampionAnalysisTool::class,
],
'inprogress' => [
\App\MCP\Tools\LolGetLiveItemRecommendationsTool::class,
],
default => $this->declaredTools($endpoint),
};
}
public function consumedQueryParameters(): array
{
return ['phase'];
}
}
// Registration
Route::mcp('/mcp/voice/lol/live')
->setServerInfo(
name: 'OP.GG MCP Server - Voice lol Live',
version: '1.0.0',
)
->dynamicTools(LolPhaseToolResolver::class);