Getting Started
Installation
Section titled “Installation”Install mcp-lite using your preferred package manager:
npm install mcp-liteYour First MCP Server
Section titled “Your First MCP Server”Let’s create a minimal MCP server that exposes a simple tool. This example uses Hono for the HTTP server and Zod for schema validation.
Step 1: Install Dependencies
Section titled “Step 1: Install Dependencies”npm install mcp-lite hono zodStep 2: Create the Server
Section titled “Step 2: Create the Server”Create a new file server.ts:
import { Hono } from "hono";import { McpServer, StreamableHttpTransport } from "mcp-lite";import { z } from "zod";
// Create the MCP server instanceconst mcp = new McpServer({ name: "my-first-server", version: "1.0.0", schemaAdapter: (schema) => z.toJSONSchema(schema as z.ZodType),});
// Define a simple toolmcp.tool("echo", { description: "Echoes back the message you send", inputSchema: z.object({ message: z.string(), }), handler: (args) => ({ content: [{ type: "text", text: `You said: ${args.message}` }], }),});
// Create the transport and bind it to the serverconst transport = new StreamableHttpTransport();const httpHandler = transport.bind(mcp);
// Set up the HTTP serverconst app = new Hono();app.all("/mcp", async (c) => { const response = await httpHandler(c.req.raw); return response;});
// Export for your runtimeexport default app;Step 3: Run the Server
Section titled “Step 3: Run the Server”For Bun:
bun run server.tsFor Node with a bundler:
npx tsx server.tsYour MCP server is now running and ready to accept requests!
Understanding the Code
Section titled “Understanding the Code”Let’s break down what’s happening:
-
McpServer Creation: The
McpServerinstance manages your tools, resources, and prompts. -
Schema Adapter: The
schemaAdapterconverts your validation library’s schema (Zod in this case) to JSON Schema for the MCP protocol. -
Tool Definition: The
.tool()method registers a callable function with input validation and a handler. -
Transport:
StreamableHttpTransporthandles HTTP + SSE communication using the Fetch API. -
HTTP Handler: Binding the transport to the server creates a request handler compatible with any framework.
Next Steps
Section titled “Next Steps”Now that you have a basic server running, explore:
- Tools - Learn about different tool patterns
- Type Safety - Understand automatic type inference
- Resources - Expose data through resources
- Middleware - Add authentication and logging