MCP

MCP & AI Agent Cheat Sheet

MODEL CONTEXT PROTOCOL · AGENTIC AI · QUICK REFERENCE GUIDE

🎓 Next Gen QA IT Coaching Classes
📞 Mr. Khan Sir  |  8700350994
MCP Servers Agentic AI OpenAI Agents SDK LangGraph AutoGen
MCP Architecture · Server Setup (TypeScript SDK) · Tools · Resources & Prompts
MCP Core Architecture
3 core pieces: Host, Client, Server
// Host = app using AI (Claude Desktop, IDE) // Client = lives inside Host, 1 per Server // Server = exposes Tools/Resources/Prompts // Transport = JSON-RPC 2.0 over stdio or HTTP
3 building blocks a server exposes
Tools // actions model can call (functions) Resources // data model can read (files/URIs) Prompts // reusable prompt templates
Install SDK
Node.js / TypeScript SDK
npm install @modelcontextprotocol/sdk zod
Python SDK
pip install mcp
Server Boilerplate (TS)
Create server instance
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; const server = new McpServer({ name: "jira-mcp-server", version: "1.0.0" });
Connect via stdio transport
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; const transport = new StdioServerTransport(); await server.connect(transport);
Defining Tools
Register a tool with zod schema
server.registerTool( "create_jira_issue", { title: "Create Jira Issue", description: "Creates a new issue", inputSchema: { project: z.string(), summary: z.string() } }, async ({ project, summary }) => ({ content: [{ type: "text", text: `Created in ${project}` }] }) );
Resources & Prompts
Register a resource (URI-based data)
server.registerResource( "config", "config://app", { title: "App Config" }, async (uri) => ({ contents: [{ uri: uri.href, text: "..." }] }) );
Register a reusable prompt template
server.registerPrompt("review-code", { title: "Review Code", argsSchema: { code: z.string() } }, ({ code }) => ({ messages: [{ role: "user", content: { type: "text", text: `Review:\n${code}` } }] }));
Transports (stdio / HTTP) · Client Connection · Claude Desktop Config · Testing & Debugging
Transport Options
stdio – local process (most common)
// Host spawns server as child process // communicates via stdin/stdout // best for local tools (Jira, DB, files)
Streamable HTTP – remote server
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js"; // exposes server over HTTP(S) endpoint // needed for cloud/remote agent access
MCP Client (TS)
Connect to a server from client code
import { Client } from "@modelcontextprotocol/sdk/client/index.js"; const client = new Client({ name: "my-client", version: "1.0" }); await client.connect(transport); const tools = await client.listTools(); const result = await client.callTool({ name: "create_jira_issue", arguments: {...} });
Claude Desktop Config
claude_desktop_config.json
{ "mcpServers": { "jira": { "command": "node", "args": ["/path/build/index.js"], "env": { "JIRA_TOKEN": "xxx" } } } }
Testing & Debugging
MCP Inspector – visual test tool
npx @modelcontextprotocol/inspector node build/index.js
Common pitfalls
// stdout must stay clean (no console.log!) // use console.error() for server-side logs // tool names: lowercase_snake_case // always return content[] array shape
AI Agent Core Concepts · OpenAI Agents SDK (JS/TS) · Tools, Handoffs & Guardrails
Agent Core Concepts
What makes an "agent" (vs simple LLM call)
Loop: think → act (tool call) → observe → repeat Autonomy: decides next step itself Tools: functions/MCP servers it can call Memory: conversation + long-term state
ReAct pattern (Reason + Act)
// Thought: I need the ticket status // Action: call get_jira_ticket(id) // Observation: status = "In Progress" // Thought: now I can answer the user
OpenAI Agents SDK – Basics
Install (JS/TS)
npm install @openai/agents zod
Create & run an Agent
import { Agent, run } from "@openai/agents"; const agent = new Agent({ name: "QA Assistant", instructions: "Help with test automation", model: "gpt-4.1" }); const result = await run(agent, "Write a login test"); console.log(result.finalOutput);
Tools in Agents SDK
Define a function tool
import { tool } from "@openai/agents"; const getTicket = tool({ name: "get_jira_ticket", description: "Fetch ticket by ID", parameters: z.object({ id: z.string() }), execute: async ({ id }) => fetchTicket(id) }); const agent = new Agent({ ..., tools: [getTicket] });
Handoffs & Guardrails
Agent-to-agent handoff
const billingAgent = new Agent({ name: "Billing" }); const triage = new Agent({ name: "Triage", handoffs: [billingAgent, techAgent] });
Input guardrail (validate before running)
const guardrail = { name: "no-pii", execute: async ({ input }) => ({ tripwireTriggered: containsPII(input) }) };
LangGraph · AutoGen · Multi-Agent Patterns · Best Practices
LangGraph Basics
Define state graph with nodes/edges
from langgraph.graph import StateGraph, END graph = StateGraph(AgentState) graph.add_node("chatbot", chatbot_node) graph.add_node("tools", tool_node) graph.add_conditional_edges( "chatbot", route_fn, {"tools": "tools", END: END}) graph.set_entry_point("chatbot") app = graph.compile()
AutoGen Basics
RoundRobinGroupChat (turn-based agents)
from autogen_agentchat.teams import RoundRobinGroupChat team = RoundRobinGroupChat( [writer_agent, reviewer_agent], max_turns=6 ) result = await team.run(task="Draft a test plan")
SelectorGroupChat (model picks next speaker)
from autogen_agentchat.teams import SelectorGroupChat team = SelectorGroupChat(agents, model_client=model)
Multi-Agent Patterns
Common architectures
Orchestrator-Worker: 1 planner, N executors Sequential: agent A output → agent B input Handoff: triage agent routes to specialist Parallel: fan-out tasks, aggregate results Human-in-loop: approval step before action
Best Practices
MCP + Agent build checklist
✔ Keep tool names/descriptions crystal clear ✔ Validate inputs with zod/pydantic schemas ✔ Never console.log() in stdio MCP servers ✔ Add guardrails for cost/PII/scope control ✔ Log every tool call for traceability ✔ Version-pin SDKs (breaking changes are common)