mcp-server-pexels
This server enables searching and retrieving free stock photos and videos from Pexels, optimized for LLM integration.
Search Photos (
pexels_search_photos): Search by keyword with optional filters for orientation (landscape, portrait, square), size (large, medium, small), color (named or hex code), and locale. Returns up to 10 results with mandatory photographer attribution.Search Videos (
pexels_search_videos): Search by keyword with optional filters for orientation, size, and locale. Automatically selects HD.mp4links closest to 1920×1080. Returns up to 10 results with attribution.Get Details (
pexels_get_details): Retrieve full metadata for a specific photo or video by ID, including dimensions, URLs, and creator credits.Intelligent Caching: Search results are cached for 10 minutes, ID lookups for 60 minutes. A
force_refreshflag bypasses the cache to fetch fresh data, helping preserve the Pexels API quota.Attribution: Photographer credits are automatically included in every response, as required by Pexels' terms of service.
LLM Optimization: Structured JSON output and graceful error handling with informative messages for invalid requests or API issues.
Provides tools for searching stock photos and videos via the Pexels API, including filters for orientation, size, color, and locale, as well as retrieving detailed metadata by ID.
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
Related MCP server: Pexels MCP Server
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 build3. 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_keyDevelopment
npm run dev # watch mode
npm run inspector # MCP Inspector
npm test # run testsTools
Tool | Description |
| Search for photos by query |
| Search for videos |
| 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 |
Zod validation schemas | MCP v2 SDK requires |
resource_link for media | Remote images and videos are provided as MCP |
Pure video selection | Video selection logic isolated in |
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.
Maintenance
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/afshinator/mcp-server-pexels'
If you have feedback or need assistance with the MCP directory API, please join our Discord server