# 迁移

从 legacy 或 direct-client setup 迁移，同时保留 scope、identity 和删除边界。

- Canonical: https://docs.xmemo.dev/zh/docs/migration
- Locale: zh-CN
- Content-Locale: zh-CN
- Canonical-Content-Digest: fb66f83d45da488fee5cccfe9563c1ab56211a358d339b0f73df16cfed352b5f
- Edition-Digest: 9af61c50d709bc1fe37b873f1bbc28c467efea96d67653ca00d83df901aa9e25
- Source-Revision: sha256:a9d9383136b66e379e92a66eabd971c6ca172b426fff3067024039b4e2ec6f2e

## 从 direct-token client 迁移到 OAuth

当 client 支持 OAuth 时，切换会从本地 configuration 中移除已存储的 bearer token。Memory、scope 和 attribution 不会因切换改变，只有 credential path 会移动。

- 移除 XMEMO_KEY 前，确认 client 显示为 OAuth-capable。
- 重新连接并批准 memory:read 和 memory:write。
- 先执行一次无害的 recall，再写入任何内容。
- 从旧 configuration 文件和环境中移除 token。

## 之前：direct token 配置

```json
{
  "mcpServers": {
    "XMemo": {
      "type": "http",
      "url": "https://xmemo.dev/mcp",
      "headers": { "Authorization": "Bearer ${env:XMEMO_KEY}" }
    }
  }
}
```

## 之后：OAuth 配置

只保留 hosted server URL；grant 会提供 scopes。

```json
{
  "servers": {
    "XMemo": {
      "type": "http",
      "url": "https://xmemo.dev/mcp"
    }
  }
}
```

## 验证迁移

先读后写，这样 broken credential 会在不改变已存储 memory 的情况下暴露。

```ts
await client.recallContext('current task and recent decisions', {
  preferWorking: true,
});
```

