Skip to content

Commit 4e6a4fe

Browse files
authored
fix: fixed spring-ai-community#4 ,The mcpPrompt parameter cannot be mounted (spring-ai-community#5)
1 parent cf779a8 commit 4e6a4fe

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mcp-annotations/src/main/java/com/logaritex/mcp/method/prompt/AbstractMcpPromptMethodCallback.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12+
import com.logaritex.mcp.annotation.McpArg;
1213
import io.modelcontextprotocol.spec.McpSchema.GetPromptRequest;
1314
import io.modelcontextprotocol.spec.McpSchema.GetPromptResult;
1415
import io.modelcontextprotocol.spec.McpSchema.Prompt;
@@ -143,7 +144,8 @@ else if (Map.class.isAssignableFrom(paramType)) {
143144
}
144145
else {
145146
// For individual argument parameters, extract from the request arguments
146-
String paramName = param.getName();
147+
McpArg arg = param.getAnnotation(McpArg.class);
148+
String paramName = arg != null && !arg.name().isBlank() ? arg.name() : param.getName();
147149
if (request.arguments() != null && request.arguments().containsKey(paramName)) {
148150
Object argValue = request.arguments().get(paramName);
149151
args[i] = convertArgumentValue(argValue, paramType);

mcp-annotations/src/test/java/com/logaritex/mcp/method/prompt/SyncMcpPromptMethodCallbackTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Map;
1111
import java.util.function.BiFunction;
1212

13+
import com.logaritex.mcp.annotation.McpArg;
1314
import com.logaritex.mcp.annotation.McpPrompt;
1415
import com.logaritex.mcp.method.prompt.SyncMcpPromptMethodCallback;
1516
import io.modelcontextprotocol.server.McpSyncServerExchange;
@@ -55,13 +56,15 @@ public GetPromptResult getPromptWithArguments(Map<String, Object> arguments) {
5556
}
5657

5758
@McpPrompt(name = "individual-args", description = "A prompt with individual arguments")
58-
public GetPromptResult getPromptWithIndividualArgs(String name, Integer age) {
59+
public GetPromptResult getPromptWithIndividualArgs(@McpArg(name = "name", description = "The user's name", required = true) String name,
60+
@McpArg(name = "age", description = "The user's age", required = true) Integer age) {
5961
return new GetPromptResult("Individual arguments prompt", List.of(new PromptMessage(Role.ASSISTANT,
6062
new TextContent("Hello " + name + ", you are " + age + " years old"))));
6163
}
6264

6365
@McpPrompt(name = "mixed-args", description = "A prompt with mixed argument types")
64-
public GetPromptResult getPromptWithMixedArgs(McpSyncServerExchange exchange, String name, Integer age) {
66+
public GetPromptResult getPromptWithMixedArgs(McpSyncServerExchange exchange,@McpArg(name = "name", description = "The user's name", required = true) String name,
67+
@McpArg(name = "age", description = "The user's age", required = true) Integer age) {
6568
return new GetPromptResult("Mixed arguments prompt", List.of(new PromptMessage(Role.ASSISTANT,
6669
new TextContent("Hello " + name + ", you are " + age + " years old (with exchange)"))));
6770
}

0 commit comments

Comments
 (0)