4.4K
Tool Use & Environment validated in production

MCP Pattern Injection

By Rajath Bharadwaj (@Rajathbharadwaj)
Add to Pack
or

Saved locally in this browser for now.

Cite This Pattern
APA
Rajath Bharadwaj (@Rajathbharadwaj) (2026). MCP Pattern Injection. In *Awesome Agentic Patterns*. Retrieved April 24, 2026, from https://agentic-patterns.com/patterns/mcp-pattern-injection
BibTeX
@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}
}
01

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.

02

Solution

Use MCP (Model Context Protocol) servers to inject production patterns directly into the AI assistant's context:

  1. Create an MCP server that exposes domain patterns as tools and resources
  2. Structure patterns with clear signatures, descriptions, and code snippets
  3. Configure Claude Desktop or Cursor to connect to the MCP server
  4. 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: `
03

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 npx for easy distribution: npx your-patterns-mcp
04

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.

06

References