middleware-patterns

Implement MCP middleware patterns for HTTP and Lambda transports.

2|Updated Aug 17, 2025
One-click install
npx skills add https://github.com/aussierobots/turul-mcp-framework --skill middleware-patterns-aussierobots
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: middleware-patterns
Source: https://github.com/aussierobots/turul-mcp-framework/tree/main/plugins/turul-mcp-skills/skills/middleware-patterns
Command: npx skills add https://github.com/aussierobots/turul-mcp-framework --skill middleware-patterns-aussierobots

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Enables developers to implement cross-cutting MCP concerns (authentication, rate limiting, logging, auditing) with reusable middleware patterns that work across HTTP and Lambda transports.

Core Features & Use Cases

  • Provides the McpMiddleware trait with before_dispatch and after_dispatch hooks to intercept requests.
  • Demonstrates common patterns: Auth middleware, Rate limiting, Logging/Timing, and Lambda authorizer extraction.
  • Use case: apply consistent security, observability, and pacing across tools and dispatch flows in Turul MCP Server.

Quick Start

Register and compose your middleware with the MCP server builder, then run the server to apply these cross-cutting concerns.

Frequently Asked Questions about middleware-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add authentication and rate limiting to MCP server requests?

You can add authentication and rate limiting to MCP server requests by implementing reusable middleware patterns using the McpMiddleware trait. This trait provides before_dispatch and after_dispatch hooks to intercept and modify requests across HTTP and Lambda transports.

Can I inject session state into MCP tools using middleware?

Yes, you can inject session state into MCP tools using middleware. The middleware implementation supports SessionInjection and RequestContext, allowing you to pass session data and request context across your tools and dispatch handlers.

Does MCP middleware work with both HTTP and Lambda transports?

Yes, MCP middleware works with both HTTP and Lambda transports. The middleware patterns apply cross-cutting concerns like authentication, logging, and rate limiting consistently across both transport layers without requiring separate implementations.

What is the best way to log and time MCP dispatch handlers?

The best way to log and time MCP dispatch handlers is by registering a logging middleware with the MCP server builder. Using the McpMiddleware trait, the after_dispatch hook captures timing data while before_dispatch logs incoming requests for observability.

How do I configure middleware registration order for an MCP server?

You configure middleware registration order when building the MCP server. The server builder allows you to compose and register multiple middleware components sequentially, ensuring the execution order matches your cross-cutting concern priorities for request interception.

Why do I need the McpMiddleware trait for cross-cutting concerns?

You need the McpMiddleware trait to standardize cross-cutting concerns like auditing and security across all tools. It defines the before_dispatch and after_dispatch hooks required to intercept requests and return DispatcherResult without duplicating logic in individual handlers.