Advanced MCP patterns for tool composition, resource management, and scaling. Build custom MCP servers, compose tools, manage resources efficiently. Use when composing MCP tools or scaling MCP servers.
View on GitHubyonatangross/skillforge-claude-plugin
orchestkit-complete
January 23, 2026
Select agents to install to:
npx add-skill https://github.com/yonatangross/skillforge-claude-plugin/blob/main/./skills/mcp-advanced-patterns/SKILL.md -a claude-code --skill mcp-advanced-patternsInstallation paths:
.claude/skills/mcp-advanced-patterns/# MCP Advanced Patterns
Advanced Model Context Protocol patterns for production-grade MCP implementations.
> **FastMCP 2.14.x** (Jan 2026): Enterprise auth, OpenAPI/FastAPI generation, server composition, proxying. Python 3.10-3.13.
## Overview
- Composing multiple tools into orchestrated workflows
- Managing resource lifecycle and caching efficiently
- Scaling MCP servers horizontally with load balancing
- Building custom MCP servers with middleware and transports
- Implementing auto-enable thresholds for context management
## Tool Composition Pattern
```python
from dataclasses import dataclass
from typing import Any, Callable, Awaitable
@dataclass
class ComposedTool:
"""Combine multiple tools into a single pipeline operation."""
name: str
tools: dict[str, Callable[..., Awaitable[Any]]]
pipeline: list[str]
async def execute(self, input_data: dict[str, Any]) -> dict[str, Any]:
"""Execute tool pipeline sequentially."""
result = input_data
for tool_name in self.pipeline:
tool = self.tools[tool_name]
result = await tool(result)
return result
# Example: Search + Summarize composition
search_summarize = ComposedTool(
name="search_and_summarize",
tools={
"search": search_documents,
"summarize": summarize_content,
},
pipeline=["search", "summarize"]
)
```
## FastMCP Server with Lifecycle
```python
from contextlib import asynccontextmanager
from collections.abc import AsyncIterator
from dataclasses import dataclass
from mcp.server.fastmcp import Context, FastMCP
@dataclass
class AppContext:
"""Typed application context with shared resources."""
db: Database
cache: CacheService
config: dict
@asynccontextmanager
async def app_lifespan(server: FastMCP) -> AsyncIterator[AppContext]:
"""Manage server startup and shutdown lifecycle."""
# Initialize on startup
db = await Database.connect()
cache = await CacheService.connect()