Amba

Leaderboards

Rank users by XP, streak length, or custom metrics with all-time, daily, weekly, and monthly periods.

Leaderboards rank users by a metric over a time period. Great for adding competitive elements to your app.

How it works

  1. Admin defines a leaderboard with a metric (XP, streak, or custom event count) and period
  2. Entries are updated automatically as users earn XP, maintain streaks, or track events
  3. The client SDK fetches ranked entries and the current user's position

SDK usage

List leaderboards

const leaderboards = await client.leaderboards.getAll();

Get leaderboard entries

const entries = await client.leaderboards.getEntries('lb_xxx', {
  limit: 50,
  offset: 0,
});
// Returns ranked entries with user display names and avatars

Get my rank

const myRank = await client.leaderboards.getMyRank('lb_xxx');
// Returns: { rank: 12, score: 1500, app_user_id: "..." }

Metrics

MetricDescription
xpTotal XP earned (within period)
streakLongest streak (within period)
customCount of a specific event

Periods

PeriodDescription
all_timeCumulative, never resets
dailyResets every day at midnight UTC
weeklyResets every Monday at midnight UTC
monthlyResets on the 1st of each month

Admin API reference

MethodPathDescription
POST/admin/leaderboardsCreate leaderboard
GET/admin/leaderboardsList leaderboards
GET/admin/leaderboards/:id/entriesGet ranked entries

Client API reference

MethodPathDescription
GET/client/leaderboardsList active leaderboards
GET/client/leaderboards/:idGet entries (paginated, ranked)
GET/client/leaderboards/:id/meGet current user's rank

MCP tools

ToolDescription
amba_create_leaderboardCreate a leaderboard with metric, period, and max entries
amba_get_leaderboardGet leaderboard entries with user details

Example

Agent: "Create weekly and all-time XP leaderboards"

amba_create_leaderboard({
  project_id: "proj_xxx",
  name: "Weekly Top Earners",
  metric: "xp",
  period: "weekly",
  max_entries: 100
})

amba_create_leaderboard({
  project_id: "proj_xxx",
  name: "All-Time XP Leaders",
  metric: "xp",
  period: "all_time",
  max_entries: 100
})

Database tables

TablePurpose
leaderboard_definitionsLeaderboard config with metric, period, max entries
leaderboard_entriesRanked entries with score, user ID, and rank

On this page