Skip to content

Commit de53f88

Browse files
committed
Add @tool_assistant and @install_tool prompts
1 parent 6c29016 commit de53f88

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

core/src/main/java/software/amazon/smithy/java/core/schema/SchemaIndex.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ public Schema getSchema(ShapeId id) {
4343
throw new IllegalArgumentException("No schema found for id `" + id + "`");
4444
}
4545
}
46+
47+
public static SchemaIndex compose(SchemaIndex... indexes) {
48+
return new CombinedSchemaIndex(List.of(indexes));
49+
}
4650
}

mcp/mcp-schemas/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies {
1212
api(project(":core"))
1313
api(libs.smithy.model)
1414
api(project(":server:server-api"))
15+
api(project(":smithy-ai-traits"))
1516
smithyBuild(project(":codegen:plugins:types-codegen"))
1617
smithyBuild(project(":codegen:plugins:server-codegen"))
1718
}

mcp/mcp-schemas/model/tool-assistant.smithy

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ $version: "2"
22

33
namespace smithy.mcp.toolassistant
44

5-
/// This service provides methods to search MCP Tools and install MCP servers.
6-
/// Be aware that tools installed using InstallTool are available as part of the ToolAssistant MCP server and the MCP serverId returned from search tool needs to be ignored while tool calling.
5+
use smithy.ai#prompts
6+
7+
@prompts({
8+
tool_assistant: { description: "Tool assistant prompt to guide the LLM to use ToolAssistant's Search and Install Tool", template: "{{query}}. Use the SearchTools and InstallTools from ToolAssistant if the current list of MCP tools is not enough to accomplish the task.", arguments: ToolAssistantQuery, preferWhen: "User wants to do a dynamically search and install tools to accomplish a task." }
9+
install_tool: { description: "Install tool using ToolAssistant.", template: "Install tool {{toolName}} server using InstallTools.", arguments: InstallToolInput, preferWhen: "User wants to install a tool." }
10+
})
11+
@documentation("This service provides methods to search MCP Tools and install MCP servers. Be aware that tools installed using InstallTool are available as part of the ToolAssistant MCP server and the MCP serverId returned from search tool needs to be ignored while tool calling.")
712
service ToolAssistant {
813
operations: [
914
SearchTools
@@ -72,3 +77,8 @@ operation InstallTool {
7277
message: String
7378
}
7479
}
80+
81+
structure ToolAssistantQuery {
82+
@required
83+
query: String
84+
}

mcp/mcp-schemas/smithy-build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"service": "smithy.mcp.toolassistant#ToolAssistant",
1111
"namespace": "software.amazon.smithy.java.mcp.toolassistant",
1212
"headerFile": "license.txt",
13-
"runtimeTraits": ["smithy.api#documentation", "smithy.api#examples" ]
13+
"runtimeTraits": ["smithy.api#documentation", "smithy.api#examples", "smithy.ai#prompts" ]
1414
}
1515
}
1616
}

mcp/mcp-server/src/main/java/software/amazon/smithy/java/mcp/server/PromptLoader.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import software.amazon.smithy.ai.PromptTemplateDefinition;
1515
import software.amazon.smithy.ai.PromptsTrait;
1616
import software.amazon.smithy.java.core.schema.Schema;
17+
import software.amazon.smithy.java.core.schema.SchemaIndex;
1718
import software.amazon.smithy.java.core.schema.TraitKey;
1819
import software.amazon.smithy.java.mcp.model.PromptArgument;
1920
import software.amazon.smithy.java.mcp.model.PromptInfo;
@@ -62,15 +63,16 @@ public static Map<String, Prompt> loadPrompts(Collection<Service> services) {
6263
+ promptTemplateDefinition.getPreferWhen().get()
6364
: templateString;
6465

66+
var schemaIndex = SchemaIndex.compose(service.schemaIndex(), SchemaIndex.getCombinedSchemaIndex());
67+
6568
var promptInfo = PromptInfo
6669
.builder()
6770
.name(promptName)
6871
.title(StringUtils.capitalize(promptName))
6972
.description(promptTemplateDefinition.getDescription())
7073
.arguments(promptTemplateDefinition.getArguments().isPresent()
7174
? convertArgumentShapeToPromptArgument(
72-
service.schemaIndex()
73-
.getSchema(promptTemplateDefinition.getArguments().get()))
75+
schemaIndex.getSchema(promptTemplateDefinition.getArguments().get()))
7476
: List.of())
7577
.build();
7678

0 commit comments

Comments
 (0)