Cmmv Mcp
Model Context Protocol (MCP) module for CMMV
cmmvio
README
<p align="center"> <a href="https://cmmv.io/" target="blank"><img src="https://raw.githubusercontent.com/cmmvio/docs.cmmv.io/main/public/assets/logo_CMMV2_icon.png" width="300" alt="CMMV Logo" /></a> </p> <p align="center">Contract-Model-Model-View (CMMV) <br/> Building scalable and modular applications using contracts.</p> <p align="center"> <a href="https://www.npmjs.com/package/@cmmv/mcp"><img src="https://img.shields.io/npm/v/@cmmv/mcp.svg" alt="NPM Version" /></a> <a href="https://github.com/cmmvio/cmmv/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@cmmv/mcp.svg" alt="Package License" /></a> </p>
<p align="center"> <a href="https://cmmv.io">Documentation</a> • <a href="https://github.com/cmmvio/cmmv/issues">Report Issue</a> </p>
Description
The @cmmv/mcp
module implements the Model Context Protocol (MCP) for CMMV applications, allowing standardized interactions between LLMs (Large Language Models) and your application. MCP provides a structured interface for defining tools usable by AI models in a standard format.
Features
- LLM Integration: Facilitates bidirectional communication between your application and language models.
- Flexible Transport: Supports transport via Server-Sent Events (SSE) or Standard I/O.
- API Decorator-Based: Intuitive decorators like
@MCPTool
to register tools. - Validation with Zod: Input schema validation using Zod.
- Connection Management: Robust implementation for handling multiple concurrent connections.
Installation
Install @cmmv/mcp
via pnpm:
$ pnpm add @cmmv/mcp
Configuration
Configure the MCP module in your .cmmv.config.cjs
or using ConfigSchema
:
import { ConfigSchema } from '@cmmv/core';
export const MCPConfig: ConfigSchema = {
mcp: {
name: {
type: 'string',
required: true,
default: 'mcp',
},
version: {
type: 'string',
required: true,
default: '0.0.1',
},
port: {
type: 'number',
required: true,
default: 8765,
},
transport: {
type: 'string',
required: true,
default: 'sse', // 'sse' or 'stdio'
},
jwtSecret: {
type: 'string',
required: true,
default: 'your-secret-key',
},
pingInterval: {
type: 'number',
required: true,
default: 30000,
},
connectionTimeout: {
type: 'number',
required: true,
default: 300000,
},
},
};
Setting Up the Application
In your main file, include the MCPModule
and configure your application:
import { Application, Config } from '@cmmv/core';
import { DefaultAdapter, DefaultHTTPModule } from '@cmmv/http';
import { MCPModule } from '@cmmv/mcp';
import { MCPHandlers } from './mcp-handlers';
Application.create({
httpAdapter: DefaultAdapter,
modules: [MCPModule],
providers: [MCPHandlers],
});
Creating MCP Tool Handlers
Use the @MCPTool
decorator to register tools callable by LLMs:
import { MCPTool, z } from '@cmmv/mcp';
export class MCPHandlers {
@MCPTool('greet', {
name: z.string(),
age: z.number(),
})
public async greet({ name, age }: { name: string; age: number }) {
return {
content: `Hello \${name}, you are \${age} years old`,
};
}
}
Using the MCP Client
The MCP client can connect to your server using the SSE endpoint:
curl -X POST http://localhost:8765/messages \\
-H "Content-Type: application/json" \\
-d '{"type":"tool_call","name":"greet","arguments":{"name":"John","age":30}}'
Decorators
@MCPTool(name: string, schema: Record<string, z.ZodSchema>)
Registers a method as an MCP tool with a name and validation schema.
Best Practices
- Define Schemas Clearly: Use Zod schemas to clearly define parameters for each tool.
- Provide Meaningful Responses: Return structured and helpful responses for LLMs.
- Handle Errors Gracefully: Implement robust error handling in your handlers.
- Security First: Consider using JWT for public endpoints.
- Performance: Use timeouts and keep handlers lightweight and fast.
推荐服务器
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Claude Code MCP
一个实现了 Claude Code 作为模型上下文协议(Model Context Protocol, MCP)服务器的方案,它可以通过标准化的 MCP 接口来使用 Claude 的软件工程能力(代码生成、编辑、审查和文件操作)。
@kazuph/mcp-taskmanager
用于任务管理的模型上下文协议服务器。它允许 Claude Desktop(或任何 MCP 客户端)在基于队列的系统中管理和执行任务。
MCP Package Docs Server
促进大型语言模型高效访问和获取 Go、Python 和 NPM 包的结构化文档,通过多语言支持和性能优化来增强软件开发。
mermaid-mcp-server
一个模型上下文协议 (MCP) 服务器,用于将 Mermaid 图表转换为 PNG 图像。
Jira-Context-MCP
MCP 服务器向 AI 编码助手(如 Cursor)提供 Jira 工单信息。

Linear MCP Server
一个模型上下文协议(Model Context Protocol)服务器,它与 Linear 的问题跟踪系统集成,允许大型语言模型(LLM)通过自然语言交互来创建、更新、搜索和评论 Linear 问题。

Sequential Thinking MCP Server
这个服务器通过将复杂问题分解为顺序步骤来促进结构化的问题解决,支持修订,并通过完整的 MCP 集成来实现多条解决方案路径。
Curri MCP Server
通过管理文本笔记、提供笔记创建工具以及使用结构化提示生成摘要,从而实现与 Curri API 的交互。