Skip to main content
Glama

lastfmcp

License

A Model Context Protocol (MCP) server that connects Claude to your Last.fm listening history. Ask Claude to recommend new artists, explore genres, or summarize what you've been listening to — all grounded in your actual play data.

How it works

The server exposes four tools that Claude can call during a conversation:

  • get_playback_history — fetch your recent tracks or top artists/tracks over a time period

  • get_recommendations — run a fan-out pipeline across Last.fm's similarity graph to surface discovery candidates you're likely to enjoy

  • get_artist_info — look up biography, stats, genre tags, and similar artists for any artist

  • get_tag_info — explore a genre or mood tag and find its top artists

Claude handles the reasoning layer: it reads the raw signals these tools return and synthesizes personalized recommendations with explanations.

Related MCP server: Spotify MCP Server

Requirements

Setup

1. Clone and build

git clone https://github.com/yourname/lastfmcp
cd lastfmcp
npm install
npm run build

2. Get a Last.fm API key

Go to https://www.last.fm/api/account/create, fill in the form (any contact email and application name works), and copy the API key.

3. Configure Claude Desktop

Open ~/Library/Application Support/Claude/claude_desktop_config.json (create it if it doesn't exist) and add:

{
  "mcpServers": {
    "lastfmcp": {
      "command": "node",
      "args": ["/absolute/path/to/lastfmcp/dist/index.js"],
      "env": {
        "LASTFM_API_KEY": "your_api_key_here",
        "LASTFM_DEFAULT_USER": "your_lastfm_username"
      }
    }
  }
}

Replace the path, API key, and username with your own values. The LASTFM_DEFAULT_USER is used when you don't specify a username in your request — set it to your own account to make every interaction feel seamless.

4. Restart Claude Desktop

Quit and reopen Claude Desktop. The lastfmcp tools will appear in the tool list.

Example prompts

Once set up, try asking Claude:

  • "What have I been listening to most this month?"

  • "Recommend me some new artists based on my recent listening."

  • "I'm in a post-rock mood — what should I listen to?"

  • "Tell me about Godspeed You! Black Emperor."

  • "What artists are similar to Four Tet that I haven't heard much of?"

  • "What were my top 10 artists of all time?"

Environment variables

Variable

Required

Description

LASTFM_API_KEY

Yes

Your Last.fm API key. The server will not start without this.

LASTFM_DEFAULT_USER

No

Last.fm username used when no user is specified in a request.

LASTFM_BASE_URL

No

Override the Last.fm API base URL. Defaults to https://ws.audioscrobbler.com/2.0/.

Tools reference

get_playback_history

Fetches listening history for a Last.fm user.

Parameter

Type

Default

Description

user

string

default user

Last.fm username

view

recent_tracks | top_artists | top_tracks

—

Which history view to fetch

period

7day | 1month | 3month | 6month | 12month | overall

1month

Time window for top views

limit

number (1–50)

20

Number of results

get_artist_info

Returns biography, listener stats, genre tags, and similar artists for a named artist.

Parameter

Type

Default

Description

artist

string

—

Artist name

include_similar

boolean

true

Include up to 5 similar artists

include_top_tracks

boolean

false

Include top 5 tracks

get_tag_info

Returns a description and top artists for a music tag or genre.

Parameter

Type

Default

Description

tag

string

—

Tag name (e.g. post-rock, lo-fi, baroque pop)

include_top_artists

boolean

true

Include top artists for the tag

limit

number (1–20)

10

Number of top artists

get_recommendations

Runs a multi-step pipeline to generate artist discovery candidates:

  1. Fetches the user's top artists for the given period (seeds)

  2. Fans out to Last.fm's similar-artist graph for each seed

  3. Fetches the user's genre tags and the seeds' tags to compute overlap

  4. Deduplicates candidates, removes already-known artists, and ranks by similarity

Returns a structured candidate list with similarity scores, which artists triggered each recommendation, and shared genre tags. Claude then reasons over this data to produce a personalized recommendation.

Parameter

Type

Default

Description

user

string

default user

Last.fm username

period

7day | 1month | ...

1month

Time period for top artists

seed_artist_count

number (3–15)

8

Number of top artists to use as seeds

similar_per_seed

number (5–20)

10

Similar artists fetched per seed

max_candidates

number (5–50)

25

Maximum candidates returned

Note: A cold call fetches roughly 40 Last.fm API requests and takes 10–15 seconds. Subsequent calls within the same session return in under a second thanks to in-memory caching.

Development

npm run dev      # run directly with tsx (no build step)
npm test         # run all tests
npm run build    # compile to dist/

Tests use Vitest and mock all external dependencies. No Last.fm API key is needed to run them.

Caching

All Last.fm responses are cached in memory for the duration of the server process:

Data

Cache duration

Recent tracks

2 minutes

Top artists / tracks / tags

10 minutes

Artist and tag metadata

60 minutes

The cache is process-scoped — it resets when Claude Desktop restarts the server.

Rate limiting

The server serializes all Last.fm API requests with a 200ms gap between calls, staying within Last.fm's guideline of ~5 requests per second. If a rate limit error is returned, the request is retried once after one second.

Available Tools

4 tools
get_artist_infoA

Retrieves detailed information about a specific music artist from Last.fm. Returns a biography summary, listener and play statistics, top tags (genres/moods), similar artists, and optionally top tracks. Use this when you need to explain why an artist might appeal to a user, or to explore an unfamiliar name from a recommendation list.

Inputs: artist (required), include_similar, include_top_tracks.

get_playback_historyA

Retrieves a Last.fm user's listening history. Use this to understand what music someone has been playing. Provides three views: recent_tracks (chronological, most recent plays), top_artists or top_tracks (aggregated by play count over a time period). Call this first to understand a user's taste before making recommendations.

Inputs: view (required), user, limit, period.

get_recommendationsA

Generates a raw candidate list for music artist recommendations by combining a user's top artists with their similar artists and shared tag analysis. Returns a deduplicated list of artists the user likely doesn't know well yet, along with signals explaining each candidate (which known artist triggered them, similarity score, shared tags). This provides the raw material — use your own reasoning to rank, explain, and personalize the final recommendations. Note: a cold call fetches ~40 API requests and takes 10-15 seconds; subsequent calls are fast due to caching.

Inputs: user, period, max_candidates, similar_per_seed, +1 more.

get_tag_infoA

Retrieves information about a music tag or genre from Last.fm, including a description and the top artists associated with that tag. Use this when a user mentions a genre, mood, or style, or when you want to find artists in a specific niche that overlaps with a user's known taste.

Inputs: tag (required), limit, include_top_artists.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool targets a distinct entity: user history, an artist, a tag/genre, and a recommendation candidate list. get_recommendations internally uses history data, but the descriptions make the boundary explicit and the intended call order (history first, then recommendations) removes any overlap.

    Naming Consistency5/5

    All four tools follow a uniform snake_case get_<noun> pattern (get_playback_history, get_artist_info, get_tag_info, get_recommendations). The convention is predictable and readable throughout.

    Tool Count4/5

    Four tools is lean but each serves a clear role in a read-only taste-analysis workflow. It sits at the low end of the range and could reasonably add a lookup/search tool, but nothing here feels redundant or missing its purpose.

    Completeness3/5

    The core discovery chain (history -> artist/tag exploration -> recommendations) is covered, but there is no artist/track/album search tool, no track-level metadata, and no user profile or write operations (love/rate). Agents can work around this with tag and artist lookups, but gaps are notable for a Last.fm surface.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Connects Claude to Spotify for music discovery, playlist creation, and collection analysis through natural language. Enables searching songs, analyzing music diversity, creating playlists, and getting recommendations using Spotify's API.
      -
    • A
      license
      B
      quality
      C
      maintenance
      Enables Claude to manage Spotify playlists and analyze personal listening history, including account reads, playlist writes, local analytics from data exports, and building playlists from track lists.
      35
      MIT