一个强大的模型上下文协议(MCP)服务器,提供跨多个图标库的统一搜索功能,包括模糊搜索、智能缓存和全面过滤选项。
npm install -g icon-mcp
git clone https://github.com/your-org/icon-mcp.git
cd icon-mcp
npm install
npm run build
# 从 NPM 包构建图标索引
npm run build-icons
# 启动 MCP 服务器
npm start
服务器可以通过环境变量进行配置:
# 缓存配置
CACHE_TTL=300000 # 缓存生存时间(毫秒,默认:5分钟)
CACHE_MAX_SIZE=1000 # 最大缓存条目数(默认:1000)
# 搜索配置
DEFAULT_SEARCH_LIMIT=50 # 默认搜索结果限制
FUZZY_THRESHOLD=0.3 # 默认模糊搜索阈值
# 日志
LOG_LEVEL=info # 日志级别(error, warn, info, debug)
在 Claude Desktop 配置中添加图标 MCP 服务器:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"icon-search": {
"command": "npx",
"args": ["icon-mcp"],
"env": {
"CACHE_TTL": "300000",
"DEFAULT_SEARCH_LIMIT": "50",
"LOG_LEVEL": "info"
}
}
}
}
在 VS Code 设置中配置 MCP 扩展:
{
"mcp.servers": [
{
"name": "icon-search",
"command": "npx",
"args": ["icon-mcp"],
"cwd": "${workspaceFolder}",
"env": {
"CACHE_TTL": "300000",
"DEFAULT_SEARCH_LIMIT": "50"
}
}
]
}
用于本地构建的开发:
{
"mcpServers": {
"icon-search-dev": {
"command": "node",
"args": ["dist/index.js"],
"cwd": "/path/to/icon-mcp",
"env": {
"NODE_ENV": "development",
"LOG_LEVEL": "debug",
"CACHE_TTL": "60000"
}
}
}
}
使用 Docker 镜像:
{
"mcpServers": {
"icon-search-docker": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"--env",
"CACHE_TTL=300000",
"--env",
"LOG_LEVEL=info",
"icon-mcp:latest"
]
}
}
}
通过环境变量配置服务器行为:
| 变量 | 描述 | 默认值 | 示例 |
|---|---|---|---|
CACHE_TTL | 缓存生存时间(毫秒) | 300000 | 600000 |
CACHE_MAX_SIZE | 最大缓存条目数 | 1000 | 2000 |
DEFAULT_SEARCH_LIMIT | 默认搜索结果数量 | 50 | 100 |
FUZZY_THRESHOLD | 默认模糊搜索阈值(0.0-1.0) | 0.3 | 0.5 |
LOG_LEVEL | 日志详细程度 | info | debug |
NODE_ENV | 环境模式 | production | development |
配置好 MCP 客户端后,验证连接:
list_libraries 工具以验证连接性服务器无法启动
# 检查包是否已安装
npm list -g icon-mcp
# 如需重新安装
npm install -g icon-mcp
权限错误
# 在 Unix 系统上,确保正确的权限
chmod +x $(which icon-mcp)
图标索引丢失
# 构建图标索引
cd /path/to/icon-mcp
npm run build-icons
启用调试日志以进行故障排除:
{
"mcpServers": {
"icon-search": {
"command": "npx",
"args": ["icon-mcp"],
"env": {
"LOG_LEVEL": "debug",
"NODE_ENV": "development"
}
}
}
}
手动测试服务器:
# 直接启动服务器
npx icon-mcp
# 或带有调试输出
LOG_LEVEL=debug npx icon-mcp
通过设置图标索引来配置额外的图标库:
# 将自定义库添加到 package.json 依赖项
npm install custom-icon-library
# 重建图标索引
npm run build-icons
针对高性能场景:
{
"env": {
"CACHE_TTL": "1800000",
"CACHE_MAX_SIZE": "5000",
"DEFAULT_SEARCH_LIMIT": "100",
"FUZZY_THRESHOLD": "0.2"
}
}
针对内存受限环境:
{
"env": {
"CACHE_MAX_SIZE": "500",
"DEFAULT_SEARCH_LIMIT": "25",
"NODE_OPTIONS": "--max-old-space-size=512"
}
}
search_icons通过名称在所有或特定库中搜索图标,并支持模糊匹配。
参数:
query (字符串,必需):图标的搜索词libraries (字符串数组,可选):要搜索的具体库fuzzy (布尔值,可选):启用模糊搜索(默认:true)limit (数字,可选):返回的最大结果数(默认:10)threshold (数字,可选):模糊搜索阈值 0.0-1.0(默认:0.3)includeScore (布尔值,可选):包含匹配分数(默认:true)示例:
{
"query": "home",
"libraries": ["bootstrap-icons", "feather"],
"fuzzy": true,
"limit": 20,
"threshold": 0.3
}
响应:
{
"query": "home",
"results": [
{
"item": {
"name": "house",
"library": "bootstrap-icons",
"tags": ["house", "home", "building"],
"style": "regular",
"path": "node_modules/bootstrap-icons/icons/house.svg",
"categories": ["navigation"],
"size": "16x16"
},
"score": 0.0
}
],
"totalResults": 15,
"searchType": "fuzzy",
"executionTime": 45,
"libraries": ["bootstrap-icons", "feather"]
}
get_icon获取特定图标的详细信息。
参数:
id (字符串,必需):图标的唯一标识符library (字符串,必需):图标的库名示例:
{
"id": "house",
"library": "bootstrap-icons"
}
list_libraries获取所有可用图标库的列表。
参数: 无
响应:
{
"libraries": ["bootstrap-icons", "feather", "octicons", "lucide", "tabler-icons"],
"count": 5
}
get_library_info获取特定库的详细信息。
参数:
library (字符串,必需):库名响应:
{
"name": "bootstrap-icons",
"displayName": "Bootstrap Icons",
"description": "官方开源的 Bootstrap SVG 图标库",
"version": "1.11.3",
"iconCount": 1800,
"categories": ["navigation", "communication", "media", "ui"],
"styles": ["regular"],
"isAvailable": true
}
search_by_category通过类别或标签查找图标,并支持模糊匹配。
参数:
category (字符串,必需):要搜索的类别名libraries (字符串数组,可选):要搜索的具体库fuzzy (布尔值,可选):启用模糊搜索(默认:true)limit (数字,可选):返回的最大结果数(默认:10)src/
├── index.ts # 主 MCP 服务器入口点
├── providers/ # 图标提供者实现
│ ├── icon-provider.interface.ts
│ ├── base-npm-provider.ts
│ ├── heroicons.provider.ts
│ ├── bootstrap-icons.provider.ts
│ ├── feather.provider.ts
│ ├── octicons.provider.ts
│ ├── lucide.provider.ts
│ ├── simple-icons.provider.ts
│ └── tabler-icons.provider.ts
├── services/ # 核心服务
│ ├── search.service.ts # 统一搜索服务
│ └── cache.service.ts # 缓存服务
├── tools/ # MCP 工具
│ └── index.ts # 图标搜索工具
├── types/ # TypeScript 类型定义
│ └── index.ts
└── utils/ # 实用函数
└── errors.ts
提供者系统允许轻松添加新的图标库:
export abstract class IconProvider {
abstract initialize(): Promise<void>;
abstract searchIcons(query: string, options?: FuseSearchOptions): Promise<FuseResult<Icon>[]>;
abstract getIcon(id: string): Promise<Icon | null>;
abstract getAllIcons(): Promise<Icon[]>;
abstract getInfo(): Promise<IconLibrary>;
}
搜索服务提供了跨所有提供者的统一搜索:
# 运行所有测试
npm test
# 运行带覆盖率的测试
npm run test:coverage
# 运行集成测试
npm run test:integration
# 运行性能测试
npm run test:performance
git clone https://github.com/your-org/icon-mcp.git
cd icon-mcp
npm install
# 安装图标库依赖项
npm install
# 构建项目
npm run build
# 在开发模式下启动
npm run dev
npm install new-icon-library
BaseNpmProvider 的提供者类:export class NewLibraryProvider extends BaseNpmProvider {
constructor() {
super('new-library', 'New Library', '1.0.0', 'new-icon-library', ['icons/*.svg']);
}
protected getDescription(): string {
return '新库的描述';
}
protected getSourceUrl(): string {
return 'https://github.com/library/icons';
}
protected getLicense(): string {
return 'MIT';
}
}
src/providers/index.ts 中注册提供者:registry.register(new NewLibraryProvider());
scripts/build-index.js 中添加库配置:'new-icon-library': {
name: 'new-library',
displayName: 'New Library',
description: '新库的描述',
sourceUrl: 'https://github.com/library/icons',
license: 'MIT',
iconPaths: ['icons/*.svg'],
styles: ['regular'],
}
git checkout -b feature/amazing-featuregit commit -m '添加神奇的功能'git push origin feature/amazing-feature本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
为开发者社区制作 ❤️