| Filename | Latest commit message | Latest commit date |
|---|---|---|
* feat: implement MCP completion specification 2025-06-18 Complete implementation of MCP completion specification with performance optimizations: Core Features: - Add CompletionContext for context-aware completion with previously resolved arguments - Implement CompletionProvider trait with async support and dyn compatibility - Create DefaultCompletionProvider with optimized fuzzy matching algorithm - Add comprehensive validation and helper methods to CompletionInfo - Update ServerHandler to handle completion/complete requests - Add client convenience methods for prompt and resource completion Performance Optimizations: - Zero-allocation fuzzy matching using index-based scoring - Top-k selection with select_nth_unstable instead of full sorting - Pre-allocated vectors to avoid reallocations during matching - Char-based case-insensitive matching to minimize string operations - 5-8x performance improvement for large candidate sets API Design: - Context-aware completion supporting multi-argument scenarios - Type-safe validation with MAX_VALUES limit (100 per MCP spec) - Helper methods: with_all_values, with_pagination, validate - Reference convenience methods: for_prompt, for_resource - Client methods: complete_prompt_argument, complete_resource_argument Testing: - 17 comprehensive tests covering all functionality - Schema compliance tests for MCP 2025-06-18 specification - Performance tests with <100ms target for 1000 candidates - Edge case and validation tests Schema Updates: - Add CompletionContext to JSON schema - Update CompleteRequestParam with optional context field - Maintain backward compatibility with existing API * test: add comprehensive fuzzy matching tests for completion Add three new test cases to enhance coverage of fuzzy matching algorithm: - test_fuzzy_matching_with_typos_and_missing_chars: Tests subsequence matching with real-world scenarios including abbreviated patterns, case-insensitive matching, and complex file/package name completion - test_fuzzy_matching_scoring_priority: Validates scoring system prioritizes exact matches > prefix matches > substring matches > subsequence matches - test_fuzzy_matching_edge_cases: Covers boundary conditions including single character queries, oversized queries, and repeated characters These tests ensure robust fuzzy search functionality for MCP completion specification implementation with proper handling of user typos and incomplete input patterns. * feat: improve completion algorithms, add comprehensive tests and example - Enhance fuzzy matching algorithm with acronym support for multi-word entries - Add comprehensive scoring system for better relevance ranking - Implement multi-level matching: exact, prefix, word prefix, acronym, substring - Add context-aware completion scoring with proper priority ordering - Optimize performance through efficient character-by-character matching - Support case-insensitive acronym matching - Improve code quality with clippy fixes and async fn syntax - Add comprehensive test suite covering edge cases and acronym matching - Create completion example server demonstrating weather-related prompts * fix(test): typos * refactor: improve completion API and replace example with SQL query builder - Remove DefaultCompletionProvider from library core - Move completion logic to examples following review feedback - Update CompletionContext.argument_names() to return Iterator for better performance - Replace tech search example with SQL query builder demonstrating progressive completion - Add context-aware completion that adapts based on filled arguments - Use proper Option types for optional SQL fields (columns, where_clause, values) - Demonstrate real-world value of argument_names() method for dynamic completion flow The SQL query builder showcases: • Progressive field availability based on operation type • Context validation using argument_names() • Proper Optional field handling • Smart completion that guides user through multi-step form * fix: fmt |
||
| .. | ||
| src | ||
| templates | ||
| Cargo.toml | ||
| README.md | ||
MCP Server Examples
This directory contains Model Context Protocol (MCP) server examples implemented in Rust. These examples demonstrate how to create MCP servers using different transport methods and how to implement various server capabilities including tools, resources, prompts, and authentication.
Example List
Counter Standard I/O Server (counter_stdio.rs)
A basic MCP server that communicates using standard input/output transport.
- Provides a simple counter tool with increment, decrement, and get_value operations
- Demonstrates basic tool implementation and stdio transport
Counter SSE Server (counter_sse.rs)
A server that provides counter functionality using Server-Sent Events (SSE) transport.
- Runs on
http://127.0.0.1:8000/sseby default - Provides the same counter tools as the stdio version
- Demonstrates SSE transport setup with graceful shutdown
- Can be accessed via web browsers or SSE-compatible clients
Counter SSE Direct Server (counter_sse_directly.rs)
A minimal SSE server implementation showing direct SSE server usage.
- Simplified version of the SSE server
- Demonstrates basic SSE server configuration
- Provides counter functionality with minimal setup
Memory Standard I/O Server (memory_stdio.rs)
A minimal server example using stdio transport.
- Lightweight server implementation
- Demonstrates basic server setup patterns
- Good starting point for custom server development
Counter Streamable HTTP Server (counter_streamhttp.rs)
A server using streamable HTTP transport for MCP communication, with axum.
- Runs on HTTP with streaming capabilities
- Provides counter tools via HTTP streaming
- Demonstrates streamable HTTP transport configuration
Counter Streamable HTTP Server with Hyper (counter_hyper_streamable_http.rs)
A server using streamable HTTP transport for MCP communication, with hyper.
- Runs on HTTP with streaming capabilities
- Provides counter tools via HTTP streaming
- Demonstrates streamable HTTP transport configuration
Complex OAuth SSE Server (complex_auth_sse.rs)
A comprehensive example demonstrating OAuth 2.0 integration with MCP servers.
- Full OAuth 2.0 authorization server implementation
- Client registration and token management
- User authorization flow with web interface
- Token validation middleware
- Integrated with MCP SSE transport
- Demonstrates enterprise-grade authentication patterns
Simple OAuth SSE Server (simple_auth_sse.rs)
A simplified OAuth example showing basic token-based authentication.
- Basic token store and validation
- Authorization middleware for SSE endpoints
- Token generation API
- Simplified authentication flow
- Good starting point for adding authentication to MCP servers
Elicitation Demo (elicitation_stdio.rs)
A working MCP server demonstrating elicitation for user name collection.
- Real MCP server using rmcp library
context.peer.elicit::<T>()API usage- Type-safe elicitation with
elicit_safe!macro - JSON Schema validation with schemars
- Tools:
greet_user(collects name),reset_name(clears stored name)
Prompt Standard I/O Server (prompt_stdio.rs)
A server demonstrating the prompt framework capabilities.
- Shows how to implement prompts in MCP servers
- Provides code review and debugging prompts
- Demonstrates prompt argument handling with JSON schema
- Uses standard I/O transport
- Good example of prompt implementation patterns
How to Run
Each example can be run using Cargo:
# Run the counter standard I/O server
cargo run --example servers_counter_stdio
# Run the counter SSE server
cargo run --example servers_counter_sse
# Run the counter SSE direct server
cargo run --example servers_counter_sse_directly
# Run the memory standard I/O server
cargo run --example servers_memory_stdio
# Run the counter streamable HTTP server
cargo run --example servers_counter_streamhttp
# Run the complex OAuth SSE server
cargo run --example servers_complex_auth_sse
# Run the simple OAuth SSE server
cargo run --example servers_simple_auth_sse
# Run the elicitation standard I/O server
cargo run --example servers_elicitation_stdio
# Run the prompt standard I/O server
cargo run --example servers_prompt_stdio
Testing with MCP Inspector
Many of these servers can be tested using the MCP Inspector tool: See inspector
Dependencies
These examples use the following main dependencies:
rmcp: Rust implementation of the MCP server librarytokio: Asynchronous runtimeserdeandserde_json: For JSON serialization and deserializationtracingandtracing-subscriber: For logginganyhow: Error handlingaxum: Web framework for HTTP-based transportstokio-util: Utilities for async programmingaskama: Template engine (used in OAuth examples)tower-http: HTTP middleware (used for CORS in OAuth examples)uuid: UUID generation (used in OAuth examples)chrono: Date and time handling (used in OAuth examples)rand: Random number generation (used in OAuth examples)schemars: JSON Schema generation (used in elicitation examples)
Common Module
The common/ directory contains shared code used across examples:
counter.rs: Counter tool implementation with MCP server traitscalculator.rs: Calculator tool examplesgeneric_service.rs: Generic service implementations
This modular approach allows for code reuse and demonstrates how to structure larger MCP server applications.