1212import static org .mockito .Mockito .times ;
1313import static org .mockito .Mockito .verify ;
1414
15+ import io .modelcontextprotocol .server .McpSyncServer ;
1516import io .modelcontextprotocol .spec .McpSchema ;
1617import modelengine .fel .tool .mcp .entity .ServerSchema ;
1718import modelengine .fel .tool .mcp .entity .Tool ;
3839@ DisplayName ("Unit tests for DefaultMcpServer" )
3940public class DefaultMcpServerTest {
4041 private ToolExecuteService toolExecuteService ;
42+ private McpSyncServer mcpSyncServer ;
4143
4244 @ BeforeEach
4345 void setup () {
4446 this .toolExecuteService = mock (ToolExecuteService .class );
47+ this .mcpSyncServer = mock (McpSyncServer .class );
4548 }
4649
4750 @ Nested
@@ -51,7 +54,7 @@ class GivenConstructor {
5154 @ DisplayName ("Should throw IllegalArgumentException when toolExecuteService is null" )
5255 void throwIllegalArgumentExceptionWhenToolExecuteServiceIsNull () {
5356 IllegalArgumentException exception =
54- catchThrowableOfType (IllegalArgumentException .class , () -> new DefaultMcpServer (null ));
57+ catchThrowableOfType (IllegalArgumentException .class , () -> new DefaultMcpServer (null , mcpSyncServer ));
5558 assertThat (exception ).isNotNull ().hasMessage ("The tool execute service cannot be null." );
5659 }
5760 }
@@ -62,17 +65,10 @@ class GivenGetInfo {
6265 @ Test
6366 @ DisplayName ("Should return expected server information" )
6467 void returnExpectedServerInfo () {
65- McpServer server = new DefaultMcpServer (toolExecuteService );
68+ McpServer server = new DefaultMcpServer (toolExecuteService , mcpSyncServer );
6669 ServerSchema info = server .getSchema ();
6770
6871 assertThat (info ).returns ("2025-06-18" , ServerSchema ::protocolVersion );
69-
70- McpSchema .ServerCapabilities capabilities = info .capabilities ();
71- assertThat (capabilities ).isNotNull ();
72-
73- McpSchema .Implementation serverInfo = info .serverInfo ();
74- assertThat (serverInfo ).returns ("FIT Store MCP Server" , McpSchema .Implementation ::name )
75- .returns ("3.6.0-SNAPSHOT" , McpSchema .Implementation ::version );
7672 }
7773 }
7874
@@ -82,7 +78,7 @@ class GivenRegisterAndNotify {
8278 @ Test
8379 @ DisplayName ("Should notify observers when tools are added or removed" )
8480 void notifyObserversOnToolAddOrRemove () {
85- DefaultMcpServer server = new DefaultMcpServer (toolExecuteService );
81+ DefaultMcpServer server = new DefaultMcpServer (toolExecuteService , mcpSyncServer );
8682 McpServer .ToolsChangedObserver observer = mock (McpServer .ToolsChangedObserver .class );
8783 server .registerToolsChangedObserver (observer );
8884
@@ -105,7 +101,7 @@ class GivenOnToolAdded {
105101 @ Test
106102 @ DisplayName ("Should add tool successfully with valid parameters" )
107103 void addToolSuccessfully () {
108- DefaultMcpServer server = new DefaultMcpServer (toolExecuteService );
104+ DefaultMcpServer server = new DefaultMcpServer (toolExecuteService , mcpSyncServer );
109105 String name = "tool1" ;
110106 String description = "description1" ;
111107 Map <String , Object > schema = MapBuilder .<String , Object >get ()
@@ -127,7 +123,7 @@ void addToolSuccessfully() {
127123 @ Test
128124 @ DisplayName ("Should ignore invalid parameters and not add any tool" )
129125 void ignoreInvalidParameters () {
130- DefaultMcpServer server = new DefaultMcpServer (toolExecuteService );
126+ DefaultMcpServer server = new DefaultMcpServer (toolExecuteService , mcpSyncServer );
131127 Map <String , Object > schema = MapBuilder .<String , Object >get ()
132128 .put ("type" , "object" )
133129 .put ("properties" , Collections .emptyMap ())
@@ -151,7 +147,7 @@ class GivenOnToolRemoved {
151147 @ Test
152148 @ DisplayName ("Should remove an added tool correctly" )
153149 void removeToolSuccessfully () {
154- DefaultMcpServer server = new DefaultMcpServer (toolExecuteService );
150+ DefaultMcpServer server = new DefaultMcpServer (toolExecuteService , mcpSyncServer );
155151 Map <String , Object > schema = MapBuilder .<String , Object >get ()
156152 .put ("type" , "object" )
157153 .put ("properties" , Collections .emptyMap ())
@@ -167,7 +163,7 @@ void removeToolSuccessfully() {
167163 @ Test
168164 @ DisplayName ("Should ignore removal if name is blank" )
169165 void ignoreBlankName () {
170- DefaultMcpServer server = new DefaultMcpServer (toolExecuteService );
166+ DefaultMcpServer server = new DefaultMcpServer (toolExecuteService , mcpSyncServer );
171167 Map <String , Object > schema = MapBuilder .<String , Object >get ()
172168 .put ("type" , "object" )
173169 .put ("properties" , Collections .emptyMap ())
0 commit comments