SR P3 MCP Server
An MCP server providing access to Sveriges Radio's P3 channel music playlists, including real-time tracks and historical data. It enables AI assistants to fetch current songs and search the last 90 days of playlist history by date or artist.
README
SR P3 MCP Server
A Model Context Protocol (MCP) server that provides access to Sveriges Radio's P3 channel music playlists. This server enables AI assistants to fetch current and historical playlist data from P3, Sweden's popular music radio station.
Features
- Real-time Current Playlist: Get the currently playing song, previous song, and next song on P3
- Historical Playlist Search: Search P3's playlist history by date or date range (last 90 days)
- Artist Filtering: Filter historical results by artist name
- Rate Limiting: Built-in rate limiting (10 requests/minute) to respect SR's infrastructure
- Input Validation: Robust input validation using Zod schemas
- Error Handling: User-friendly error messages with graceful degradation
Installation
Prerequisites
- Node.js 18 or higher
- npm or yarn
Setup
- Clone this repository:
git clone https://github.com/tomellen/mcpsrtest.git
cd mcpsrtest
- Install dependencies:
npm install
- Build the TypeScript code:
npm run build
Usage
Configuring with Claude Desktop
To use this server with Claude Desktop, you need to add it to your Claude Desktop configuration:
-
Build the server (see Installation above)
-
Find your Claude Desktop config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
-
Add the server to your config:
{
"mcpServers": {
"sr-p3": {
"command": "node",
"args": [
"/absolute/path/to/mcpsrtest/dist/server.js"
]
}
}
}
- Restart Claude Desktop
See CONFIGURATION.md for detailed setup instructions, including platform-specific examples.
Running Locally
Start the server:
npm start
The server runs on stdio transport, suitable for local deployment (including Raspberry Pi).
Development Mode
For development with auto-rebuild:
npm run watch
In another terminal:
npm run dev
MCP Tools
1. get_p3_current_playlist
Fetch the currently playing song on SR P3.
Parameters: None
Returns:
- Current song with artist, title, album, timestamps
- Previous song
- Next song
Example Response:
{
"songs": [
{
"title": "Song Title",
"artist": "Artist Name",
"albumName": "Album Name",
"startTimeUTC": "2024-12-15T10:30:00Z",
"stopTimeUTC": "2024-12-15T10:33:45Z",
"duration": 225
}
],
"metadata": {
"channel": "P3",
"channelId": 164,
"timestamp": "2024-12-15T10:32:00Z",
"query": {
"type": "current"
}
}
}
2. search_p3_playlist_by_date
Search P3 playlist history for a specific date or date range.
Parameters:
date(required): ISO 8601 date string or date range- Single date:
"2024-12-15" - Date range:
"2024-12-01 to 2024-12-31"
- Single date:
artist_filter(optional): Filter by artist name (case-insensitive)limit(optional): Max songs to return (default: 25, max: 100)
Validation:
- Date must be within last 90 days
- Future dates are rejected
- Date format must be ISO 8601
Example Request:
{
"date": "2024-12-15",
"artist_filter": "Taylor Swift",
"limit": 10
}
Example Response:
{
"songs": [
{
"id": "song-0",
"title": "Anti-Hero",
"artist": "Taylor Swift",
"albumName": "Midnights",
"startTimeUTC": "2024-12-15T08:15:00Z",
"stopTimeUTC": "2024-12-15T08:18:30Z",
"duration": 210
}
],
"metadata": {
"channel": "P3",
"channelId": 164,
"timestamp": "2024-12-15T10:00:00Z",
"query": {
"type": "date-range",
"startDate": "2024-12-15T00:00:00Z",
"endDate": "2024-12-15T23:59:59Z",
"artistFilter": "Taylor Swift",
"limit": 10
}
}
}
Technical Details
P3 Channel ID
The P3 channel ID is hardcoded as 164 in the server. This is Sveriges Radio's official channel identifier for P3.
API Integration
This server uses Sveriges Radio's Open API:
- Base URL:
https://api.sr.se/api/v2/playlists/ - No authentication required
- All requests are read-only
- Responses are in JSON format
Rate Limiting
The server implements rate limiting to respect SR's infrastructure:
- Maximum 10 requests per minute
- Tracked per server instance
- Returns helpful error messages when limit is exceeded
Error Handling
All errors are converted to user-friendly messages:
- Network timeouts: "Request timed out. Please try again."
- API unavailable: "Service may be temporarily unavailable."
- Invalid dates: Clear explanation of valid date range
- Rate limit: "Please wait X seconds before trying again."
Security
- All user inputs validated with Zod schemas
- No API keys or secrets required
- Date inputs sanitized and validated
- No raw API URLs exposed in errors
- Request logging to stderr (not stdout)
Project Structure
SRMCP/
├── src/
│ ├── server.ts # Main MCP server
│ ├── api-client.ts # SR API client with rate limiting
│ ├── types.ts # TypeScript interfaces
│ └── tools/
│ ├── current-playlist.ts # get_p3_current_playlist tool
│ └── search-playlist.ts # search_p3_playlist_by_date tool
├── dist/ # Compiled JavaScript (generated)
├── package.json
├── tsconfig.json
└── README.md
Development
Building
npm run build
Type Checking
TypeScript is configured with strict mode enabled. All code is fully typed.
Logging
Server logs are written to stderr (not stdout, which is reserved for MCP protocol). This allows for debugging without interfering with the MCP communication.
Deployment
Raspberry Pi
This server is designed for Raspberry Pi deployment:
- Ensure Node.js 18+ is installed
- Clone and build the project
- Run with
npm start - Configure your MCP client to connect via stdio
Docker (Optional)
A Dockerfile can be added for containerized deployment if needed.
Testing
Basic functionality test:
npm test
This runs the server and verifies it starts without errors.
API Reference
For more information about Sveriges Radio's Open API:
License
MIT
Contributing
Contributions are welcome! Please ensure:
- All inputs are validated
- Error messages are user-friendly
- Code follows TypeScript best practices
- Tests pass before submitting PRs
Support
For issues or questions:
- GitHub Issues: github.com/tomellen/mcpsrtest/issues
Acknowledgments
Built with:
- @modelcontextprotocol/sdk - MCP SDK
- Zod - Input validation
- Axios - HTTP client
- fast-xml-parser - XML parsing
Data provided by Sveriges Radio's Open API.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。