← Back to Skills Marketplace
jonasgao

Consul API

by JonasGao · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
112
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install consul-api
Description
Consul HTTP API operations for service discovery, key-value store, health checks, and service mesh management. Use when working with Consul clusters for: (1)...
README (SKILL.md)

Consul API

HashiCorp Consul HTTP API 操作指南。提供服务发现、KV 存储、健康检查和服务网格管理能力。

Quick Start

Base URL: http://127.0.0.1:8500/v1/

认证方式:

# 方式 1: X-Consul-Token header (推荐)
curl -H "X-Consul-Token: \x3Ctoken>" http://127.0.0.1:8500/v1/agent/members

# 方式 2: Bearer token
curl -H "Authorization: Bearer \x3Ctoken>" http://127.0.0.1:8500/v1/agent/members

常用查询参数:

  • dc - 指定数据中心
  • ns - 指定命名空间 (Enterprise)
  • pretty - 格式化 JSON 输出
  • wait=\x3Cduration> - 阻塞查询等待时间
  • index=\x3Cnum> - 阻塞查询索引

Service Discovery (Catalog)

列出所有服务

GET /catalog/services
GET /catalog/services?dc=dc1

返回: {"service-name": ["tag1", "tag2"], ...}

查询服务的所有实例

GET /catalog/service/:service_name
GET /catalog/service/redis?dc=dc1&ns=default

列出所有节点

GET /catalog/nodes
GET /catalog/nodes?near=_agent

注册服务

PUT /catalog/register
{
  "Node": "node1",
  "Address": "192.168.1.1",
  "Service": {
    "Service": "redis",
    "ID": "redis-1",
    "Tags": ["primary", "v1"],
    "Address": "127.0.0.1",
    "Port": 6379
  }
}

注销服务

PUT /catalog/deregister
{
  "Node": "node1",
  "ServiceID": "redis-1"
}

Key-Value Store

读取 KV

GET /kv/:key              # 单个 key
GET /kv/:prefix?recurse   # 递归读取前缀下所有 key
GET /kv/:prefix?keys      # 只返回 key 列表
GET /kv/:key?raw          # 返回原始值 (text/plain)

返回值是 base64 编码,需解码:

curl -s http://127.0.0.1:8500/v1/kv/my-key | jq -r '.[0].Value' | base64 -d

写入 KV

PUT /kv/:key
PUT /kv/:key?flags=123    # 附加 flags
PUT /kv/:key?cas=100      # Check-And-Set (乐观锁)

curl -X PUT -d 'my value' http://127.0.0.1:8500/v1/kv/my-key

删除 KV

DELETE /kv/:key           # 删除单个 key
DELETE /kv/:prefix?recurse  # 删除前缀下所有 key
DELETE /kv/:key?cas=100   # Check-And-Set 删除

分布式锁

# 获取锁
PUT /kv/:key?acquire=\x3Csession-id>

# 释放锁
PUT /kv/:key?release=\x3Csession-id>

Health Checks

查询节点健康状态

GET /health/node/:node

查询服务的健康检查

GET /health/checks/:service
GET /health/checks/redis?passing  # 只返回 passing 状态

查询健康的服务实例

GET /health/service/:service
GET /health/service/redis?passing  # 只返回健康实例

按状态查询

GET /health/state/passing
GET /health/state/warning
GET /health/state/critical
GET /health/state/any

健康状态: passing, warning, critical

ACL (Access Control)

创建 Token

PUT /acl/create
{
  "Name": "my-token",
  "Type": "client",
  "Rules": "key \"secret/\" { policy = \"read\" }"
}

列出 Tokens

GET /acl/list
GET /acl/token/self  # 当前 token 信息

读取/更新 Token

GET /acl/token/:accessor_id
PUT /acl/token/:accessor_id

Agent Operations

查看 Agent 成员

GET /agent/members

查看 Agent 自身信息

GET /agent/self

查看本地服务

GET /agent/services
GET /agent/service/:service_id

注册服务 (Agent 端点)

PUT /agent/service/register
{
  "Name": "redis",
  "ID": "redis-1",
  "Tags": ["primary"],
  "Address": "127.0.0.1",
  "Port": 6379,
  "Check": {
    "HTTP": "http://localhost:6379/health",
    "Interval": "10s"
  }
}

注销服务 (Agent 端点)

PUT /agent/service/deregister/:service_id

Service Mesh (Connect)

查询 Connect 服务

GET /catalog/connect/:service
GET /health/connect/:service?passing

查询 Ingress Gateway

GET /health/ingress/:service

服务意图 (Intentions)

GET /connect/intentions
POST /connect/intention
{
  "SourceName": "web",
  "DestinationName": "db",
  "Action": "allow"
}
DELETE /connect/intention/:id

Sessions (分布式锁)

创建 Session

PUT /session/create
{
  "Name": "my-lock",
  "TTL": "30s",
  "Behavior": "delete"
}

返回: {"ID": "session-uuid"}

查询 Session

GET /session/info/:session-id
GET /session/node/:node

销毁 Session

PUT /session/destroy/:session-id

Transactions

原子操作多个 KV 或 Catalog 操作:

PUT /txn
[
  {"KV": {"Verb": "set", "Key": "key1", "Value": "dGVzdA=="}},
  {"KV": {"Verb": "get", "Key": "key2"}},
  {"Service": {"Verb": "register", "Service": {...}}}
]

支持的 Verb:

  • KV: set, get, delete, check-index, lock, unlock
  • Service: register, deregister

Blocking Queries

使用 indexwait 实现长轮询:

# 等待 key 变化
GET /kv/my-key?index=100
GET /kv/my-key?wait=5m&index=100

响应头 X-Consul-Index 返回当前索引。

Error Handling

常见 HTTP 状态码:

  • 200 - 成功
  • 404 - 资源不存在
  • 400 - 请求格式错误
  • 403 - ACL 权限不足
  • 500 - 服务器错误

响应头:

  • X-Consul-Index - 当前状态索引
  • X-Consul-KnownLeader - 是否有已知 leader
  • X-Consul-LastContact - 最后联系 leader 的时间
  • X-Consul-Default-ACL-Policy - 默认 ACL 策略

References

For detailed API specifications, see:

Usage Guidance
This is a documentation-only skill describing the Consul HTTP API. It is internally consistent, but note: many of the shown endpoints (ACL bootstrap, token creation, service deregistration) are powerful and require appropriate Consul tokens — only provide such tokens to trusted code or users. The skill itself does not request credentials, so if you plan to use it interactively or have an agent perform calls, ensure the agent is only given least-privilege Consul tokens and that network access is limited to the intended Consul cluster (avoid exposing tokens to untrusted networks or agents).
Capability Analysis
Type: OpenClaw Skill Name: consul-api Version: 1.0.0 The consul-api skill bundle provides a comprehensive guide for an AI agent to interact with the HashiCorp Consul HTTP API. It includes instructions for service discovery, KV store operations, health checks, and ACL management. The content in SKILL.md and references/api-reference.md consists of standard API documentation and examples using curl against a local Consul agent (127.0.0.1:8500). There is no evidence of malicious intent, data exfiltration, or prompt injection.
Capability Assessment
Purpose & Capability
The name/description match the content: the SKILL.md and api-reference provide Consul HTTP API endpoints and examples. There are no unrelated environment variables, binaries, or installs requested that would be unexpected for a Consul API helper.
Instruction Scope
The instructions are a reference/specification and only show example HTTP endpoints and curl headers (X-Consul-Token / Authorization). They do not direct the agent to read local files, access unrelated services, or exfiltrate data. The doc includes administrative endpoints (ACL, bootstrap, deregister) which are legitimately part of Consul's API.
Install Mechanism
No install spec and no code files — this is instruction-only, so nothing will be fetched or written to disk during install. Lowest-risk install posture.
Credentials
The skill declares no required environment variables or credentials. The documentation shows how Consul tokens are used (X-Consul-Token / Bearer) but does not request or store any credentials itself. This is proportionate for an API reference.
Persistence & Privilege
always:false and no install actions; the skill does not request persistent privileges or modify other skills. Autonomous invocation is allowed (platform default) but is not combined with any other elevated privileges here.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install consul-api
  3. After installation, invoke the skill by name or use /consul-api
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release - HTTP API reference for Consul service discovery, KV store, health checks, and service mesh
Metadata
Slug consul-api
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Consul API?

Consul HTTP API operations for service discovery, key-value store, health checks, and service mesh management. Use when working with Consul clusters for: (1)... It is an AI Agent Skill for Claude Code / OpenClaw, with 112 downloads so far.

How do I install Consul API?

Run "/install consul-api" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Consul API free?

Yes, Consul API is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Consul API support?

Consul API is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Consul API?

It is built and maintained by JonasGao (@jonasgao); the current version is v1.0.0.

💬 Comments