Skip to main content
Glama
README.md
# lastfm-mcp

An MCP server for **read-only** Last.fm listening history and catalog info. `lastfm-mcp` is packaged as an
[Agent Plugin](https://agent-plugins.org) (a stdio MCP server plus a skill) and ships a CLI over the same core.

It talks to `https://ws.audioscrobbler.com/2.0/?format=json` directly with your own API key. There is no third-party
proxy, no shared secret, no session key, and no write methods (it cannot scrobble or love tracks).

- Zero dependencies. Node.js >= 20. All logic is in `lib/core.mjs`.
- Results come back trimmed to small, stable shapes, not raw Last.fm JSON.

> lastfm-mcp is an independent project. It is not affiliated with, sponsored by, or endorsed by Last.fm.
> "Last.fm" is a trademark of Last.fm Limited and is used here only to describe the API this tool works with.

## Shapes

These are the domain types the tools return (upstream Last.fm JSON is normalized into them):

- **Scrobble** `{ artist, track, album, playedAt, nowPlaying, url }`
- **TopArtist** `{ name, playcount, url, rank }`
- **TopAlbum** `{ name, artist, playcount, url, rank }`
- **TopTrack** `{ name, artist, playcount, url, rank }`
- **LovedTrack** `{ artist, track, url, lovedAt }`
- **UserInfo** `{ name, realname, url, country, playcount, artistCount, trackCount, albumCount, registeredAt }`
- **ArtistInfo** `{ name, url, mbid, listeners, playcount, tags[], similar[{name, url, match}], bio{summary, published}, userPlaycount? }`
- **SimilarArtist** `{ name, url, match }`
- **TrackInfo** `{ name, artist, album, url, mbid, durationMs, listeners, playcount, tags[], userPlaycount?, userLoved? }`
- **SimilarTrack** `{ name, artist, url, match }`
- **WeeklyArtist** `{ name, playcount, url, rank }`
- **WeeklyTrack** `{ name, artist, playcount, url, rank }`
- **ChartRange** `{ from, to, fromAt, toAt }`

`playedAt`, `lovedAt`, `registeredAt`, `fromAt`, and `toAt` are ISO 8601 UTC instants. `from` / `to` on weekly charts
are Unix timestamps in seconds, as Last.fm uses them. Missing values are `null`.

## 1. Get a Last.fm API key

1. Sign in at [Last.fm](https://www.last.fm/) and open [Create an API account](https://www.last.fm/api/account/create).
2. Copy the **API key**. You do **not** need the shared secret; this plugin never authenticates a user session and
   never calls write methods.
3. Set two environment variables (the key is a secret; never commit it or paste it into the repo):

```bash
export LASTFM_API_KEY="your-api-key"
export LASTFM_USERNAME="your-lastfm-username"
```

`LASTFM_USERNAME` is the default for user-scoped tools. You can still pass a `user` argument to read someone else's
public profile and charts. An unexpanded `${LASTFM_API_KEY}` or `${LASTFM_USERNAME}` placeholder counts as unset.

If the key is missing, tools return `api_key_missing` with the setup hint above. If the username is missing on a
user-scoped tool, they return `username_missing`.

## 2. Use it

### CLI (any agent that can run shell commands)

```bash
LFM=/path/to/lastfm-mcp/bin/lastfm-mcp
$LFM tools
$LFM get_user_info
$LFM get_recent_tracks --limit 10
$LFM get_recent_tracks --json '{"from":"2026-11-01T00:00:00Z","to":"2026-11-22T00:00:00Z","limit":50}'
$LFM get_top_artists --period 7day --limit 10
$LFM get_top_albums --period 1month
$LFM get_top_tracks --period overall --limit 20
$LFM get_loved_tracks --limit 20
$LFM get_artist_info --artist 'Bill Evans'
$LFM get_similar_artists --artist 'Bill Evans' --limit 10
$LFM get_track_info --json '{"artist":"Cher","track":"Believe"}'
$LFM get_similar_tracks --json '{"artist":"Cher","track":"Believe","limit":10}'
$LFM get_weekly_charts --type list
$LFM get_weekly_charts --json '{"type":"artist","from":1212321600,"to":1212926400}'
```

You can pass arguments as `--json '{...}'`, as a bare JSON object, or as `--key value`. Output is JSON. On failure it
prints `{"error":{"code","message","hint"?,"lastfm_code"?,"status"?}}` and exits with code 1.

Error codes worth handling: `api_key_missing`, `invalid_api_key`, `username_missing`, `invalid_argument`,
`invalid_parameters`, `not_found`, `rate_limited`, `service_offline`, `temporary_error`, `api_key_suspended`.

### MCP: generic stdio

The server speaks newline-delimited JSON-RPC 2.0 on stdio: `node /path/to/lastfm-mcp/bin/lastfm-mcp-server`.

The process needs `LASTFM_API_KEY` and (usually) `LASTFM_USERNAME` in its environment.

### Cursor

Option A, as a local plugin: copy the folder itself (not a symlink) to `~/.cursor/plugins/local/lastfm-mcp` and reload,
then fill in the `LASTFM_API_KEY` and `LASTFM_USERNAME` plugin variables. Cursor doesn't expand the standard
`${PLUGIN_ROOT}` placeholder used in `mcp.json`'s `cwd`. The server doesn't depend on its working directory, but if it
won't start that way, use option B.

Option B, as a plain MCP server in `~/.cursor/mcp.json` (or `.cursor/mcp.json` in a project):

```json
{
  "mcpServers": {
    "lastfm-mcp": {
      "command": "node",
      "args": ["/ABSOLUTE/PATH/lastfm-mcp/bin/lastfm-mcp-server"],
      "env": {
        "LASTFM_API_KEY": "YOUR_API_KEY",
        "LASTFM_USERNAME": "YOUR_USERNAME"
      }
    }
  }
}
```

If `node` isn't found, use its absolute path (`which node`). Do not commit that config if it contains the API key.

### Other Agent Plugins clients

Install the directory as a plugin. `mcp.json` declares a stdio server (`./bin/lastfm-mcp-server`) and
`skills/lastfm/SKILL.md` tells the agent when to call each tool.
`LASTFM_API_KEY` and `LASTFM_USERNAME` are declared under `extensions["com.cursor"].variables`, because the Agent
Plugins manifest schema has no top-level `variables` key.

## Tools

| tool | purpose |
|---|---|
| get_recent_tracks | Recent scrobbles (`Scrobble[]`), including now-playing. `from`/`to` Unix or ISO, `limit` ≤ 200 |
| get_top_artists | Top artists for a `period` → `TopArtist[]` |
| get_top_albums | Top albums for a `period` → `TopAlbum[]` |
| get_top_tracks | Top tracks for a `period` → `TopTrack[]` |
| get_loved_tracks | Loved tracks → `LovedTrack[]` |
| get_user_info | Profile stats → `UserInfo` |
| get_artist_info | Artist metadata, tags, similar, bio summary → `ArtistInfo` |
| get_similar_artists | Similar artists → `SimilarArtist[]` |
| get_track_info | Track metadata, tags, optional user playcount/loved → `TrackInfo` |
| get_similar_tracks | Similar tracks → `SimilarTrack[]` |
| get_weekly_charts | `type=list` → `ChartRange[]`; `type=artist` or `track` for a from/to range (omit for the latest week) |

`period` is one of `overall`, `7day`, `1month`, `3month`, `6month`, `12month` (default `overall`).
Optional `user` on every user-scoped tool defaults to `LASTFM_USERNAME`.

## Development

```bash
npm test     # node --test, no network: fetch is mocked; the stdio smoke test spawns the real server with the key unset
```

If `LASTFM_API_KEY` and `LASTFM_USERNAME` are set in the environment, `npm test` also makes one live `get_user_info`
call. The key is never printed. Otherwise that check is skipped.

See `VERIFY.md` for the verification checklist.

## License

MIT. See `LICENSE`.