Skip to content

Getting Started

Install mcp-lite using your preferred package manager:

Terminal window
npm install mcp-lite

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.

Terminal window
npm install mcp-lite hono zod

Create a new file server.ts:

import { Hono } from "hono";
import { McpServer, StreamableHttpTransport } from "mcp-lite";
import { z } from "zod";
// Create the MCP server instance
const mcp = new McpServer({
name: "my-first-server",
version: "1.0.0",
schemaAdapter: (schema) => z.toJSONSchema(schema as z.ZodType),
});
// Define a simple tool
mcp.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 server
const transport = new StreamableHttpTransport();
const httpHandler = transport.bind(mcp);
// Set up the HTTP server
const app = new Hono();
app.all("/mcp", async (c) => {
const response = await httpHandler(c.req.raw);
return response;
});
// Export for your runtime
export default app;

For Bun:

Terminal window
bun run server.ts

For Node with a bundler:

Terminal window
npx tsx server.ts

Your MCP server is now running and ready to accept requests!

Let’s break down what’s happening:

  1. McpServer Creation: The McpServer instance manages your tools, resources, and prompts.

  2. Schema Adapter: The schemaAdapter converts your validation library’s schema (Zod in this case) to JSON Schema for the MCP protocol.

  3. Tool Definition: The .tool() method registers a callable function with input validation and a handler.

  4. Transport: StreamableHttpTransport handles HTTP + SSE communication using the Fetch API.

  5. HTTP Handler: Binding the transport to the server creates a request handler compatible with any framework.

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