MCP Pattern Injection
Runs an MCP server that exposes framework best-practice patterns as tools, so the coding assistant fetches current patterns on demand
Add to Pack
Saved locally in this browser for now.
Cite This Pattern
Rajath Bharadwaj (@Rajathbharadwaj) (2026). MCP Pattern Injection. In *Awesome Agentic Patterns*. Retrieved September 28, 2026, from https://agentic-patterns.com/patterns/mcp-pattern-injection
@misc{agentic_patterns_mcp-pattern-injection,
title = {MCP Pattern Injection},
author = {Rajath Bharadwaj (@Rajathbharadwaj)},
year = {2026},
howpublished = {\url{https://agentic-patterns.com/patterns/mcp-pattern-injection}},
note = {Awesome Agentic Patterns}
} Use when
- Team uses a fast-moving framework that model training data covers poorly
- Developers keep pasting the same framework patterns into prompts
- Coding assistant supports MCP
Avoid when
- Framework is stable and well covered by training data
- No one can maintain the pattern library
Problem
AI coding assistants lack domain-specific knowledge about framework best practices. When building LangGraph agents, developers must repeatedly explain patterns, copy-paste from docs, or watch the AI reinvent suboptimal solutions. The assistant's training data is often outdated relative to fast-moving frameworks.
Solution
Use MCP (Model Context Protocol) servers to inject production patterns directly into the AI assistant's context:
- Create an MCP server that exposes domain patterns as tools and resources
- Structure patterns with clear signatures, descriptions, and code snippets
- Configure Claude Desktop or Cursor to connect to the MCP server
- The AI can now "call" patterns on-demand, getting current best practices
// Example: MCP tool that returns a LangGraph pattern
server.tool("get_pattern", { name: z.string() }, async ({ name }) => {
const pattern = PATTERNS[name];
return {
content: [{
type: "text",
text: `## ${pattern.title}\n\n${pattern.description}\n\n\`\`\`python\n${pattern.code}\n\`\`\``
}]
};
});
The key insight: MCP servers act as live documentation that the AI can query, rather than static context that burns tokens.
Trade-offs
Pros: Always up-to-date patterns; on-demand retrieval saves context space; patterns are structured and tested.
Cons: Requires MCP server setup; adds latency for tool calls; patterns must be maintained.
How to use it
- Build MCP servers for any framework your team uses heavily (LangGraph, FastAPI, React patterns)
- Keep patterns small and focused—one pattern per tool call
- Include "when to use" and "when NOT to use" guidance in pattern descriptions
- Version your patterns alongside your codebase
- Use
npxfor easy distribution:npx your-patterns-mcp
References
- Model Context Protocol: https://modelcontextprotocol.io/
- LangGraph Patterns MCP (reference impl): https://github.com/Rajathbharadwaj/langgraph-patterns-mcp
- Claude Desktop MCP Integration: https://docs.anthropic.com/en/docs/claude-code/mcp
- Cursor MCP Support: https://docs.cursor.com/context/model-context-protocol