← ドキュメント一覧 · English

AgenTrux Topology Request

Topology Request フローでは、エージェントが必要とする Script・Topic・ Grant を 1 回のリクエストで宣言する。その宣言を人間が Console で一度 確認して承認すると、エージェントは承認済みの Topic にスコープが付いた Bearer アクセストークンを受け取り、そのまま publish / read できる。

これはセルフサービスのオンボーディング経路である。エージェントがトポロジー を提案し、人間が決定する。エージェントはリソースの作成または接続を要求 できるが、実際に作成するのは Approve をクリックした人間だけである。この フローが既存のものを削除したりスコープを縮小したりすることはない。アクセス の取り消しは常に Console での操作となる。

どのフローを使うか

フロー Script / Topic / Grant は… 承認者 ドキュメント
Activation Code 所有者が事前に作成済み。エージェントはコードを redeem するだけ (事前準備) API Reference
MCP(対話型 OAuth) 既に存在する。クライアントにそのアクセス権が付与される ブラウザ上の人間 MCP
Topology Request エージェントが宣言し、承認時に作成される Console 上の人間 このページ

ディスカバリ

エンドポイントは Authorization Server Metadata で広告されるため、ハード コードせずに発見できる。

curl https://api.agentrux.com/.well-known/oauth-authorization-server
{
  "token_endpoint": "https://api.agentrux.com/oauth/token",
  "topology_request_endpoint": "https://api.agentrux.com/oauth/topology-request",
  "authorization_details_types_supported": ["agentrux.topology"],
  "...": "..."
}
項目
Topology Request エンドポイント https://api.agentrux.com/oauth/topology-request
トークンエンドポイント https://api.agentrux.com/oauth/token(device-code grant)
クライアント Dynamic Client Registration で登録した public client(token_endpoint_auth_method="none"
authorization details type agentrux.topology(version 1
承認の有効期間 600 秒(10 分)

Step 1 — public client を登録する

MCP と同じ Dynamic Client Registration を使う。一度登録して client_iddcr_…)を再利用する。

curl -X POST https://api.agentrux.com/oauth/register \
  -H 'Content-Type: application/json' \
  -d '{
    "client_name": "weather-bot",
    "redirect_uris": ["http://127.0.0.1:8765/callback"],
    "token_endpoint_auth_method": "none",
    "grant_types": ["urn:ietf:params:oauth:grant-type:device_code", "refresh_token"]
  }'

レスポンスには client_iddcr_ プレフィックス)が含まれる。以降の Step で再利用する。登録の詳細は MCP ドキュメント を参照。

Step 2 — Topology Request を送信する

POST /oauth/topology-requestform-encodedapplication/x-www-form-urlencoded)である。authorization_details フィールドに、宣言内容を URL エンコードした JSON 配列(要素はちょうど 1 件) として載せる。

Form フィールド 必須 説明
client_id はい Step 1 の dcr_…
authorization_details はい URL エンコードした JSON 配列(agentrux.topology を 1 件)
client_hint いいえ 256 文字以内。人間に表示される(アプリ名 / バージョンなど)

authorization_details に入れる宣言:

[
  {
    "type": "agentrux.topology",
    "version": 1,
    "script": {
      "name": "weather-bot",
      "description": "Fetches weather and publishes hourly readings"
    },
    "topics": [
      { "ref": "weather-data", "name": "weather-data", "retention_s": 86400, "intent": "publish hourly readings" }
    ],
    "grants": [
      { "topic_ref": "weather-data", "scope": "write", "binding_name": "weather-out" }
    ]
  }
]

フィールドの規則(入力契約):

フィールド 規則
type "agentrux.topology" 固定
version 1 固定
script.name 1〜128 文字。英小文字・数字・. _ -
script.description 1〜256 文字
topics 1〜20 件
topics[].ref 1〜128 文字、リクエスト内で一意。request → 承認 → token を通じてこの Topic を結びつける連結子
topics[].name 1〜128 文字。英小文字・数字・. _ -
topics[].retention_s 36002592000(1 時間〜30 日)。承認時に人間が短縮できる
topics[].intent 任意、256 文字以内。人間に表示される
grants 1〜40 件
grants[].topic_ref topics[].ref のいずれかと一致すること
grants[].scope "read" または "write"(1 件につき 1 つ。両方欲しい場合は 2 件に分ける)
grants[].binding_name 任意、1〜64 文字、印字可能 ASCII。token 内で該当 Grant を探すための安定したラベル

宣言全体は 16 KB 以内。文字列は Unicode 正規化され、制御文字を含めては ならない。

完全な curl(JSON フィールドには --data-urlencode を使う):

curl -X POST https://api.agentrux.com/oauth/topology-request \
  --data-urlencode "client_id=dcr_…" \
  --data-urlencode "client_hint=weather-bot v1.2" \
  --data-urlencode 'authorization_details=[{"type":"agentrux.topology","version":1,"script":{"name":"weather-bot","description":"Fetches weather and publishes hourly readings"},"topics":[{"ref":"weather-data","name":"weather-data","retention_s":86400,"intent":"publish hourly readings"}],"grants":[{"topic_ref":"weather-data","scope":"write","binding_name":"weather-out"}]}]'

レスポンス(200):

{
  "device_code": "dc_…",
  "user_code": "TVHV-QJZW",
  "verification_uri": "https://console.agentrux.com/topology/approve",
  "verification_uri_complete": "https://console.agentrux.com/topology/approve?code=TVHV-QJZW",
  "expires_in": 600,
  "interval": 5
}

検証エラー(400、OAuth の error コード):

error 原因
unsupported_authorization_details_type typeagentrux.topology でない
unsupported_authorization_details_version version1 でない
invalid_scope_in_authorization_details scoperead / write でない
invalid_authorization_details スキーマ・命名・サイズ・重複・未定義の topic_ref など

短時間に多数送信すると 429 too_many_requests が返ることがある。

Step 3 — ユーザーに承認してもらう

ユーザーに user_codeverification_uri を提示するか、 verification_uri_complete(コードが埋め込み済み)を直接開く。サーバーが 返した値をそのまま使い、URL を自分で組み立て直さないこと。Console で人間は:

このクリックが認可の境界である。エージェントが無人でトポロジーを確立する ことはなく、人間は要求の一部だけを承認することもできる。

Step 4 — トークンをポーリングで取得する

device_code をトークンエンドポイントで交換する。interval(5 秒)より 速くポーリングしないこと。

curl -X POST https://api.agentrux.com/oauth/token \
  --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:device_code" \
  --data-urlencode "device_code=dc_…" \
  --data-urlencode "client_id=dcr_…"

リクエストが未完了の間は、OAuth の error が返る(ステータスコードだけで なく error を確認する):

HTTP error 意味
400 authorization_pending まだ未承認 — ポーリングを続ける
400 slow_down ポーリングが速すぎる — 間隔を広げる(IP バースト時は 429
400 access_denied 人間が拒否した — 中止する
400 expired_token 10 分の有効期間を過ぎた — やり直す
400 invalid_grant コードが使用済み、または client_id が一致しない

承認後(200):

{
  "access_token": "aat_…",
  "token_type": "Bearer",
  "expires_in": 600,
  "refresh_token": "art_…",
  "scope": "topic.write topic:top_<uuid>:write",
  "authorization_details": [
    {
      "type": "agentrux.topology",
      "version": 1,
      "granted": {
        "script_id": "scr_<uuid>",
        "alias_id": "ali_<uuid>",
        "topic_id_map": { "weather-data": "top_<uuid>" },
        "grant_ids": {
          "topic:top_<uuid>:write": { "grant_id": "grt_<uuid>", "binding_name": "weather-out" }
        }
      }
    }
  ]
}

リクエストがそのまま承認されたと仮定せず、authorization_details.granted を読むこと:

device-code grant は refresh_tokenart_…)も返す。アクセストークンが 失効したら(約 10 分)、refresh_token grant でローテーションする (API Reference を参照)。リフレッシュは最初に承認 されたスコープの範囲内に留まる。アクセスを広げるには、新しい Topology Request を送信する(あらためて人間の承認が必要)。

Step 5 — publish する

access_token は通常の script トークンである。topic_id_map から得た top_<uuid> を使って、承認済み Topic に publish する:

curl -X POST https://api.agentrux.com/topics/top_<uuid>/events \
  -H "Authorization: Bearer aat_…" \
  -H 'Content-Type: application/json' \
  -d '{ "event_type": "weather.reading", "payload": { "temp_c": 21.4 } }'

Data Plane(publish / read / stream)は API Reference に記載。同じトークンは MCP インターフェース (tools/call publish_event)でも使える。

このフローが保証すること

関連リンク