npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

code-intelligence-mcp

v1.0.0

Published

MCP Service for Intelligent Code Suggestion - Components and Utilities Recommendation

Readme

Code Intelligence MCP

License: MIT Node.js Version TypeScript pnpm

English | 中文

智能代码建议 MCP 服务,为 AI IDE 提供组件与工具方法的智能推荐能力。

项目简介

本项目是一个基于 Model Context Protocol (MCP) 的智能代码建议服务,通过 AI 分析用户需求,从私有代码库中推荐最合适的组件和工具方法,帮助开发者提高代码复用率和开发效率。

核心能力

🎨 UI 组件智能推荐

  • 分析 UI 开发需求(页面、表单、界面等)
  • 从组件知识库中匹配最相关的私有组件
  • 生成包含组件引入和使用方式的优化提示词
  • 提供完整的实现指南和代码示例

🔧 工具方法智能推荐

  • 分析逻辑功能需求(数据处理、格式转换、工具函数等)
  • 从方法知识库中查找可复用的工具方法
  • 生成包含方法引入和调用方式的优化提示词
  • 避免重复造轮子,提升代码质量

功能特性

智能分析引擎

  • 需求理解:基于 AI 深度理解用户开发意图
  • 关键词提取:自动识别需求中的核心要素
  • 复杂度评估:智能评估实现难度和组件适配度

知识库管理

  • 组件知识库:管理私有 UI 组件库(props、events、slots、示例)
  • 方法知识库:管理工具方法库(参数、返回值、类型、用法)
  • 相关性算法:基于语义匹配计算推荐评分

提示词优化

  • 双向优化:支持组件和方法两种场景的提示词重设计
  • 结构化输出:生成包含引入语句、实现步骤的完整方案
  • 最佳实践:融入代码规范和使用建议

项目结构

code-intelligence-mcp/
├── src/
│   ├── core/                          # 核心功能模块
│   │   ├── knowledge-base.ts          # 组件知识库管理
│   │   ├── utility-knowledge-base.ts  # 工具方法知识库管理
│   │   ├── prompt-redesigner.ts       # UI 组件提示词重设计
│   │   ├── logic-prompt-redesigner.ts # 逻辑方法提示词重设计
│   │   ├── ai-suggester.ts            # AI 组件推荐引擎
│   │   ├── ai-utility-suggester.ts    # AI 方法推荐引擎
│   │   └── index.ts
│   ├── config/                        # 配置管理
│   │   ├── model-manager.ts           # AI 模型管理器
│   │   ├── ai-client-adapter.ts       # AI 客户端适配器
│   │   ├── types.ts                   # 配置类型定义
│   │   └── index.ts
│   ├── tools/                         # MCP 工具定义
│   │   ├── suggestion.ts              # 组件建议工具
│   │   ├── utility-suggestion.ts      # 方法建议工具
│   │   ├── query.ts                   # 查询工具
│   │   └── index.ts
│   ├── resources/                     # MCP 资源定义
│   │   └── index.ts
│   ├── types/                         # 类型定义
│   │   └── mcp-types.ts
│   ├── utils/                         # 工具函数
│   │   ├── logger.ts                  # 日志工具
│   │   ├── ai-caller.ts               # AI 统一调用工具
│   │   ├── path-utils.ts              # 路径解析工具
│   │   └── index.ts
│   └── mcp-server.ts                  # MCP 服务器主入口
├── ci-mcp-data/                       # 配置数据(用户私有)
│   ├── components.example.json        # UI 组件知识库示例
│   ├── utils.example.json             # 工具方法知识库示例
│   └── config.example.json            # AI 模型配置示例
├── scripts/                           # 脚本工具
│   ├── setup.js                       # 初始化脚本
│   └── start.sh                       # 启动脚本
├── package.json
├── tsconfig.json
└── .npmignore                         # NPM 发布排除配置

安装和使用

方式一:使用 npx(推荐)

这是在 AI IDE(如 Claude Desktop)中使用 MCP 服务的推荐方式。

步骤 1:准备配置文件

创建配置目录(推荐位置:~/.config/ci-mcp):

mkdir -p ~/.config/ci-mcp

下载或创建以下三个配置文件:

  1. config.json - AI 模型配置
  2. components.json - UI 组件知识库
  3. utils.json - 工具方法知识库

你可以从 npm 包或仓库中找到示例文件。

步骤 2:配置 AI IDE

在 AI IDE 配置文件中添加(如 Claude Desktop 的 claude_desktop_config.json):

{
  "mcpServers": {
    "code-intelligence": {
      "command": "npx",
      "args": ["-y", "code-intelligence-mcp"],
      "env": {
        "CI_MCP_DATA_DIR": "~/.config/ci-mcp"
      }
    }
  }
}

环境变量说明:

  • CI_MCP_DATA_DIR(推荐):指定配置目录,所有三个文件将从该目录加载
  • CI_MCP_CONFIG:直接指定 config.json 的路径
  • CI_MCP_COMPONENTS:直接指定 components.json 的路径
  • CI_MCP_UTILS:直接指定 utils.json 的路径

支持的路径格式:

  • 绝对路径:/Users/xxx/.config/ci-mcp
  • 主目录:~/.config/ci-mcp$HOME/.config/ci-mcp
  • 环境变量:${MY_CONFIG_DIR}/ci-mcp

步骤 3:重启 AI IDE

重启你的 AI IDE(如 Claude Desktop),MCP 服务将通过 npx 自动启动。


方式二:本地开发

前置准备

配置知识库数据文件

项目需要在 ci-mcp-data/ 目录中手动配置以下数据文件:

  1. ci-mcp-data/config.json - AI 模型配置(包含 API Key)

    cp ci-mcp-data/config.example.json ci-mcp-data/config.json
    # 编辑 config.json,填入你的 API Key
  2. ci-mcp-data/components.json - UI 组件知识库

    cp ci-mcp-data/components.example.json ci-mcp-data/components.json
    # 编辑 components.json,根据你的私有组件库配置组件信息
    • 参考现有格式添加组件的 descriptionimportrelativePath 等字段
  3. ci-mcp-data/utils.json - 工具方法知识库

    cp ci-mcp-data/utils.example.json ci-mcp-data/utils.json
    # 编辑 utils.json,根据你的工具方法库配置方法信息
    • 包含方法的 descriptionimportparamsreturns 等字段

说明:

  • config.json 包含敏感信息(API Key),已添加到 .gitignore,不会提交到版本库
  • components.jsonutils.json 需要根据你的实际代码库进行配置
  • 可以参考示例文件 config.example.json 了解配置格式

安装依赖

pnpm install

开发模式运行

pnpm dev

构建

pnpm build

生产模式运行

pnpm start:prod

MCP 工具说明

🎨 UI 组件建议工具

1. suggest_components

智能分析 UI 开发需求,推荐最合适的私有组件。

使用场景:

  • 创建页面、表单、界面等 UI 功能
  • 需要使用私有组件库快速开发
  • 希望获得完整的实现方案

输入参数:

{
  prompt: string; // 用户需求描述,如 "创建用户登录页面"
}

输出内容:

  • 需求分析:关键词、组件类型、复杂度评估
  • 推荐组件:组件列表 + 相关性评分 + 推荐理由
  • 优化提示词:包含具体组件引入和使用方式
  • 实现指南:分步骤的开发建议

示例:

// 输入
{"prompt": "生成一个用户信息编辑表单"}

// 输出
{
  "analysis": {
    "keywords": ["表单", "编辑", "用户信息"],
    "componentTypes": ["form", "input", "button"]
  },
  "suggestedComponents": [
    {
      "name": "das-form",
      "relevance": 0.95,
      "reason": "最适合用户信息编辑场景"
    }
  ],
  "redesignedPrompt": "使用 das-form 组件创建...",
  "implementationGuide": "1. 引入组件...\n2. 配置表单字段..."
}

2. query_component

查询指定组件的详细信息。

输入参数:

{
  componentName: string; // 组件名称,如 "das-button"
}

输出内容:

  • 组件描述、分类、标签
  • Props 参数列表
  • Events 事件列表
  • Slots 插槽说明
  • 使用示例代码
  • 引入路径

🔧 工具方法建议工具

1. suggest_utilities

智能分析逻辑开发需求,推荐可复用的工具方法。

使用场景:

  • 实现数据处理、格式转换功能
  • 需要加密、校验等工具函数
  • 希望避免重复造轮子

输入参数:

{
  prompt: string; // 逻辑需求描述,如 "需要格式化数字为千分位"
}

输出内容:

  • 需求分析:关键功能点、方法类型
  • 推荐方法:方法列表 + 相关性评分 + 推荐理由
  • 优化提示词:包含方法引入和调用方式
  • 实现指南:使用步骤和注意事项

示例:

// 输入
{"prompt": "实现密码加密功能"}

// 输出
{
  "analysis": {
    "keywords": ["加密", "密码", "安全"],
    "methodTypes": ["encryption", "security"]
  },
  "suggestedUtilities": [
    {
      "name": "encryptPassword",
      "relevance": 0.98,
      "reason": "提供 MD5/SHA256 密码加密"
    }
  ],
  "redesignedPrompt": "使用 encryptPassword 方法...",
  "implementationGuide": "1. 引入方法...\n2. 调用加密..."
}

2. query_utility

查询指定工具方法的详细信息。

输入参数:

{
  utilityName: string; // 方法名称,如 "formatNumber"
}

输出内容:

  • 方法描述、分类、类型
  • 参数列表(参数名、类型、说明)
  • 返回值类型和说明
  • 使用示例代码
  • 引入路径

MCP 资源

code-intelligence://component-library

组件库资源

提供完整的私有组件库信息,包括:

  • 所有可用组件列表
  • 组件分类和标签
  • 组件能力概览

code-intelligence://utility-library

工具方法库资源

提供完整的工具方法库信息,包括:

  • 所有可用方法列表
  • 方法分类和功能
  • 方法能力概览

code-intelligence://usage-guide

使用指南资源

包含:

  • MCP 工具使用说明
  • 最佳实践建议
  • 常见问题解答
  • 集成配置指南

技术栈

核心框架

  • TypeScript - 类型安全开发
  • Node.js - 运行时环境
  • MCP SDK (@modelcontextprotocol/sdk) - Model Context Protocol 实现

AI 集成

  • Vercel AI SDK - 统一 AI 接口
  • OpenAI - GPT 系列模型支持
  • Anthropic - Claude 系列模型支持
  • DeepSeek - 国产大模型支持

开发工具

  • pnpm - 包管理器
  • tsx - TypeScript 执行器
  • ESLint + Prettier - 代码规范
  • Husky - Git hooks

开发规范

  • 使用 TypeScript 进行类型安全开发
  • 遵循 ESLint 和 Prettier 代码规范
  • 使用 Husky 进行 Git hooks 管理

配置说明

1. MCP 服务配置(mcp-config.json)

在 AI IDE 中注册 MCP 服务:

{
  "mcpServers": {
    "code-intelligence": {
      "command": "/bin/zsh",
      "args": ["/path/to/code-intelligence-mcp/scripts/start.sh"]
    }
  }
}

2. AI 模型配置(data/config.json)

配置 AI 推荐引擎使用的模型:

{
  "defaultModel": "claude-3-7-sonnet-latest",
  "providers": [
    {
      "provider": "anthropic",
      "models": [
        {
          "model": "claude-3-7-sonnet-latest",
          "title": "Claude 3.7 Sonnet",
          "baseURL": "https://api.302.ai/v1",
          "apiKey": "your-api-key"
        }
      ]
    },
    {
      "provider": "openai",
      "models": [
        {
          "model": "gpt-4o",
          "title": "GPT-4o",
          "baseURL": "https://api.openai.com/v1",
          "apiKey": "your-api-key"
        }
      ]
    }
  ]
}

配置说明:

  • defaultModel: 默认使用的模型名称,必须存在于 providers
  • providers: 支持的 AI 提供商列表
    • provider: 提供商类型 (anthropicopenaideepseekollama)
    • models: 该提供商下的模型配置列表
      • model: 模型名称(必须与 defaultModel 匹配)
      • title: 模型显示名称
      • baseURL: API 端点地址
      • apiKey: API 密钥

支持的提供商:

  • anthropic - Claude 系列模型
  • openai - GPT 系列模型
  • deepseek - DeepSeek 国产模型
  • ollama - 本地模型

3. 知识库数据

组件知识库(data/components.json)

{
  "components": [
    {
      "name": "das-button",
      "description": "按钮组件",
      "category": "基础组件",
      "tags": ["按钮", "交互"],
      "props": [...],
      "events": [...],
      "example": "..."
    }
  ]
}

工具方法知识库(data/utils.json)

{
  "utilities": [
    {
      "name": "formatNumber",
      "description": "格式化数字为千分位",
      "category": "格式化",
      "type": "formatter",
      "params": [...],
      "returns": {...},
      "example": "..."
    }
  ]
}

License

MIT

贡献指南

欢迎贡献!请查看 CONTRIBUTING.md 了解如何为本项目做出贡献。

变更日志

查看 CHANGELOG.md 了解版本历史和发布说明。