Skip to content

Add a new module for MCP specific traits with Prompts trait#817

Merged
adwsingh merged 6 commits intosmithy-lang:mainfrom
yasmewad:add-mcp-traits-clean
Jul 23, 2025
Merged

Add a new module for MCP specific traits with Prompts trait#817
adwsingh merged 6 commits intosmithy-lang:mainfrom
yasmewad:add-mcp-traits-clean

Conversation

@yasmewad
Copy link
Contributor

@yasmewad yasmewad commented Jul 21, 2025

This PR introduces a new @prompts trait that enables Smithy service authors to provide contextual guidance for Large Language Models (LLMs) when interacting with their services. The trait can be applied to services, resources, and operations to define prompt templates, parameter descriptions, and usage conditions.

The logic for using the data from the traits to serve prompts as part of the MCP server will be a separate PR.

Key features:
Prompt Templates: Define template text with placeholders for parameters and multi-operation workflows
Parameter Guidance: Optional argument descriptions to help LLMs understand parameter usage
Conditional Usage: Specify when certain operations should be preferred over others
Flexible Application: Can be applied at service, resource, or operation level

Added an example that builds.

Example Usage
$version: "2"
                                                                                                                                                                                                                                                                                                                           
namespace com.example
                                                                                                                                                                                                                                                                                                                           
use amazon.smithy.llm#prompts
                                                                                                                                                                                                                                                                                                                           
@prompts({                                                                                                                                                                                                                                                                                                                 
    "search_users": {                                                                                                                                                                                                                                                                                                      
        description: "Search for users in the system by various criteria"                                                                                                                                                                                                                                                  
        template: "Search for users where {searchCriteria}. Use pagination with limit={limit} if many results expected."                                                                                                                                                                                                   
        arguments: SearchUsersInput                                                                                                                                                                                                                                                                                        
        preferWhen: "User wants to find specific users or browse user lists"                                                                                                                                                                                                                                               
    }                                                                                                                                                                                                                                                                                                                      
    "get_user_details": {                                                                                                                                                                                                                                                                                                  
        description: "Retrieve detailed information about a specific user"                                                                                                                                                                                                                                                 
        template: "Get detailed information for user with ID {userId}. This provides complete user profile data."                                                                                                                                                                                                          
        arguments: GetUserInput                                                                                                                                                                                                                                                                                            
        preferWhen: "User asks for specific details about a known user"                                                                                                                                                                                                                                                    
    }                                                                                                                                                                                                                                                                                                                      
})                                                                                                                                                                                                                                                                                                                         
service UserService {                                                                                                                                                                                                                                                                                                      
    operations: [SearchUsers, GetUser]                                                                                                                                                                                                                                                                                     
}                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                           
@prompts({                                                                                                                                                                                                                                                                                                                 
    "create_with_validation": {                                                                                                                                                                                                                                                                                            
        description: "Create a new user with input validation"                                                                                                                                                                                                                                                             
        template: "Create user with name='{name}' and email='{email}'. Validate email format before submission."                                                                                                                                                                                                           
        arguments: CreateUserInput                                                                                                                                                                                                                                                                                         
    }                                                                                                                                                                                                                                                                                                                      
})                                                                                                                                                                                                                                                                                                                         
operation CreateUser {                                                                                                                                                                                                                                                                                                     
    input: CreateUserInput                                                                                                                                                                                                                                                                                                 
    output: CreateUserOutput                                                                                                                                                                                                                                                                                               
}                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                           
structure SearchUsersInput {                                                                                                                                                                                                                                                                                               
    searchCriteria: String                                                                                                                                                                                                                                                                                                 
    limit: Integer                                                                                                                                                                                                                                                                                                         
}                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                           
structure GetUserInput {                                                                                                                                                                                                                                                                                                   
    userId: String                                                                                                                                                                                                                                                                                                         
}                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                           
structure CreateUserInput {                                                                                                                                                                                                                                                                                                
    name: String                                                                                                                                                                                                                                                                                                           
    email: String                                                                                                                                                                                                                                                                                                          
}                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                           

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

… Smithy services. Includes prompt templates, parameter descriptions, and usage conditions for services, resources, and operations.
@yasmewad yasmewad changed the title Add a new module for Mcp Traits with Prompts trait Add a new module for MCP specific traits with Prompts trait Jul 21, 2025
@@ -0,0 +1,33 @@
$version: "2"

namespace amazon.smithy.llm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK, these feel very MCP specific and I wouldn't like to name something tied to a particular model architecture.

Either we keep the namespace as software.amazon.smithy.mcp or software.amazon.smtihy.ai

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discussed with @mtdowling and we are going to be placing these in smithy.llm following the patterns for smithy.api, smithy.rules , etc.

Copy link
Contributor Author

@yasmewad yasmewad Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now that change is blocked on a PR to update logic on trait-codegen plugin restrictions being flexible.
Also this namespace is pretty changeable. The software.amazon.smithy.llm will be the package name used for the Java classes generated off it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

llm is technically incorrect. These traits are for use with generative AI, but llm refers to a specific type of model architecture.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. So how about smithy.ai ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And for the package name for java class as software.amazon.smtihy.ai ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mtdowling and @kstich you good with the naming?

Copy link
Contributor

@rhernandez35 rhernandez35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traits are A-OK

The selector had incorrect syntax from my local testing where it would really only be applied to a service shape. This corrects it.
@adwsingh adwsingh enabled auto-merge (rebase) July 23, 2025 17:39
@adwsingh adwsingh merged commit e6ee2b7 into smithy-lang:main Jul 23, 2025
2 checks passed
}

/// Defines the structure of the prompt
structure PromptTemplateDefinition {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be @private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. Will update with the namespace update PR.

}

@idRef(failWhenMissing: true, selector: "structure")
string ArgumentShape
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be @private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. Will update with the namespace update PR.


// Prompt template trait - applied at operation level to provide guidance to LLMs
@trait(selector: ":is(service, resource, operation)")
map prompts {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The seems MCP specific, @mcpPrompts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid directly naming any protocols in case we support more in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants