Provides type-safe integration with the KPC component library through complete TypeScript type definitions for all component APIs, props, events, and methods.
KPC组件库MCP服务
基于官方 @modelcontextprotocol/sdk 开发的KPC组件库AI代码生成服务,彻底解决AI幻觉问题。
🎯 解决的问题
- AI幻觉问题: AI经常使用不存在的组件属性或错误的API
- 导入方式错误: AI使用错误的包名导入组件
- 嵌套关系错误: 如Form组件不使用FormItem包裹表单控件
- 依赖源码环境: 传统方案需要访问KPC源码
🚀 方案优势
特性 | 静态文档 | 官方SDK MCP服务 |
---|---|---|
开发标准 | 自定义实现 | 官方TypeScript SDK |
类型安全 | 无类型检查 | 完整TypeScript类型 |
错误处理 | 简单异常 | 标准MCP错误码 |
可维护性 | 手工维护 | 官方标准+自动化 |
Token消耗 | ~50KB+ | ~5KB 精确API |
覆盖范围 | 部分组件 | 全部58个组件 |
📁 项目结构
🛠️ 快速开始
1. 安装依赖
2. 编译项目
3. 运行测试
4. 启动服务
5. 配置Claude Desktop
编辑 Claude Desktop 配置文件:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
🔧 MCP工具列表
工具名 | 功能 | 参数 |
---|---|---|
get_kpc_component | 获取组件完整API | component : 组件名 |
search_kpc_components | 搜索相关组件 | query : 搜索关键词category ?: 分类筛选fuzzy ?: 模糊搜索 |
list_kpc_components | 列出所有组件 | category ?: 分类筛选summary ?: 简要信息 |
validate_kpc_usage | 验证组件使用 | component : 组件名props : 属性对象context ?: 上下文 |
get_kpc_usage_examples | 获取使用示例 | component : 组件名scenario ?: 使用场景framework ?: 目标框架 |
get_kpc_stats | 获取统计信息 | 无参数 |
💡 实际使用示例
场景1: AI需要数字输入框
场景2: 验证代码正确性
场景3: 获取使用示例
📊 API数据统计
运行 get_kpc_stats
工具查看最新统计:
- 组件总数: 58个
- 分类: 7大类(基础组件、表单组件、数据展示等)
- API覆盖:
- ✅ Props属性: 完整类型定义和默认值
- ✅ Events事件: 参数类型和描述
- ✅ Methods方法: 返回值类型和用途
- ✅ Slots插槽: 参数定义和说明
- ✅ 使用示例: 真实可用代码
- ✅ 嵌套规则: 防止错误用法
🧪 测试验证
测试覆盖:
- ✅ 数据加载和缓存
- ✅ 组件检索和搜索
- ✅ 使用验证和错误检查
- ✅ 示例生成和格式化
- ✅ 边界情况和异常处理
🏗️ 开发指南
项目结构
添加新功能
- 添加新的MCP工具:
- 扩展验证规则:
- 自定义示例生成:
🔄 数据更新流程
当KPC组件库更新时:
- 重新提取API数据(在KPC源码环境中):
- 更新MCP服务数据:
- 重新编译和测试:
- 重启服务:
🔐 安全性和性能
安全性
- 只读操作: 服务只提供API查询,不修改任何代码
- 数据验证: 严格的TypeScript类型检查
- 错误处理: 完善的异常捕获和MCP标准错误码
- 输入验证: 所有用户输入都经过验证
性能优化
- 数据缓存: 组件数据加载后缓存在内存
- 按需查询: 只返回请求的组件信息
- 分类索引: 支持快速分类查找和筛选
- 异步加载: 使用异步I/O避免阻塞
🎉 最终效果
✅ 100%消除AI幻觉: 基于真实API数据,确保属性、事件、方法都存在
✅ 正确的导入方式: 明确使用 @king-design/vue
等正确包名
✅ 准确的嵌套关系: Form → FormItem → 表单控件等规则自动验证
✅ 完整的API覆盖: 58个组件的全部Props、Events、Methods、Slots
✅ 智能验证机制: 实时检查代码正确性并提供修复建议
✅ 官方标准实现: 基于官方TypeScript SDK,类型安全,易维护
🚢 部署选项
开发环境
生产环境
Docker部署
CI/CD集成
- KPC更新时自动重新提取API
- 自动运行测试套件
- 版本化管理API数据
- 自动部署新版本服务
tools说明
- extract-api.js 用于kpc根目录下生成kpc-api-full.json相关json
- supplement_kpc_api.py 用于补全extract-api.js生成组件丢失的属性等
- generate_api.files.py 用于基于kpc-api-full.json生成其他分类压缩json
debugger
npx -y @modelcontextprotocol/inspector npx kpc-mcp-server
这个基于官方SDK的实现提供了更高的代码质量、类型安全和维护性,是企业级应用的最佳选择。
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
AI code generation service for KPC component library that solves hallucination problems by providing accurate component APIs, validation rules, and usage examples.
Related MCP Servers
- AsecurityAlicenseAqualityEnables intelligent code analysis and debugging through the Perplexity AI's API, offering detailed error analysis, pattern detection, and comprehensive solutions, with integration support for the Claude desktop client.Last updated -110JavaScriptMIT License
- AsecurityAlicenseAqualityA server enabling integration between KoboldAI's text generation capabilities and MCP-compatible applications, with features like chat completion, Stable Diffusion, and OpenAI-compatible API endpoints.Last updated -2053JavaScriptMIT License
- -securityFlicense-qualityProvides code generation and completion capabilities using the DeepSeek API, with support for tool chaining and cost optimization.Last updated -3JavaScript
- -securityAlicense-qualityMCP server to provide Sketch layout information to AI coding agents like CursorLast updated -6332JavaScriptMIT License