logger->info('SamplingTool instantiated for sampling example.'); } /** * @return array{incident: string, recommended_actions: string, model: string} */ #[McpTool(name: 'coordinate_incident_response', description: 'Coordinate an incident response with logging, progress, and sampling.')] public function coordinateIncident(RequestContext $context, string $incidentTitle): array { $clientGateway = $context->getClientGateway(); $clientGateway->log(LoggingLevel::Warning, \sprintf('Incident triage started: %s', $incidentTitle)); $steps = [ 'Collecting telemetry', 'Assessing scope', 'Coordinating responders', ]; foreach ($steps as $index => $step) { $progress = ($index + 1) / \count($steps); $clientGateway->progress($progress, 1, $step); usleep(180_000); // Simulate work being done } $prompt = \sprintf( 'Provide a concise response strategy for incident "%s" based on the steps completed: %s.', $incidentTitle, implode(', ', $steps) ); $result = $clientGateway->sample($prompt, 350, 90, ['temperature' => 0.5]); $recommendation = $result->content instanceof TextContent ? trim((string) $result->content->text) : ''; $clientGateway->log(LoggingLevel::Info, \sprintf('Incident triage completed for %s', $incidentTitle)); return [ 'incident' => $incidentTitle, 'recommended_actions' => $recommendation, 'model' => $result->model, ]; } }