MCP Travrse流执行器
Travrse AI的轻量级MCP(模型上下文协议)集成,提供流发现和执行功能。
特性
- 流量发现:列出并获取可用流的详细信息
- 流程执行:使用消息执行流(标准和流式)
- 简单API:具有所有功能的单个类
- HTTP/2支持:采用HTTP/2的现代httpx客户端,性能更好
- 连接池:可重复使用的连接可提高效率
- 最小依赖性:只需要
httpx图书馆
安装```bash
Install from local directory
pip install -e .
Or install with dev dependencies
pip install -e ".[dev]"
## 快速开始
### 1.设置环境变量
创建 `.env` 文件或设置环境变量:```bash
TRAVRSE_API_KEY=tv_test_your_api_key_here
TRAVRSE_API_BASE=https://api.travrse.ai/v1
TRAVRSE_TIMEOUT=60
2.基本用法```python
from mcp_travrse_flow_executor import MCPTravrseExecutor
Initialize (reads from environment)
executor = MCPTravrseExecutor()
List available flows
flows = executor.list_flows(limit=10)
print(f"Found {flows['total']} flows")
Get specific flow
flow = executor.get_flow("flow_01k9pf...")
print(f"Flow: {flow['name']}")
Execute flow
result = executor.execute_flow(
flow_id="flow_01k9pf...",
messages=[{"role": "user", "content": "Hello!"}],
)
print(result)
### 3.流媒体执行```python
# Execute with streaming
for line in executor.execute_flow(
flow_id="flow_01k9pf...",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
):
print(line)
API 参考
MCPTravrse执行器
具有所有功能的主执行器类。
方法
流量发现:
list_flows(limit=50, offset=0)-列出可用流get_flow(flow_id)-按ID获取流量详细信息
流程执行:
execute_flow(flow_id, messages, record_name="execution", stream=False)-使用可选流媒体执行流
例子
看 examples/ 更多示例的目录:
basic_usage.py-基本使用示例
测试```bash
Run tests
pytest
Run tests with coverage
pytest --cov=mcp_travrse_flow_executor
Run specific test
pytest tests/test_executor.py
## 发展```bash
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code (if using black)
black mcp_travrse_flow_executor tests examples
项目结构```
mcp_travrse_flow_executor/
├── mcp_travrse_flow_executor/
│ ├── init.py # Package exports
│ ├── config.py # Configuration
│ ├── client.py # HTTP client
│ ├── mcp_travrse_flow_executor.py # Main executor
│ └── tests/ # Test suite
│ ├── conftest.py # Test fixtures
│ └── test_executor.py # Tests
├── examples/
│ └── basic_usage.py # Usage examples
├── .env.example # Environment template
├── pyproject.toml # Project config
└── README.md # This file
```
许可证
MIT许可证
