setServerInfo('Merchant MCP', '1.0.0') ->addTool( handler: function () use ($token): array { $client = new Client([ 'timeout' => 10, ]); $response = $client->get( 'https://tpoint.agrimedia.cn/adminapi/offline/list', [ 'headers' => [ 'accept' => 'application/json', 'authori-zation' => 'Bearer ' . $token, ], 'query' => [ 'status' => -1, 'field_key' => 'all', 'page' => 1, 'limit' => 100, 'time' => '2026/06/23-2026/06/23', ], ] ); $data = json_decode( (string) $response->getBody(), true ); $orders = $data['data']['list'] ?? []; $activeMerchants = []; $successOrderCount = 0; $totalOrderAmount = 0.0; $totalRealPay = 0.0; foreach ($orders as $order) { $merchantId = (int) ($order['merchant_id'] ?? 0); if ($merchantId > 0) { $activeMerchants[$merchantId] = true; } /* * 这里暂时按 status = 1 作为成功订单。 * 后面再确认你项目的真实状态含义。 */ if ((int) ($order['status'] ?? -1) === 1) { $successOrderCount++; } $totalOrderAmount += (float) ($order['order_price'] ?? 0); $totalRealPay += (float) ($order['real_pay'] ?? 0); } return [ 'orderCount' => count($orders), 'activeMerchantCount' => count($activeMerchants), 'successOrderCount' => $successOrderCount, 'totalOrderAmount' => round($totalOrderAmount, 2), 'totalRealPay' => round($totalRealPay, 2), ]; }, name: 'get_order_summary', description: '获取订单总数、活跃商户数、成功订单数和金额统计' ) ->build(); $transport = new StdioTransport(); $server->run($transport);