项目简介
Mosaic是一个创新性的隐私保护场外交易平台,利用Miden零知识证明系统实现去信任化交易,同时保护参与者身份隐私。该项目包含前端Web应用、后端服务、Miden区块链集成、金融业务逻辑以及一个MCP服务器,旨在为LLM(大型语言模型)应用提供标准化的区块链交互能力。
主要功能点
- 账户管理: 创建客户端账户、做市商账户(Desk)、流动性账户和资产发行账户(Faucet)。
- 资产操作: 查询账户状态,包括持有的资产种类和数量。
- 订单与交易: 创建交易订单,提交或消费Miden区块链上的隐私票据(Note),实现资产转移和交易结算。
- 做市商(Desk)功能: 允许做市商接收并处理流动性报价。
- 区块链同步: 同步Miden客户端状态,获取最新的区块链信息。
- 低级票据创建: 支持通过Miden汇编语言(MASM)创建自定义的原始票据。
- 版本查询: 获取当前Mosaic MCP服务器的版本信息。
安装步骤
- 环境准备: 确保您的系统已安装Rust编程语言和Cargo包管理器。
- 克隆仓库: 从GitHub克隆Mosaic项目到本地。
git clone https://github.com/edfixyz/mosaic.git cd mosaic - 构建项目: 在项目根目录运行以下命令进行构建。
cargo build --release - 初始化存储路径: 为服务器创建数据存储目录。例如,在项目根目录创建一个名为'mosaic_store'的文件夹。
mkdir mosaic_store - 配置OAuth (可选): 如果需要启用OAuth认证,请设置以下环境变量:
- 'MOSAIC_AUTH_DOMAIN': 您的Auth0域名。
- 'MOSAIC_MCP_CLIENT_ID': 从Auth0应用程序获取的客户端ID。
- 'MOSAIC_MCP_CLIENT_SECRET': 从Auth0应用程序获取的客户端密钥。
- 'MOSAIC_CORS_ALLOWED_ORIGINS': 允许跨域请求的来源,多个来源用逗号分隔(例如:"http://localhost:3000,https://example.com")。如果未设置,则允许所有来源。 如果您不设置这些变量并运行带OAuth的服务器,服务器将报错退出。如需禁用OAuth,可以在启动命令中添加'--no-auth'参数。
- 启动Miden节点 (Localnet): 如果您计划使用Localnet进行测试,请确保本地Miden节点正在运行。
服务器配置(MCP客户端使用)
MCP客户端需要MCP服务器的地址和能力声明来建立连接。以下是推荐的MCP客户端配置信息(JSON格式):
{ "name": "Mosaic-MCP-Server", "command": "target/release/mosaic-server", "args": [ "--mcp", "--mcp-port", "8000", "--storage-path", "./mosaic_store" // 可以根据需要添加其他参数,例如: // "--no-auth" // 禁用OAuth认证 (仅限测试环境) ], "capabilities": { "tools": { "create_client_account": { "description": "创建一个新的客户端账户。", "parameters": { "type": "object", "properties": { "network": { "type": "string", "description": "网络类型:\"Testnet\" 或 \"Localnet\"。", "enum": ["Testnet", "Localnet"] } }, "required": ["network"] } }, "create_desk_account": { "description": "创建一个新的做市商(Desk)账户,包含市场信息。", "parameters": { "type": "object", "properties": { "network": { "type": "string", "description": "网络类型:\"Testnet\" 或 \"Localnet\"。", "enum": ["Testnet", "Localnet"] }, "market": { "$ref": "#/definitions/MarketDescription", "description": "市场信息,包含基础货币和报价货币。" } }, "required": ["network", "market"] }, "definitions": { "MarketCurrency": { "type": "object", "properties": { "code": { "type": "string", "description": "货币代码(例如:BTC,USDC)。" }, "issuer": { "type": "string", "description": "发行方账户ID(bech32格式)。" } }, "required": ["code", "issuer"] }, "MarketDescription": { "type": "object", "properties": { "base": { "$ref": "#/definitions/MarketCurrency", "description": "基础货币(例如:BTC/USDC中的BTC)。" }, "quote": { "$ref": "#/definitions/MarketCurrency", "description": "报价货币(例如:BTC/USDC中的USDC)。" } }, "required": ["base", "quote"] } } }, "create_liquidity_account": { "description": "创建一个新的流动性账户。", "parameters": { "type": "object", "properties": { "network": { "type": "string", "description": "网络类型:\"Testnet\" 或 \"Localnet\"。", "enum": ["Testnet", "Localnet"] } }, "required": ["network"] } }, "create_faucet_account": { "description": "创建一个新的资产发行账户(Faucet),并指定代币符号、小数位数和最大供应量。", "parameters": { "type": "object", "properties": { "token_symbol": { "type": "string", "description": "代币符号(例如:MID)。" }, "decimals": { "type": "number", "format": "u8", "description": "代币的小数位数。" }, "max_supply": { "type": "number", "format": "u64", "description": "代币的最大供应量。" }, "network": { "type": "string", "description": "网络类型:\"Testnet\" 或 \"Localnet\"。", "enum": ["Testnet", "Localnet"] } }, "required": ["token_symbol", "decimals", "max_supply", "network"] } }, "list_accounts": { "description": "列出所有已认证用户下的账户ID(bech32格式)及其网络。", "parameters": { "type": "object", "properties": {} } }, "client_sync": { "description": "将客户端状态与Miden网络同步。", "parameters": { "type": "object", "properties": { "network": { "type": "string", "description": "网络类型:\"Testnet\" 或 \"Localnet\"。", "enum": ["Testnet", "Localnet"] } }, "required": ["network"] } }, "create_order": { "description": "为已认证用户的账户创建订单票据。可选择是否立即提交到网络。", "parameters": { "type": "object", "properties": { "network": { "type": "string", "description": "网络类型:\"Testnet\" 或 \"Localnet\"。", "enum": ["Testnet", "Localnet"] }, "account_id": { "type": "string", "description": "账户ID(bech32格式)。" }, "order": { "type": "object", "description": "订单对象,例如 {\"LiquidityOffer\": {\"market\": \"BTC/USD\", \"uuid\": 12345, \"amount\": 1000, \"price\": 50000}}。" }, "commit": { "type": "boolean", "description": "创建后是否立即提交票据(默认为 true)。" } }, "required": ["network", "account_id", "order"] } }, "create_raw_note": { "description": "使用低级Miden汇编代码和输入为已认证用户的账户创建原始票据。", "parameters": { "type": "object", "properties": { "network": { "type": "string", "description": "网络类型:\"Testnet\" 或 \"Localnet\"。", "enum": ["Testnet", "Localnet"] }, "account_id": { "type": "string", "description": "账户ID(bech32格式)。" }, "note_type": { "type": "string", "description": "票据类型:\"Private\" 或 \"Public\"(目前仅支持Private)。", "enum": ["Private", "Public"] }, "program": { "type": "string", "description": "Miden汇编程序源代码。" }, "libraries": { "type": "array", "description": "可选的外部库,格式为 [name, source] 对的数组。", "items": { "type": "array", "items": [{ "type": "string" }, { "type": "string" }], "minItems": 2, "maxItems": 2 } }, "inputs": { "type": "array", "description": "可选的输入,格式为 [name, value] 对的数组,其中 value 为 {\"Word\": [u64, u64, u64, u64]} 或 {\"Element\": u64}。", "items": { "type": "array", "items": [{ "type": "string" }, { "type": "object", "oneOf": [{ "type": "object", "properties": { "Word": { "type": "array", "items": { "type": "number", "format": "u64" }, "minItems": 4, "maxItems": 4 } }, "required": ["Word"] }, { "type": "object", "properties": { "Element": { "type": "number", "format": "u64" } }, "required": ["Element"] }] }], "minItems": 2, "maxItems": 2 } }, "note_secret": { "type": "array", "description": "可选的票据密钥,4个u64元素的数组。", "items": { "type": "number", "format": "u64" }, "minItems": 4, "maxItems": 4 } }, "required": ["network", "account_id", "note_type", "program"] } }, "get_account_status": { "description": "获取已认证用户账户的状态,包括账户类型和所有持有的资产。", "parameters": { "type": "object", "properties": { "network": { "type": "string", "description": "网络类型:\"Testnet\" 或 \"Localnet\"。", "enum": ["Testnet", "Localnet"] }, "account_id": { "type": "string", "description": "账户ID(bech32格式)。" } }, "required": ["network", "account_id"] } }, "consume_note": { "description": "使用已认证用户的账户消费票据。这将执行一个交易来消费票据并将其资产添加到账户。", "parameters": { "type": "object", "properties": { "network": { "type": "string", "description": "网络类型:\"Testnet\" 或 \"Localnet\"。", "enum": ["Testnet", "Localnet"] }, "account_id": { "type": "string", "description": "账户ID(bech32格式)。" }, "miden_note": { "type": "object", "description": "要消费的Miden票据对象,JSON格式。" } }, "required": ["network", "account_id", "miden_note"] } }, "desk_push_note": { "description": "将Mosaic票据推送到做市商(Desk)的票据存储中。", "parameters": { "type": "object", "properties": { "desk_uuid": { "type": "string", "description": "做市商的UUID。" }, "note": { "type": "object", "description": "要推送到做市商的Mosaic票据对象。" } }, "required": ["desk_uuid", "note"] } }, "get_desk_info": { "description": "获取做市商(Desk)信息,包括账户ID、网络和市场数据。", "parameters": { "type": "object", "properties": { "desk_uuid": { "type": "string", "description": "做市商的UUID。" } }, "required": ["desk_uuid"] } }, "flush": { "description": "清除所有缓存的客户端和内存对象。", "parameters": { "type": "object", "properties": {} } }, "version": { "description": "获取当前Mosaic MCP服务器的版本字符串。", "parameters": { "type": "object", "properties": {} } } } } }
基本使用方法
- 启动服务器: 在项目根目录运行以下命令启动MCP服务器:
如果禁用了OAuth认证:target/release/mosaic-server --mcp --mcp-port 8000 --storage-path ./mosaic_storetarget/release/mosaic-server --mcp --mcp-port 8000 --storage-path ./mosaic_store --no-auth - MCP客户端连接: 您的MCP客户端(例如LLM应用)可以使用上述'服务器配置'中的'command'和'args'来启动并连接到Mosaic MCP服务器。客户端将通过JSON-RPC协议与服务器进行通信,调用其暴露的工具。
- 调用工具示例: 一旦连接成功,客户端可以调用'create_client_account'工具来创建一个新的客户端账户:
- 工具名称: 'create_client_account'
- 参数: '{"network": "Localnet"}'
- 预期响应: '{"success": true, "account_id": "mtcl1qy..."}'
信息
分类
商业系统