AI Engineering & LLMs (50 Qs)•Part 3: Agentic Workflows, Function Calling & MCP
Model Context Protocol (MCP): Client-Host-Server Architecture & Dynamic Tool Discovery
1. What is the Model Context Protocol (MCP)?
Created by Anthropic and established as an open standard, the Model Context Protocol (MCP) provides a universal, open standard for connecting AI assistants and agents to external data sources, business tools, and developer environments. Prior to MCP, every LLM provider and tool developer wrote custom, proprietary plugins (OpenAI Plugins, LangChain custom tools, Claude artifacts).
arduino
┌────────────────────────────────────────────────────────────────────────┐
│ MCP Architecture │
└────────────────────────────────────────────────────────────────────────┘
Host Application (Claude Desktop, IDE, Agent Framework)
│
├── Client (Manages protocol lifecycle, auth, & tool routing)
│ │
│ ├─► Transport (stdio / SSE / WebSocket)
│ │
▼ ▼
MCP Servers (Isolated Processes / Microservices)
┌───────────────────┐ ┌───────────────────┐ ┌───────────────────┐
│ GitHub MCP Server │ │ Postgres Server │ │ FileSystem Server │
│ Tools: PRs, Issues│ │ Tools: Run Query │ │ Tools: Read, Edit │
└───────────────────┘ └───────────────────┘ └───────────────────┘
2. Core Primitives of the Protocol
| Primitive | Initiator | Purpose | Example |
|---|---|---|---|
| Tools | Model-controlled | Executable functions that cause external side-effects or fetch data. | query_sales_db(sql), create_jira_issue() |
| Resources | Application-controlled | File-like read-only data that provide context to the model. | postgres://db/schema, file:///docs/spec.md |
| Prompts | User-controlled | Pre-defined, interactive prompt templates surfaced in the UI. | debug_incident_template, code_review_prompt |
3. Writing an Enterprise MCP Tool in TypeScript
typescript
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
const server = new Server({ name: 'enterprise-ops', version: '1.0.0' }, { capabilities: { tools: {} } });
// Register available tools
server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
{
name: 'get_service_health',
description: 'Checks Kubernetes cluster health and active incident count',
inputSchema: {
type: 'object',
properties: { serviceName: { type: 'string' } },
required: ['serviceName']
}
}
]
}));
// Handle tool execution
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if (request.params.name === 'get_service_health') {
const { serviceName } = request.params.arguments as { serviceName: string };
return { content: [{ type: 'text', text: JSON.stringify({ service: serviceName, status: 'healthy', replicas: 5 }) }] };
}
throw new Error('Tool not found');
});
const transport = new StdioServerTransport();
await server.connect(transport);