Skip to content

Commit 1ea1cd2

Browse files
committed
feat: add code style prompt
1 parent adc2c54 commit 1ea1cd2

4 files changed

Lines changed: 44 additions & 29 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MCP Server AntV ![](https://badge.mcpx.dev?type=server 'MCP Server') [![npm Version](https://img.shields.io/npm/v/@antv/mcp-server-antv.svg)](https://www.npmjs.com/package/@antv/mcp-server-antv) [![smithery badge](https://smithery.ai/badge/@antvis/mcp-server-antv)](https://smithery.ai/server/@antvis/mcp-server-antv) [![npm License](https://img.shields.io/npm/l/@antv/mcp-server-antv.svg)](https://www.npmjs.com/package/@antv/mcp-server-antv)
22

3-
> A **Model Context Protocol (MCP)** server designed for AI development and QA that provides **AntV** documentation context and code examples using the latest APIs.
3+
> A **Model Context Protocol (MCP)** server designed for AI development and QA that provides **AntV** documentation context and code examples using the latest APIs.
44
55
<img width="768" alt="mcp-server-antv Technical Architecture" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*WHSOR7L8U0YAAAAATjAAAAgAemJ7AQ/fmt.webp" />
66

@@ -52,7 +52,7 @@ On Window system:
5252

5353
### Connect to VSCode
5454

55-
[![Install in VSCode](https://img.shields.io/badge/Install%20in-VSCode-007ACC?logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%22%3A%22mcp-server-antv%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40antv%2Fmcp-server-antv%22%5D%7D)
55+
[![Install in VSCode](https://img.shields.io/badge/Install%20in-VSCode-2C2C2C?style=for-the-badge&logo=visualstudiocode&logoColor=white)](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%22%3A%22mcp-server-antv%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40antv%2Fmcp-server-antv%22%5D%7D)
5656

5757
Pasting the following configuration into your VSCode `~/.vscode/mcp.json` file is the recommended approach.
5858

@@ -79,8 +79,8 @@ An example workflow.
7979

8080
## 🧰 Tools Overview
8181

82-
| Tool | Functionality |
83-
| --------------------- | --------------------------------------------------------------------------- |
82+
| Tool | Functionality |
83+
| --------------------- | ---------------------------------------------------------------------------- |
8484
| `extract_antv_topic` | Extract user intent, detects library (G2/G6/F2), and infers task complexity. |
8585
| `query_antv_document` | fetch latest documentation and code examples with context7 |
8686

src/constant.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,29 @@ export const ANTV_LIBRARY_META = {
77
name: 'G2',
88
description:
99
'Statistical charts, data visualization, business intelligence charts',
10-
keywords: [],
10+
keywords: '',
11+
codeStyle: '',
1112
},
1213
g6: {
1314
id: 'g6' as AntVLibrary,
1415
name: 'G6',
1516
description: 'Graph analysis, network diagrams, node-link relationships',
16-
keywords: [],
17+
keywords: '',
18+
codeStyle: '',
1719
},
1820
l7: {
1921
id: 'l7' as AntVLibrary,
2022
name: 'L7',
2123
description: 'Geospatial visualization, maps, geographic data analysis',
22-
keywords: [],
24+
keywords: '',
25+
codeStyle: '',
2326
},
2427
x6: {
2528
id: 'x6' as AntVLibrary,
2629
name: 'X6',
2730
description: 'Graph editing, flowcharts, diagram creation tools',
28-
keywords: [],
31+
keywords: '',
32+
codeStyle: '',
2933
},
3034
f2: {
3135
id: 'f2' as AntVLibrary,
@@ -42,17 +46,21 @@ export const ANTV_LIBRARY_META = {
4246
- 饼图标签 (PieLabel)
4347
- 象形柱图 (PictorialBar)
4448
<components>
49+
`,
50+
codeStyle: `
4551
<convention>
46-
- JSX 语法
47-
- Guides, Legend, Timeline, Axis 组件必须在 Chart 组件内使用
52+
- Use F2's components directly in JSX. If TypeScript errors occur, add @ts-ignore above the component
53+
- Code examples are for Node environment. For React framework, import ReactCanvas from '@antv/f2-react' and use <ReactCanvas/> component instead of <Canvas/> component
54+
- In F2's canvas coordinate system, Y coordinates increase from top to bottom, and X coordinates increase from left to right by default. Therefore, all values for offsetY, offsetX, x, y and similar properties are relative to the top-left corner of the canvas.
4855
</convention>
4956
`,
5057
},
5158
s2: {
5259
id: 's2' as AntVLibrary,
5360
name: 'S2',
5461
description: 'Table analysis, spreadsheet-like interactions, data grids',
55-
keywords: [],
62+
keywords: '',
63+
codeStyle: '',
5664
},
5765
};
5866

@@ -74,5 +82,5 @@ export function getLibraryDescription(library: AntVLibrary): string {
7482
}
7583

7684
export function getLibraryKeywords(library: AntVLibrary) {
77-
return ANTV_LIBRARY_META[library]?.keywords || [];
85+
return ANTV_LIBRARY_META[library]?.keywords || '';
7886
}

src/tools/query_antv_document.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import { z } from 'zod';
11-
import type { AntVLibrary } from '../types';
11+
import type { AntVConfig, AntVLibrary } from '../types';
1212
import { logger, getLibraryId, fetchLibraryDocumentation } from '../utils';
1313
import {
1414
getLibraryConfig,
@@ -150,14 +150,13 @@ async function handleComplexTaskWithDocCheck(
150150
response += `---\n\n`;
151151
}
152152
response += `## 🎯 Task Integration Recommendations\n\n`;
153-
response += generateComplexTaskSummary(args, subTaskResults);
154-
response += generateIntentSpecificGuidance(args.intent, library);
153+
response += generateComplexTaskSummary(subTaskResults);
154+
response += generateIntentSpecificGuidance(args.intent, libraryConfig);
155155
response += generateFollowUpGuidance();
156156
return { response, hasDocumentation: hasValidDocumentation };
157157
}
158158

159159
function generateComplexTaskSummary(
160-
args: QueryAntVDocumentArgs,
161160
subTaskResults: Array<{
162161
task: any;
163162
documentation: string | null;
@@ -196,7 +195,7 @@ function generateResponse(
196195
response += `\n---\n\n`;
197196
if (context) {
198197
response += `## 📚 Related Documentation\n\n${context}\n\n`;
199-
response += generateIntentSpecificGuidance(args.intent, library);
198+
response += generateIntentSpecificGuidance(args.intent, libraryConfig);
200199
} else {
201200
response += `## ⚠️ Documentation Retrieval Failed\n\n`;
202201
response += `\nError: ${errorMsg}\n`;
@@ -211,21 +210,21 @@ function generateResponse(
211210

212211
function generateIntentSpecificGuidance(
213212
intent: string,
214-
library: string,
213+
libraryConfig: AntVConfig,
215214
): string {
216215
switch (intent) {
217216
case 'learn':
218-
return generateLearnGuidance(library);
217+
return generateLearnGuidance();
219218
case 'implement':
220-
return generateImplementGuidance(library);
219+
return generateImplementGuidance(libraryConfig);
221220
case 'solve':
222-
return generateSolveGuidance(library);
221+
return generateSolveGuidance(libraryConfig);
223222
default:
224-
return generateDefaultGuidance(library);
223+
return generateDefaultGuidance(libraryConfig);
225224
}
226225
}
227226

228-
function generateLearnGuidance(library: string): string {
227+
function generateLearnGuidance(): string {
229228
return `## 💡 Learning Recommendations
230229
231230
- First understand the core concepts and basic usage in the documentation
@@ -236,9 +235,9 @@ function generateLearnGuidance(library: string): string {
236235
`;
237236
}
238237

239-
function generateImplementGuidance(library: string): string {
238+
function generateImplementGuidance(libraryConfig: AntVConfig): string {
240239
return `## 🛠️ Implementation Recommendations
241-
240+
- Follow the code style and best practices of the library: ${libraryConfig.codeStyle}
242241
- Refer to example code in the documentation
243242
- Pay attention to required and optional parameter configurations
244243
- Implement basic features first, then add advanced features
@@ -247,24 +246,24 @@ function generateImplementGuidance(library: string): string {
247246
`;
248247
}
249248

250-
function generateSolveGuidance(library: string): string {
249+
function generateSolveGuidance(libraryConfig: AntVConfig): string {
251250
return `## 🔧 Troubleshooting
252251
253252
- Check error messages and parameter configurations
254253
- Compare your code with documentation examples for differences
255-
- Confirm ${library} version and dependency compatibility
254+
- Confirm ${libraryConfig.name} version and dependency compatibility
256255
- If problems persist, check official GitHub Issues
257256
258257
`;
259258
}
260259

261-
function generateDefaultGuidance(library: string): string {
260+
function generateDefaultGuidance(libraryConfig: AntVConfig): string {
262261
return `## 📖 Usage Recommendations
263262
264263
- Carefully read the above documentation content
265264
- Practice with reference to code examples
266265
- Adjust relevant parameters according to requirements
267-
- Consult ${library} official documentation for more information
266+
- Consult ${libraryConfig.name} official documentation for more information
268267
269268
`;
270269
}

src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@
88
* These libraries are used to fetch documentation and provide context for the AntV Assistant tool.
99
*/
1010
export type AntVLibrary = 'g2' | 'g6' | 'l7' | 'x6' | 'f2' | 's2';
11+
12+
export type AntVConfig = {
13+
id: AntVLibrary;
14+
name: string;
15+
description: string;
16+
keywords: string;
17+
codeStyle: string;
18+
};

0 commit comments

Comments
 (0)