使用说明
FLUX协议SDK
通用AI连接层 -用4条线将AI连接到任何东西。 代币减少40% 采用TOON格式。
为什么选择FLUX?
| 功能 | MCP | FLUX |
|---|---|---|
| 代码行数 | 120+ | 4 |
| 协议 | 仅限STDIO | STDIO、HTTP、WebSocket |
| 令牌效率 | JSON | TOON(代币减少40%) |
| 类型安全 | 手动 | 自动 |
安装
npm install fluxprotocol-sdk
快速开始
npx fluxprotocol-cli create weather
cd weather && pnpm install && pnpm dev
四线承诺
import { connector, method, FluxServer, StdioTransport } from 'fluxprotocol-sdk';
@connector('weather')
class WeatherConnector {
@method()
async getWeather(city: string) {
return fetch(`https://api.weather.com/${city}`).then(r => r.json());
}
}
const server = new FluxServer(WeatherConnector);
server.setTransport(new StdioTransport(server));
server.start();
包裹
| 软件包 | 说明 | 安装 |
|---|---|---|
fluxprotocol-sdk |
带传输的核心SDK | npm i fluxprotocol-sdk |
fluxprotocol-cli |
CLI工具 | npm i -g fluxprotocol-cli |
fluxprotocol-client |
HTTP/WS客户端 | npm i fluxprotocol-client |
运输
import { StdioTransport, HttpTransport, WebSocketTransport } from 'fluxprotocol-sdk';
new StdioTransport(server); // MCP (Claude Desktop)
new HttpTransport(server, { port: 3000 }); // REST API + TOON
new WebSocketTransport(server, { port: 3001 }); // Real-time
TOON格式(代币减少40%)
FLUX支持 TOON(面向令牌的对象表示法) 为了实现高效的人工智能通信:
import { FluxClient } from 'fluxprotocol-client';
const client = new FluxClient('http://localhost:3000');
// Enable TOON format (40% fewer tokens)
const tools = await client.useToon().listTools();
// Or use JSON (default)
const weather = await client.call('weather.getWeather', { city: 'Tokyo' });
服务器通过自动检测格式 Accept 头球
Accept: application/toon→ TOON响应Accept: application/json→ JSON响应(默认)
生产装饰师
import { cache, rateLimit, retry, config } from 'fluxprotocol-sdk';
@connector('api')
@config({ auth: { type: 'bearer', env: 'API_TOKEN' } })
class ApiConnector {
@method()
@cache({ ttl: 60000 }) // Cache 1 minute
@rateLimit({ requests: 100, window: '1m' }) // 100 req/min
@retry({ attempts: 3, backoff: 'exponential' }) // Auto-retry
async fetchData(id: string) { ... }
}
| 装饰器 | 用途 |
|---|---|
@cache |
带TTL的LRU缓存 |
@rateLimit |
令牌桶速率限制 |
@retry |
指数/线性回退 |
@config |
身份验证和环境配置 |
CLI命令
fluxprotocol-cli create <name> # Scaffold connector
fluxprotocol-cli dev <file> # Dev with hot reload
fluxprotocol-cli build <file> # Production build
许可证
麻省理工学院©2025