icon for mcp server

Last.fm

HTTP-SSE

Last.fm音乐数据访问MCP服务器

🎵 Last.fm MCP Server

License: MIT TypeScript Cloudflare Workers Last.fm MCP CI

A Model Context Protocol (MCP) server that provides seamless access to Last.fm listening data and music information via AI assistants like Claude.

A powerful, production-ready server that bridges AI assistants with Last.fm's comprehensive music database.

✨ Features

  • 🎧 Personal Listening Data: Recent tracks, top artists, albums, loved tracks
  • 🎵 Music Information: Detailed track, artist, and album information
  • 🔍 Music Discovery: Similar artists/tracks, personalized recommendations
  • 📊 Listening Statistics: Comprehensive stats and listening habits analysis
  • 🔐 Secure Authentication: Last.fm Web Authentication with JWT sessions
  • Smart Caching: Intelligent caching with optimized TTLs for performance
  • 🛡️ Rate Limiting: Built-in rate limiting respecting Last.fm API limits
  • 🌐 Production Ready: Deployed on Cloudflare Workers with global edge and CI/CD

🚀 Quick Start

Using with Claude Code (Recommended)

The easiest way to get started:

claude mcp add --transport http lastfm https://lastfm-mcp-prod.rian-db8.workers.dev

That's it! Claude Code now supports HTTP transport natively, no additional tools needed.

Using with Claude Desktop

Recommended Method (Connectors UI):

Claude Desktop now supports remote MCP servers natively:

  1. Open Claude Desktop
  2. Go to SettingsConnectors
  3. Click Add Connector
  4. Enter the server URL: https://lastfm-mcp-prod.rian-db8.workers.dev
  5. Click Add

That's it! No configuration files or command-line tools needed. The server will appear in your Connectors list and be ready to use.

Alternative Method (Configuration File):

For advanced users who prefer config files, add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{ "mcpServers": { "lastfm": { "command": "npx", "args": ["-y", "mcp-remote", "https://lastfm-mcp-prod.rian-db8.workers.dev"] } } }

💡 Note: The Connectors UI method is recommended as it's simpler and doesn't require any command-line tools.

Using with Other MCP Clients

This server works with any MCP client that supports Streamable HTTP transport:

Continue.dev (VS Code/JetBrains):

Add to your Continue config (~/.continue/config.json):

{ "mcpServers": { "lastfm": { "command": "npx", "args": ["-y", "mcp-remote", "https://lastfm-mcp-prod.rian-db8.workers.dev"] } } }

Zed Editor:

Add to your Zed settings:

{ "context_servers": { "lastfm": { "command": "npx", "args": ["-y", "mcp-remote", "https://lastfm-mcp-prod.rian-db8.workers.dev"] } } }

MCP Inspector (Testing):

Test the server directly:

npx @modelcontextprotocol/inspector https://lastfm-mcp-prod.rian-db8.workers.dev

Custom Implementation:

Use the MCP client SDK for your language:

  • TypeScript/JavaScript: @modelcontextprotocol/sdk
  • Python: mcp package
  • Server endpoint: https://lastfm-mcp-prod.rian-db8.workers.dev
  • Transport: Streamable HTTP (protocol version 2024-11-05 or 2025-06-18)

🐛 Platform-Specific Troubleshooting

If you get "spawn npx NOENT" error

For NixOS users:

{ "mcpServers": { "lastfm": { "command": "/run/current-system/sw/bin/npx", "args": ["mcp-remote", "https://lastfm-mcp-prod.rian-db8.workers.dev/sse"], "env": { "PATH": "/run/current-system/sw/bin:$PATH" } } } }

For other systems:

  1. Find your npx path: which npx
  2. Use the full path in your config:
{ "command": "/usr/local/bin/npx", // Use your actual path "args": ["mcp-remote", "https://lastfm-mcp-prod.rian-db8.workers.dev/sse"] }

🔑 Authentication Flow

  1. Try any authenticated tool (like "Get my recent tracks")
  2. Claude will provide a Last.fm authentication URL
  3. Sign in with your Last.fm account and authorize the app
  4. Return to Claude - you're now authenticated!
  5. Enjoy access to your personal Last.fm data

🛠️ Available Tools

🔓 Public Tools (No Authentication Required)

ToolDescription
get_track_infoGet detailed information about any track
get_artist_infoGet detailed artist information and bio
get_album_infoGet album details and track listings
get_similar_artistsFind artists similar to a given artist
get_similar_tracksFind tracks similar to a given track
pingTest server connectivity
server_infoGet server status and capabilities
auth_statusCheck your authentication status

🔐 Personal Tools (Authentication Required)

ToolDescription
get_recent_tracksYour recent listening history (supports pagination)
get_top_artistsYour top artists by time period
get_top_albumsYour top albums by time period
get_loved_tracksYour loved/favorite tracks
get_user_infoYour Last.fm profile information
get_listening_statsComprehensive listening statistics
get_music_recommendationsPersonalized music recommendations

🕰️ Temporal Query Tools (Authentication Required)

ToolDescription
get_weekly_chart_listGet available historical time periods for temporal analysis
get_weekly_artist_chartGet artist listening data for specific time periods
get_weekly_track_chartGet track listening data for specific time periods

Perfect for questions like:

  • "When did I start listening to Led Zeppelin?"
  • "What was I listening to in March 2023?"
  • "How has my music taste evolved over time?"

📚 MCP Resources

Access Last.fm data via standardized MCP resource URIs:

lastfm://user/{username}/recent          # Recent tracks
lastfm://user/{username}/top-artists     # Top artists
lastfm://user/{username}/top-albums      # Top albums
lastfm://user/{username}/loved           # Loved tracks
lastfm://user/{username}/profile         # User profile
lastfm://track/{artist}/{track}          # Track info
lastfm://artist/{artist}                 # Artist info
lastfm://album/{artist}/{album}          # Album info
lastfm://artist/{artist}/similar         # Similar artists
lastfm://track/{artist}/{track}/similar  # Similar tracks

🤖 MCP Prompts

Rich AI prompts for music analysis and discovery:

PromptDescriptionArguments
listening_insightsAnalyze user's listening habits and patternsusername, period?
music_discoveryDiscover new music based on listening historyusername, genre?
track_analysisGet detailed analysis of a specific trackartist, track
album_analysisGet detailed analysis of a specific albumartist, album
artist_analysisGet detailed analysis of a specific artistartist
listening_habitsAnalyze and summarize user's listening habitsusername, timeframe?

These prompts generate contextual messages that guide AI assistants to provide meaningful music insights using the available Last.fm tools and data.

🏗️ Development

Prerequisites

  • Node.js 18+
  • Cloudflare Workers account
  • Last.fm API credentials (Get them here)

Local Setup

  1. Clone and install:

    git clone https://github.com/rianvdm/lastfm-mcp.git cd lastfm-mcp npm install
  2. Configure environment (.dev.vars):

    LASTFM_API_KEY=your_api_key_here LASTFM_SHARED_SECRET=your_shared_secret_here JWT_SECRET=your_secure_jwt_secret
  3. Start development server:

    npm run dev
  4. Connect with Claude Code (for interactive testing):

    claude mcp add --transport http lastfm-local http://localhost:8787

    Or test with MCP Inspector:

    npx @modelcontextprotocol/inspector http://localhost:8787
  5. Test with curl (for basic API testing):

    curl -X POST http://localhost:8787 \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_track_info","arguments":{"artist":"The Beatles","track":"Yesterday"}}}'

🚀 Deployment

  1. Set production secrets:

    echo "your_api_key" | wrangler secret put LASTFM_API_KEY --env production echo "your_shared_secret" | wrangler secret put LASTFM_SHARED_SECRET --env production echo "your_jwt_secret" | wrangler secret put JWT_SECRET --env production
  2. Deploy:

    wrangler deploy --env production
  3. Test production:

    curl https://your-worker.workers.dev

📋 Example Usage

🎵 Public Music Data (No Authentication)

Get track information:

curl -X POST https://lastfm-mcp-prod.rian-db8.workers.dev \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get_track_info", "arguments": { "artist": "Radiohead", "track": "Paranoid Android" } } }'

Find similar artists:

curl -X POST https://lastfm-mcp-prod.rian-db8.workers.dev \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get_similar_artists", "arguments": { "artist": "Pink Floyd", "limit": 10 } } }'

🔐 Personal Data (Requires Authentication)

Get recent tracks with pagination:

curl -X POST https://lastfm-mcp-prod.rian-db8.workers.dev \ -H "Content-Type: application/json" \ -H "Cookie: session=your_session_token" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get_recent_tracks", "arguments": { "username": "your_username", "limit": 500, "page": 2 } } }'

🕰️ Temporal Queries

Get available historical periods:

curl -X POST https://lastfm-mcp-prod.rian-db8.workers.dev \ -H "Content-Type: application/json" \ -H "Cookie: session=your_session_token" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get_weekly_chart_list", "arguments": { "username": "your_username" } } }'

Discover what you were listening to in a specific time period:

curl -X POST https://lastfm-mcp-prod.rian-db8.workers.dev \ -H "Content-Type: application/json" \ -H "Cookie: session=your_session_token" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "get_weekly_artist_chart", "arguments": { "username": "your_username", "from": 1577836800, "to": 1578441600 } } }'

🤖 AI Assistant Examples

With Claude or other AI assistants, you can now ask natural language questions like:

  • "When did I start listening to Led Zeppelin?"
  • "What was I obsessed with in summer 2023?"
  • "Show me how my music taste has evolved over the years"
  • "Find artists similar to my current favorites"
  • "What tracks should I check out based on my listening history?"

🏗️ Architecture

  • 🌐 Runtime: Cloudflare Workers (global edge deployment)
  • 📡 Protocol: Model Context Protocol (MCP) 2024-11-05
  • 🔐 Authentication: Last.fm Web Auth + JWT sessions
  • 💾 Storage: Cloudflare KV (sessions, caching, rate limiting)
  • 🎵 API: Last.fm Web API v2.0
  • ⚡ Performance: Smart caching, rate limiting, retry logic

🧪 Testing

# Run tests npm test # Type checking npm run typecheck # Linting npm run lint # Build check npm run build

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments


🎵 Built with ❤️ for music lovers and AI enthusiasts

MCP Now 重磅来袭,抢先一步体验