Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wong2/litemcp
A TypeScript library that simplifies MCP server development
https://github.com/wong2/litemcp
Last synced: about 2 months ago
JSON representation
A TypeScript library that simplifies MCP server development
- Host: GitHub
- URL: https://github.com/wong2/litemcp
- Owner: wong2
- License: mit
- Created: 2024-12-09T10:25:06.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-12-09T11:25:29.000Z (2 months ago)
- Last Synced: 2024-12-09T11:32:23.825Z (2 months ago)
- Language: TypeScript
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mcp-servers - LiteMCP - A TypeScript framework for building MCP servers elegantly (Frameworks)
README
# LiteMCP
A TypeScript framework for building MCP (Model Context Protocol) servers elegantly
## Features
- Simple Tool, Resource, Prompt definition
- Full TypeScript support
- Built-in error handling
- Built-in CLI for testing and debugging## Installation
```bash
npm install litemcp zod
```## Quickstart
```js
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.addResource({
uri: "file:///logs/app.log",
name: "Application Logs",
mimeType: "text/plain",
async load() {
return {
text: "Example log content",
};
},
});server.start();
```You can test the server in terminal with:
```bash
npx litemcp dev server.js
```## Core Concepts
### Tools
Tools in MCP allow servers to expose executable functions that can be invoked by clients and used by LLMs to perform actions.
```js
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 any kind of data that an MCP server wants to make available to clients. This can include:
- File contents
- Screenshots and images
- Log files
- And moreEach resource is identified by a unique URI and can contain either text or binary data.
```js
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`:
```js
async load() {
return {
blob: 'base64-encoded-data'
}
}
```### Prompts
Prompts enable servers to define reusable prompt templates and workflows that clients can easily surface to users and LLMs. They provide a powerful way to standardize and share common LLM interactions.
```js
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}`;
},
});
```## Running Your Server
### Test with `mcp-cli`
The fastest way to test and debug your server is with [`mcp-cli`](https://github.com/wong2/mcp-cli):
```bash
npx litemcp dev server.js
npx litemcp dev server.ts // ts files are also supported
```This will run your server with `mcp-cli` for testing and debugging your MCP server in the terminal.
### Inspect with `MCP Inspector`
Another way is to use the official [`MCP Inspector`](https://modelcontextprotocol.io/docs/tools/inspector) to inspect your server with a Web UI:
```bash
npx litemcp inspect server.js
```## Showcase
> If you've developed a server using LiteMCP, please submit a PR to showcase it here!
- https://github.com/wong2/mcp-jina-reader
## Roadmap
- Add support for Resource Templates
## Related
- [mcp-cli](https://github.com/wong2/mcp-cli) - A CLI for testing and debugging MCP servers
- [mcpservers.org](https://mcpservers.org) - A curated list of MCP servers
- [FastMCP](https://github.com/jlowin/fastmcp) - A Python library for MCP server development, inspiration for this project