|
| 1 | +/* |
| 2 | + * Copyright 2024-2026 the original author or authors. |
| 3 | + */ |
| 4 | + |
| 5 | +package io.modelcontextprotocol.server; |
| 6 | + |
| 7 | +import io.modelcontextprotocol.json.McpJsonMapper; |
| 8 | +import io.modelcontextprotocol.json.schema.JsonSchemaValidator; |
| 9 | +import io.modelcontextprotocol.spec.McpSchema; |
| 10 | +import io.modelcontextprotocol.spec.McpServerTransportProvider; |
| 11 | +import io.modelcontextprotocol.spec.McpStreamableServerTransportProvider; |
| 12 | +import org.junit.jupiter.api.Test; |
| 13 | + |
| 14 | +import static org.assertj.core.api.Assertions.assertThat; |
| 15 | +import static org.mockito.Mockito.mock; |
| 16 | + |
| 17 | +class McpAsyncServerCapabilitiesTests { |
| 18 | + |
| 19 | + @Test |
| 20 | + void standardTransportPreservesCallerProvidedCapabilities() { |
| 21 | + McpServerTransportProvider transportProvider = mock(McpServerTransportProvider.class); |
| 22 | + McpSchema.ServerCapabilities capabilities = McpSchema.ServerCapabilities.builder().tools(true).build(); |
| 23 | + |
| 24 | + McpAsyncServer server = McpServer.async(transportProvider) |
| 25 | + .jsonMapper(mock(McpJsonMapper.class)) |
| 26 | + .jsonSchemaValidator(mock(JsonSchemaValidator.class)) |
| 27 | + .capabilities(capabilities) |
| 28 | + .build(); |
| 29 | + |
| 30 | + assertThat(server.getServerCapabilities()).isEqualTo(capabilities); |
| 31 | + assertThat(server.getServerCapabilities().logging()).isNull(); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + void streamableTransportPreservesCallerProvidedCapabilities() { |
| 36 | + McpStreamableServerTransportProvider transportProvider = mock(McpStreamableServerTransportProvider.class); |
| 37 | + McpSchema.ServerCapabilities capabilities = McpSchema.ServerCapabilities.builder().tools(true).build(); |
| 38 | + |
| 39 | + McpAsyncServer server = McpServer.async(transportProvider) |
| 40 | + .jsonMapper(mock(McpJsonMapper.class)) |
| 41 | + .jsonSchemaValidator(mock(JsonSchemaValidator.class)) |
| 42 | + .capabilities(capabilities) |
| 43 | + .build(); |
| 44 | + |
| 45 | + assertThat(server.getServerCapabilities()).isEqualTo(capabilities); |
| 46 | + assertThat(server.getServerCapabilities().logging()).isNull(); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void preservesExplicitLoggingCapability() { |
| 51 | + McpServerTransportProvider transportProvider = mock(McpServerTransportProvider.class); |
| 52 | + McpSchema.ServerCapabilities capabilities = McpSchema.ServerCapabilities.builder().logging().build(); |
| 53 | + |
| 54 | + McpAsyncServer server = McpServer.async(transportProvider) |
| 55 | + .jsonMapper(mock(McpJsonMapper.class)) |
| 56 | + .jsonSchemaValidator(mock(JsonSchemaValidator.class)) |
| 57 | + .capabilities(capabilities) |
| 58 | + .build(); |
| 59 | + |
| 60 | + assertThat(server.getServerCapabilities()).isEqualTo(capabilities); |
| 61 | + assertThat(server.getServerCapabilities().logging()).isNotNull(); |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments