](https://mseep.ai/app/glassbead-tc-python-to-typescript-assistant)
🐍➡️📘 Python到TypeScript移植MCP服务器
](https://smithery.ai/server/@glassBead-tc/python-to-typescript-assistant)
一个全面的模型上下文协议(MCP)服务器,为将Python代码移植到TypeScript提供系统工具和参考。此服务器组合 模型增强能力 拥有实用的移植资源,以解决Python到TypeScript迁移项目中发现的挑战。
🎯 目的
研究表明,目前的人工智能翻译方法只能实现 成功率47% 对于真实世界的Python到TypeScript转换,此MCP服务器提供:
- 系统思维框架 用于分解复杂的移植任务
- 类型分析工具 用于理解Python类型和建议TypeScript等价物
- 图书馆地图数据库 提供迁移指导和替代方案
- 模式识别 将Python习惯用法转换为TypeScript的最佳实践
- 验证策略 确保移植的正确性
- 质量参考 Python开发人员的TypeScript最佳实践
⚡ 快速开始
立即开始使用npx-无需安装:
# Run the server with npx
npx python-to-typescript-porting-mcp-server然后配置您的MCP客户端(如Claude Desktop)以使用服务器:
{
"mcpServers": {
"python-to-typescript-porting": {
"command": "npx",
"args": ["python-to-typescript-porting-mcp-server"],
"env": {}
}
}
}🚀 特性
🛠️ 工具
porting-strategy-分析和规划移植项目的系统框架
- 具有复杂性评估的战略分析 - 风险评估和分阶段迁移规划 - 依赖图分析和关键路径识别 - 工作量估算和时间表建议
type-analysis-Python类型分析与TypeScript映射建议
- 全面的类型系统映射(基元、集合、泛型、联合) - 迁移复杂性评估 - 运行时注意事项和测试方法 - 特定于库的类型映射(日期时间、路径库、数据类等)
library-mapping-查找Python库的Types/JavaScript等效项
- 具有置信度评级的广泛图书馆数据库 - 安装命令和API差异说明 - 迁移复杂性评估 - 当不存在直接等价物时的替代方法
pattern-mapping-将Python语言模式转换为TypeScript等效模式
- 列表/字典理解→ 数组方法 - 上下文管理器→ try/finally模式 - 多重赋值→ 破坏 - 带有警告和最佳实践的代码示例
validation-strategy-转换的测试和验证方法
- 类型安全验证策略 - 行为等效性测试 - 性能验证技术
📚 资源
typescript://best-practices-Python开发人员的TypeScript最佳实践typescript://type-system-全面的TypeScript类型系统指南guides://methodology-逐步移植方法db://libraries-快速参考库映射数据库
💬 提示
analyze-python-file-生成用于分析Python代码复杂性的提示review-typescript-conversion-生成查看转换代码的提示
📦 安装
通过Smithery安装
通过以下方式自动将python安装到Claude Desktop的打字助手中 史密瑟里:
npx -y @smithery/cli install @glassBead-tc/python-to-typescript-assistant --client claude先决条件
- Node.js 18+和npm
- MCP兼容客户端(如Claude Desktop)
NPX快速入门(推荐)
使用服务器最简单的方法是通过npx-不需要安装:
# Run directly with npx
npx python-to-typescript-porting-mcp-server
# Or use the shorter command alias
npx py-to-ts-server从NPM安装
# Install globally
npm install -g python-to-typescript-porting-mcp-server
# Run the server
py-to-ts-server从源代码构建
对于开发或定制:
# Clone the repository
git clone https://github.com/glassBead-tc/python-to-typescript-assistant.git
cd python-to-typescript-assistant
# Install dependencies
npm install
# Build the project
npm run build
# Test the server
npm start🔧 配置
克劳德桌面
选项1:使用NPX(推荐)
将此配置添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"python-to-typescript-porting": {
"command": "npx",
"args": ["python-to-typescript-porting-mcp-server"],
"env": {}
}
}
}选项2:使用全局安装
如果你使用npm全局安装:
{
"mcpServers": {
"python-to-typescript-porting": {
"command": "py-to-ts-server",
"env": {}
}
}
}选项3:使用本地构建
如果你从源代码构建:
{
"mcpServers": {
"python-to-typescript-porting": {
"command": "node",
"args": ["/path/to/python-to-typescript-assistant/dist/index.js"],
"env": {}
}
}
}其他MCP客户端
服务器使用stdio传输,可以与任何支持子流程通信的MCP兼容客户端集成。根据您的安装方法,使用上述选项中的相应命令。
🐳 Docker支持
该项目包括对开发和生产环境的全面Docker支持。
Docker快速入门
# Build and run with Docker Compose
npm run compose:up
# View logs
npm run compose:logs
# Stop the server
npm run compose:downDocker开发
# Start development environment with hot reloading
npm run compose:dev
# View development logs
docker-compose logs -f mcp-server-dev可用的Docker脚本
| 脚本 | 描述 |
|---|---|
npm run docker:build | 构建生产Docker镜像 |
npm run docker:build-dev | 构建开发Docker镜像 |
npm run compose:up | 开始生产服务 |
npm run compose:dev | 启动开发服务 |
npm run compose:down | 停止所有服务 |
npm run compose:logs | 查看服务日志 |
Docker功能
- 多阶段构建 用于优化生产图像
- 开发环境 热重新加载
- 健康检查 资源限制
- 非root用户 出于安全考虑
- Alpine Linux 占地面积最小的基础
有关Docker的详细文档,请参阅 医生.md.
🎯 使用示例
分析Python项目
// Use the porting-strategy tool
{
"projectId": "my-flask-app",
"projectName": "Flask API Server",
"stage": "analysis",
"components": [
{
"name": "app.py",
"type": "module",
"complexity": "medium",
"dependencies": ["flask", "sqlalchemy"],
"challenges": ["Dynamic routing", "ORM relationships"],
"portingApproach": "Convert to Express.js + TypeORM",
"estimatedEffort": 16
}
]
}分析Python类型
// Use the type-analysis tool
{
"pythonType": "Dict[str, Optional[List[User]]]",
"context": "API response format"
}寻找图书馆等价物
// Use the library-mapping tool
{
"pythonLibrary": "requests"
}转换Python模式
// Use the pattern-mapping tool
{
"pattern": "list comprehension"
}🧠 模型增强方法
该服务器实现了“模型增强”模式,其灵感来自 顺序思维 方法,提供:
- 系统问题分解 用于复杂的移植任务
- 上下文维护 跨越长时间迁移操作
- 决策框架 评估迁移策略的工具
- 逐步求精 移植方法
- 风险评估 以及缓解规划
📊 研究基金会
该服务器解决了Python到TypeScript迁移研究中发现的具体挑战:
- 类型系统不匹配 -Python的动态类型与TypeScript的静态类型
- 图书馆生态系统差距 -缺少Python库的TypeScript等效项
- 模式翻译 -将Python习惯用法转换为TypeScript最佳实践
- 验证复杂性 -确保迁移后的行为等效性
- 战略规划 -大规模移民的系统方法
🏗️ 建筑
src/
├── index.ts # Main server entry point
├── tools/ # MCP tools for analysis and mapping
│ ├── porting-strategy.ts # Strategic planning framework
│ ├── type-analysis.ts # Type system analysis
│ ├── library-mapping.ts # Library equivalents database
│ ├── pattern-mapping.ts # Pattern conversion guide
│ └── validation.ts # Testing strategies
├── resources/ # Reference materials and guides
│ ├── typescript-references.ts
│ ├── porting-guides.ts
│ └── library-database.ts
└── prompts/ # Template prompts for common tasks
└── porting-prompts.ts🔬 测试
使用NPX进行快速测试
# Test the server directly
npx python-to-typescript-porting-mcp-server
# Test with MCP Inspector
npx @modelcontextprotocol/inspector开发测试
对于开发和定制:
# Run the development server with watch mode
npm run dev
# Test with MCP Inspector
npx @modelcontextprotocol/inspector手动测试
- 战略分析:使用示例Python项目结构进行测试
- 类型映射:尝试复杂的Python类型注释
- 图书馆查询:测试常用Python库
- 模式转换:测试Python习惯用法和模式
🤝 贡献
欢迎投稿!需要改进的关键领域:
- 扩展库映射 -添加更多Python到TypeScript库等效项
- 模式数据库 -扩展Python模式识别和转换
- 验证工具 -改进测试和验证策略
- 类型推断 -增强Python类型分析功能
- 性能优化 -缩短服务器响应时间
📝 许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
🙏 致谢
📖 相关资源
______________________________________________________________________
内置于❤️ Python和TypeScript社区 #python到打字助手
