Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions __tests__/utils/deepwiki.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, it, expect } from 'vitest';
import { queryDeepWiki } from '../../src/utils/deepwiki';

describe('DeepWiki Integration Test', () => {
it('should get real response from DeepWiki for G2 question', async () => {
// Set timeout to 120s as this is a real network request

try {
const result = await queryDeepWiki({
repoName: 'antvis/G2',
question: '如何调整折线图两端的间隔',
});

console.log('DeepWiki Answer:', result);

expect(result).toBeDefined();
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(10);
// Basic check to see if it returned something relevant or at least not an error string
expect(result).not.toMatch(/^Error/);
} catch (error) {
console.error('DeepWiki Query Failed:', error);
throw error;
}
}, 120000);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/mcp-server-antv",
"version": "0.1.6",
"version": "0.1.7",
"description": "MCP Server for AntV visualization libraries development, which provides documentation context and examples for visualization developers.",
"main": "build/index.js",
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions src/utils/deepwiki.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import EventSource from 'eventsource';
import { logger } from './logger';
import { AntVLibrary } from '../types';
Expand All @@ -18,7 +18,7 @@ if (!global.EventSource) {
// 2. 单例状态管理
// ---------------------------------------------------------
let _client: Client | null = null;
let _transport: SSEClientTransport | null = null;
let _transport: StreamableHTTPClientTransport | null = null;
let _connectingPromise: Promise<Client> | null = null;

/**
Expand All @@ -27,7 +27,7 @@ let _connectingPromise: Promise<Client> | null = null;
*/
async function getMcpClient(): Promise<Client> {
// 如果客户端已存在且传输层看似正常,直接返回
// 注意:SSEClientTransport 目前没有直观的 isConnected 属性,
// 注意:StreamableHTTPClientTransport 目前没有直观的 isConnected 属性,
// 这里的检查主要是防止对象为空。更严谨的做法是监听 transport 的 close 事件来重置 _client。
if (_client && _transport) {
return _client;
Expand All @@ -43,8 +43,8 @@ async function getMcpClient(): Promise<Client> {
try {
logger.info('DeepWiki MCP: 初始化连接...');

const transport = new SSEClientTransport(
new URL('https://mcp.deepwiki.com/sse'),
const transport = new StreamableHTTPClientTransport(
new URL('https://mcp.deepwiki.com/mcp'),
);

const client = new Client(
Expand Down Expand Up @@ -185,7 +185,7 @@ export async function closeDeepWikiConnection() {
if (_transport) {
logger.info('DeepWiki MCP: 关闭连接...');
// SDK 目前可能没有直接暴露 close 方法,通常关闭 transport 即可
// SSEClientTransport 内部并没有显式的 close 方法暴露出来,
// StreamableHTTPClientTransport 内部并没有显式的 close 方法暴露出来,
// 但我们可以将引用置空,让 GC 回收,或者依赖进程退出
// 如果 SSEClientTransport 实现了 close,则调用:
// await _transport.close();
Expand Down