Lite_MCP_sdk

MCP.Pizza Chef: S2thend

Lite_MCP_sdk is a lightweight JavaScript client SDK for the Model Context Protocol, designed specifically for Server-Sent Events (SSE) communication. It simplifies building remote MCP clients and servers with minimal setup, making AI agent technology accessible even to beginners with basic JavaScript knowledge. This SDK avoids complexity by focusing solely on SSE, omitting stdio, and enabling quick integration for real-time AI workflows.

Use This MCP client To

Build lightweight MCP clients using JavaScript with SSE communication Create remote AI agents with minimal JavaScript coding Integrate MCP protocol in web apps without complex dependencies Develop real-time AI workflows using SSE-based context streaming Prototype AI-enhanced tools quickly with simple JavaScript SDK Enable easy MCP client setup for developers new to AI agents

README

Introduction

This repo now includes 2 parts:

  1. Lite mcp sdk for javascript
  2. Lite mcp for javascript

Project Goal

The goal of this project is to make best of the AI Agent tech available to any GrandmaπŸ‘΅ who learned 5 minutes of javascript.

Why javascript?

Because I want the project to condense on the running logics, rather than distracted by the types.

Lite mcp for javascript Introduction

npm badge compatibility badge License badge Contributor Covenant

Lite mcp for javascript is the BEST yet way to start a REMOTE SSE javascript MCP server and Client.

πŸš€ Quick start

REAL COPY AND PASTE experince for you to get started with MCP.

Installation

npm install litemcpjs
npm install express
npm install cors

Build a SSE MCP client under 5 lines

import { MCPClient } from "litemcpjs";

async function main() {
  const client = new MCPClient("http://localhost:3000") // change this to your server url
  await client.connect()
  await client.listTools()
  const result = await client.callTool("calculate-bmi", {weightKg: 70, heightM: 1.75})
  console.log(result)
}

main();

Start a REMOTE MCP SSE server with expressJS

const { MCPServerInit } = require("litemcpjs");

// define the tools
const TOOLS = [
    {
        name: "calculate-bmi",
        description: "Calculate the BMI of a person",
        inputSchema: {
            type: "object",
            properties: {
                weightKg: { type: "number" },
                heightM: { type: "number" },
            },
            required: ["weightKg", "heightM"],
        },
        method: async ({ weightKg, heightM }) => {
            return {
                content: [{
                    type: "text",                
                    text: String(weightKg / (heightM * heightM))
                }]
            }
        }
    }
];

// define extra handlers for resources etc.
const handlers = {};

// compatible for server have .use(middleware) method such as express
const middlewares = [
    cors(),
];

const MCPapp = express();  

const MCPServer = MCPServerInit(
    MCPapp,
    middlewares,
    handlers,
    TOOLS,
).listen(5556);

Lite mcp sdk for javascript Introduction

npm badge compatibility badge License badge Contributor Covenant

For Anyone wants a little more low level control over the MCP protocol:

Lite mcp sdk for javascript is a lightweight mcp sdk remix with minimal dependencies.

Quick start

npm install lite-mcp-sdk

Server

const { Server, SSEServerTransport } = require("lite-mcp-sdk");

//or module import
import { Server, SSEServerTransport } from "lite-mcp-sdk";

//create a server
const server = new Server({
    port: 3000,
    transport: new SSEServerTransport(),
});


// 1. Define the server info
const server = new Server({
    name: "example-servers/puppeteer",
    version: "0.1.0",
}, {
    capabilities: {
        resources: {},
        tools: {},
    },
});

// 2. Define the request handlers
server.setRequestHandler("tools/call", async (request) => {
    const { name, arguments: args } = request.params;
    return handleToolCall(name, args);
});

//3. Define the transport
const transports = new Map();
const transport = new SSEServerTransport("/messages", res);
transports.set(clientId, transport);

//4. Connect the server to the transport
await server.connect(transport);

//5. Handle the post message
await transport.handlePostMessage(req, res);

Client

import { Client, SSEClientTransport } from "lite-mcp-sdk";

// 1. Define the client
let client = new Client( {
      name: "fastmcp-client",
      version: "0.1.0"
    }, {
      capabilities: {
        sampling: {},
        roots: {
          listChanged: true,
        },
      },
    } );

// 2. Init the client transport
const serverUrl = "http://localhost:3000"; // for example

const backendUrl = new URL(`${serverUrl}/sse`);
  
backendUrl.searchParams.append("transportType", "sse");

backendUrl.searchParams.append("url", `${serverUrl}/sse`);

const headers = {};

const clientTransport = new SSEClientTransport(backendUrl, {
    eventSourceInit: {
        fetch: (url, init) => fetch(url, { ...init, headers }),
    },
    requestInit: {
        headers,
    },
});

// 3. Connect the client to the transport
await client.connect(clientTransport);
const abortController = new AbortController();
let progressTokenRef = 0;

// 4. start the tool call
const name = "toolcall name";
const params = {}; // tool call params

const response = await client.request(
    {
          method: "tools/call",
          params: {
            name,
            arguments: params,
            _meta: {
              progressToken: progressTokenRef++,
            },
          },
    },
    {signal: abortController.signal,}
);

Project structure:

The project is clearly and cleanlyorganized into the following directories:

src
β”œβ”€β”€ index.js
└── lib
    β”œβ”€β”€ client
    β”‚   β”œβ”€β”€ client.js
    β”‚   └── clientTransport.js
    β”œβ”€β”€ server
    β”‚   β”œβ”€β”€ server.js
    β”‚   └── serverTransport.js
    └── shared
        β”œβ”€β”€ helpers
        β”‚   β”œβ”€β”€ constants.js
        β”‚   └── util.js
        β”œβ”€β”€ protocol.js
        └── validators
            β”œβ”€β”€ capabilityValidators.js
            └── schemaValidators.js (IN CONSTRUCTION)

Why choose lite-mcp-sdk?

1. No fixed zod types

NO More zod types!!! zod types contributes to unneccessary complexity for easy setups.

Furthermore, the way zod type is used in the original sdk is rigid and not flexible, and it is an well received issue.

2. Fully SSE solution

Focus on SSE, and removed stdio support for simplicity considerations, since it is not a as univerial solution as SSE.

Suprisingly, the SSE solution is scarce on the internet, so I decided to write my own.

BELOW images shows that stdio support is always descripted, but no SSE support is mentioned. Even when you search deliberately for SSE, result is scarce, SEE for first page google results.

Replace codes like requestSchema.parse to fully customizable validators and hand it over to the user to define the validation logic here. e.g.

const validatedMessage = validator(message);

How timeout is used in original sdk is vague and has some redundant implementations,which are removed in lite mcp for not causing further confusion.(Ok I think they also removed these in latest version)

3. More detailed documentation on how to quickly get started

They actually listed this problem in the official roadmap. lol

Lite MCP SDK provides better documentation on how to use and modify the sdk, with more ready to copy code examples.

4. Cleaner architecthure with only core functionalities

Lite MCP SDK:

src
β”œβ”€β”€ index.js
└── lib
    β”œβ”€β”€ client
    β”‚   β”œβ”€β”€ client.js
    β”‚   └── clientTransport.js
    β”œβ”€β”€ server
    β”‚   β”œβ”€β”€ server.js
    β”‚   └── serverTransport.js
    └── shared
        β”œβ”€β”€ helpers
        β”‚   β”œβ”€β”€ constants.js
        β”‚   └── util.js
        β”œβ”€β”€ protocol.js
        └── validators
            β”œβ”€β”€ capabilityValidators.js
            └── schemaValidators.js (IN CONSTRUCTION)

Official sdk: Although it is listed on the roadmap, I think putting auth in this project is poor product design. Honestly I think left users to handle auth problem provides more flexibility and better dev experience.

src/
β”œβ”€β”€ client
β”‚   β”œβ”€β”€ auth.test.ts
β”‚   β”œβ”€β”€ auth.ts
β”‚   β”œβ”€β”€ cross-spawn.test.ts
β”‚   β”œβ”€β”€ index.test.ts
β”‚   β”œβ”€β”€ index.ts
β”‚   β”œβ”€β”€ sse.test.ts
β”‚   β”œβ”€β”€ sse.ts
β”‚   β”œβ”€β”€ stdio.test.ts
β”‚   β”œβ”€β”€ stdio.ts
β”‚   └── websocket.ts
β”œβ”€β”€ cli.ts
β”œβ”€β”€ inMemory.test.ts
β”œβ”€β”€ inMemory.ts
β”œβ”€β”€ integration-tests
β”‚   └── process-cleanup.test.ts
β”œβ”€β”€ server
β”‚   β”œβ”€β”€ auth
β”‚   β”‚   β”œβ”€β”€ clients.ts
β”‚   β”‚   β”œβ”€β”€ errors.ts
β”‚   β”‚   β”œβ”€β”€ handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ authorize.test.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ authorize.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ metadata.test.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ metadata.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ register.test.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ register.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ revoke.test.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ revoke.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ token.test.ts
β”‚   β”‚   β”‚   └── token.ts
β”‚   β”‚   β”œβ”€β”€ middleware
β”‚   β”‚   β”‚   β”œβ”€β”€ allowedMethods.test.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ allowedMethods.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ bearerAuth.test.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ bearerAuth.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ clientAuth.test.ts
β”‚   β”‚   β”‚   └── clientAuth.ts
β”‚   β”‚   β”œβ”€β”€ provider.ts
β”‚   β”‚   β”œβ”€β”€ router.test.ts
β”‚   β”‚   β”œβ”€β”€ router.ts
β”‚   β”‚   └── types.ts
β”‚   β”œβ”€β”€ completable.test.ts
β”‚   β”œβ”€β”€ completable.ts
β”‚   β”œβ”€β”€ index.test.ts
β”‚   β”œβ”€β”€ index.ts
β”‚   β”œβ”€β”€ mcp.test.ts
β”‚   β”œβ”€β”€ mcp.ts
β”‚   β”œβ”€β”€ sse.ts
β”‚   β”œβ”€β”€ stdio.test.ts
β”‚   └── stdio.ts
β”œβ”€β”€ shared
β”‚   β”œβ”€β”€ auth.ts
β”‚   β”œβ”€β”€ protocol.test.ts
β”‚   β”œβ”€β”€ protocol.ts
β”‚   β”œβ”€β”€ stdio.test.ts
β”‚   β”œβ”€β”€ stdio.ts
β”‚   β”œβ”€β”€ transport.ts
β”‚   β”œβ”€β”€ uriTemplate.test.ts
β”‚   └── uriTemplate.ts
└── types.ts

Key Difference Table

Feature mcp-official-sdk lite-mcp-sdk
Validation zod Validators
Transport stdio or SSE SSE only
Language typescript javascript
Auth included optional
Documentation vague clear
Architecture complex lightweight

πŸ—ΊοΈ Roadmap

  • Custom Validators (under construction)
  • Add dashboard for monitoring and managing the MCP server and client
  • Add ts types
  • Add python sdk

🀝 Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Please read the contributing document.

πŸ“ Licensing

This project is licensed under the MIT License. See the LICENSE file for details.

Inspired by Original anthropic sdk,which license is also included here.

Contact

If you have any questions or suggestions, please leave a comment here. Or contact me via email: borui_cai@qq.com

Projects using lite-mcp-sdk (to add)

Lite_MCP_sdk FAQ

How does Lite_MCP_sdk handle communication?
It uses Server-Sent Events (SSE) exclusively for real-time data streaming between client and server.
Is Lite_MCP_sdk suitable for beginners?
Yes, it is designed to be simple enough for users with basic JavaScript knowledge to start building MCP clients.
Does Lite_MCP_sdk support stdio communication?
No, this SDK focuses solely on SSE and does not support stdio.
Can I use Lite_MCP_sdk in browser environments?
Yes, since it is JavaScript-based and uses SSE, it can run in modern browsers and Node.js environments.
What versions of JavaScript does Lite_MCP_sdk support?
It supports ES6 and later versions, ensuring compatibility with modern JavaScript runtimes.
Is Lite_MCP_sdk compatible with multiple LLM providers?
Yes, it is provider-agnostic and can work with OpenAI, Anthropic Claude, Google Gemini, and others via MCP protocol.
How do I get started quickly with Lite_MCP_sdk?
The SDK offers copy-and-paste ready examples for rapid setup and integration.
What is the licensing for Lite_MCP_sdk?
It is released under the MIT license, allowing free use and modification.