litemcp
by: wong2
A TypeScript framework for building MCP servers elegantly
📌Overview
Purpose: LiteMCP is designed to simplify the process of building Model Context Protocol (MCP) servers using TypeScript.
Overview: LiteMCP provides an elegant framework for developers to create and manage MCP servers efficiently. It supports a variety of features including tools, resources, and logging, ensuring robust server functionalities tailored for integration with Large Language Models (LLMs).
Key Features:
-
Simple Tool, Resource, Prompt Definition: Easily define interactive tools and resources that clients can invoke, allowing for straightforward integration of complex functionalities.
-
Full TypeScript Support: Built with TypeScript, ensuring type safety and enhancing the development experience with better IDE support and error checking.
-
Built-in Logging: Incorporates a robust logging mechanism to track server activities, helping in debugging and monitoring the server's behavior.
-
Error Handling: Features built-in error handling, ensuring that server failures are managed gracefully without disrupting user experience.
-
Built-in CLI for Testing and Debugging: Provides a command-line interface (CLI) for rapid testing of the server, facilitating the development workflow.
-
SSE Transport Support: Allows servers to communicate over Server-Sent Events (SSE), enabling real-time updates to clients in an efficient manner.
LiteMCP
A TypeScript framework for building MCP (Model Context Protocol) servers elegantly.
Features
- Simple Tool, Resource, Prompt definition
- Full TypeScript support
- Built-in logging
- Built-in error handling
- Built-in CLI for testing and debugging
- Built-in support for SSE transport
Installation
npm install litemcp zod
Quickstart
import { LiteMCP } from "litemcp";
import { z } from "zod";
const server = new LiteMCP("demo", "1.0.0");
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;
},
});
server.start();
You can test the server in terminal with:
npx litemcp dev server.js
Core Concepts
Tools
Tools in MCP allow servers to expose executable functions invokable by clients.
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
Resources represent data that an MCP server makes available to clients, using unique URIs.
server.addResource({
uri: "file:///logs/app.log",
name: "Application Logs",
mimeType: "text/plain",
async load() {
return {
text: await readLogFile(),
};
},
});
You can also return binary contents in load
.
Prompts
Prompts define reusable templates and workflows for client interactions.
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}`;
},
});
Logging
Send log messages to the client with server.logger
.
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 });
// ...
server.logger.info("Downloaded file", { url: args.url });
return response;
},
});
Running Your Server
Debugging with mcp-cli
The fastest way to test your server is with mcp-cli
:
npx litemcp dev server.js
SSE Transport
You can run the server with SSE mode:
server.start({
transportType: "sse",
sse: {
endpoint: "/sse",
port: 8080,
},
});
Showcase
If you've developed a server using LiteMCP, please submit a PR to showcase it here!
Roadmap
- Add support for Resource Templates
Related
- mcp-cli - A CLI for testing and debugging MCP servers
- mcpservers.org - A curated list of MCP servers
- FastMCP - A Python library for MCP server development