Skip to main content

Getting Started with the Model Context Protocol (MCP)

An introduction to MCP and how to build your first MCP server to connect AI models to your systems.

S

SmartTechLabs

SmartTechLabs - Intelligent Solutions for IoT, Edge Computing & AI

6 min read

The Model Context Protocol (MCP) is an open standard, originally developed by Anthropic, for connecting AI assistants to external data sources and tools. In this guide, we’ll explore what MCP is and how to get started building MCP servers.

Update, November 2026

This article describes the 2025 protocol revisions and the v1 TypeScript SDK (@modelcontextprotocol/sdk, currently 1.32.x), and the code below still works with that package. Since January:

  • Governance: Anthropic donated MCP to the Agentic AI Foundation, a Linux Foundation fund, in December 2025. Other vendors’ clients implement it.
  • Specification: the current revision is 2026-07-28. It removes the initialize handshake and protocol-level sessions; capabilities come from server/discover and each request is self-contained. Long-running work and UI extensions (Tasks, MCP Apps) are optional extensions.
  • TypeScript SDK v2: released as 2.0.0 on 2026-07-27 (2.4.0 on npm at the time of writing). It is split into @modelcontextprotocol/server and @modelcontextprotocol/client, needs Node.js 20 or later and Zod 4, and replaces the low-level setRequestHandler(Schema, ...) pattern used below with McpServer.registerTool() / registerResource() and serveStdio(). The SDK ships a codemod and an upgrade guide. For a new server, start with v2.
  • Compiler: TypeScript 7 no longer accepts moduleResolution: "node", so the tsconfig.json below uses Node16.

Open Standard

MCP is an open protocol. A server you build works with any client that implements the standard, not only with Claude.

What is MCP?

MCP provides a standardized way for AI models to:

CapabilityDescriptionExample
DiscoverFind available tools and resourcesList database tables
QueryAccess external data sourcesRead file contents
ExecutePerform actions in external systemsSend notifications
NegotiateAgree on protocol version and featuresServer declares its tools capability

Think of it as an API standard specifically designed for AI-to-system communication.


Core Concepts

MCP architecture: An MCP host talks JSON-RPC to an MCP server, which exposes resources, tools and prompts backed by external systems.

MCP Components

ComponentPurposeExamples
ResourcesData sources AI can queryDatabase tables, file contents, API responses
ToolsActions AI can executeCreate records, send notifications, trigger workflows
PromptsPre-defined templatesStructured interaction patterns

Building Your First MCP Server

Let’s build a simple MCP server in TypeScript that provides access to a list of tasks. It uses the low-level Server class so that the protocol messages are visible; the higher-level McpServer class is shorter for real projects.

Project Setup

This section uses the v1 SDK. npm install @modelcontextprotocol/sdk installs 1.x; the v2 packages have different names (see the update above).

1
2
3
4
5
mkdir my-mcp-server
cd my-mcp-server
npm init -y
npm install @modelcontextprotocol/sdk
npm install -D typescript @types/node

Basic Server Structure

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// src/index.ts
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
  ListResourcesRequestSchema,
  ReadResourceRequestSchema,
  ListToolsRequestSchema,
  CallToolRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";

// In-memory task store
const tasks = [
  { id: 1, title: "Review MCP documentation", completed: false },
  { id: 2, title: "Build sample server", completed: true },
];

const server = new Server(
  { name: "task-manager", version: "1.0.0" },
  { capabilities: { resources: {}, tools: {} } }
);

// Handle resource listing
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
  resources: [
    {
      uri: "tasks://all",
      name: "All Tasks",
      description: "List of all tasks",
    },
  ],
}));

// Handle resource reading
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
  if (request.params.uri === "tasks://all") {
    return {
      contents: [
        {
          uri: request.params.uri,
          mimeType: "application/json",
          text: JSON.stringify(tasks, null, 2),
        },
      ],
    };
  }
  throw new Error("Resource not found");
});

// Handle tool listing
server.setRequestHandler(ListToolsRequestSchema, async () => ({
  tools: [
    {
      name: "add_task",
      description: "Add a new task",
      inputSchema: {
        type: "object",
        properties: {
          title: { type: "string", description: "Task title" },
        },
        required: ["title"],
      },
    },
  ],
}));

// Handle tool execution
server.setRequestHandler(CallToolRequestSchema, async (request) => {
  if (request.params.name === "add_task") {
    const { title } = request.params.arguments as { title: string };
    const newTask = {
      id: tasks.length + 1,
      title,
      completed: false,
    };
    tasks.push(newTask);
    return {
      content: [
        {
          type: "text",
          text: `Created task: ${title}`,
        },
      ],
    };
  }
  throw new Error("Tool not found");
});

// Start the server
async function main() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
}

main().catch(console.error);

Configuration Files

package.json

1
2
3
4
5
6
7
{
  "type": "module",
  "scripts": {
    "build": "tsc",
    "start": "node dist/index.js"
  }
}

tsconfig.json

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "Node16",
    "moduleResolution": "Node16",
    "rootDir": "./src",
    "outDir": "./dist",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true
  },
  "include": ["src"]
}

Build and Run

1
2
npm run build
npm start

Connecting to Claude

To use your MCP server with Claude Desktop, add it to your configuration:

1
2
3
4
5
6
7
8
{
  "mcpServers": {
    "task-manager": {
      "command": "node",
      "args": ["/path/to/my-mcp-server/dist/index.js"]
    }
  }
}

Claude can now read the task list as a resource and create tasks through the add_task tool. Use an absolute path in args, and restart Claude Desktop after editing the file. Do not write to stdout (console.log) in a stdio server, because stdout carries the protocol messages; log to stderr.


Best Practices

Security First

Always validate inputs and implement proper authentication before exposing tools to AI models. Never trust unvalidated input from any source.

Security Guidelines

ConcernRecommendationPriority
Input ValidationValidate all inputs against schemasCritical
AuthenticationImplement proper auth for sensitive operationsCritical
Audit LoggingLog all tool executionsHigh
Rate LimitingPrevent abuse and runaway operationsHigh

Performance Guidelines

AspectRecommendationBenefit
CachingCache frequently accessed resourcesLower latency
PaginationUse pagination for large datasetsMemory efficiency
TimeoutsImplement timeouts for long operationsReliability
BatchingBatch related operationsThroughput

Error Handling

PracticeImplementation
Clear MessagesProvide actionable error descriptions
Graceful HandlingHandle edge cases without crashing
No LeaksDon’t expose internal system details
LoggingLog errors for debugging

Integration Possibilities

CategoryExamplesUse Cases
DatabasesPostgreSQL, MongoDB, RedisData access, CRUD operations
Business AppsCRM, ERP, HelpdeskCustomer data, workflows
Dev ToolsGit, CI/CD, Issue trackersDevelopment automation
Cloud ServicesAWS, GCP, AzureInfrastructure management

Next Steps

  1. Identify Use Cases: What data and actions would be valuable for AI access?
  2. Design Resources: Define the data structures AI should query
  3. Plan Tools: Determine what actions AI should execute
  4. Implement Security: Build proper authentication and validation
  5. Test Thoroughly: Verify behavior with edge cases
  6. Deploy & Monitor: Track usage and errors in production

Need help building MCP integrations? Contact us to discuss your requirements.

Share this article
S

SmartTechLabs

Building Intelligent Solutions: IoT, Edge Computing, AI & LLM Integration