Files
doubao-clone/scripts/mcp-python-test.mjs
l f056bcf45a 豆包复刻:原生安卓(Compose + 内嵌 Termux)+ Web / Windows
一个界面照着豆包抠的 AI 助手。主力是安卓端,完全离线自主:不依赖电脑、
不需要另外装 Termux。

安卓端
- 原生 Jetpack Compose,7 个页面,配色/圆角/间距对着真机截图量出来的
- 完整动效:抽屉滑入、页面切换、气泡淡入上移、面板底部升起、typing 三点、按钮回弹
- 内置 Termux:bash/apt/pkg 388 个命令、真 pty 终端;
  pty 不可用的 ROM 上自动降级成命令控制台
- APK 内嵌 CPython 3.13(Chaquopy),AI 内核跑在手机上
- 设备能力:定位 / 陀螺仪 / 加速度计 / 光线 / 电量 / 剪贴板
- 语音:朗读 + 语音输入,火山豆包音色 / OpenAI 兼容 / 设备自带三级引擎

AI 能力
- 10 家 OpenAI 兼容提供商:方舟 / OpenAI / DeepSeek / Kimi / 智谱 /
  通义 / 硅基流动 / OpenRouter / 本地 Ollama / 自定义
- 思考强度按各家支持情况发不同字段(thinking / reasoning_effort / 不发),
  认不出来的一律不发,避免给不支持的厂商发字段直接 400
- MCP 三种传输(http / stdio / inproc)、工具热加载、文件上传、权限模式

跨端
- 安卓走原生 Compose,Web / Windows 走 Lynx
- Node 与 Python 两份内核接口逐字段一致,关键路径都有对拍脚本

自检脚本(都不需要真 Key)
- verify-phone.mjs          设备端 24 项验收
- verify-speech.mjs         语音链路 31 项,两份内核各跑一遍
- parity-thinking.mjs       思考强度映射对拍
- probe-settings-wipe.mjs   设置防清空攻击测试
- mock-llm.mjs              假的 OpenAI + 火山语音服务

许可 MIT;第三方组件(Termux Apache-2.0、Chaquopy、Compose、LynxJS、Electron)
的授权见 LICENSE。
2026-10-09 14:09:36 +08:00

80 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 验证:把 Python 写的 MCP 服务接进内核(stdio 模式)。
* 用法: node scripts/mcp-python-test.mjs [base] [pythonPath] [serverPy]
*/
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const repo = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const BASE = process.argv[2] || 'http://127.0.0.1:5199';
const PYTHON = process.argv[3] || 'python';
const SERVER_PY = process.argv[4] || path.join(repo, 'tools', '_mcp_python_example.py');
const config = {
servers: [
{
name: 'py-demo',
enabled: true,
transport: 'stdio',
command: PYTHON,
args: [SERVER_PY],
env: {},
},
{
name: 'filesystem',
enabled: false,
transport: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '${DOUBAO_DATA}'],
},
{
name: 'my-python-mcp-inproc',
enabled: false,
transport: 'inproc',
path: '/sdcard/Android/data/com.doubao.lynxclone/files/tools/my_mcp_server.py',
note: '安卓端用:内核直接 import 这个 py,不依赖独立 python 解释器',
},
],
};
console.log('写入配置…');
const save = await fetch(`${BASE}/api/mcp/config`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: JSON.stringify(config, null, 2) }),
});
const saved = await save.json();
console.log('ok=', saved.ok, 'count=', saved.count, 'error=', saved.error || '无');
for (const r of saved.results || []) console.log(' ', r.ok ? '✓' : '✗', r.name, r.error || '');
console.log('\n工具列表:');
const state = await (await fetch(`${BASE}/api/state`)).json();
const mcpTools = state.toolNames.filter((n) => n.startsWith('mcp__py-demo__'));
console.log(' py-demo 暴露:', mcpTools.join(', ') || '(无)');
console.log('\n跑一下 word_count:');
const run = await fetch(`${BASE}/api/tools/run`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'mcp__py-demo__word_count', args: { text: 'hello 世界 hello' } }),
});
console.log(' ', JSON.stringify(await run.json()));
console.log('\n跑一下 host_info:');
const info = await fetch(`${BASE}/api/tools/run`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'mcp__py-demo__host_info', args: {} }),
});
console.log(' ', JSON.stringify(await info.json()).slice(0, 260));
console.log('\n跑一下 http_get(证明 MCP 里的 py 也能联网):');
const net = await fetch(`${BASE}/api/tools/run`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'mcp__py-demo__http_get', args: { url: 'https://example.com' } }),
});
const netJson = await net.json();
console.log(' ', JSON.stringify(netJson).slice(0, 200));