Skip to content
Merged
Show file tree
Hide file tree
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 @@ -337,7 +337,8 @@ private void addCompletionMethod(Method.Builder builder, ClassModel.Builder clas
.addContent(element.elementName())
.addContent("(")
.addContent(params)
.addContentLine(").toArray(new String[0]));")
.addContentLine("));")
.decreaseContentPadding()
.addContentLine("};");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ McpCompletionContent eventResourceTemplateCompletion(String nameValue) {
.stream()
.filter(name -> name.contains(nameValue))
.toList();
return McpCompletionContents.completion(values.toArray(new String[0]));
return McpCompletionContents.completion(values);
}

// -- Prompts -------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ private McpCompletionContent complete(McpRequest request) {
.stream()
.filter(name -> name.contains(nameValue))
.toList();
return McpCompletionContents.completion(values.toArray(new String[0]));
return McpCompletionContents.completion(values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.extensions.mcp.server;

import java.util.List;
Expand All @@ -27,7 +26,8 @@ private McpCompletionContents() {
}

/**
* Create a completion content from the provided list of string.
* Create a completion content from the provided list of string. The maximum
* number of suggestion cannot exceed 100.
*
* @param values completion values
* @return completion content
Expand All @@ -36,6 +36,17 @@ public static McpCompletionContent completion(String... values) {
return new McpCompletionContentImpl(List.of(values));
}

/**
* Create a completion content from provided list of string. The maximum
* number of suggestion cannot exceed 100.
*
* @param values completion values
* @return completion content
*/
public static McpCompletionContent completion(List<String> values) {
return new McpCompletionContentImpl(values);
}

/**
* Completion content default implementation.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.extensions.mcp.server;

import java.util.List;

import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

class McpCompletionContentTest {

@Test
void testDefaultMcpCompletion() {
var content = McpCompletionContents.completion(List.of());
assertThat(content.total(), is(0));
assertThat(content.hasMore(), is(false));
assertThat(content.values(), is(List.of()));
}

@Test
void testDefaultArrayMcpCompletion() {
var content = McpCompletionContents.completion();
assertThat(content.total(), is(0));
assertThat(content.hasMore(), is(false));
assertThat(content.values(), is(List.of()));
}

@Test
void testMcpCompletion() {
var content = McpCompletionContents.completion(List.of("foo"));
assertThat(content.total(), is(1));
assertThat(content.hasMore(), is(false));
assertThat(content.values(), is(List.of("foo")));
}

@Test
void testArrayMcpCompletion() {
var content = McpCompletionContents.completion("foo");
assertThat(content.total(), is(1));
assertThat(content.hasMore(), is(false));
assertThat(content.values(), is(List.of("foo")));
}
}