|
9 | 9 |
|
10 | 10 | import io.modelcontextprotocol.MockMcpServerTransport; |
11 | 11 | import io.modelcontextprotocol.MockMcpServerTransportProvider; |
| 12 | +import io.modelcontextprotocol.spec.McpSchema; |
| 13 | +import io.modelcontextprotocol.spec.McpSchema.JSONRPCNotification; |
12 | 14 | import io.modelcontextprotocol.spec.McpSchema.ReadResourceResult; |
13 | 15 | import io.modelcontextprotocol.spec.McpSchema.ResourceTemplate; |
14 | 16 | import io.modelcontextprotocol.spec.McpSchema.ServerCapabilities; |
@@ -146,6 +148,38 @@ void testRemoveNonexistentResourceTemplate() { |
146 | 148 | StepVerifier.create(mcpAsyncServer.removeResourceTemplate("nonexistent://template/{id}")).verifyComplete(); |
147 | 149 | } |
148 | 150 |
|
| 151 | + @Test |
| 152 | + void testRemoveResourceTemplateNotifiesListChanged() { |
| 153 | + ResourceTemplate template = ResourceTemplate.builder(TEST_TEMPLATE_URI, TEST_TEMPLATE_NAME).build(); |
| 154 | + |
| 155 | + McpServerFeatures.AsyncResourceTemplateSpecification specification = new McpServerFeatures.AsyncResourceTemplateSpecification( |
| 156 | + template, (exchange, req) -> Mono.just(ReadResourceResult.builder(List.of()).build())); |
| 157 | + |
| 158 | + mcpAsyncServer = McpServer.async(mockTransportProvider) |
| 159 | + .serverInfo("test-server", "1.0.0") |
| 160 | + .capabilities(ServerCapabilities.builder().resources(false, true).build()) |
| 161 | + .resourceTemplates(specification) |
| 162 | + .build(); |
| 163 | + |
| 164 | + StepVerifier.create(mcpAsyncServer.removeResourceTemplate(TEST_TEMPLATE_URI)).verifyComplete(); |
| 165 | + |
| 166 | + assertThat(mockTransportProvider.getTransport().getAllSentMessages()).singleElement() |
| 167 | + .isInstanceOfSatisfying(JSONRPCNotification.class, notification -> assertThat(notification.method()) |
| 168 | + .isEqualTo(McpSchema.METHOD_NOTIFICATION_RESOURCES_LIST_CHANGED)); |
| 169 | + } |
| 170 | + |
| 171 | + @Test |
| 172 | + void testRemoveNonexistentResourceTemplateDoesNotNotify() { |
| 173 | + mcpAsyncServer = McpServer.async(mockTransportProvider) |
| 174 | + .serverInfo("test-server", "1.0.0") |
| 175 | + .capabilities(ServerCapabilities.builder().resources(false, true).build()) |
| 176 | + .build(); |
| 177 | + |
| 178 | + StepVerifier.create(mcpAsyncServer.removeResourceTemplate("nonexistent://template/{id}")).verifyComplete(); |
| 179 | + |
| 180 | + assertThat(mockTransportProvider.getTransport().getAllSentMessages()).isEmpty(); |
| 181 | + } |
| 182 | + |
149 | 183 | @Test |
150 | 184 | void testReplaceExistingResourceTemplate() { |
151 | 185 | ResourceTemplate originalTemplate = ResourceTemplate.builder(TEST_TEMPLATE_URI, TEST_TEMPLATE_NAME) |
|
0 commit comments