Skip to content

Commit ea034eb

Browse files
committed
feat: Add comprehensive MCP prompts implementation
This PR adds full support for MCP prompts following the specification: Core Features: - Complete prompts API with message creation and validation - Dry::Schema-based argument validation like tools - ERB template support for structured messages - Multiple message format support (hash, array, builder pattern) - Support for text, image, and resource content types Architecture Enhancements: - Feature parity with tools (tags, metadata, annotations, authorization) - Prompt filtering support integrated with ServerFiltering - Stateless architecture matching resources pattern - Auto-naming from class names (CodeReviewPrompt → code_review) - Headers support for authorization context API Improvements: - Flexible messages API supporting multiple same-role messages - MessageBuilder for fluent message construction - Base64 validation for image content - Comprehensive content type handling Rails Integration: - Rails generator support for prompts - ApplicationPrompt base class - Auto-discovery of prompt descendants - Sample prompt template included Testing & Documentation: - Extensive test coverage (900+ lines) - Complete documentation with examples - Rails integration guide updates - Template validation tests Breaking Changes: - Resources now stateless (documented in CHANGELOG) Co-authored-by: @nfedyashev (review feedback)
1 parent f2f815f commit ea034eb

28 files changed

+3669
-15
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Ignore RSpec status file
32
/.rspec_status
43

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99
### Added
1010
- Tool annotations support for providing hints about tool behavior (readOnlyHint, destructiveHint, etc.)
11+
- Comprehensive Prompts Feature implementation following MCP specification
12+
- Full MCP prompts protocol support
13+
- Prompt templates with ERB support
14+
- Prompt argument validation using Dry::Schema
15+
- Prompt filtering support with ServerFiltering architecture
16+
- MessageBuilder for fluent message construction API
17+
- Auto-naming from class names (e.g., `CodeReviewPrompt``code_review`)
18+
- Support for authorization, tags, metadata, and prompt annotations
19+
- Base64 validation for image content to ensure MCP compliance
20+
- Flexible API for the `messages` method supporting hash, array, and block formats
21+
- Rails generator templates for creating prompts
1122

1223
## [1.5.0] - 2025-06-01
1324
### Added

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
fast-mcp (1.5.0)
4+
fast-mcp (1.6.0)
55
addressable (~> 2.8)
66
base64
77
dry-schema (~> 1.14)

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ Fast MCP solves all these problems by providing a clean, Ruby-focused implementa
2828

2929
- 🛠️ **Tools API** - Let AI models call your Ruby functions securely, with in-depth argument validation through [Dry-Schema](https://github.com/dry-rb/dry-schema).
3030
- 📚 **Resources API** - Share data between your app and AI models
31+
- 💬 **Prompt Handling** - Create structured message templates for LLM interactions
3132
- 🔄 **Multiple Transports** - Choose from STDIO, HTTP, or SSE based on your needs
3233
- 🧩 **Framework Integration** - Works seamlessly with Rails, Sinatra or any Rack app.
3334
- 🔒 **Authentication Support** - Secure your AI-powered endpoints with ease
3435
- 🚀 **Real-time Updates** - Subscribe to changes for interactive applications
3536
- 🎯 **Dynamic Filtering** - Control tool/resource access based on request context (permissions, API versions, etc.)
3637

37-
3838
## 💎 What Makes FastMCP Great
3939
```ruby
4040
# Define tools for AI models to use
@@ -269,6 +269,27 @@ end
269269
# Register the resource with the server
270270
server.register_resource(StatisticsResource)
271271

272+
# Define prompts for structured AI interactions
273+
class CodeReviewPrompt < FastMcp::Prompt
274+
# prompt_name is automatically generated as "code_review" from class name
275+
description "Review code for best practices"
276+
277+
arguments do
278+
required(:code).filled(:string)
279+
required(:language).filled(:string)
280+
end
281+
282+
def call(code:, language:)
283+
messages(
284+
assistant: "I'll review your #{language} code for best practices and potential improvements.",
285+
user: "Please review this #{language} code:\n\n```#{language}\n#{code}\n```\n\nFocus on readability, performance, and maintainability."
286+
)
287+
end
288+
end
289+
290+
# Register the prompt with the server
291+
server.register_prompt(CodeReviewPrompt)
292+
272293
# Start the server
273294
server.start
274295
```
@@ -338,6 +359,7 @@ Add your server to your Claude Desktop configuration at:
338359
```
339360

340361
## How to add a MCP server to Claude, Cursor, or other MCP clients?
362+
341363
Please refer to [configuring_mcp_clients](docs/configuring_mcp_clients.md)
342364

343365
## 📊 Supported Specifications
@@ -347,6 +369,7 @@ Please refer to [configuring_mcp_clients](docs/configuring_mcp_clients.md)
347369
|**JSON-RPC 2.0** | Full implementation for communication |
348370
|**Tool Definition & Calling** | Define and call tools with rich argument types |
349371
|**Resource & Resource Templates Management** | Create, read, update, and subscribe to resources |
372+
|**Prompt Handling** | Create structured message templates for LLM interactions |
350373
|**Transport Options** | STDIO, HTTP, and SSE for flexible integration |
351374
|**Framework Integration** | Rails, Sinatra, Hanami, and any Rack-compatible framework |
352375
|**Authentication** | Secure your AI endpoints with token authentication |
@@ -398,6 +421,7 @@ FastMcp.authenticated_rack_middleware(app,
398421
- [🌐 Sinatra Integration](docs/sinatra_integration.md)
399422
- [📚 Resources](docs/resources.md)
400423
- [🛠️ Tools](docs/tools.md)
424+
- [💬 Prompts](docs/prompts.md)
401425
- [🔒 Security](docs/security.md)
402426
- [🎯 Dynamic Filtering](docs/filtering.md)
403427

@@ -408,6 +432,7 @@ Check out the [examples directory](examples) for more detailed examples:
408432
- **🔨 Basic Examples**:
409433
- [Simple Server](examples/server_with_stdio_transport.rb)
410434
- [Tool Examples](examples/tool_examples.rb)
435+
- [Prompt Examples](examples/prompts)
411436

412437
- **🌐 Web Integration**:
413438
- [Rack Middleware](examples/rack_middleware.rb)
@@ -437,4 +462,4 @@ This project is available as open source under the terms of the [MIT License](ht
437462

438463
- The [Model Context Protocol](https://github.com/modelcontextprotocol) team for creating the specification
439464
- The [Dry-Schema](https://github.com/dry-rb/dry-schema) team for the argument validation.
440-
- All contributors to this project
465+
- All contributors to this project

0 commit comments

Comments
 (0)