multiplatform-code-generator
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@multiplatform-code-generator Generate Android, iOS, and HarmonyOS wrappers for: int add(int a, int b);"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
跨平台代码生成器 MCP 工具
一个强大的 MCP (Model Context Protocol) 工具,能够从 C++ 接口函数自动生成 Android、iOS 和鸿蒙等不同平台的调用代码。
功能特性
🔄 跨平台支持: 支持 Android (JNI)、iOS (Objective-C) 和鸿蒙 (NAPI)
🧠 智能解析: 自动解析 C++ 函数签名和参数类型
📦 完整生成: 生成包装类、构建文件和配置文件
🛠️ MCP 兼容: 与大模型无缝集成,支持 Claude、GPT 等
⚡ 即用型代码: 生成的代码可直接编译运行
Related MCP server: C++ Style Guide MCP Server
支持平台
平台 | 输出格式 | 描述 |
Android | JNI + Java/Kotlin | 生成 JNI C++ 代码和 Java/Kotlin 包装类 |
iOS | Objective-C | 生成 Objective-C 桥接代码和 Swift 包装 |
鸿蒙 | NAPI + ArkTS | 生成 NAPI C++ 代码和 TypeScript/ArkTS 包装 |
安装
前置要求
Node.js 18+
npm 或 yarn
安装步骤
克隆仓库:
git clone <repository-url>
cd multiplatform_code安装依赖:
npm install启动 MCP 服务器:
npm start配置 MCP 客户端
Claude Desktop 配置
在 Claude Desktop 的 claude_desktop_config.json 文件中添加:
{
"mcpServers": {
"multiplatform-code-generator": {
"command": "node",
"args": ["/path/to/multiplatform_code/src/index.js"],
"env": {}
}
}
}其他 MCP 客户端
参考您使用的 MCP 客户端文档进行配置。
使用方法
基本用法
在 MCP 客户端中调用工具
提供 C++ 接口函数代码
指定输出目录和目标平台
配置平台特定参数
示例
生成跨平台代码
// C++ 接口示例
const cppInterface = `
namespace MathUtils {
int add(int a, int b);
std::string formatNumber(double value, int precision);
}
`;
// 调用生成工具
generate_multiplatform_code({
cpp_interface: cppInterface,
output_directory: "/path/to/output",
platforms: ["android", "ios", "harmony"],
android_config: {
package_name: "com.example.mathutils",
class_name: "MathUtils",
language: "kotlin"
},
ios_config: {
class_prefix: "MU",
framework_name: "MathUtils"
},
harmony_config: {
module_name: "MathUtils",
namespace: "mathutils"
}
});解析 C++ 接口
parse_cpp_interface({
cpp_interface: "int multiply(int x, int y);"
});可用工具
1. generate_multiplatform_code
生成跨平台代码的主要工具。
参数:
cpp_interface(必需): C++ 接口函数代码output_directory(必需): 输出目录路径platforms(必需): 目标平台数组 (["android", "ios", "harmony"])android_config(可选): Android 配置package_name: Java/Kotlin 包名class_name: 类名language: "java" 或 "kotlin"
ios_config(可选): iOS 配置class_prefix: Objective-C 类前缀framework_name: 框架名称
harmony_config(可选): 鸿蒙配置module_name: 模块名称namespace: NAPI 命名空间
2. parse_cpp_interface
解析 C++ 接口函数并提取信息。
参数:
cpp_interface(必需): C++ 接口函数代码
3. list_supported_platforms
列出所有支持的目标平台。
生成的文件结构
Android (JNI)
android/
├── jni/
│ ├── function_name_jni.cpp
│ ├── function_name_jni.h
│ └── CMakeLists.txt
├── src/main/java/com/package/ClassName.java
└── build.gradle.jniiOS (Objective-C)
ios/
├── ClassName.h
├── ClassName.m
├── ClassNameBridge.hpp
├── ClassNameBridge.cpp
├── ClassNameSwift.swift
├── FrameworkName.podspec
└── Config.xcconfig鸿蒙 (NAPI)
harmony/
├── src/main/
│ ├── cpp/
│ │ ├── napi/
│ │ │ ├── function_name_napi.cpp
│ │ │ ├── function_name_napi.h
│ │ │ └── napi_init.cpp
│ │ └── CMakeLists.txt
│ └── ets/
│ ├── ModuleName.ets
│ └── types/ModuleName.d.ts
├── oh-package.json5
└── build-profile.json5高级用法
支持的 C++ 类型
C++ 类型 | Android (Java/Kotlin) | iOS (Objective-C) | 鸿蒙 (TypeScript) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
错误处理
生成的代码包含适当的错误处理:
Android: Java 异常
iOS: Objective-C 异常
鸿蒙: Promise 拒绝
内存管理
Android: 自动处理 JNI 字符串释放
iOS: 使用 ARC (Automatic Reference Counting)
鸿蒙: 自动处理 NAPI 内存
故障排除
常见问题
解析失败: 确保 C++ 代码语法正确
类型不支持: 检查类型映射表
文件权限: 确保输出目录有写权限
调试技巧
使用
parse_cpp_interface验证解析结果检查生成的代码语法
查看 MCP 服务器日志
贡献
欢迎贡献代码!请遵循以下步骤:
Fork 仓库
创建特性分支
提交更改
创建 Pull Request
许可证
MIT License - 详见 LICENSE 文件
支持
如有问题或建议,请:
创建 GitHub Issue
发送邮件至 support@example.com
查看文档和示例
注意: 此工具生成的代码需要您在项目中包含相应的 C++ 源文件和头文件。
Available Tools
3 toolsgenerate_multiplatform_codeC
Generate cross-platform code from C++ interface
Inputs: platforms (required), cpp_interface (required), output_directory (required), ios_config, +2 more.
list_supported_platformsA
List all supported target platforms
Inputs: no named parameters.
parse_cpp_interfaceC
Parse C++ interface and extract function information
Inputs: cpp_interface (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
Each tool has a clearly distinct role: parsing input, listing platforms, and generating output. There is little risk of confusing one tool with another.
All tool names follow a consistent snake_case verb_noun pattern: parse_cpp_interface, list_supported_platforms, generate_multiplatform_code.
Three tools are appropriate for a focused workflow: parse the C++ interface, discover platforms, and generate code. Each tool earns its place without bloat.
The core lifecycle is covered, but there are minor gaps such as validating the parsed interface, configuring generation options, or inspecting generated output before use.
Maintenance
Related MCP Connectors
Generate a typed SDK, CLI, and MCP server from any OpenAPI or GraphQL spec, and keep them current.
Generate software design documents (SDD) from C source code as Word or Markdown. Paid, free trial.
Design domain models and generate deterministic multi-stack code, driven by your coding agent.
Host any HTTP API as a standard MCP server; auto-distribute to 12+ mainstream agent platforms.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides project-specific context and development templates for Cangjie/ArkTS projects, including modular design documents, FFI summaries, and code generation tools to assist with IDE-based development workflows.2-
- AlicenseAqualityDmaintenanceProvides professional C++ code style checking, best practices analysis, and modern C++ upgrade suggestions with tools for naming conventions, memory safety, const correctness, and access to comprehensive C++ style documentation.5MIT
- AlicenseAqualityDmaintenanceGenerates complete, production-ready REST, GraphQL, and microservice APIs with built-in security, validation, and deployment configurations.5MIT
- FlicenseNot gradedqualityCmaintenanceBuilds a semantic knowledge graph of C++ code and exposes 9 MCP tools for AI assistants to search classes, functions, inheritance, callers, callees, overrides, and more.3-