-
Notifications
You must be signed in to change notification settings - Fork 442
feat: Add prompt support #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add prompt support #351
Conversation
|
And you can use |
c88a7c1 to
45ae1b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
crates/rmcp/tests/test_with_python/test_with_python.egg-info/PKG-INFO
Outdated
Show resolved
Hide resolved
|
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 <[email protected]>
- 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 <[email protected]>
… 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
ad7b2d9
Compare
|
Note: Had to force push to change the commit messages to pass commitlint |
4t145
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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