内容
# Qarnot MCP Server
一个 MCP(Model Context Protocol)服务器,允许 AI 客户端(这里是 Claude)使用 Anthropic MCP Python SDK 与您的 Qarnot 任务交互。当您将其连接到您的 AI 助手(Personal Chatbot, Claude 等)时,您就可以自然地与它交互,以检索有关您在 Qarnot 上运行的任务的信息(例如:我的最后一个任务的状态是什么?)。

## What it does
使客户端可以访问以下工具:
- **create_task (BETA)** - 创建一个任务,您可以在其中指定 profile、调度类型、input bucket、snapshots 等。
- **list_tasks** - 列出所有 Qarnot 任务
- **get_task_status** - 获取详细状态 + SSH 连接信息
- **get_task_stdout** - 获取任务输出
- **get_task_stderr** - 获取任务错误
- **cancel_task** - 取消正在运行的任务
- **list_buckets** - 列出所有存储 bucket
- **list_bucket_files** - 列出 bucket 中的文件
- **download_result** - 从 bucket 下载文件
- **list_profiles** - 列出可用的硬件 profile
真正酷的是:您可以要求 Agent 在 24 小时后取消任务。列出您的 profile,然后使用特定的 profile 创建任务。获取任务输出并在任务收敛时取消任务。等等。
## Setup
1. 安装依赖项:
```bash
pip install qarnot "mcp[cli]" python-dotenv
```
2. 创建一个包含您的 Qarnot token 的 `.env` 文件:
```
QARNOT_TOKEN="your-token-here"
```
## Usage
### With Claude Code (CLI) (Locally)
要使 Claude 能够使用 MCP Server 中的工具,您可以:
```bash
claude mcp add qarnot python3 /path/to/mcp_server.py
```
并重启 Claude Code。然后,您可以向 Claude 提出您的请求(例如:*"List my Qarnot tasks"*)。
### With Claude Web (Online)
在服务器(Qarnot, AWS, OVH 等)上安装 MCP 服务器后,将其添加到您的连接器。团队和企业工作流程在此处解释:
https://support.claude.com/en/articles/11175166-getting-started-with-custom-connectors-using-remote-mcp
### Debugging or Manual test
```bash
mcp dev mcp_server.py
```
可以使用交互式 MCP Inspector (https://modelcontextprotocol.io/docs/tools/inspector) 来测试他们的 MCP Server。
### Tools definition
简而言之,工具是通过 MCP 由 AI agent 执行的操作。例如,“List tasks”是如果您要求它列出您当前的任务,agent 可以执行的操作。
要添加新工具,请转到 mcp_server.py 并使用以下格式(这里,以 list_tasks 为例):
```python
@mcp.tool() #the Anthropic decorator to create a MCP tool
def list_tasks() -> str: # name of the tool and expected output
"""List all Qarnot tasks for your account.""" #Docstring description, very important for the LLM
conn = get_connection() #Qarnot Python SDK related to the tool
tasks = conn.tasks() #Qarnot Python SDK related to the tool
#Any in-between actions should be added here
result = [] #Empty format of the output
for task in tasks: #Build the reponse
result.append({
"uuid": task.uuid,
"name": task.name,
"state": task.state,
})
import json
return json.dumps(result, indent=2) #Return JSON for the AI Agent that can then answer your query
```