CC-301j · Module 1
Server Scaffolding
3 min read
An MCP server has three components: the transport layer (how it communicates), the tool registry (what it offers), and the handlers (what it does). The MCP SDK provides the transport layer and the registry. You write the handlers — the actual business logic that executes when Claude invokes a tool.
The TypeScript SDK (@modelcontextprotocol/sdk) is the fastest path to a working server. Create a new project, install the SDK, define your tools with schemas, and implement the handler for each tool. The server is a Node.js process that the SDK manages — you never touch the transport protocol directly. Your code is pure business logic: receive parameters, do work, return results.
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod';
const server = new McpServer({ name: 'my-tools', version: '1.0.0' });
// Define a tool with schema and handler
server.tool(
'get_weather',
'Get current weather for a city. Returns temperature, conditions, humidity.',
{ city: z.string().describe('City name, e.g. "San Francisco"') },
async ({ city }) => {
const data = await fetchWeather(city);
return { content: [{ type: 'text', text: JSON.stringify(data) }] };
}
);
// Start the server on stdio transport
const transport = new StdioServerTransport();
await server.connect(transport);