A comprehensive tutorial for building production-grade MCP (Model Context Protocol) servers in Rust.
This tutorial documents the architecture and implementation patterns used in the Pierre Fitness Intelligence MCP server. It covers:
- Project architecture and module organization
- Type-safe error handling with
thiserror - Configuration management and environment variables
- Database architecture with repository pattern
- Dependency injection patterns
- Cryptographic key management (MEK + DEK)
- JWT authentication with RS256
- Multi-tenant database isolation
- Middleware and request context
- JSON-RPC 2.0 foundation
- MCP request flow and tool dispatch
- Transport layers (HTTP, WebSocket, SSE, stdio)
- Tool registry and schema generation
- SDK bridge architecture
- TypeScript type generation
- OAuth 2.0 authorization server (RFC 6749, RFC 7636)
- OAuth 2.0 client for fitness providers
- Pluggable provider architecture
- A2A (Agent-to-Agent) protocol
- 47 MCP tools for fitness analysis
- Sports science algorithms (TSS, VDOT, FTP)
- Recovery and sleep analysis
- Nutrition tracking with USDA integration
- Testing patterns for async Rust
- Design system and frontend
- Deployment strategies
- Performance optimization
This tutorial uses mdBook. To build locally:
# Install mdBook
cargo install mdbook
# Build the book
mdbook build
# Serve locally with hot reload
mdbook serve --openContributions are welcome! Please:
- Keep code examples accurate and up-to-date
- Follow the existing chapter format
- Include learning objectives and exercises
- Test any code samples before submitting
This tutorial is dual-licensed under MIT or Apache 2.0, matching the Pierre MCP Server license.
Part of the Pierre Fitness Intelligence project.