| name | mcp-optimization |
| description | MCP server usage patterns for token efficiency. When to use each server, caching strategies, session-type budgets. |
| allowed-tools | mcp__* |
| token-budget | 600 |
MCP Server Optimization
Available Servers
| Server |
Purpose |
Token Cost |
When to Use |
context7 |
Library docs |
Low (cached) |
Before new library usage |
repomix |
Codebase packing |
High |
Once per session for exploration |
memory |
Persistent knowledge |
Low |
Session start/end |
sequential-thinking |
Complex planning |
Medium |
Multi-step reasoning |
fetch |
URL content |
Medium |
External documentation |
filesystem |
File operations |
Low |
Prefer native Read/Write tools |
github |
Repository operations |
Low |
PR/issue management |
playwright |
Browser automation |
Medium |
E2E testing, web scraping |
ast-grep |
AST-based search |
Low |
Code pattern matching |
Token Budget by Session Type
| Session Type |
Target Budget |
Strategy |
| Quick fix |
<5k tokens |
No MCP, minimal context |
| Feature dev |
10-20k tokens |
Targeted repomix, selective skills |
| Architecture |
30-50k tokens |
Full repomix, sequential thinking |
| Audit/review |
50-100k tokens |
Comprehensive (justified by scope) |
Context7 Patterns
Pre-fetch at Session Start
// Identify project dependencies
const deps = await readPackageJson();
// Pre-fetch docs for frequently used libraries
await Promise.all([
mcp__context7__resolve-library-id({ libraryName: "effect" }),
mcp__context7__resolve-library-id({ libraryName: "@effect/platform" }),
mcp__context7__resolve-library-id({ libraryName: "drizzle-orm" }),
]);
Mode Selection
| Mode |
Use For |
code |
Function signatures, API references, examples |
info |
Architectural concepts, guides, best practices |
Pagination Strategy
When context insufficient:
- Try
page=2, page=3 with same topic
- Narrow topic to specific API
- Switch modes if conceptual vs implementation
Repomix Patterns
Targeted Packing (Preferred)
# API changes only
repomix pack . --include "src/routes/**,src/adapters/**"
# Frontend only
repomix pack . --include "src/components/**,src/pages/**"
# Config only
repomix pack . --include "*.nix,*.json,*.toml"
When to Use Compression
| Scenario |
Compression |
| Large codebase (>50k lines) |
Enable |
| Focused feature work |
Disable |
| Full audit |
Enable |
| Quick reference |
Disable |
Incremental Analysis
1. pack_codebase → returns output_id
2. grep_repomix_output(output_id, pattern) → targeted search
3. read_repomix_output(output_id, startLine, endLine) → detailed view
Memory Server Optimization
Structured Entity Storage
// Prefer structured entities over free-form
mcp__memory__create_entities([{
name: "auth-decision",
entityType: "architecture-decision",
observations: [
"library: better-auth@1.4.6",
"pattern: session-based",
"location: src/auth/",
"reason: Effect-compatible"
]
}]);
Query Patterns
| Need |
Action |
| Recall decision |
open_nodes(["auth-decision"]) |
| Search context |
search_nodes("authentication") |
| Update learning |
add_observations(...) |
Sequential Thinking Discipline
Use For
- Multi-file refactoring
- Bug investigation with multiple hypotheses
- Architecture decisions with trade-offs
- Complex implementation planning
Skip For
- Single file edits
- Documentation updates
- Simple feature additions
- Trivial bug fixes (use TodoWrite instead)
AST-Grep Patterns
Code Pattern Search
# Find all Effect.gen usages
mcp__ast-grep__find_code({
pattern: "Effect.gen(function* () { $$$BODY })",
language: "typescript"
})
# Find any type violations
mcp__ast-grep__find_code_by_rule({
yaml: "id: any-type\nlanguage: ts\nrule:\n pattern: ': any'"
})
Rewrite Operations
// Replace console.log with logger
mcp__ast-grep__rewrite_code({
pattern: "console.log($ARG)",
replacement: "logger.info($ARG)",
auto_apply: true
})
Anti-Patterns
| Anti-Pattern |
Correct Approach |
| Pack entire codebase for small task |
Use targeted --include patterns |
| Multiple context7 calls per library |
Cache library ID, paginate docs |
| Repomix without grep |
Use grep_repomix_output for search |
| Sequential thinking for simple tasks |
Use TodoWrite for task tracking |
| Memory for temporary data |
Only store architectural decisions |
Cost Optimization Checklist