feat: Add prompt support#351
Merged
4t145 merged 5 commits intomodelcontextprotocol:mainfrom Aug 21, 2025
Merged
Conversation
4t145
suggested changes
Aug 14, 2025
Contributor
|
And you can use |
c88a7c1 to
45ae1b9
Compare
Contributor
There 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.
4t145
suggested changes
Aug 20, 2025
crates/rmcp/tests/test_with_python/test_with_python.egg-info/PKG-INFO
Outdated
Show resolved
Hide resolved
Contributor
|
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
ad7b2d9
Compare
Contributor
Author
|
Note: Had to force push to change the commit messages to pass commitlint |
Merged
9 tasks
takumi-earth
pushed a commit
to earthlings-dev/rmcp
that referenced
this pull request
Jan 27, 2026
* 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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