Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,95 @@ void builderShouldSupportMethodChaining() {
assertThat(callback.getToolDefinition().name()).isEqualTo("chained_tool_name");
}

@Test
void builderShouldNormalizeToolNameWithSpecialCharacters() {
McpSyncClient mcpClient = Mockito.mock(McpSyncClient.class);
McpSchema.Implementation clientInfo = new McpSchema.Implementation("test-client", "1.0.0");
when(mcpClient.getClientInfo()).thenReturn(clientInfo);

Tool tool = Mockito.mock(Tool.class);
when(tool.name()).thenReturn("test-tool-with-dashes");
when(tool.description()).thenReturn("Test description");

SyncMcpToolCallback callback = SyncMcpToolCallback.builder().mcpClient(mcpClient).tool(tool).build();

assertThat(callback.getOriginalToolName()).isEqualTo("test-tool-with-dashes");
assertThat(callback.getToolDefinition().name()).isEqualTo("test_tool_with_dashes");
}

@Test
void builderShouldUseCustomPrefixedNameWithoutNormalization() {
McpSyncClient mcpClient = Mockito.mock(McpSyncClient.class);

Tool tool = Mockito.mock(Tool.class);
when(tool.name()).thenReturn("original-name");
when(tool.description()).thenReturn("Test description");

String customName = "custom-name-with-dashes";

SyncMcpToolCallback callback = SyncMcpToolCallback.builder()
.mcpClient(mcpClient)
.tool(tool)
.prefixedToolName(customName)
.build();

assertThat(callback.getOriginalToolName()).isEqualTo("original-name");
assertThat(callback.getToolDefinition().name()).isEqualTo(customName);
}

@Test
void builderShouldHandlePrefixedToolNameAsNull() {
McpSyncClient mcpClient = Mockito.mock(McpSyncClient.class);
McpSchema.Implementation clientInfo = new McpSchema.Implementation("test-client", "1.0.0");
when(mcpClient.getClientInfo()).thenReturn(clientInfo);

Tool tool = Mockito.mock(Tool.class);
when(tool.name()).thenReturn("test-tool");
when(tool.description()).thenReturn("Description");

SyncMcpToolCallback callback = SyncMcpToolCallback.builder()
.mcpClient(mcpClient)
.tool(tool)
.prefixedToolName(null)
.build();

// When null, it should use the default normalized name
assertThat(callback).isNotNull();
assertThat(callback.getToolDefinition().name()).isEqualTo("test_tool");
}

@Test
void builderShouldCreateNewInstancesForEachBuild() {
McpSyncClient mcpClient = Mockito.mock(McpSyncClient.class);
McpSchema.Implementation clientInfo = new McpSchema.Implementation("test-client", "1.0.0");
when(mcpClient.getClientInfo()).thenReturn(clientInfo);

Tool tool = Mockito.mock(Tool.class);
when(tool.name()).thenReturn("test-tool");
when(tool.description()).thenReturn("Test description");

SyncMcpToolCallback.Builder builder = SyncMcpToolCallback.builder().mcpClient(mcpClient).tool(tool);

SyncMcpToolCallback callback1 = builder.build();
SyncMcpToolCallback callback2 = builder.build();

assertThat(callback1).isNotSameAs(callback2);
assertThat(callback1.getOriginalToolName()).isEqualTo(callback2.getOriginalToolName());
}

@Test
void builderShouldThrowExceptionWhenToolContextConverterIsNull() {
McpSyncClient mcpClient = Mockito.mock(McpSyncClient.class);
Tool tool = Mockito.mock(Tool.class);
when(tool.name()).thenReturn("test-tool");
when(tool.description()).thenReturn("Test description");

assertThatThrownBy(() -> SyncMcpToolCallback.builder()
.mcpClient(mcpClient)
.tool(tool)
.toolContextToMcpMetaConverter(null)
.build()).isInstanceOf(IllegalArgumentException.class)
.hasMessage("ToolContextToMcpMetaConverter must not be null");
}

}