Uh oh!
There was an error while loading. Please reload this page.
feat: Add prompt support - #351
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
And you can use |
c88a7c1 to
45ae1b9CompareThere was a problem hiding this comment.
Pull Request Overview
This PR introduces comprehensive prompt support to the Rust SDK, enabling servers to provide reusable prompt templates that LLMs can discover and use. The implementation follows the MCP specification and provides a developer-friendly API through procedural macros.
- Adds complete prompt system with
#[prompt],#[prompt_router], and#[prompt_handler]macros for type-safe parameter handling - Refactors parameter extraction infrastructure to be shared between tools and prompts, reducing code duplication
- Enhances JSON wrapper with structured output support and improved error handling
Reviewed Changes
Copilot reviewed 43 out of 43 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
examples/servers/src/prompt_stdio.rs | New comprehensive example server demonstrating prompt functionality |
crates/rmcp-macros/src/prompt*.rs | New macro implementations for prompt support |
crates/rmcp/src/handler/server/prompt.rs | Core prompt handling logic and trait implementations |
crates/rmcp/src/handler/server/wrapper/parameters.rs | Unified parameter extraction infrastructure |
examples/*/calculator.rs | Updated imports to use new unified parameter location |
crates/rmcp/tests/test_prompt_*.rs | Comprehensive test coverage for prompt functionality |
Comments suppressed due to low confidence (2)
crates/rmcp/src/service.rs:165
- The lifetime parameter should be explicit to avoid potential lifetime issues. Using
BoxFuture<'_, ...>instead ofBoxFuture<...>could lead to compilation issues in certain contexts.
) -> BoxFuture<'_, Result<R::Resp, McpError>>;
crates/rmcp/src/service.rs:170
- The lifetime parameter should be explicit to avoid potential lifetime issues. Using
BoxFuture<'_, ...>instead ofBoxFuture<...>could lead to compilation issues in certain contexts.
) -> BoxFuture<'_, Result<(), McpError>>;
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
4t145
commented
Aug 20, 2025
And please fix the document ci |
- Implement #[prompt], #[prompt_router], and #[prompt_handler] macros - Add automatic JSON schema generation from Rust types for arguments - Support flexible async handler signatures with automatic adaptation - Create PromptRouter for efficient prompt dispatch - Include comprehensive tests and example implementation This enables MCP servers to provide reusable prompt templates that LLMs can discover and invoke with strongly-typed parameters, similar to the existing tool system but optimized for prompt use cases. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
- Replace Arguments<T> with Parameters<T> for consistent API - Create shared common module for tool/prompt utilities - Modernize async handling with futures::future::BoxFuture - Move cached_schema_for_type to common module for reuse - Update error types from rmcp::Error to rmcp::ErrorData - Add comprehensive trait implementations for parameter extraction 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
… usage - Move Parameters type from common.rs to dedicated wrapper/parameters.rs module - Unify extractor traits by using FromContextPart for both tools and prompts - Remove duplicate FromToolCallContextPart and FromPromptContextPart traits - Add structured output support to Json wrapper with IntoCallToolResult impl - Improve error messages with more descriptive panic for schema serialization - Update all imports across codebase to use new module path - Clean up trailing whitespace and formatting inconsistencies This consolidates parameter extraction logic and reduces code duplication between tool and prompt handlers while maintaining backward compatibility.
86e812b to
ad7b2d9Comparesnowmead
commented
Aug 20, 2025
Note: Had to force push to change the commit messages to pass commitlint |
Uh oh!
There was an error while loading. Please reload this page.
* feat: add prompt support with typed argument handling - Implement #[prompt], #[prompt_router], and #[prompt_handler] macros - Add automatic JSON schema generation from Rust types for arguments - Support flexible async handler signatures with automatic adaptation - Create PromptRouter for efficient prompt dispatch - Include comprehensive tests and example implementation This enables MCP servers to provide reusable prompt templates that LLMs can discover and invoke with strongly-typed parameters, similar to the existing tool system but optimized for prompt use cases. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com> * refactor: unify parameter handling between tools and prompts - Replace Arguments<T> with Parameters<T> for consistent API - Create shared common module for tool/prompt utilities - Modernize async handling with futures::future::BoxFuture - Move cached_schema_for_type to common module for reuse - Update error types from rmcp::Error to rmcp::ErrorData - Add comprehensive trait implementations for parameter extraction 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com> * refactor: extract Parameters wrapper to shared module and unify trait usage - Move Parameters type from common.rs to dedicated wrapper/parameters.rs module - Unify extractor traits by using FromContextPart for both tools and prompts - Remove duplicate FromToolCallContextPart and FromPromptContextPart traits - Add structured output support to Json wrapper with IntoCallToolResult impl - Improve error messages with more descriptive panic for schema serialization - Update all imports across codebase to use new module path - Clean up trailing whitespace and formatting inconsistencies This consolidates parameter extraction logic and reduces code duplication between tool and prompt handlers while maintaining backward compatibility. * chore: remove committed .egg-info directory and update gitignore * docs: fix documentation formatting
Add Prompt Support
This PR introduces a complete prompt system for the MCP Rust SDK, enabling servers to provide reusable prompt templates that LLMs can discover and use. The implementation follows the MCP specification for prompts and provides a developer-friendly API through procedural macros.
Key Features
🎯 Core Functionality
#[prompt],#[prompt_router], and#[prompt_handler]for easy prompt definition🔧 Technical Improvements
Parameters<T>wrapper to dedicated module for better organizationFromContextPartfor both tools and prompts (removed duplicate traits)Json<T>wrapper with structured output support viaIntoCallToolResultImplementation Details
Macro Support
Router Integration
File Structure
crates/rmcp-macros/src/prompt*.rs- Macro implementationscrates/rmcp/src/handler/server/prompt.rs- Core prompt handling logiccrates/rmcp/src/handler/server/wrapper/parameters.rs- Unified parameter extractionexamples/servers/src/prompt_stdio.rs- Complete working exampleTesting
Breaking Changes
None - The refactoring maintains backward compatibility while unifying the internal architecture.
Migration Guide
For users implementing custom extractors:
FromToolCallContextPartwithFromContextPart<ToolCallContext>FromPromptContextPartwithFromContextPart<PromptContext>handler::server::tool::Parameterstohandler::server::wrapper::ParametersExamples
See
examples/servers/src/prompt_stdio.rsfor a complete implementation including:Types of changes
Checklist