mcp-server-pexels
Search and find free images and videos from Pexels.com. (free api key required)
README
mcp-server-pexels
An MCP server for Pexels stock photo and video search. Optimized for LLMs.
Pexels provides free stock photos and videos.
Features
- Photo Search — Search photos with filters (query, orientation, size, color, locale)
- Video Search — Search videos, auto-selects HD .mp4 closest to 1920x1080
- Get Details — Retrieve full metadata for a photo/video by ID
- Intelligent Caching — 10 min TTL for searches, 60 min for ID lookups
- Error Handling — Graceful failures with helpful messages (per MCP best practices)
- Attribution — Mandatory photographer credits in every result
Prerequisites
- Node.js v20+
- Pexels API key (free at pexels.com/api)
Quick Start (2 minutes)
1. Get an API Key
Sign up at pexels.com/api — free, no credit card.
2. Build the Server
npm install && npm run build
3. Add to Claude Desktop
Open ~/Library/Application Support/Claude/claude_desktop_config.json (Mac) or %APPDATA%\Claude\claude_desktop_config.json (Windows), add:
{
"mcpServers": {
"pexels": {
"command": "node",
"args": ["/absolute/path/to/mcp-server-pexels/build/index.js"],
"env": {
"PEXELS_API_KEY": "YOUR_PEXELS_API_KEY"
}
}
}
}
Windows note: Use
node.exefull path or add Node to PATH. Forward slashes in paths work on Windows.
4. Restart Claude Desktop
The server is now available as pexels_search_photos, pexels_search_videos, and pexels_get_details.
Configuration
Add to your .mcp.json or claude_desktop_config.json:
{
"mcpServers": {
"pexels": {
"command": "node",
"args": ["/absolute/path/to/build/index.js"],
"env": {
"PEXELS_API_KEY": "YOUR_API_KEY"
}
}
}
}
Environment
Set PEXELS_API_KEY in your environment. For local dev, create a .env file:
PEXELS_API_KEY=your_pexels_api_key
Development
npm run dev # watch mode
npm run inspector # MCP Inspector
npm test # run tests
Tools
| Tool | Description |
|---|---|
pexels_search_photos |
Search for photos by query |
pexels_search_videos |
Search for videos |
pexels_get_details |
Get details by ID and type |
Architecture
src/index.ts— Entry point, MCP server setupsrc/tools/— Tool implementationssrc/shared/— Cache, API client, errors, types, video selectorsrc/utils/— Zod validation schemas
Engineering Decisions
| Decision | Rationale |
|---|---|
| Cache-first architecture | Pexels API allows 200 requests/hour. Caching (10m TTL for searches, 60m for ID lookups) preserves quota, reduces latency to <5ms on cache hit, and demonstrates awareness of API costs — critical for production AI systems where agents frequently re-request the same context. |
| Fail-fast at call time | MCP servers are spawned as child processes — starting is not the time to fail. Server warns on startup but fails gracefully on first tool call with structured isError: true. |
| Zod validation schemas | MCP v2 SDK requires z.object() wrappers. Catches invalid input before it reaches the API. |
| resource_link for media | Remote images and videos are provided as MCP resource_link content blocks with proper mimeType. The markdown image link in the text block remains as a fallback for clients that do not render resource_link. |
| Pure video selection | Video selection logic isolated in video-selector.ts — testable independently from tool handler. |
| Hardcoded attribution | Required by Pexels Terms of Service. Embedded in every text response. |
Compatibility
Tested with @modelcontextprotocol/sdk v1.29+ via StdioClientTransport. The integration test suite spawns the built server and validates every tool call against the SDK's CallToolResultSchema and ContentBlockSchema.
A structured JSON block is appended as the last content element in every successful response, containing typed data (id, kind, creatorName, dimensions, URLs). Downstream clients and agent frameworks can parse this block directly instead of regex-parsing the markdown text.
Future Improvements
- Tool execution telemetry — Add structured logging for cache hits/misses, query execution time, and error rates. This supports troubleshooting AI agents in production and demonstrates observability best practices.
- Metrics endpoint — Expose counters (requests served, cache hit ratio, API quota remaining) for monitoring.
- Custom TTL configuration — Allow users to tune cache TTL via environment variables.
Community Submissions
- are welcome! 🌟
License
Unofficial community project. Not affiliated with Pexels.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。