pit-docs-mcp 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/README.md +180 -0
  2. package/dist/codegen.d.ts +5 -0
  3. package/dist/codegen.d.ts.map +1 -0
  4. package/dist/codegen.js +112 -0
  5. package/dist/constants.d.ts +6 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/constants.js +10 -0
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +115 -0
  11. package/dist/resources.d.ts +3 -0
  12. package/dist/resources.d.ts.map +1 -0
  13. package/dist/resources.js +80 -0
  14. package/dist/tools.d.ts +3 -0
  15. package/dist/tools.d.ts.map +1 -0
  16. package/dist/tools.js +258 -0
  17. package/dist/utils.d.ts +26 -0
  18. package/dist/utils.d.ts.map +1 -0
  19. package/dist/utils.js +198 -0
  20. package/docs/codegen/pit-simplify-web.md +686 -0
  21. package/docs/pitBusinessUi/README.md +102 -0
  22. package/docs/pitBusinessUi/add-date-picker.md +57 -0
  23. package/docs/pitBusinessUi/add-operation.md +64 -0
  24. package/docs/pitBusinessUi/batch-download.md +44 -0
  25. package/docs/pitBusinessUi/bill-tree-dialog.md +82 -0
  26. package/docs/pitBusinessUi/collapse.md +88 -0
  27. package/docs/pitBusinessUi/date-time-picker.md +74 -0
  28. package/docs/pitBusinessUi/design-report-explain.md +47 -0
  29. package/docs/pitBusinessUi/dialog.md +89 -0
  30. package/docs/pitBusinessUi/dic-radio.md +67 -0
  31. package/docs/pitBusinessUi/dic.md +78 -0
  32. package/docs/pitBusinessUi/document-preview.md +54 -0
  33. package/docs/pitBusinessUi/drawer.md +67 -0
  34. package/docs/pitBusinessUi/editor.md +63 -0
  35. package/docs/pitBusinessUi/expand-search-form.md +65 -0
  36. package/docs/pitBusinessUi/file-preview.md +56 -0
  37. package/docs/pitBusinessUi/flow-table-status.md +47 -0
  38. package/docs/pitBusinessUi/icon-box.md +74 -0
  39. package/docs/pitBusinessUi/image-preview.md +55 -0
  40. package/docs/pitBusinessUi/image.md +53 -0
  41. package/docs/pitBusinessUi/input-formatter.md +100 -0
  42. package/docs/pitBusinessUi/input-number.md +47 -0
  43. package/docs/pitBusinessUi/input-select.md +68 -0
  44. package/docs/pitBusinessUi/input.md +56 -0
  45. package/docs/pitBusinessUi/jm-preview.md +47 -0
  46. package/docs/pitBusinessUi/json-editor.md +71 -0
  47. package/docs/pitBusinessUi/loading-btn.md +64 -0
  48. package/docs/pitBusinessUi/monaco.md +82 -0
  49. package/docs/pitBusinessUi/money-input.md +59 -0
  50. package/docs/pitBusinessUi/pagination.md +70 -0
  51. package/docs/pitBusinessUi/password-strength.md +59 -0
  52. package/docs/pitBusinessUi/positive-number.md +63 -0
  53. package/docs/pitBusinessUi/preview-image.md +62 -0
  54. package/docs/pitBusinessUi/preview-office.md +50 -0
  55. package/docs/pitBusinessUi/preview.md +57 -0
  56. package/docs/pitBusinessUi/quill.md +52 -0
  57. package/docs/pitBusinessUi/runflow-btn.md +52 -0
  58. package/docs/pitBusinessUi/search-date-picker.md +60 -0
  59. package/docs/pitBusinessUi/select-bid-list.md +66 -0
  60. package/docs/pitBusinessUi/select-color.md +38 -0
  61. package/docs/pitBusinessUi/select-contract-tree.md +41 -0
  62. package/docs/pitBusinessUi/select-dept.md +38 -0
  63. package/docs/pitBusinessUi/select-project-unit.md +48 -0
  64. package/docs/pitBusinessUi/select-section-tree.md +45 -0
  65. package/docs/pitBusinessUi/select-section.md +66 -0
  66. package/docs/pitBusinessUi/select-string.md +60 -0
  67. package/docs/pitBusinessUi/select-system-unit.md +41 -0
  68. package/docs/pitBusinessUi/select-user-by-role.md +51 -0
  69. package/docs/pitBusinessUi/switch.md +43 -0
  70. package/docs/pitBusinessUi/table-contract.md +66 -0
  71. package/docs/pitBusinessUi/table-operation.md +81 -0
  72. package/docs/pitBusinessUi/table.md +75 -0
  73. package/docs/pitBusinessUi/tag.md +86 -0
  74. package/docs/pitBusinessUi/textarea.md +65 -0
  75. package/docs/pitBusinessUi/transfer-direct.md +57 -0
  76. package/docs/pitBusinessUi/transfer-user-project.md +78 -0
  77. package/docs/pitBusinessUi/transfer.md +68 -0
  78. package/docs/pitBusinessUi/tree-lazy.md +72 -0
  79. package/docs/pitBusinessUi/tree-select-name.md +59 -0
  80. package/docs/pitBusinessUi/tree-select-plus.md +106 -0
  81. package/docs/pitBusinessUi/tree-select.md +86 -0
  82. package/docs/pitBusinessUi/upload-avatar.md +60 -0
  83. package/docs/pitBusinessUi/upload-file-dialog.md +86 -0
  84. package/docs/pitBusinessUi/upload-file.md +77 -0
  85. package/docs/pitBusinessUi/upload-list-card.md +62 -0
  86. package/docs/pitBusinessUi/upload-table.md +77 -0
  87. package/docs/pitBusinessUi/user-transform.md +72 -0
  88. package/docs/pitBusinessUi/utils.md +272 -0
  89. package/docs/pitBusinessUtils/README.md +144 -0
  90. package/docs/pitBusinessUtils/auth.md +170 -0
  91. package/docs/pitBusinessUtils/clipboard.md +72 -0
  92. package/docs/pitBusinessUtils/filePreview.md +60 -0
  93. package/docs/pitBusinessUtils/formValidate.md +75 -0
  94. package/docs/pitBusinessUtils/generateTitle.md +49 -0
  95. package/docs/pitBusinessUtils/get-page-title.md +65 -0
  96. package/docs/pitBusinessUtils/i18n.md +130 -0
  97. package/docs/pitBusinessUtils/jwks.md +82 -0
  98. package/docs/pitBusinessUtils/oss.md +391 -0
  99. package/docs/pitBusinessUtils/passwordValidate.md +120 -0
  100. package/docs/pitBusinessUtils/pit.md +496 -0
  101. package/docs/pitBusinessUtils/print.md +126 -0
  102. package/docs/pitBusinessUtils/request.md +137 -0
  103. package/docs/pitBusinessUtils/scroll-to.md +68 -0
  104. package/docs/pitBusinessUtils/utils.md +762 -0
  105. package/docs/pitBusinessUtils/validate.md +224 -0
  106. package/docs/pitElementUi/alert.md +238 -0
  107. package/docs/pitElementUi/avatar.md +147 -0
  108. package/docs/pitElementUi/backtop.md +60 -0
  109. package/docs/pitElementUi/badge.md +120 -0
  110. package/docs/pitElementUi/base-tabs.md +73 -0
  111. package/docs/pitElementUi/border.md +135 -0
  112. package/docs/pitElementUi/breadcrumb.md +44 -0
  113. package/docs/pitElementUi/button.md +301 -0
  114. package/docs/pitElementUi/calendar.md +66 -0
  115. package/docs/pitElementUi/card.md +170 -0
  116. package/docs/pitElementUi/carousel.md +212 -0
  117. package/docs/pitElementUi/cascader.md +1966 -0
  118. package/docs/pitElementUi/checkbox.md +283 -0
  119. package/docs/pitElementUi/collapse.md +131 -0
  120. package/docs/pitElementUi/color-picker.md +123 -0
  121. package/docs/pitElementUi/color.md +244 -0
  122. package/docs/pitElementUi/container.md +240 -0
  123. package/docs/pitElementUi/custom-theme.md +131 -0
  124. package/docs/pitElementUi/date-picker.md +448 -0
  125. package/docs/pitElementUi/datetime-picker.md +254 -0
  126. package/docs/pitElementUi/descriptions.md +191 -0
  127. package/docs/pitElementUi/dialog-header.md +53 -0
  128. package/docs/pitElementUi/dialog.md +239 -0
  129. package/docs/pitElementUi/divider.md +61 -0
  130. package/docs/pitElementUi/drawer.md +307 -0
  131. package/docs/pitElementUi/dropdown.md +308 -0
  132. package/docs/pitElementUi/empty.md +61 -0
  133. package/docs/pitElementUi/font-family.md +90 -0
  134. package/docs/pitElementUi/form-base.md +1239 -0
  135. package/docs/pitElementUi/form-item-checkbox-group.md +48 -0
  136. package/docs/pitElementUi/form-item-date.md +60 -0
  137. package/docs/pitElementUi/form-item-dic.md +18 -0
  138. package/docs/pitElementUi/form-item-editor.md +16 -0
  139. package/docs/pitElementUi/form-item-input-money.md +19 -0
  140. package/docs/pitElementUi/form-item-input-number.md +20 -0
  141. package/docs/pitElementUi/form-item-input.md +18 -0
  142. package/docs/pitElementUi/form-item-radio-group.md +21 -0
  143. package/docs/pitElementUi/form-item-select.md +21 -0
  144. package/docs/pitElementUi/form-item-switch.md +15 -0
  145. package/docs/pitElementUi/form-item-textarea.md +20 -0
  146. package/docs/pitElementUi/form-item-tree-select.md +27 -0
  147. package/docs/pitElementUi/form-item-upload-card.md +18 -0
  148. package/docs/pitElementUi/form-item-upload.md +1 -0
  149. package/docs/pitElementUi/form-two.md +102 -0
  150. package/docs/pitElementUi/form.md +952 -0
  151. package/docs/pitElementUi/i18n.md +228 -0
  152. package/docs/pitElementUi/icon-custom.md +99 -0
  153. package/docs/pitElementUi/icon-line-custom.md +12 -0
  154. package/docs/pitElementUi/icon.md +28 -0
  155. package/docs/pitElementUi/image.md +178 -0
  156. package/docs/pitElementUi/infiniteScroll.md +87 -0
  157. package/docs/pitElementUi/input-number.md +197 -0
  158. package/docs/pitElementUi/input-select.md +1 -0
  159. package/docs/pitElementUi/input.md +800 -0
  160. package/docs/pitElementUi/installation.md +9 -0
  161. package/docs/pitElementUi/layout-column.md +376 -0
  162. package/docs/pitElementUi/layout-tree.md +715 -0
  163. package/docs/pitElementUi/layout.md +354 -0
  164. package/docs/pitElementUi/link.md +66 -0
  165. package/docs/pitElementUi/loading.md +208 -0
  166. package/docs/pitElementUi/menu.md +403 -0
  167. package/docs/pitElementUi/message-box.md +326 -0
  168. package/docs/pitElementUi/message.md +219 -0
  169. package/docs/pitElementUi/notification.md +311 -0
  170. package/docs/pitElementUi/page-header.md +40 -0
  171. package/docs/pitElementUi/pagination.md +200 -0
  172. package/docs/pitElementUi/popconfirm.md +60 -0
  173. package/docs/pitElementUi/popover.md +167 -0
  174. package/docs/pitElementUi/progress.md +178 -0
  175. package/docs/pitElementUi/quickstart.md +290 -0
  176. package/docs/pitElementUi/radio.md +211 -0
  177. package/docs/pitElementUi/rate.md +135 -0
  178. package/docs/pitElementUi/result.md +76 -0
  179. package/docs/pitElementUi/select-tree.md +661 -0
  180. package/docs/pitElementUi/select.md +586 -0
  181. package/docs/pitElementUi/skeleton.md +316 -0
  182. package/docs/pitElementUi/slider.md +237 -0
  183. package/docs/pitElementUi/steps.md +154 -0
  184. package/docs/pitElementUi/switch.md +142 -0
  185. package/docs/pitElementUi/table.md +4023 -0
  186. package/docs/pitElementUi/tabs.md +303 -0
  187. package/docs/pitElementUi/tag.md +203 -0
  188. package/docs/pitElementUi/time-picker.md +199 -0
  189. package/docs/pitElementUi/timeline.md +154 -0
  190. package/docs/pitElementUi/tooltip.md +177 -0
  191. package/docs/pitElementUi/transfer.md +249 -0
  192. package/docs/pitElementUi/transition.md +155 -0
  193. package/docs/pitElementUi/tree.md +1157 -0
  194. package/docs/pitElementUi/typography.md +151 -0
  195. package/docs/pitElementUi/upload-table.md +39 -0
  196. package/docs/pitElementUi/upload.md +392 -0
  197. package/docs/pitElementUi/virtual-list.md +154 -0
  198. package/docs/pitElementUi/virtual-select-tree.md +243 -0
  199. package/docs/pitElementUi/virtual-select.md +451 -0
  200. package/docs/pitElementUi/virtual-table-column.md +1 -0
  201. package/docs/pitElementUi/virtual-table.md +490 -0
  202. package/docs/pitElementUi/virtual-tree.md +119 -0
  203. package/package.json +33 -0
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # PIT Docs MCP Server
2
+
3
+ MCP (Model Context Protocol) 服务,用于将公司内部的 Vue 组件文档和规范文档暴露给 AI,使其在编写前端代码时能够参考内部最佳实践和 API 规范。
4
+
5
+ **pit-xxx** 和 **el-xxx** 为内部私有组件,互联网上无任何官方文档,此 MCP 是查询其用法、Props、Events、Slots 的**唯一途径**。
6
+
7
+ ## 功能
8
+
9
+ 1. **Tools(工具)**:提供 4 个工具供 AI 查询组件文档和代码生成规范。
10
+ 2. **Resources(Resource Templates)**:通过 `pit-docs:///` URI 将文档作为只读资源暴露。
11
+ 3. **Prompts(提示)**:提供 2 个 Prompt,引导 AI 正确使用 pit 组件及生成后台管理页面。
12
+
13
+ ## 支持的库
14
+
15
+ | 库名 | 说明 |
16
+ |-----|------|
17
+ | **pitBusinessUi** | 业务组件(如 pit-table、pit-dic、pit-document-preview) |
18
+ | **pitElementUi** | 基础 UI 组件(如 el-form-base、el-upload-table) |
19
+ | **pitBusinessUtils** | 工具函数(如 formValidate、auth、request) |
20
+
21
+ ## 工具说明
22
+
23
+ ### search_docs
24
+
25
+ 在文档中按关键字搜索。**涉及任何 pit-xxx 或 el-xxx 组件时,必须先调用此工具**。
26
+
27
+ | 参数 | 类型 | 默认 | 说明 |
28
+ |-----|------|------|------|
29
+ | `keyword` | string | 必填 | 组件名或关键词,如 `pit-table`、`el-form-base`。多词空格分隔(OR 匹配) |
30
+ | `maxResults` | number | 20 | 最大返回条数 |
31
+ | `contextLines` | number | 3 | 每行匹配的上下文行数 |
32
+
33
+ ### read_doc
34
+
35
+ 读取组件文档全文。当 `search_docs` 返回的片段不足以完整回答时使用。
36
+
37
+ | 参数 | 类型 | 说明 |
38
+ |-----|------|------|
39
+ | `pathOrUri` | string | 文档相对路径(如 `pitBusinessUi/table.md`)或完整 URI(如 `pit-docs:///pitBusinessUi/table.md`) |
40
+
41
+ ### list_docs
42
+
43
+ 列出可用组件文档目录,便于浏览或不确定组件准确名称时使用。
44
+
45
+ | 参数 | 类型 | 默认 | 说明 |
46
+ |-----|------|------|------|
47
+ | `category` | string | 可选 | 按库筛选:`pitBusinessUi`、`pitElementUi`、`pitBusinessUtils` |
48
+ | `offset` | number | 0 | 分页偏移 |
49
+ | `limit` | number | 50 | 每页数量 |
50
+
51
+ ### get_codegen_spec
52
+
53
+ 获取 pit-simplify-web 后台管理页面代码生成规范。**生成 CRUD/管理页面时,必须先调用此工具**。
54
+
55
+ | 参数 | 类型 | 默认 | 说明 |
56
+ |-----|------|------|------|
57
+ | `pageType` | string | "all" | `standard`(标准 CRUD)、`left-tree`(左树右表)、`flow`(流程表单)、`all`(全部) |
58
+ | `includeComponentDocs` | boolean | true | 是否包含相关组件的 Props/API 文档摘要 |
59
+
60
+ ## Resources
61
+
62
+ 通过 Resource Templates 暴露文档,URI 格式:`pit-docs:///pitBusinessUi/{component}.md`。
63
+
64
+ - **pitBusinessUi**:`pit-docs:///pitBusinessUi/table.md` → pit-table
65
+ - **pitElementUi**:`pit-docs:///pitElementUi/form-base.md` → el-form-base
66
+ - **pitBusinessUtils**:`pit-docs:///pitBusinessUtils/validate.md` → pit-validate
67
+
68
+ ## Prompts
69
+
70
+ 在 Cursor 等客户端中可选择以下提示:
71
+
72
+ 1. **PIT Component Docs Lookup**:查询 pit-xxx / el-xxx 组件文档。引导 AI 在涉及内部组件时主动调用 search_docs → read_doc。
73
+ 2. **pit-simplify-web Page Code Generation**:生成 pit-simplify-web 后台管理页面。引导 AI 先调用 get_codegen_spec 获取规范,再按规范生成 CRUD/左树右表/流程表单页面。
74
+
75
+ ## 文档目录
76
+
77
+ 文档已内置在包内(`docs/` 目录)。默认使用包自带的文档,无需额外配置。
78
+
79
+ 若需使用外部文档目录,可通过环境变量 `DOCS_PATH` 自定义:
80
+
81
+ ```bash
82
+ set DOCS_PATH=E:\my-docs
83
+ pit-docs-mcp
84
+ ```
85
+
86
+ ## 安装与运行
87
+
88
+ **从 npm 安装(推荐):**
89
+
90
+ ```bash
91
+ npm install -g pit-docs-mcp
92
+ # 或 项目内安装
93
+ npm install pit-docs-mcp
94
+ ```
95
+
96
+ **从源码安装:**
97
+
98
+ ```bash
99
+ git clone <repo>
100
+ cd pit-docs
101
+ npm install
102
+ npm run build
103
+ ```
104
+
105
+ **运行方式:**
106
+
107
+ - 全局安装后:`pit-docs-mcp`
108
+ - npx:`npx pit-docs-mcp`
109
+ - 项目内:`node node_modules/pit-docs-mcp/dist/index.js`
110
+
111
+ ## Cursor 配置
112
+
113
+ 在 `%USERPROFILE%\.cursor\mcp.json` 的 `mcpServers` 中添加:
114
+
115
+ ```json
116
+ {
117
+ "mcpServers": {
118
+ "pit-docs": {
119
+ "type": "command",
120
+ "command": "npx",
121
+ "args": ["pit-docs-mcp"]
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ 若使用全局安装:
128
+
129
+ ```json
130
+ {
131
+ "mcpServers": {
132
+ "pit-docs": {
133
+ "type": "command",
134
+ "command": "pit-docs-mcp"
135
+ }
136
+ }
137
+ }
138
+ ```
139
+
140
+ 若需使用外部文档目录:
141
+
142
+ ```json
143
+ {
144
+ "mcpServers": {
145
+ "pit-docs": {
146
+ "type": "command",
147
+ "command": "npx",
148
+ "args": ["pit-docs-mcp"],
149
+ "env": {
150
+ "DOCS_PATH": "D:\\your-custom-docs"
151
+ }
152
+ }
153
+ }
154
+ }
155
+ ```
156
+
157
+ ## 使用方式
158
+
159
+ ### 推荐工作流
160
+
161
+ 1. **查询组件**:`search_docs` → 若片段不足 → `read_doc` 传入返回的 URI
162
+ 2. **浏览组件**:`list_docs` 获取目录,再 `read_doc` 读取感兴趣文档
163
+ 3. **生成管理页**:`get_codegen_spec` 获取规范 → 收集用户信息(表结构、服务名等)→ 按规范生成代码 → 用 `search_docs` 补充组件细节
164
+
165
+ ### 组件名映射
166
+
167
+ 文档文件名与组件名的对应关系:`image.md` → pit-image,`form-base.md` → el-form-base,`dic.md` → pit-dic。
168
+
169
+ ## 支持的文档类型
170
+
171
+ - `.md`, `.mdx` - Markdown
172
+ - `.vue` - Vue 组件
173
+ - `.ts`, `.tsx`, `.js`, `.jsx` - TypeScript/JavaScript
174
+ - `.json` - JSON
175
+
176
+ ## 技术栈
177
+
178
+ - TypeScript
179
+ - @modelcontextprotocol/sdk
180
+ - Zod
@@ -0,0 +1,5 @@
1
+ export type PageType = "standard" | "left-tree" | "flow" | "all";
2
+ export declare function loadCodegenSpec(): Promise<string>;
3
+ export declare function extractSections(spec: string, pageType: PageType): string;
4
+ export declare function getComponentDocs(pageType: PageType): Promise<string>;
5
+ //# sourceMappingURL=codegen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC;AAiEjE,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,CAGvD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CA6BxE;AAED,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAsB1E"}
@@ -0,0 +1,112 @@
1
+ import fs from "fs/promises";
2
+ import path from "path";
3
+ import { DOCS_PATH } from "./constants.js";
4
+ import { getCachedFileContent, extractPropsSection } from "./utils.js";
5
+ const BASE_COMPONENTS = [
6
+ { component: "el-form-base", docPath: "pitElementUi/form-base.md" },
7
+ { component: "pit-input", docPath: "pitBusinessUi/input.md" },
8
+ { component: "pit-textarea", docPath: "pitBusinessUi/textarea.md" },
9
+ { component: "pit-input-number", docPath: "pitBusinessUi/input-number.md" },
10
+ { component: "pit-dic", docPath: "pitBusinessUi/dic.md" },
11
+ { component: "pit-table-operation", docPath: "pitBusinessUi/table-operation.md" },
12
+ { component: "pit-upload-table", docPath: "pitBusinessUi/upload-table.md" },
13
+ ];
14
+ const LEFT_TREE_COMPONENTS = [
15
+ { component: "el-layout-tree", docPath: "pitElementUi/layout-tree.md" },
16
+ { component: "el-layout-column", docPath: "pitElementUi/layout-column.md" },
17
+ ];
18
+ const COMPONENT_MAP = {
19
+ standard: BASE_COMPONENTS,
20
+ "left-tree": [...BASE_COMPONENTS, ...LEFT_TREE_COMPONENTS],
21
+ flow: BASE_COMPONENTS,
22
+ all: [...BASE_COMPONENTS, ...LEFT_TREE_COMPONENTS],
23
+ };
24
+ const SPEC_REL_PATH = "codegen/pit-simplify-web.md";
25
+ const SECTION_MARKERS = {
26
+ standard: [
27
+ { start: /^## 1\. /, stop: /^## 2-ext1\. / },
28
+ { start: /^## 2\. /, stop: /^## 2-ext1\. / },
29
+ { start: /^## 3\. /, stop: /^## 4\. / },
30
+ { start: /^## 4\. /, stop: /^## 5\. / },
31
+ { start: /^## 5\. /, stop: /^## 6\. / },
32
+ { start: /^## 6\. /, stop: /^## 7\. / },
33
+ { start: /^## 7\. /, stop: /^## 8\. / },
34
+ { start: /^## 8\. / },
35
+ ],
36
+ "left-tree": [
37
+ { start: /^## 1\. /, stop: /^## 2\. / },
38
+ { start: /^## 2-ext1\. Left-Tree/, stop: /^## 2-ext2\. / },
39
+ { start: /^## 3\. /, stop: /^## 4\. / },
40
+ { start: /^## 4\. /, stop: /^## 5\. / },
41
+ { start: /^## 5\. /, stop: /^## 6\. / },
42
+ { start: /^## 6\. /, stop: /^## 7\. / },
43
+ { start: /^## 7\. /, stop: /^## 8\. / },
44
+ { start: /^## 8\. / },
45
+ ],
46
+ flow: [
47
+ { start: /^## 1\. /, stop: /^## 2\. / },
48
+ { start: /^## 2-ext2\. Workflow/, stop: /^## 3\. / },
49
+ { start: /^## 3\. /, stop: /^## 4\. / },
50
+ { start: /^## 4\. /, stop: /^## 5\. / },
51
+ { start: /^## 5\. /, stop: /^## 6\. / },
52
+ { start: /^## 6\. /, stop: /^## 7\. / },
53
+ { start: /^## 7\. /, stop: /^## 8\. / },
54
+ { start: /^## 8\. / },
55
+ ],
56
+ all: [],
57
+ };
58
+ export async function loadCodegenSpec() {
59
+ const fullPath = path.join(DOCS_PATH, SPEC_REL_PATH);
60
+ return await fs.readFile(fullPath, "utf-8");
61
+ }
62
+ export function extractSections(spec, pageType) {
63
+ if (pageType === "all")
64
+ return spec;
65
+ const markers = SECTION_MARKERS[pageType];
66
+ if (!markers || markers.length === 0)
67
+ return spec;
68
+ const lines = spec.split("\n");
69
+ const collected = [];
70
+ for (const marker of markers) {
71
+ let capturing = false;
72
+ for (let i = 0; i < lines.length; i++) {
73
+ const line = lines[i];
74
+ if (!capturing && marker.start.test(line)) {
75
+ capturing = true;
76
+ }
77
+ if (capturing) {
78
+ if (marker.stop && marker.stop.test(line)) {
79
+ break;
80
+ }
81
+ collected.push(line);
82
+ }
83
+ }
84
+ if (collected.length > 0 && collected[collected.length - 1] !== "") {
85
+ collected.push("");
86
+ }
87
+ }
88
+ return collected.join("\n").trim();
89
+ }
90
+ export async function getComponentDocs(pageType) {
91
+ const refs = COMPONENT_MAP[pageType] ?? COMPONENT_MAP.all;
92
+ const sections = [];
93
+ for (const ref of refs) {
94
+ try {
95
+ const content = await getCachedFileContent(ref.docPath);
96
+ const props = extractPropsSection(content);
97
+ if (props) {
98
+ sections.push(`### ${ref.component} (${ref.docPath})\n\n${props}`);
99
+ }
100
+ else {
101
+ const truncated = content.length > 2000
102
+ ? content.slice(0, 2000) + "\n\n... (truncated — use read_doc to view full content)"
103
+ : content;
104
+ sections.push(`### ${ref.component} (${ref.docPath})\n\n${truncated}`);
105
+ }
106
+ }
107
+ catch {
108
+ sections.push(`### ${ref.component}\n\n> Document not found: ${ref.docPath}`);
109
+ }
110
+ }
111
+ return sections.join("\n\n---\n\n");
112
+ }
@@ -0,0 +1,6 @@
1
+ export declare const VERSION: string;
2
+ export declare const DEFAULT_DOCS_PATH: string;
3
+ export declare const DOCS_PATH: string;
4
+ export declare const RESOURCE_URI_PREFIX = "pit-docs://";
5
+ export declare const DOC_EXTENSIONS: Set<string>;
6
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,OAAO,EAAE,MAAoB,CAAC;AAC3C,eAAO,MAAM,iBAAiB,QAAwC,CAAC;AACvE,eAAO,MAAM,SAAS,QAA6C,CAAC;AACpE,eAAO,MAAM,mBAAmB,gBAAgB,CAAC;AACjD,eAAO,MAAM,cAAc,aAA0E,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { readFileSync } from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
5
+ const pkg = JSON.parse(readFileSync(path.resolve(__dirname, "..", "package.json"), "utf-8"));
6
+ export const VERSION = pkg.version;
7
+ export const DEFAULT_DOCS_PATH = path.resolve(__dirname, "..", "docs");
8
+ export const DOCS_PATH = process.env.DOCS_PATH || DEFAULT_DOCS_PATH;
9
+ export const RESOURCE_URI_PREFIX = "pit-docs://";
10
+ export const DOC_EXTENSIONS = new Set([".md", ".mdx", ".vue", ".ts", ".tsx", ".js", ".jsx", ".json"]);
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { VERSION, DOCS_PATH } from "./constants.js";
5
+ import { registerResourceTemplates } from "./resources.js";
6
+ import { registerTools } from "./tools.js";
7
+ const server = new McpServer({
8
+ name: "pit-docs",
9
+ version: VERSION,
10
+ }, {
11
+ instructions: `你可以通过此 MCP 服务查询 pitBusinessUi,pitElementUi和pitBusinessUtils三个内部 Vue 组件库的文档,以及获取 pit-simplify-web 后台管理页面的代码生成规范。
12
+ 【何时必须调用】
13
+ - 当用户提到 pit-xxx(如 pit-table、pit-dialog、pit-image)或 el-xxx(如 el-form-base、el-upload-table)组件时
14
+ - 当用户询问内部组件的 Props、Events、Slots、用法、示例时
15
+ - 当你不确定某个 pit/el 组件的 API 时
16
+ - 当用户要求生成后台管理 CRUD 页面(标准页面、左树右表页面、流程审批页面)时
17
+ - 这些是公司内部组件,互联网和代码库中没有相关文档,唯一信息源就是此 MCP
18
+ 【文档查询】
19
+ 1. 先用 search_docs 搜索关键词(组件名或中文名)
20
+ 2. 若片段不足,用 read_doc 读取完整文档
21
+ 3. 若不确定组件名,先用 list_docs 列出目录
22
+ 【代码生成】
23
+ 当用户要求生成 pit-simplify-web 后台管理页面时,必须先调用 get_codegen_spec 获取编码规范和组件文档,然后严格按规范生成代码。支持三种页面类型:standard(标准CRUD)、left-tree(左树右表)、flow(流程表单)。`,
24
+ });
25
+ // 注册工具和资源模板
26
+ registerTools(server);
27
+ // 注册 Prompt
28
+ server.registerPrompt("pit-docs-help", {
29
+ title: "PIT 组件文档查询",
30
+ description: "此 MCP 仅为 pitBusinessUi,pitElementUi和pitBusinessUtils三个内部组件库提供文档支持。选择此提示将引导 AI 主动检索相关文档。",
31
+ }, async (_extra) => ({
32
+ messages: [
33
+ {
34
+ role: "user",
35
+ content: {
36
+ type: "text",
37
+ text: `此 MCP 仅服务 pitBusinessUi,pitElementUi和pitBusinessUtils 三个内部组件库的文档查询。当涉及 pit 组件(如 PitTable、PitButton、PitDialog、pit-document-preview 等)时,若对用法、API、Props 或最佳实践不确定,请务必通过 search_docs 或 resources 查询文档,不要凭猜测编写。
38
+
39
+ 【调用 search_docs 的规范】
40
+ - 使用组件名或技术关键词(如 pit-image、props、v-model),勿用自然语言短语(如「属性」「怎么用」)。
41
+ - 多关键词按 OR 语义匹配,如「pit-document-preview 参数」。
42
+ - 提取组件名时剔除无关描述,只保留全称(如 pit-image、pit-dic)。
43
+ - 若不确定组件拼写,先调用 list_docs(category 仅支持 pitBusinessUi,pitElementUi和pitBusinessUtils)获取列表。
44
+
45
+ 【重要】当 search_docs 片段不足以回答(如问「有哪些参数」)时,必须用 read_doc 传入 pit-docs:// URI 读取完整文档后再回答。`,
46
+ },
47
+ },
48
+ ],
49
+ }));
50
+ server.registerPrompt("pit-simplify-web-codegen", {
51
+ title: "pit-simplify-web 页面代码生成",
52
+ description: "当需要为 pit-simplify-web 项目生成后台管理 CRUD 页面时,选择此提示。AI 将按照内部编码规范生成标准页面(standard)、左树右表页面(left-tree)或流程表单页面(flow)。",
53
+ }, async (_extra) => ({
54
+ messages: [
55
+ {
56
+ role: "user",
57
+ content: {
58
+ type: "text",
59
+ text: `你现在处于 pit-simplify-web 后台管理页面代码生成模式。请严格遵循以下工作流:
60
+
61
+ 【第一步:获取规范】
62
+ 在生成任何代码之前,必须先调用 get_codegen_spec 工具获取完整的编码规范和组件文档。
63
+ - 标准 CRUD 页面:get_codegen_spec(pageType: "standard")
64
+ - 左树右表页面:get_codegen_spec(pageType: "left-tree")
65
+ - 流程表单页面:get_codegen_spec(pageType: "flow")
66
+ - 不确定类型:get_codegen_spec(pageType: "all")
67
+
68
+ 【第二步:收集信息】
69
+ 用户通常会提供以下信息(若缺失则主动询问):
70
+ - 表结构 SQL(字段名、类型、是否必填、注释)
71
+ - 服务名(service)和模块名(module)
72
+ - 字典字段信息(哪些字段使用字典、字典编码)
73
+ - 页面类型(标准/左树右表/流程)
74
+
75
+ 【第三步:生成代码】
76
+ 严格按规范生成以下文件:
77
+ 1. API 文件:src/api/projectLevel/{moduleName}.js
78
+ 2. 页面文件:src/views/projectLevel/{moduleName}/{moduleName}.vue
79
+ 3. 流程表单(若需要):src/views/projectLevel/{moduleName}/{moduleName}Flow.vue
80
+
81
+ 【第四步:自检】
82
+ 生成后按规范的「验收基准」逐项检查。
83
+
84
+ 【注意】
85
+ - 不要凭记忆编写 pit 组件用法,必须参考 get_codegen_spec 返回的组件文档
86
+ - 若需要某个组件的更详细文档,使用 search_docs 或 read_doc 补充查阅
87
+ - SQL 字段名(snake_case)必须转换为前端字段名(camelCase)`,
88
+ },
89
+ },
90
+ ],
91
+ }));
92
+ // 启动服务器
93
+ async function runServer() {
94
+ console.error(`[pit-docs-mcp] 启动服务器 v${VERSION}`);
95
+ await registerResourceTemplates(server);
96
+ const transport = new StdioServerTransport();
97
+ await server.connect(transport);
98
+ console.error("[pit-docs-mcp] MCP 服务已启动,文档目录:", DOCS_PATH);
99
+ }
100
+ // Graceful shutdown
101
+ function shutdown() {
102
+ console.error("[pit-docs-mcp] 正在关闭服务...");
103
+ server.close().then(() => {
104
+ console.error("[pit-docs-mcp] 服务已关闭");
105
+ process.exit(0);
106
+ }).catch(() => {
107
+ process.exit(1);
108
+ });
109
+ }
110
+ process.on("SIGINT", shutdown);
111
+ process.on("SIGTERM", shutdown);
112
+ runServer().catch((err) => {
113
+ console.error("[pit-docs-mcp] 启动失败:", err);
114
+ process.exit(1);
115
+ });
@@ -0,0 +1,3 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ export declare function registerResourceTemplates(server: McpServer): Promise<void>;
3
+ //# sourceMappingURL=resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,MAAM,yCAAyC,CAAC;AAUtF,wBAAsB,yBAAyB,CAAC,MAAM,EAAE,SAAS,iBAoFhE"}
@@ -0,0 +1,80 @@
1
+ import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import fs from "fs/promises";
3
+ import { DOCS_PATH, RESOURCE_URI_PREFIX } from "./constants.js";
4
+ import { getComponentsInCategory, docNameToComponentName, pathToUri, safePath, } from "./utils.js";
5
+ export async function registerResourceTemplates(server) {
6
+ try {
7
+ const stats = await fs.stat(DOCS_PATH);
8
+ if (!stats.isDirectory()) {
9
+ console.error(`[pit-docs-mcp] 文档路径不是目录: ${DOCS_PATH}`);
10
+ return;
11
+ }
12
+ }
13
+ catch (err) {
14
+ console.error(`[pit-docs-mcp] 文档目录不存在或不可访问: ${DOCS_PATH}`, err);
15
+ return;
16
+ }
17
+ const categories = ["pitBusinessUi", "pitElementUi", "pitBusinessUtils"];
18
+ for (const category of categories) {
19
+ const uriTemplate = `${RESOURCE_URI_PREFIX}/${category}/{component}.md`;
20
+ server.registerResource(`${category}-component-docs`, new ResourceTemplate(uriTemplate, {
21
+ list: async () => {
22
+ const components = await getComponentsInCategory(category);
23
+ const resources = components.map((component) => {
24
+ const relPath = `${category}/${component}.md`;
25
+ const uri = pathToUri(relPath);
26
+ const componentName = docNameToComponentName(component, category);
27
+ return {
28
+ uri,
29
+ name: componentName,
30
+ description: `${componentName} 组件文档(内部文档,非外部网络文档)`,
31
+ mimeType: "text/markdown",
32
+ };
33
+ });
34
+ return { resources };
35
+ },
36
+ complete: {
37
+ component: async (value) => {
38
+ const components = await getComponentsInCategory(category);
39
+ const lower = value.toLowerCase();
40
+ return components.filter((c) => c.toLowerCase().includes(lower)).slice(0, 20);
41
+ },
42
+ },
43
+ }), {
44
+ description: category === "pitBusinessUi"
45
+ ? "pitBusinessUi 组件文档。组件名称映射:image → pit-image,table → pit-table"
46
+ : category === "pitElementUi"
47
+ ? "pitElementUi 组件文档。组件名称映射:form-base → el-form-base,dialog → el-dialog"
48
+ : "pitBusinessUtils 工具函数文档。工具名称映射:validate → pit-validate,auth → pit-auth",
49
+ mimeType: "text/markdown",
50
+ }, async (uri, variables, _extra) => {
51
+ const component = typeof variables.component === "string" ? variables.component : variables.component?.[0];
52
+ if (!component || /[<>:"/\\|?*]/.test(component)) {
53
+ throw new Error(`无效的 component 参数: ${component}`);
54
+ }
55
+ const relPath = `${category}/${component}.md`;
56
+ const filePath = safePath(relPath);
57
+ try {
58
+ const content = await fs.readFile(filePath, "utf-8");
59
+ const fullUri = pathToUri(relPath);
60
+ return {
61
+ contents: [
62
+ {
63
+ uri: fullUri,
64
+ mimeType: "text/markdown",
65
+ text: content,
66
+ },
67
+ ],
68
+ };
69
+ }
70
+ catch (err) {
71
+ const msg = err instanceof Error ? err.message : String(err);
72
+ throw new Error(`无法读取文档 pit-docs:///${relPath}: ${msg}`);
73
+ }
74
+ });
75
+ }
76
+ const totalComponents = (await getComponentsInCategory("pitBusinessUi")).length +
77
+ (await getComponentsInCategory("pitElementUi")).length +
78
+ (await getComponentsInCategory("pitBusinessUtils")).length;
79
+ console.error(`[pit-docs-mcp] 已注册 3 个 Resource Templates,共 ${totalComponents} 个文档`);
80
+ }
@@ -0,0 +1,3 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ export declare function registerTools(server: McpServer): void;
3
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAqBpE,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,QAK9C"}