代码处理工具

一个基于Node.js的代码处理工具集,提供代码分析、格式化和验证功能,支持CLI和HTTP两种调用方式。

  • by dzunhowz
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 dzunhowz/wizelit-mcp-server-test

使用说明

Wizelit MCP服务器测试

一个使用通用MCP桥演示Node.js与Wizelit平台集成的测试项目。该项目展示了两者 子进程(CLI) 和 HTTP服务 整合模式。

🎯 概述

该项目提供了可通过通用MCP桥调用的JavaScript代码处理工具:

  • 代码分析:安全扫描、质量检查、复杂性度量
  • 代码格式化:基于预分级的代码格式
  • 代码验证:语法检查和结构验证
  • 批处理:通过HTTP进行多操作代码处理

📋 先决条件

  • Node.js>=16.0.0
  • Python>=3.9(适用于wizelit sdk)
  • 支持通用桥接的wizelit sdk

🚀 快速开始

1.安装依赖项

npm install

2.启动HTTP服务(可选)

npm start
# Service will run on http://localhost:3000

3.直接测试CLI工具

# Analyze code
node tools/analyze-code.js 'function test() { eval("x"); }'

# Format code
node tools/format-code.js 'function   test(){return 1}'

# Validate code
node tools/validate-code.js 'function test() { return 1; }'

4.通过环球桥跑步

# From wizelit-sdk directory
wizelit-sdk run-bridge --config ../wizelit-mcp-server-test/config/bridge-config.yaml

📁 项目结构

wizelit-mcp-server-test/
├── config/
│   └── bridge-config.yaml      # Universal Bridge configuration
├── tools/                       # CLI tools (subprocess integration)
│   ├── analyze-code.js         # Code analyzer
│   ├── format-code.js          # Code formatter
│   └── validate-code.js        # Code validator
├── services/                    # HTTP services
│   └── code-processor/
│       └── server.js           # Express HTTP service
├── package.json
└── README.md

🛠️ 可用工具

CLI工具(子进程适配器)

1. analyze_code_cli

分析JavaScript代码中的问题和指标。

输入:

{
  "code": "function test() { eval('x'); }"
}

输出:

{
  "metrics": { "lines": 1, "complexity": 1 },
  "issues": [
    { "severity": "high", "message": "Use of eval()", "category": "security" }
  ],
  "summary": { "total_issues": 1, "high": 1, "medium": 0, "low": 0 }
}

2. format_code_cli

使用Prettier格式化JavaScript代码。

输入:

{
  "code": "function   test(){return 1}",
  "options": { "tabWidth": 2, "semi": true }
}

输出:

{
  "original": "function   test(){return 1}",
  "formatted": "function test() {\n  return 1;\n}\n",
  "changed": true,
  "stats": { "before_lines": 1, "after_lines": 3, "changes": 1 }
}

3. validate_code_cli

验证JavaScript代码语法。

输入:

{
  "code": "function test() { return 1; }",
  "strict": false
}

输出:

{
  "valid": true,
  "errors": [],
  "warnings": [],
  "summary": { "total_issues": 0 }
}

HTTP工具(HTTP适配器)

4. process_code

处理具有多个操作的代码。

端点: POST http://localhost:3000/process

输入:

{
  "code": "function test() { return 1; }",
  "operations": ["validate", "analyze"]
}

5. analyze_code_deep

深度代码分析并给出建议。

端点: POST http://localhost:3000/analyze

输入:

{
  "code": "function complex() { ... }",
  "deep": true,
  "include_suggestions": true
}

6. format_code_http

通过HTTP服务格式化代码。

端点: POST http://localhost:3000/format

7. health_check

检查服务运行状况。

端点: GET http://localhost:3000/health

🧪 测试

测试CLI工具

# Test analyzer
npm run test:analyze

# Test formatter
npm run test:format

# Test validator
npm run test:validate

测试HTTP服务

# Start service
npm start

# In another terminal, test endpoints
curl -X POST http://localhost:3000/process \
  -H "Content-Type: application/json" \
  -d '{"code":"function test(){return 1}","operations":["validate","analyze"]}'

curl http://localhost:3000/health

通过通用电桥进行测试

# Start HTTP service first
npm start

# In another terminal, run bridge
cd ../wizelit-sdk
wizelit-sdk run-bridge --config ../wizelit-mcp-server-test/config/bridge-config.yaml

# The bridge will expose all tools via MCP protocol

📝 配置

编辑 config/bridge-config.yaml 致:

  • 添加/删除工具
  • 更改适配器类型(子流程↔ HTTP)
  • 调整超时
  • 配置HTTP端点
  • 设置MCP服务器选项

示例:添加新的CLI工具

tools:
  - name: 'my_new_tool'
    description: 'My new Node.js tool'
    adapter_type: 'subprocess'
    config:
      command: ['node', 'tools/my-tool.js']
      timeout: 30
    input_schema:
      type: 'object'
      properties:
        input:
          type: 'string'
      required: ['input']

示例:添加新的HTTP端点

tools:
  - name: 'my_http_tool'
    description: 'My HTTP-based tool'
    adapter_type: 'http'
    config:
      url: 'http://localhost:3000/my-endpoint'
      method: 'POST'
      timeout: 60
    input_schema:
      type: 'object'
      properties:
        data:
          type: 'string'
      required: ['data']

🔍 集成模式

模式1:简单CLI工具(推荐用于快速工具)

在以下情况下使用:

  • 简单、无状态的操作
  • 不需要共享状态
  • 执行速度快(<30s)

例子: 代码验证、格式化

模式2:HTTP服务(建议用于复杂操作)

在以下情况下使用:

  • 长期运行操作
  • 需要共享状态/缓存
  • 多个相关端点
  • 需要流媒体响应

例子: 深度分析,批量处理

模式3:混合(最适合完整解决方案)

两者都使用:

  • 用于快速操作的CLI工具
  • 用于复杂操作的HTTP服务
  • 桥梁无缝协调

这个项目展示了混合模式!

🐛 故障排除

CLI工具不工作

# Check Node.js version
node --version  # Should be >= 16.0.0

# Test tool directly
node tools/analyze-code.js 'function test() {}'

# Check permissions (macOS/Linux)
chmod +x tools/*.js

HTTP服务未启动

# Check if port 3000 is in use
lsof -i :3000

# Use different port
PORT=3001 npm start

桥找不到工具

# Check config path
wizelit-sdk run-bridge --config $(pwd)/config/bridge-config.yaml

# Verify config syntax
python -c "import yaml; yaml.safe_load(open('config/bridge-config.yaml'))"

📚 文档

🤝 贡献

这是一个演示集成模式的测试项目。请随意:

  1. 在中添加新工具 tools/
  2. 在中添加新端点 services/code-processor/server.js
  3. 更新 config/bridge-config.yaml 注册新工具
  4. 部署前进行彻底测试

📄 许可证

与母公司wizelit sdk项目相同。

🔗 相关项目


内置于❤️ Wizelit平台