1
+ import { describe , it , expect , beforeEach } from 'vitest'
2
+ import { MCPExtension } from './mcp'
3
+ import { ExtensionTypeEnum } from '../extension'
4
+ import { MCPTool , MCPToolCallResult } from '../../types'
5
+
6
+ class TestMCPExtension extends MCPExtension {
7
+ constructor ( ) {
8
+ super ( 'test://mcp' , 'test-mcp' )
9
+ }
10
+
11
+ async getTools ( ) : Promise < MCPTool [ ] > {
12
+ return [
13
+ {
14
+ name : 'test_tool' ,
15
+ description : 'A test tool' ,
16
+ inputSchema : { type : 'object' } ,
17
+ server : 'test-server'
18
+ }
19
+ ]
20
+ }
21
+
22
+ async callTool ( toolName : string , args : Record < string , unknown > ) : Promise < MCPToolCallResult > {
23
+ return {
24
+ error : '' ,
25
+ content : [ { type : 'text' , text : `Called ${ toolName } with ${ JSON . stringify ( args ) } ` } ]
26
+ }
27
+ }
28
+
29
+ async getConnectedServers ( ) : Promise < string [ ] > {
30
+ return [ 'test-server' ]
31
+ }
32
+
33
+ async refreshTools ( ) : Promise < void > {
34
+ // Mock implementation
35
+ }
36
+
37
+ async isHealthy ( ) : Promise < boolean > {
38
+ return true
39
+ }
40
+
41
+ async onLoad ( ) : Promise < void > {
42
+ // Mock implementation
43
+ }
44
+
45
+ onUnload ( ) : void {
46
+ // Mock implementation
47
+ }
48
+ }
49
+
50
+ describe ( 'MCPExtension' , ( ) => {
51
+ let mcpExtension : TestMCPExtension
52
+
53
+ beforeEach ( ( ) => {
54
+ mcpExtension = new TestMCPExtension ( )
55
+ } )
56
+
57
+ describe ( 'type' , ( ) => {
58
+ it ( 'should return MCP extension type' , ( ) => {
59
+ expect ( mcpExtension . type ( ) ) . toBe ( ExtensionTypeEnum . MCP )
60
+ } )
61
+ } )
62
+
63
+ describe ( 'getTools' , ( ) => {
64
+ it ( 'should return array of MCP tools' , async ( ) => {
65
+ const tools = await mcpExtension . getTools ( )
66
+ expect ( tools ) . toHaveLength ( 1 )
67
+ expect ( tools [ 0 ] ) . toEqual ( {
68
+ name : 'test_tool' ,
69
+ description : 'A test tool' ,
70
+ inputSchema : { type : 'object' } ,
71
+ server : 'test-server'
72
+ } )
73
+ } )
74
+ } )
75
+
76
+ describe ( 'callTool' , ( ) => {
77
+ it ( 'should call tool and return result' , async ( ) => {
78
+ const result = await mcpExtension . callTool ( 'test_tool' , { param : 'value' } )
79
+ expect ( result ) . toEqual ( {
80
+ error : '' ,
81
+ content : [ { type : 'text' , text : 'Called test_tool with {"param":"value"}' } ]
82
+ } )
83
+ } )
84
+ } )
85
+
86
+ describe ( 'getConnectedServers' , ( ) => {
87
+ it ( 'should return list of connected servers' , async ( ) => {
88
+ const servers = await mcpExtension . getConnectedServers ( )
89
+ expect ( servers ) . toEqual ( [ 'test-server' ] )
90
+ } )
91
+ } )
92
+
93
+ describe ( 'isHealthy' , ( ) => {
94
+ it ( 'should return health status' , async ( ) => {
95
+ const healthy = await mcpExtension . isHealthy ( )
96
+ expect ( healthy ) . toBe ( true )
97
+ } )
98
+ } )
99
+ } )
0 commit comments