Back to MCP directory
publicPublicdnsLocal runtime

mcp-nodejs-debugger

一个Node.js调试工具,通过MCP服务器为Cursor和Claude Code提供运行时调试能力

article

README

🚀 MCP Node 节点

MCP(MongoDB Connection Pool)节点用于管理 MongoDB 连接池。本指南将详细介绍如何配置和使用 MCP 节点。

🚀 快速开始

1. 安装依赖

在开始使用 MCP 节点之前,请确保您已经安装了以下依赖项:

  • Node.js 和 npm
  • MongoDB 驻留(Mongoose)

使用以下命令安装所需依赖:

npm install mongoose mcp-node

2. 创建 MCP 节点实例

以下是使用 mcp-node 创建一个简单的 MCP 实例的示例代码:

const mcp = require('mcp-node');
const config = {
    url: 'mongodb://localhost:27017/test',
    options: {
        useNewUrlParser: true,
        useUnifiedTopology: true
    }
};

// 创建 MCP 实例
const db = new mcp(config);

// 连接数据库
db.connect().then(() => {
    console.log('连接到 MongoDB 成功');
}).catch(err => {
    console.error('连接到 MongoDB 失败:', err);
});

// 断开连接
process.on('exit', () => {
    db.disconnect();
});

✨ 主要特性

  • 管理 MongoDB 连接池,提高数据库连接效率。
  • 支持自定义配置,如连接池大小、超时时间等。
  • 支持使用自定义 SSL 证书和身份验证。

📦 安装指南

安装 MCP 节点,只需在项目根目录下运行以下命令:

npm install mongoose mcp-node

💻 使用示例

基础用法

以下是使用 MCP 节点进行基本数据库操作(插入数据)的示例代码:

const mcp = require('mcp-node');
const config = {
    url: 'mongodb://localhost:27017/test',
    options: {
        useNewUrlParser: true,
        useUnifiedTopology: true
    }
};

// 创建 MCP 实例
const db = new mcp(config);

// 连接数据库
db.connect().then(() => {
    // 插入数据
    const collection = db.db.collection('users');
    return collection.insertOne({ name: 'John', age: 30 });
}).then(result => {
    console.log('插入成功:', result);
}).catch(err => {
    console.error('操作失败:', err);
});

// 断开连接
process.on('exit', () => {
    db.disconnect();
});

高级用法

使用自定义 SSL 证书

如果您需要使用自定义 SSL 证书进行 MongoDB 连接,可以将证书路径添加到配置中:

const config = {
    url: 'mongodb://localhost:27017/test',
    options: {
        sslCAFile: path.join(__dirname, 'ssl', 'ca.pem'), // 自定义 CA 文件
        sslCertFile: path.join(__dirname, 'ssl', 'client.pem'), // 客户端证书
        sslKeyFile: path.join(__dirname, 'ssl', 'client-key.pem') // 客户端密钥
    }
};

使用身份验证

如果您在 MongoDB 中启用了身份验证,可以在连接字符串中包含凭据:

const config = {
    url: 'mongodb://username:password@localhost:27017/test',
    options: {
        useNewUrlParser: true,
        useUnifiedTopology: true
    }
};

📚 详细文档

配置 MongoDB 连接池

您可以使用以下选项来自定义 MCP 节点的行为: | 属性 | 详情 | |------|------| | url | MongoDB 连接字符串。 | | options | - useNewUrlParser: 使用新的UrlParser。
- useUnifiedTopology: 启用统一拓扑(默认为 true)。 | | poolSize | 连接池大小(默认为 10)。 | | idleTimeoutMS | 空闲超时时间(以毫秒为单位)。 | | connectTimeoutMS | 连接超时时间(以毫秒为单位)。 |

示例配置:

const config = {
    url: 'mongodb://localhost:27017/test',
    options: {
        useNewUrlParser: true,
        useUnifiedTopology: true
    },
    poolSize: 20,
    idleTimeoutMS: 3600000, // 1 小时空闲超时
    connectTimeoutMS: 5000 // 5 秒连接超时
};

错误处理

以下是一个包含错误处理的示例代码:

const mcp = require('mcp-node');
const config = {
    url: 'mongodb://localhost:27017/test',
    options: {
        useNewUrlParser: true,
        useUnifiedTopology: true
    }
};

// 创建 MCP 实例
const db = new mcp(config);

// 连接数据库
db.connect().then(() => {
    // 插入数据
    const collection = db.db.collection('users');
    return collection.insertOne({ name: 'John', age: 30 });
}).then(result => {
    console.log('插入成功:', result);
}).catch(err => {
    console.error('操作失败:', err);
});

// 断开连接
process.on('exit', () => {
    db.disconnect();
});

性能调优

调整连接池大小

通过调整 poolSize 参数可以优化性能:

const config = {
    url: 'mongodb://localhost:27017/test',
    // 其他配置项...
    poolSize: 20 // 调整连接池大小为 20
};
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client