TCPING MCP服务器
一种模型上下文协议(MCP)服务器,使用自然语言命令为网络和防火墙验证提供TCP连接测试功能。
特性
- TCPING:测试与特定主机和端口的TCP连接
- 防火墙规则验证:验证具有预期结果的多个防火墙规则
- 网络扫描:扫描目标主机上的端口范围
- 自然语言接口:通过Claude使用对话命令
安装
- 克隆或创建项目:
# Option 1: Clone from repository (if available)
git clone tcping-mcp-server
cd tcping-mcp-server
- 构建项目:
npm run build配置
Claude桌面配置
将此添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%\Claude\claude_desktop_config.json VSCode\*:
json示例
"tcping": {
"type": "stdio",
"command": "node",
"args": ["~/tcping_mcp/dist/index.js"]
}更新路径以匹配您的安装目录。
使用示例
配置后,您可以在Claude中使用自然语言命令:
基本TCP连接测试
"Test if I can connect to google.com on port 80"
"Check connectivity to 192.168.1.1 port 22 with 5 second timeout"
"Ping TCP port 443 on example.com 10 times"图片: tcping-mcp tcp
防火墙规则验证
"Validate these firewall rules:
- Web traffic to google.com:80 should work
- SSH to internal server 10.0.1.5:22 should be blocked
- HTTPS to api.example.com:443 should work"网络扫描
"Scan ports 20-30 on 192.168.1.1"
"Check which common ports are open on example.com between 80-443"工具功能
tcping
测试与主机和端口的TCP连接。
- 主机:目标主机名或IP地址
- 端口:目标端口号
- 超时:连接超时(毫秒)(默认值:3000)
- 计数:连接尝试次数(默认值:4)
- 间隔:尝试之间的间隔(毫秒)(默认值:1000)
validate_firewall_rule
通过测试多个主机:端口组合来验证防火墙连接。
- 规则:一系列具有预期结果的防火墙规则
- 超时:连接超时(毫秒)(默认值:3000)
网络扫描
扫描目标主机上的一系列端口。
- 主机:目标主机名或IP地址
- startPort:起始端口号
- endPort:结束端口号
- 超时:连接超时(毫秒)(默认值:1000)
自然语言命令示例
工程顾问场景
部署前测试:
"Before deploying the new application, validate that:
1. Load balancer can reach app servers on port 8080
2. App servers can connect to database on port 5432
3. External API calls to api.stripe.com:443 are working"防火墙更改验证:
"After the firewall change, verify:
- Internal subnet 10.0.1.0/24 can still reach file server on port 445
- External access to web server port 80 is blocked as intended
- Management access to switches on port 22 works from admin network"网络故障排除:
"Help me troubleshoot connectivity to our service:
- Test if port 3306 is reachable on db.company.com
- Scan ports 80, 443, 8080, 8443 on app-server.company.com
- Verify that backup server 10.0.2.50 port 22 is accessible"安全验证:
"Validate our security posture by confirming:
- External connections to internal DB port 3306 are blocked
- Public web ports 80 and 443 are accessible
- SSH access (port 22) is only available from management subnet"工程顾问的好处
- 自然语言接口:无需记住复杂的命令语法
- 综合报告:详细的输出,包括时间和成功率
- 批量验证:同时测试多个规则
- 文档准备就绪:输出可以直接包含在报告中
- 交叉平台的:适用于Windows、macOS和Linux
- 无外部依赖关系:使用Node.js内置的网络功能
发展
项目结构
├── dist/ # Compiled JavaScript files
├── src/ # TypeScript source
│ └── index.ts # Main application file
├── package.json # Project configuration
└── tsconfig.json # TypeScript configuration修改服务器
要修改或扩展服务器,请执行以下操作:
# Make changes to src/index.ts
npm run build
# Restart Claude Desktop to pick up changes添加新工具
要向MCP服务器添加新工具,请执行以下操作:
- 在中定义工具模式
ListToolsRequestSchema处理器 - 在中添加新案例
CallToolRequestSchema处理程序开关语句 - 实现新工具的处理函数
- 构建并重新启动服务器
例子:
// In the ListToolsRequestSchema handler
{
name: "my_new_tool",
description: "Description of the new tool",
inputSchema: {
type: "object",
properties: {
// Define properties here
},
required: ["requiredProperty"]
}
}
// In the CallToolRequestSchema handler
case "my_new_tool":
return await this.handleMyNewTool(args);
// Implement the handler
private async handleMyNewTool(args: any) {
// Implementation goes here
}故障排除
常见问题
- 确保Node.js已安装并可在PATH中访问
- 验证Claude Desktop配置中的路径是否正确
- 检查Claude Desktop日志中是否有任何错误消息
- 独立测试服务器:
node dist/index.js
TypeScript错误
如果你遇到TypeScript编译器错误:
- 服务器构造函数错误:The
ServerMCP SDK的构造函数接受一个包含所有配置的单个对象参数。正确的格式是:
this.server = new Server({
name: "tcping-mcp",
version: "1.0.0",
capabilities: {
tools: {},
},
});- 类型转换错误:处理工具参数时,使用正确的类型断言
unknown:
return await this.handleTcping(args as unknown as TcpingOptions);- TypeScript配置:确保你的
tsconfig.json配置正确,特别是ESM支持的模块设置。
许可证
MIT许可证-可根据需要自由修改和分发。
发布到npm
此项目配置了GitHub Actions,以便在您创建新的发布标签时自动构建并发布到npm注册表。
安装说明
- 生成npm访问令牌:
- 登录您的npm帐户 - 转到您的个人资料→ 访问令牌 - 创建“自动化”类型的新令牌(推荐) - 复制生成的令牌
- 将令牌添加到您的GitHub存储库:
- 转到您的GitHub存储库 - 点击“设置”→ “秘密和变量”→ “行动” - 点击“新建存储库密钥” - 姓名: NPM_TOKEN - 值:粘贴你的npm令牌 - 点击“添加秘密”
- 发布新版本:
- 更新中的版本 package.json - 承诺并推动你的改变 - 创建并推送新标签:
git tag v1.0.1
git push origin v1.0.1- GitHub操作将自动触发并发布您的包
或者,您可以从GitHub存储库中的“操作”选项卡手动触发工作流。
测试
该项目包括一个使用Jest的全面测试套件。测试涵盖了实用函数和验证器,以确保应用程序正确运行。
运行测试
# Run all tests
npm test
# Run tests in watch mode (useful during development)
npm run test:watch
# Run tests with coverage report
npm run test:coverage
# Run tests and build (used in CI pipeline)
npm run ci测试结构
- 单元测试:单独测试单个功能
- 集成测试:验证不同组件是否协同工作
- 验证测试:确保输入验证工作正常
测试覆盖率
该项目保持高测试覆盖率,以确保可靠性:
- 声明:>90%
- 分支机构:>90%
- 功能:100%
- 线路:>90%
持续集成
在发布到npm之前,测试会自动在GitHub Actions CI/CD管道中运行。如果测试失败,则不会发布该包。
