@dedalus/许可证检查
MCP服务器,用于检测软件许可证并检查与组织策略的兼容性。为合规性文档生成通知文件摘要。
特性
- 许可证检测:从依赖元数据或LICENSE文件内容中识别许可证
- 兼容性检查:根据可配置策略(允许/拒绝列表、copyleft限制)验证许可证
- 通知生成:生成合规文档的标准化通知文件
- SPDX合规性:全程使用SPDX许可证标识符
- 双重运输:支持stdio(MCP协议)和HTTP(REST API)传输
安装
npm install @dedalus/license-check快速开始
作为MCP服务器(stdio)
# Start with default stdio transport
npx license-check
# Or explicitly
npx license-check --transport stdio作为HTTP服务器
# Start HTTP server on port 3000
npx license-check --transport http
# Custom port
npx license-check --transport http --port 8080工具
检测许可证
从依赖关系列表或文件内容中检测许可证。
输入选项:
{
"dependencies": [
{ "name": "lodash", "version": "4.17.21", "license_id": "MIT" },
{ "name": "custom-pkg", "license_text": "MIT License\n\nPermission is hereby granted..." }
]
}或从文件:
{
"files": [
{ "filename": "LICENSE", "content": "Apache License, Version 2.0..." }
]
}输出:
{
"ok": true,
"data": {
"detected": [
{
"name": "lodash",
"version": "4.17.21",
"license_id": "MIT",
"confidence": "high",
"source": "dependency_metadata"
}
]
},
"meta": {
"source": "license-check",
"retrieved_at": "2024-01-15T10:30:00.000Z",
"pagination": { "next_cursor": null }
}
}检查兼容性
检查检测到的许可证是否与目标策略兼容。
输入:
{
"licenses": [
{ "name": "lodash", "license_id": "MIT" },
{ "name": "gpl-lib", "license_id": "GPL-3.0-only" }
],
"policy": {
"allowed": ["MIT", "Apache-2.0", "ISC", "BSD-3-Clause"],
"denied": ["AGPL-3.0-only"],
"copyleft_ok": false
}
}输出:
{
"ok": true,
"data": {
"compatible": false,
"violations": [
{
"name": "gpl-lib",
"license_id": "GPL-3.0-only",
"reason": "License \"GPL-3.0-only\" is a copyleft license and copyleft_ok is false"
}
],
"warnings": []
},
"meta": {
"source": "license-check",
"retrieved_at": "2024-01-15T10:30:00.000Z"
}
}生成通知
生成一个通知文件内容,总结所有许可证和归属。
输入:
{
"licenses": [
{
"name": "lodash",
"version": "4.17.21",
"license_id": "MIT",
"copyright": "Copyright JS Foundation",
"url": "https://github.com/lodash/lodash"
}
],
"project_name": "MyProject"
}输出:
{
"ok": true,
"data": {
"notice_text": "==============================================================================\nNOTICE file for MyProject\n..."
},
"meta": {
"source": "license-check",
"retrieved_at": "2024-01-15T10:30:00.000Z"
}
}HTTP API终结点
使用HTTP传输运行时:
| 端点 | 方法 | 描述 |
|---|---|---|
/health | GET | 健康检查 |
/tools | GET | 列出可用工具 |
/tools/:toolName | POST | 执行工具 |
例子:
# List tools
curl http://localhost:3000/tools
# Detect licenses
curl -X POST http://localhost:3000/tools/detect_licenses \
-H "Content-Type: application/json" \
-d '{"dependencies": [{"name": "lodash", "license_id": "MIT"}]}'配置
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
LICENSE_CHECK_TRANSPORT | stdio | 运输类型: stdio 或 http |
LICENSE_CHECK_PORT | 3000 | HTTP服务器端口 |
LICENSE_CHECK_HOST | 127.0.0.1 | HTTP服务器主机 |
LICENSE_CHECK_LOG_LEVEL | info | 日志级别: debug, info, warn, error |
CLI选项
-t, --transport Transport type: stdio (default) or http
-p, --port
HTTP port (default: 3000)
-h, --host HTTP host (default: 127.0.0.1)
--help Show help message
-v, --version Show version number支持的许可证
服务器识别以下SPDX许可证标识符:
- 宽松的:麻省理工学院、Apache-2.0、BSD-2条款、BSD-3条款、ISC、0BSD、无许可、CC0-1.0、Zlib、BSL-1.0
- 著佐权:仅GPL-2.0、仅GPL-3.0、仅LGPL-2.1、仅LGPL-3.0、仅AGPL-3.0、MPL-2.0、EPL-2.0
- 知识共享:CC-BY-4.0,CC-BY-SA-4.0
- 其他:Artistic-2.0,WTFPL,CDDL-1.0
启发式和局限性
许可证检测
- 使用正则表达式模式匹配进行许可证文本分析
- 可能无法检测到非标准或严重修改的许可证文本
- 置信度表示检测可靠性:
- high:完整许可证标题/文本匹配 - medium:检测到部分匹配或常见短语 - low:只找到许可证名称关键字或未知许可证
- 不验证许可证文本的完整性
- SPDX复合表达式(例如“MIT OR Apache-2.0”)未完全解析
兼容性检查
- 不执行许可证之间的完整许可证兼容性分析
- 不解析SPDX表达式运算符(OR、AND、WITH)
- 假设使用简单的许可证标识符,而不是复合表达式
- 使用允许列表时,“未知”许可证被标记为违规
响应信封
所有工具均以标准Dedalus信封格式返回响应:
成功:
{
"ok": true,
"data": {},
"meta": {
"source": "license-check",
"retrieved_at": "ISO-8601 timestamp",
"pagination": { "next_cursor": null },
"warnings": []
}
}错误:
{
"ok": false,
"error": {
"code": "INVALID_INPUT | INTERNAL_ERROR | ...",
"message": "human readable message",
"details": {}
},
"meta": {
"retrieved_at": "ISO-8601 timestamp"
}
}发展
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Development mode (watch)
npm run dev许可证
麻省理工学院
