Add two numbers
Fetch the content of a URL
Download a file from a URL
LiteMCP is a lightweight, elegant TypeScript framework designed specifically for building Model Context Protocol (MCP) servers. It provides a clean, type-safe API for defining tools, resources, and prompts that can be exposed to LLM clients. With built-in features like logging, error handling, and debugging tools, LiteMCP simplifies the development process for MCP server creators. Note that as of April 2025, the project has been deprecated in favor of the official MCP TypeScript SDK, which now offers similar high-level APIs. However, the CLI commands from this project are still available as a standalone package.
LiteMCP provides a streamlined approach to building Model Context Protocol servers in TypeScript. It offers a clean API for defining tools, resources, and prompts with full TypeScript support, making it easier to create robust MCP servers.
To get started with LiteMCP, you'll need to install the package along with Zod, which is used for parameter validation:
npm install litemcp zod
Here's a simple example of how to create an MCP server with LiteMCP:
import { LiteMCP } from "litemcp";
import { z } from "zod";
// Create a new server instance
const server = new LiteMCP("demo", "1.0.0");
// Add a tool
server.addTool({
name: "add",
description: "Add two numbers",
parameters: z.object({
a: z.number(),
b: z.number(),
}),
execute: async (args) => {
return args.a + args.b;
},
});
// Add a resource
server.addResource({
uri: "file:///logs/app.log",
name: "Application Logs",
mimeType: "text/plain",
async load() {
return {
text: "Example log content",
};
},
});
// Start the server
server.start();
Tools allow your server to expose executable functions that can be invoked by clients and used by LLMs to perform actions:
server.addTool({
name: "fetch",
description: "Fetch the content of a URL",
parameters: z.object({
url: z.string(),
}),
execute: async (args) => {
const content = await fetchWebpageContent(args.url);
return content;
},
});
Resources represent data that your MCP server makes available to clients, such as file contents, images, or logs:
server.addResource({
uri: "file:///logs/app.log",
name: "Application Logs",
mimeType: "text/plain",
async load() {
return {
text: await readLogFile(),
};
},
});
For binary content, you can return a base64-encoded blob:
async load() {
return {
blob: 'base64-encoded-data'
}
}
Prompts enable servers to define reusable prompt templates and workflows:
server.addPrompt({
name: "git-commit",
description: "Generate a Git commit message",
arguments: [
{
name: "changes",
description: "Git diff or description of changes",
required: true,
},
],
load: async (args) => {
return `Generate a concise but descriptive commit message for these changes:\n\n${args.changes}`;
},
});
LiteMCP provides a built-in logger that sends messages to the client:
server.addTool({
name: "download",
description: "Download a file from a URL",
parameters: z.object({
url: z.string(),
}),
execute: async (args) => {
server.logger.info("Downloading file", { url: args.url });
// ... download logic ...
server.logger.info("Downloaded file", { url: args.url });
return response;
},
});
The logger supports different log levels: debug
, info
, warn
, and error
.
The easiest way to test your server is with the built-in CLI:
npx litemcp dev server.js
# TypeScript files are also supported
npx litemcp dev server.ts
You can also use the official MCP Inspector for a web-based UI:
npx litemcp inspect server.js
By default, servers run with stdio transport, but you can also use SSE:
server.start({
transportType: "sse",
sse: {
endpoint: "/sse",
port: 8080,
},
});
This will start the server and listen for SSE connections on http://localhost:8080/sse.
As of April 2025, LiteMCP has been deprecated since the official MCP TypeScript SDK now offers similar high-level APIs. If you like the CLI commands from LiteMCP, you can use them independently from the mcp-cli package.