电磁兼容性计划
叉子 LiteMCP TS库具有内置身份验证处理和自定义中间件等扩展功能。
特性
这被设计为LiteMCP等工具的近乎直接的替代品。因此,所有添加的功能目前都是可选的。
- 当前LiteMCP的所有功能
- 内置身份验证处理程序
- 自定义分层中间件支持
快速启动
通过Bun或NPM安装:
npm i emcp
# or use Bun (preferred)
bun add emcp基本用法
(可选)运行示例:
bun run example:basic
bun run example:auth
bun run example:middleware
bun run example:advancedconst 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;
},
});自定义中间件
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;
});中间件的工作原理
eMCP中的中间件按注册顺序运行。一旦每个中间件处理程序都命中了它 next() 则将进行标准MCP程序。一旦服务器完成处理,那么中间件处理程序的顺序将反向运行,并在 next() 块。
简单地说,它看起来像这样:
4. Server handler
5. Middleware 2
6. Middleware 1
---- Response sent ---->如果你熟悉像Hono这样的框架,那么这对你来说就很熟悉了。
路线图
- 符合人体工程学的MCP\MCP通信
- 融入框架
为什么?
因为我喜欢

