Plex 标志

Plex

社区
niavasha

Plex MCP Server

发布者niavasha
代码仓库plex-mcp-server
语言TypeScript
复刻数
14
星标数
52
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    Plex 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 52 个 Star 和 14 个 Fork。

Plex MCP Server

A Model Context Protocol (MCP) server that provides AI assistants with comprehensive access to your Plex Media Server, Sonarr, Radarr, and Trakt.tv — all from a single unified server.

TypeScript Node.js MCP License: MIT

What is this?

This MCP server transforms your Plex Media Server into an AI-queryable database. Ask your AI assistant questions like:

  • "What movies have I watched recently?"
  • "Show me my viewing statistics for the past month"
  • "What's the most popular content on my server?"
  • "Find action movies in my library"
  • "What's on my continue watching list?"
  • "Add that new show to Sonarr"
  • "What's in my download queue?"
  • "Sync my watch history to Trakt"
  • "Recommend me some movies I haven't seen"

Features

46 tools out of the box (58 with write operations enabled):

  • Plex Library Management — Browse libraries, search media, get detailed metadata, list playlists and watchlist
  • Tautulli-Style Analytics — Viewing statistics, user activity, popular content, watch history
  • Personalized Recommendations — AI-powered movie suggestions based on your watch history, genres, directors, and actors. Supports per-user profiles for multi-user Plex servers.
  • Sonarr/Radarr Integration — Browse, search, add series/movies, view queues, trigger downloads
  • Trakt.tv Sync — OAuth authentication, watch history sync, enhanced statistics, scrobbling. When configured, Trakt data enriches recommendations by catching movies watched outside Plex.
  • Write Operations (opt-in) — Create/edit playlists, update metadata, manage watchlist, rate media, and mark media watched or unwatched

One server, all tools. Trakt and Sonarr/Radarr credentials are optional — tools that need them return a helpful setup message if the key is missing. You don't need to configure everything upfront.

Quick Start

Prerequisites

  • Node.js 20+
  • Plex Media Server (any recent version)
  • Plex Token (How to get your token)
  • MCP-compatible client (Claude Desktop, etc.)

Installation

bash
# Clone the repository
git clone https://github.com/niavasha/plex-mcp-server.git
cd plex-mcp-server

# Install dependencies
npm install

# Build the project
npm run build

Or install directly from npm:

bash
npx plex-mcp-server

Configuration

  1. Get your Plex token (see instructions below)

  2. Configure your MCP client (e.g., Claude Desktop):

json
{
  "mcpServers": {
    "plex": {
      "command": "node",
      "args": ["/path/to/plex-mcp-server/build/plex-mcp-server.js"],
      "env": {
        "PLEX_URL": "http://localhost:32400",
        "PLEX_TOKEN": "your_plex_token_here",

        "SONARR_URL": "http://localhost:8989",
        "SONARR_API_KEY": "optional_sonarr_api_key",

        "RADARR_URL": "http://localhost:7878",
        "RADARR_API_KEY": "optional_radarr_api_key",

        "TRAKT_CLIENT_ID": "optional_trakt_client_id",
        "TRAKT_CLIENT_SECRET": "optional_trakt_client_secret"
      }
    }
  }
}

Only PLEX_TOKEN is required. All other credentials are optional — tools for unconfigured services return a clear error message explaining how to set them up, rather than crashing the server.

Sonarr/Radarr API keys can be found at Settings > General > API Key in each app's web UI.

Trakt.tv setup requires a Trakt OAuth application. Create one with redirect URI urn:ietf:wg:oauth:2.0:oob, then add the Client ID and Secret to your config. Once the server is running, ask your AI assistant to "authenticate with Trakt" — it will guide you through the OAuth flow. See the Trakt setup guide for detailed instructions.

Compact Responses (optional)

Tools answer with JSON by default. Setting PLEX_OUTPUT_FORMAT=toon switches them to TOON, which writes an array of records once as a header and then as rows instead of repeating every field name on every record:

results[3]{ratingKey,title,year}:
  1001,Arrival,2016
  1002,Sicario,2015
  1003,Dune,2021

That is the same data your assistant would have received, in fewer tokens — around a third fewer across a spread of tool responses, and 40–60% fewer on the list-shaped ones like search_media, get_library_items and radarr_get_movies. The saving is only worth having on long lists, so each response is emitted as TOON only when TOON is actually shorter, and as JSON otherwise; enabling this cannot make a response larger than it is today.

json
"env": {
  "PLEX_TOKEN": "your_plex_token_here",
  "PLEX_OUTPUT_FORMAT": "toon"
}

Leave the variable unset — the default — and responses are byte-for-byte the JSON they have always been.

In v1.0.x there were three separate server binaries (build/index.js, build/plex-trakt-server.js, build/plex-arr-server.js). In v1.1.0+ these are replaced by a single unified binary: build/plex-mcp-server.js.

The old binaries still work but emit a deprecation warning. Update your MCP config to point to build/plex-mcp-server.js and remove any duplicate server entries.

See the migration guide for full details.

Usage

Once configured, you can ask your AI assistant:

"What movies did I watch last week?"
"Show me my most popular TV shows this month"
"Give me viewing statistics for the past 30 days"
"Search for Night of the Living Dead in my library"
"What's on my continue watching list?"
"List all my Plex libraries"
"Add that new show to Sonarr"
"What's in my Radarr download queue?"
"Sync my Plex history to Trakt"

Recommended Workflows

Sync Plex watch history to Trakt:

  1. Set up Trakt credentials (see above)
  2. Ask: "Authenticate with Trakt" — follow the OAuth flow
  3. Ask: "Do a dry run sync of my Plex history to Trakt" — preview what would sync
  4. Ask: "Sync my Plex watch history to Trakt" — run the actual sync

Find and add new content:

  1. Ask: "Search Sonarr for The Beverly Hillbillies" — find the TVDB ID
  2. Ask: "Add The Beverly Hillbillies to Sonarr" — it auto-detects quality profiles and root folders
  3. Ask: "What's in my Sonarr download queue?" — monitor progress

Get personalized recommendations:

  1. Ask: "Recommend me some movies from my library"
  2. The engine analyzes your watch history — genres, directors, actors, ratings
  3. Scores every unwatched movie and returns the top matches with reasons
  4. For multi-user servers, specify the user: "Recommend movies for Titus"
  5. If Trakt is configured, it automatically uses your Trakt history too — catching movies you watched outside Plex (other platforms, before tracking was set up)

Cross-platform viewing analytics:

  1. Ask: "Show me my Plex viewing stats for the last 30 days"
  2. Ask: "What are my Trakt stats?" — see lifetime stats (movies watched, hours, milestones)
  3. Ask: "What are my most popular movies this month?"

Available Functions

46 tools out of the box (58 with write operations enabled).

Plex Tools (20 tools)

FunctionDescription
get_librariesList all Plex libraries
get_library_itemsList items in a library with pagination
export_libraryExport a full library to JSON (under ./exports)
search_mediaSearch media globally or within one library
get_recently_addedRecently added content
get_on_deckContinue watching list
get_media_detailsDetailed media info
get_editable_fieldsShow editable fields and available tags for an item
get_playlistsList all Plex playlists
get_playlist_itemsList items in a playlist
get_watchlistGet the current account Watchlist from Plex Discover
get_recently_watchedRecently watched content
get_watch_historyDetailed watch sessions
get_fully_watchedFully watched movies/shows
get_watch_statsComprehensive viewing statistics
get_user_statsUser activity statistics
get_library_statsLibrary usage metrics
get_popular_contentMost popular content analysis
get_recommendationsPersonalized movie recommendations based on your watch history
get_active_sessionsCurrently active Plex streams — who is watching what, player state, transcoding

Write Operations (12 tools, opt-in)

Set PLEX_ENABLE_MUTATIVE_OPS=true to enable these tools. They allow your AI assistant to make changes to your Plex server. Use with care — while we test these tools, there are no guarantees. Review changes your assistant proposes before confirming.

FunctionDescription
update_metadataUpdate metadata fields and editable tags for a media item
update_metadata_from_jsonApply a metadata JSON payload using best-effort field mapping
create_playlistCreate a new smart or static playlist
add_to_playlistAdd a media item to a playlist
remove_from_playlistRemove an item from a playlist
clear_playlistPreview and optionally clear all items from a playlist (confirm=true)
delete_playlistDelete a playlist without deleting the underlying media
add_to_watchlistAdd a matched local movie or show to the account Watchlist
remove_from_watchlistRemove an account Watchlist item by its global Plex GUID or local rating key
rate_mediaSet the user's rating for a media item from 0 to 10
mark_watchedMark a media item as watched
mark_unwatchedMark a media item as unwatched

Sonarr Tools (8 tools)

FunctionDescription
sonarr_get_seriesList series with optional title filter
sonarr_searchSearch TheTVDB for new series
sonarr_add_seriesAdd series by TVDB ID
sonarr_get_missingMissing/wanted episodes
sonarr_get_queueDownload queue
sonarr_get_calendarUpcoming episodes
sonarr_get_profilesQuality profiles and root folders
sonarr_trigger_searchTrigger missing episode search

Radarr Tools (8 tools)

FunctionDescription
radarr_get_moviesList movies with optional title filter
radarr_searchSearch TMDB for new movies
radarr_add_movieAdd movie by TMDB ID
radarr_get_missingMissing/wanted movies
radarr_get_queueDownload queue
radarr_get_calendarUpcoming movies
radarr_get_profilesQuality profiles and root folders
radarr_trigger_searchTrigger missing movie search

Cross-Service Tools (1 tool)

FunctionDescription
arr_get_statusCheck Sonarr/Radarr connection status

Trakt Tools (9 tools)

FunctionDescription
trakt_authenticateStart Trakt.tv OAuth flow
trakt_complete_authComplete authentication
trakt_get_auth_statusCheck auth status
trakt_sync_to_traktSync Plex history to Trakt
trakt_sync_from_traktGet Trakt data for comparison
trakt_get_user_statsEnhanced stats from Trakt
trakt_searchSearch Trakt database
trakt_start_scrobblingReal-time scrobbling
trakt_get_sync_statusCheck sync operation status

Getting Your Plex Token

  1. Open Plex Web App in your browser
  2. Navigate to Settings > Account > Privacy
  3. Click "Show Advanced" at the bottom
  4. Copy your Plex Token

Alternative method:

  • Visit: http://YOUR_PLEX_IP:32400/web/index.html#!/settings/account
  • Look for the "Plex Token" field

Project Structure

plex-mcp-server/
├── src/
│   ├── plex-mcp-server.ts    # Unified server entry point (44+ tools)
│   ├── index.ts               # Deprecated shim → plex-mcp-server
│   ├── plex-arr-server.ts     # Deprecated shim → plex-mcp-server
│   ├── plex-trakt-server.ts   # Deprecated shim → plex-mcp-server
│   ├── plex/                  # Shared Plex module
│   │   ├── client.ts          #   Plex API client
│   │   ├── tools.ts           #   Plex tool implementations
│   │   ├── tool-registry.ts   #   Map-based tool dispatch
│   │   ├── tool-schemas.ts    #   MCP tool schema definitions
│   │   ├── constants.ts       #   Configuration defaults
│   │   └── types.ts           #   TypeScript type definitions
│   ├── arr/                   # Sonarr/Radarr module
│   │   ├── client.ts          #   Base ArrClient + Sonarr/Radarr subclasses
│   │   ├── mcp-functions.ts   #   Tool implementations (17 tools)
│   │   ├── tool-registry.ts   #   Map-based tool dispatch
│   │   ├── tool-schemas.ts    #   MCP tool schema definitions
│   │   ├── constants.ts       #   Configuration defaults
│   │   └── types.ts           #   TypeScript type definitions
│   ├── trakt/                 # Trakt.tv module
│   │   ├── client.ts          #   Trakt API client + OAuth
│   │   ├── sync.ts            #   Plex-to-Trakt sync engine
│   │   ├── mapper.ts          #   Plex-to-Trakt data mapping
│   │   ├── mcp-functions.ts   #   Tool implementations (9 tools)
│   │   ├── tool-registry.ts   #   Map-based tool dispatch
│   │   └── tool-schemas.ts    #   MCP tool schema definitions
│   ├── shared/                # Shared utilities
│   │   └── utils.ts           #   truncate, sleep, chunkArray
│   └── __tests__/             # Test suite (94 tests)
├── build/                     # Compiled JavaScript output
├── docs/                      # Documentation
├── package.json
├── tsconfig.json
├── vitest.config.ts
├── .env.example               # Environment variables template
└── README.md

Development

Scripts

bash
# Development mode with auto-reload
npm run dev

# Build for production
npm run build

# Start production server
npm start

# Run tests
npm test
npm run test:watch

Building from Source

bash
git clone https://github.com/niavasha/plex-mcp-server.git
cd plex-mcp-server
npm install
npm run dev

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Merged contributors are credited in CONTRIBUTORS.md. Please use Conventional Commits — releases and the changelog are generated from them, see docs/RELEASING.md.

Development Guidelines

  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

Troubleshooting

Common Issues

Connection refused:

  • Verify your Plex server is running
  • Check the PLEX_URL in your environment config
  • Ensure the port (usually 32400) is correct

Host unreachable (EHOSTUNREACH / connect errors) on macOS:

  • On macOS Sequoia, Sonoma, or later, connections to local IP addresses (like 10.0.0.10 or 192.168.1.50) may be blocked by Local Network Privacy settings.
  • Workaround 1: Try connecting using the local hostname (e.g., plex.local or your Plex server name) rather than the direct IP address. Alternatively, use a Plex *.plex.direct domain.
  • Workaround 2: Go to System Settings -> Privacy & Security -> Local Network on your Mac and ensure that the MCP client (e.g., Claude Desktop, Terminal, or VS Code) is enabled and has permission to access the local network.

Authentication errors:

  • Verify your Plex token is correct
  • Check token permissions in Plex settings
  • Ensure token hasn't expired

Empty responses:

  • Some features require Plex Pass
  • Check if your libraries are accessible
  • Verify media has been scanned and is available

Sonarr/Radarr connection issues:

  • Verify Sonarr/Radarr is running and accessible from the MCP server host
  • Check that the API key is correct (Settings > General > API Key)
  • Sonarr uses API v3 at /api/v3/ — ensure your URL doesn't include a trailing path
  • For large Radarr libraries (20k+ movies), the initial radarr_get_movies call may take up to 30 seconds

Trakt authentication issues:

  • Ensure TRAKT_CLIENT_ID and TRAKT_CLIENT_SECRET are both set
  • Use the trakt_authenticate tool to start the OAuth flow
  • Complete authentication with trakt_complete_auth using the code from Trakt

MCP client issues:

  • Ensure the path is set to build/plex-mcp-server.js (the unified server)
  • Check that Node.js is in your system PATH
  • Verify environment variables are set in client config

Getting Help

Requirements

  • Node.js 20.0.0 or higher
  • Plex Media Server (any recent version)
  • Network access between MCP server and Plex server
  • Valid Plex token with appropriate permissions

Security Notes

  • Keep your Plex token secure - never commit it to version control
  • Use environment variables for sensitive configuration
  • Run on trusted networks - the server communicates directly with Plex
  • Regular token rotation - consider refreshing tokens periodically
  • Write operations are disabled by default — enable only if you trust your AI assistant's judgment

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Related Projects


Built with love for the Plex and AI community

将 Plex MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Plex 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 Plex 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Plex MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "plex-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Plex MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Plex MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Plex 帮我完成这项任务吗?
Plex
当然。我已阅读。
以下是我使用 Plex 得到的结果。

常见问题

Plex MCP 服务器有什么用途?

Plex 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Plex MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 Plex,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 Plex MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 Plex 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Plex MCP 连接到 TypingMind?

Plex 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Plex MCP 在 TypingMind 中提供哪些工具?

Plex 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Plex MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 Plex 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇