mcp-server-pexels
mcp-server-pexels
一个用于 Pexels 库存照片和视频搜索的 MCP 服务器。针对 LLM 进行了优化。
Pexels 提供免费的库存照片和视频。
功能
照片搜索 — 使用过滤器(查询、方向、尺寸、颜色、区域设置)搜索照片
视频搜索 — 搜索视频,自动选择最接近 1920x1080 的高清 .mp4
获取详情 — 通过 ID 获取照片/视频的完整元数据
智能缓存 — 搜索结果 10 分钟 TTL,ID 查询 60 分钟 TTL
错误处理 — 优雅地处理失败并提供有用的消息(遵循 MCP 最佳实践)
署名 — 每个结果中必须包含摄影师署名
Related MCP server: Pexels MCP Server
先决条件
Node.js v20+
Pexels API 密钥(在 pexels.com/api 免费获取)
快速入门(2 分钟)
1. 获取 API 密钥
在 pexels.com/api 注册 — 免费,无需信用卡。
2. 构建服务器
npm install && npm run build3. 添加到 Claude Desktop
打开 ~/Library/Application Support/Claude/claude_desktop_config.json (Mac) 或 %APPDATA%\Claude\claude_desktop_config.json (Windows),添加:
{
"mcpServers": {
"pexels": {
"command": "node",
"args": ["/absolute/path/to/mcp-server-pexels/build/index.js"],
"env": {
"PEXELS_API_KEY": "YOUR_PEXELS_API_KEY"
}
}
}
}Windows 注意: 使用
node.exe的完整路径或将 Node 添加到 PATH。路径中的正斜杠在 Windows 上同样有效。
4. 重启 Claude Desktop
服务器现在可用,工具包括 pexels_search_photos、pexels_search_videos 和 pexels_get_details。
配置
添加到您的 .mcp.json 或 claude_desktop_config.json:
{
"mcpServers": {
"pexels": {
"command": "node",
"args": ["/absolute/path/to/build/index.js"],
"env": {
"PEXELS_API_KEY": "YOUR_API_KEY"
}
}
}
}环境
在您的环境中设置 PEXELS_API_KEY。对于本地开发,创建一个 .env 文件:
PEXELS_API_KEY=your_pexels_api_key开发
npm run dev # watch mode
npm run inspector # MCP Inspector
npm test # run tests工具
工具 | 描述 |
| 按查询搜索照片 |
| 搜索视频 |
| 按 ID 和类型获取详情 |
架构
src/index.ts— 入口点,MCP 服务器设置src/tools/— 工具实现src/shared/— 缓存、API 客户端、错误、类型、视频选择器src/utils/— Zod 验证模式
工程决策
决策 | 原理 |
缓存优先架构 | Pexels API 允许每小时 200 次请求。缓存(搜索 10 分钟 TTL,ID 查询 60 分钟 TTL)可节省配额,将缓存命中的延迟降低到 <5ms,并展示了对 API 成本的考量 — 这对于代理频繁重新请求相同上下文的生产 AI 系统至关重要。 |
调用时快速失败 | MCP 服务器作为子进程启动 — 启动时不是失败的时机。服务器在启动时发出警告,但在第一次工具调用时通过结构化的 |
Zod 验证模式 | MCP v2 SDK 需要 |
媒体的 resource_link | 远程图像和视频作为带有正确 mimeType 的 MCP |
纯视频选择 | 视频选择逻辑隔离在 |
硬编码署名 | Pexels 服务条款要求。嵌入在每个文本响应中。 |
兼容性
通过 StdioClientTransport 在 @modelcontextprotocol/sdk v1.29+ 上进行了测试。集成测试套件会启动构建好的服务器,并根据 SDK 的 CallToolResultSchema 和 ContentBlockSchema 验证每个工具调用。
结构化的 JSON 块作为每个成功响应的最后一个内容元素附加,包含类型化数据(id、kind、creatorName、dimensions、URLs)。下游客户端和代理框架可以直接解析此块,而不是通过正则表达式解析 markdown 文本。
未来改进
工具执行遥测 — 添加用于缓存命中/未命中、查询执行时间和错误率的结构化日志记录。这支持生产中 AI 代理的故障排除,并展示了可观测性最佳实践。
指标端点 — 公开计数器(已处理请求、缓存命中率、剩余 API 配额)以进行监控。
自定义 TTL 配置 — 允许用户通过环境变量调整缓存 TTL。
社区贡献
欢迎提交!🌟
许可证
非官方社区项目。与 Pexels 无关联。
Available Tools
3 toolspexels_get_detailsGet Pexels DetailsARead-onlyIdempotent
Get detailed information about a specific photo or video by ID.
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| type | Yes | ||
| force_refresh | No |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations already indicate read-only, non-destructive, and idempotent behavior. The description adds that it returns 'detailed information' but does not disclose any additional behavioral traits like rate limits or required permissions.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, front-loaded sentence with no wasted words. It efficiently conveys the core purpose.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple tool with three parameters and no output schema, the description is minimally adequate. It fails to hint at the output format or behavior of the optional 'force_refresh' parameter, leaving some gaps.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
With 0% schema description coverage, the description should compensate. It only mentions 'by ID', leaving parameters like 'type' and 'force_refresh' unexplained. While the enum for type provides some guidance, the description adds minimal value beyond the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Description clearly states the verb 'Get', resource 'detailed information about a specific photo or video', and method 'by ID'. It effectively distinguishes from sibling search tools (pexels_search_photos, pexels_search_videos) which query by keywords.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage when a specific ID is known, contrasting with search tools. However, it does not explicitly state when not to use it or mention alternative tools.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
pexels_search_photosSearch Pexels PhotosARead-onlyIdempotent
Search for stock photos by query with optional filters for orientation, size, color, and locale. Returns 3-5 results with mandatory photographer attribution.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| orientation | No | ||
| size | No | ||
| color | No | ||
| locale | No | ||
| per_page | No | ||
| force_refresh | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| id | Yes | |
| kind | Yes | |
| creatorName | Yes | |
| creatorUrl | Yes | |
| pageUrl | Yes | |
| previewUrl | Yes | |
| mediaUrl | Yes | |
| mediaMimeType | Yes | |
| dimensions | Yes | |
| avgColor | Yes | |
| alt | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations already indicate read-only, non-destructive, and idempotent behavior. The description adds valuable behavioral details: returns 3-5 results and requires photographer attribution, which goes beyond annotations.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is two sentences, extremely concise, with no filler. Every word adds value.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the presence of an output schema and annotations, the description covers core functionality well. It lacks mention of per_page and force_refresh, but is otherwise sufficient for a search tool.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description mentions four optional filters (orientation, size, color, locale), adding semantic context that they are filters. However, it omits per_page and force_refresh, and schema coverage is 0%. The added value is marginal.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states 'Search for stock photos by query with optional filters', specifying verb and resource. It distinguishes from siblings (pexels_get_details for individual photos, pexels_search_videos for videos) by focusing on photo search.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
While the purpose is clear, the description does not provide explicit guidance on when to use this tool versus its siblings or alternatives. Usage is implied but not contrasted.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
pexels_search_videosSearch Pexels VideosARead-onlyIdempotent
Search for stock videos by query with optional filters. Returns HD-quality .mp4 links with mandatory attribution.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| orientation | No | ||
| size | No | ||
| locale | No | ||
| per_page | No | ||
| force_refresh | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| id | Yes | |
| kind | Yes | |
| creatorName | Yes | |
| creatorUrl | Yes | |
| pageUrl | Yes | |
| previewUrl | Yes | |
| mediaUrl | Yes | |
| mediaMimeType | Yes | |
| dimensions | Yes | |
| durationSeconds | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Annotations already signal read-only, non-destructive, idempotent behavior. The description adds value by disclosing that results are HD-quality .mp4 links with mandatory attribution, which are not implied by annotations.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single sentence that front-loads the action and key details. Every word earns its place with no fluff.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The output schema exists, covering return values. The description adds helpful context on output format and attribution. Missing aspects like pagination and enum specifics are minor given overall clarity.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, but the description provides no individual parameter explanations. It only mentions 'optional filters' generically, failing to compensate for the missing schema descriptions of the 6 parameters.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool searches for stock videos by query with optional filters. It mentions HD-quality .mp4 links and mandatory attribution, which distinguishes it from sibling tools like pexels_search_photos (photos) and pexels_get_details (details).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage for video searches via 'stock videos' and optional filters, but does not explicitly state when to use this tool over siblings. However, the tool name and context signals make the distinction clear.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
2 tool updates
- Changed
pexels_search_photos1 field changed- changed
Output schema / (root)Previous value: -nullNew value: +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "additionalProperties": false, + "properties": { + "alt": { + "type": "string" + }, + "avgColor": { + "type": "string" + }, + "creatorName": { + "type": "string" + }, + "creatorUrl": { + "type": "string" + }, + "dimensions": { + "additionalProperties": false, + "properties": { + "height": { + "type": "number" + }, + "width": { + "type": "number" + } + }, + "required": [ + "width", + "height" + ], + "type": "object" + }, + "id": { + "type": "number" + }, + "kind": { + "const": "photo", + "type": "string" + }, + "mediaMimeType": { + "const": "image/jpeg", + "type": "string" + }, + "mediaUrl": { + "type": "string" + }, + "pageUrl": { + "type": "string" + }, + "previewUrl": { + "type": "string" + } + }, + "required": [ + "id", + "kind", + "creatorName", + "creatorUrl", + "pageUrl", + "previewUrl", + "mediaUrl", + "mediaMimeType", + "dimensions", + "avgColor", + "alt" + ], + "type": "object" +}
- Changed
pexels_search_videos1 field changed- changed
Output schema / (root)Previous value: -nullNew value: +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "additionalProperties": false, + "properties": { + "creatorName": { + "type": "string" + }, + "creatorUrl": { + "type": "string" + }, + "dimensions": { + "additionalProperties": false, + "properties": { + "height": { + "type": "number" + }, + "width": { + "type": "number" + } + }, + "required": [ + "width", + "height" + ], + "type": "object" + }, + "durationSeconds": { + "type": "number" + }, + "id": { + "type": "number" + }, + "kind": { + "const": "video", + "type": "string" + }, + "mediaMimeType": { + "type": "string" + }, + "mediaUrl": { + "type": "string" + }, + "pageUrl": { + "type": "string" + }, + "previewUrl": { + "type": "string" + } + }, + "required": [ + "id", + "kind", + "creatorName", + "creatorUrl", + "pageUrl", + "previewUrl", + "mediaUrl", + "mediaMimeType", + "dimensions", + "durationSeconds" + ], + "type": "object" +}
3 tool updates
v1.0.0- First observed
pexels_get_details - First observed
pexels_search_photos - First observed
pexels_search_videos
TDQS
Scored across 3 tools
Each tool has a clearly distinct purpose: searching photos, searching videos, and getting details by ID. No overlap or ambiguity.
All tools follow a consistent 'pexels_verb_noun' pattern using snake_case, making it predictable for an agent to infer functionality.
Three tools is minimal but appropriate for a focused image/video search service. It covers the core workflow without unnecessary bloat.
The set covers search and retrieval of photos and videos, but lacks features like curated collections or trending content, which are minor omissions.
Maintenance
Related MCP Connectors
Search photos/videos; manage collections, people and duplicates. Requires paid OwAI Cloud Access.
Find free-to-use stock photos by words, by image or by similarity; every result names its licence.
Google, Bing, DuckDuckGo and Google Maps search results, free without an API key.
Image Search: Fast and Simple Image Search API. You can get 100+ search results in one query!.
Related MCP Servers
- AlicenseAqualityCmaintenanceA Model Context Protocol server that extracts images from URLs or base64 data and converts them into a format suitable for LLM analysis, allowing AI models to process and understand visual content.3952 npm21MIT
- AlicenseNot gradedqualityDmaintenanceEnables searching and retrieving high-quality stock photos from Pexels with advanced filtering options including orientation, size, color, and localization support.29 npmISC
- AlicenseCqualityFmaintenanceEnables AI models to search and retrieve photos, videos, and collections from Pexels via the Pexels API.1129 npm9ISC
- FlicenseNot gradedqualityDmaintenanceEnables searching and displaying high-quality, royalty-free photos from Pexels directly in ChatGPT conversations via an interactive gallery widget.2-