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 @@ -21,10 +21,25 @@

import java.util.List;

/**
* Function metadata with optional MCP annotations. Omitted hints use the MCP defaults:
* readOnlyHint=false, destructiveHint=true, idempotentHint=false.
*/
public record DDMcpFunctionDescriptor(
@NotNull String id,
@NotNull String name,
@Nullable String description,
@NotNull List<DDMcpFunctionParameter> parameters
@NotNull List<DDMcpFunctionParameter> parameters,
@Nullable Boolean readOnlyHint,
@Nullable Boolean destructiveHint,
@Nullable Boolean idempotentHint
) {
public DDMcpFunctionDescriptor(
@NotNull String id,
@NotNull String name,
@Nullable String description,
@NotNull List<DDMcpFunctionParameter> parameters
) {
this(id, name, description, parameters, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@ void preservesTypedParametersAndOptionalDescription() {
Assertions.assertEquals(descriptor, gson.fromJson(gson.toJson(descriptor), DDMcpFunctionDescriptor.class));
}

@Test
void readsLegacyDescriptorsWithoutAnnotations() {
var descriptor = gson.fromJson("""
{"id":"database_query","name":"Query","parameters":[]}
""", DDMcpFunctionDescriptor.class);
Assertions.assertEquals(new DDMcpFunctionDescriptor("database_query", "Query", null, List.of()), descriptor);
Assertions.assertNull(descriptor.readOnlyHint());
Assertions.assertNull(descriptor.destructiveHint());
Assertions.assertNull(descriptor.idempotentHint());
}

@Test
void preservesExplicitFalseAndPartialAnnotations() {
var descriptor = new DDMcpFunctionDescriptor("database_query", "Query", null, List.of(), true, false, true);
var json = gson.toJsonTree(descriptor).getAsJsonObject();
Assertions.assertTrue(json.get("readOnlyHint").getAsBoolean());
Assertions.assertFalse(json.get("destructiveHint").getAsBoolean());
Assertions.assertTrue(json.get("idempotentHint").getAsBoolean());
Assertions.assertEquals(descriptor, gson.fromJson(json, DDMcpFunctionDescriptor.class));

var partial = gson.fromJson("""
{"id":"database_query","name":"Query","parameters":[],"destructiveHint":false}
""", DDMcpFunctionDescriptor.class);
Assertions.assertNull(partial.readOnlyHint());
Assertions.assertEquals(Boolean.FALSE, partial.destructiveHint());
Assertions.assertNull(partial.idempotentHint());
}

@Test
void preservesMapArgumentsWithoutLosingNullsOrNumericPrecision() {
Map<String, Object> arguments = new LinkedHashMap<>();
Expand Down
Loading