Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

emcp

MCP.Pizza Chef: joeymeere

eMCP is a TypeScript framework for building simple MCP servers, extending LiteMCP with built-in authentication handling and layered custom middleware support. It offers a near drop-in replacement for LiteMCP, enabling developers to quickly create secure, customizable MCP servers with optional advanced features.

Use This MCP server To

Build MCP servers with integrated authentication handling Create MCP servers supporting custom layered middleware Replace LiteMCP with a more feature-rich MCP server framework Develop secure MCP servers with minimal setup Extend MCP servers with custom request processing logic Run example MCP servers demonstrating auth and middleware usage

README

eMCP


A fork of the LiteMCP TS library with extended features like built-in authentication handling, and custom middleware.

Features

This is designed to be a near drop-in replacement for tools like LiteMCP. Because of this, all added features are currently optional.

  • All current LiteMCP features
  • Built-in authentication handler
  • Custom layered middleware support

Quickstart

Install via Bun or NPM:

npm i emcp
# or use Bun (preferred)
bun add emcp

Basic Usage

(Optional) Run the examples:

bun run example:basic
bun run example:auth
bun run example:middleware
bun run example:advanced
const server = new eMCP("mcp-server-with-auth", "1.0.0", {
  authenticationHandler: async (request) => {
    // implement your custom auth logic here
    return true;
  },
});

// Request to this tool, or any other resource or prompt will
// require authentication governed by the handler
server.addTool({
  name: "add",
  description: "Add two numbers",
  parameters: z.object({
    a: z.number(),
    b: z.number(),
  }),
  execute: async (args) => {
    server.logger.debug("Adding two numbers", args);
    return args.a + args.b;
  },
});

Custom Middleware

const server = new eMCP("mcp-server-with-middleware", "1.0.0", {
  authenticationHandler: async (request) => {
    // implement your custom auth logic here
    return true;
  },
});

// This will time entire req -> res cycle, including middlewares
server.use(async (request, next) => {
  const startTime = Date.now();
  server.logger.debug("Request started", { method: request.method });

  // Wait for all inner middleware and the handler to complete
  const response = await next();

  const endTime = Date.now();
  server.logger.debug("Request completed", {
    method: request.method,
    duration: `${endTime - startTime}ms`,
  });

  return response;
});

How Middleware Works

Middleware in eMCP runs in order of registration. Once every middleware handler has hit it's next() block, then the standard MCP procedure will occur. Once the server is finished processing, then the order will run in reverse for middleware handlers with code after the next() block.

To put it simply, it looks something like this:

<---- Request received ----
1. Middleware 1
2. Middleware 2
<---- Pre-processing done ---->
4. Server handler
<---- Post-processing start ---->
5. Middleware 2
6. Middleware 1
---- Response sent ---->

If you're familiar with frameworks like Hono, then this will be familiar to you.

Roadmap

  • Ergonomic MCP<->MCP communication
  • Integration into frameworks

Why?

Because I felt like it

emcp FAQ

How do I install eMCP?
Install eMCP via npm with 'npm i emcp' or via Bun with 'bun add emcp'.
Does eMCP support authentication?
Yes, eMCP includes a built-in authentication handler for secure MCP server implementations.
Can I add custom middleware to eMCP servers?
Yes, eMCP supports layered custom middleware to extend server functionality.
Is eMCP compatible with LiteMCP?
eMCP is designed as a near drop-in replacement for LiteMCP with additional features.
Are there example projects to get started with eMCP?
Yes, eMCP provides example scripts demonstrating basic usage, authentication, middleware, and advanced features.
What programming language is eMCP written in?
eMCP is a TypeScript library, suitable for Node.js and Bun environments.
Can eMCP be used with multiple LLM providers?
Yes, eMCP servers can integrate with any MCP client or host, supporting providers like OpenAI, Claude, and Gemini.
How customizable is eMCP?
eMCP allows extensive customization through middleware and authentication handlers to fit various MCP server needs.