Cover image
Try Now
2025-01-23

Un marco de TypeScript para construir servidores MCP elegantemente

3 years

Works with Finder

2

Github Watches

8

Github Forks

162

Github Stars

LiteMCP

A TypeScript framework for building MCP (Model Context Protocol) servers elegantly

Features

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.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:

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.

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 more

Each resource is identified by a unique URI and can contain either text or binary data.

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:

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.

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

You can 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;
  },
});

The logger object has the following methods:

  • debug(message: string, context?: JsonValue)
  • info(message: string, context?: JsonValue)
  • warn(message: string, context?: JsonValue)
  • error(message: string, context?: JsonValue)

Running Your Server

Debugging with mcp-cli

The fastest way to test and debug your server is with mcp-cli:

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 to inspect your server with a Web UI:

npx litemcp inspect server.js

SSE Transport

The servers are running with stdio transport by default. You can also run the server with SSE mode:

server.start({
  transportType: "sse",
  sse: {
    endpoint: "/sse",
    port: 8080,
  },
});

This will start the server and listen for SSE connections on http://localhost:8080/sse.

You can then connect to the server with SSE transport in the client.

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, inspiration for this project

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • https://reddgr.com
  • Delivers concise Python code and interprets non-English comments

  • apappascs
  • Descubra la colección más completa y actualizada de servidores MCP en el mercado. Este repositorio sirve como un centro centralizado, que ofrece un extenso catálogo de servidores MCP de código abierto y propietarios, completos con características, enlaces de documentación y colaboradores.

  • ShrimpingIt
  • Manipulación basada en Micrypthon I2C del expansor GPIO de la serie MCP, derivada de AdaFruit_MCP230xx

  • pontusab
  • La comunidad de cursor y windsurf, encontrar reglas y MCP

  • av
  • Ejecute sin esfuerzo LLM Backends, API, frontends y servicios con un solo comando.

  • 1Panel-dev
  • 🔥 1Panel proporciona una interfaz web intuitiva y un servidor MCP para administrar sitios web, archivos, contenedores, bases de datos y LLM en un servidor de Linux.

  • GeyserMC
  • Una biblioteca para la comunicación con un cliente/servidor de Minecraft.

  • Mintplex-Labs
  • La aplicación AI de escritorio todo en uno y Docker con trapo incorporado, agentes de IA, creador de agentes sin código, compatibilidad de MCP y más.

  • awslabs
  • Servidores AWS MCP: servidores MCP especializados que traen las mejores prácticas de AWS directamente a su flujo de trabajo de desarrollo

  • WangRongsheng
  • 🧑‍🚀 全世界最好的 llM 资料总结(数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Resumen de los mejores recursos del mundo.

  • esxr
  • Plantilla de solución de Langgraph para MCP

    Reviews

    3 (1)
    Avatar
    user_yaVu0bVx
    2025-04-17

    I have been using litemcp by wong2 for a while now, and I must say it’s an excellent tool. It's lightweight and very efficient, making my workflow much smoother. The seamless integration and user-friendly interface are impressive. Highly recommend it! Check it out at https://github.com/wong2/litemcp.