-
Notifications
You must be signed in to change notification settings - Fork 16
Agent Skill Server Discovery Guide
Rick Hightower edited this page Feb 1, 2026
·
2 revisions
Automatic discovery and management of Agent Brain instances.
Agent Brain writes connection details to .claude/doc-serve/runtime.json:
{
"schema_version": "1.0",
"mode": "project",
"project_root": "/path/to/project",
"instance_id": "a1b2c3d4e5f6",
"base_url": "http://127.0.0.1:54321",
"port": 54321,
"pid": 12345,
"started_at": "2026-01-28T10:30:00+00:00"
}| Field | Description |
|---|---|
base_url |
Server URL for API calls |
port |
Auto-assigned port number |
instance_id |
Unique instance identifier |
pid |
Process ID for health checks |
mode |
"project" (per-project) or "shared" |
-
Project Root Resolution:
git rev-parse --show-toplevelor marker files (.claude/,pyproject.toml) -
Runtime File Check: Look for
.claude/doc-serve/runtime.json -
Health Validation: Verify server via
/health/endpoint -
URL Extraction: Use
base_urlfor API calls
import json
import subprocess
from pathlib import Path
import urllib.request
def discover_server():
"""Discover a running Agent Brain instance for the current project.
Returns:
str: Server base URL if found and healthy, None otherwise.
"""
# Find project root
try:
result = subprocess.run(
["git", "rev-parse", "--show-toplevel"],
capture_output=True, text=True, check=True
)
project_root = Path(result.stdout.strip())
except subprocess.CalledProcessError:
project_root = Path.cwd()
# Check for runtime.json
runtime_path = project_root / ".claude" / "doc-serve" / "runtime.json"
if not runtime_path.exists():
return None
# Read and parse runtime state
try:
state = json.loads(runtime_path.read_text())
except json.JSONDecodeError:
return None
# Validate server is alive
base_url = state.get("base_url", "")
if not base_url:
return None
try:
req = urllib.request.Request(f"{base_url}/health/", method="GET")
with urllib.request.urlopen(req, timeout=3) as resp:
if resp.status == 200:
return base_url
except Exception:
pass
return None
def get_server_url():
"""Get server URL, starting server if needed.
Returns:
str: Server base URL.
"""
url = discover_server()
if url:
return url
# Start server and wait
subprocess.run(["agent-brain", "start", "--daemon"], check=True)
# Re-discover after startup
import time
for _ in range(10):
time.sleep(1)
url = discover_server()
if url:
return url
raise RuntimeError("Failed to start Agent Brain server")
# Usage
if __name__ == "__main__":
server_url = discover_server()
if server_url:
print(f"Connected to: {server_url}")
else:
print("No running server found - starting one...")
subprocess.run(["agent-brain", "start", "--daemon"])Multiple Claude agents in the same project share one instance:
-
First agent starts server:
agent-brain start --daemon -
Other agents discover via
runtime.json -
All agents use same
base_url - Any agent can stop when work complete
Lock file protocol prevents race conditions during concurrent startup attempts.
Error: No running Agent Brain instance found for this project
Solution: agent-brain start --daemon
Warning: Server not responding, cleaning up stale state
Solution: CLI auto-cleans stale files. Manual cleanup:
rm .claude/doc-serve/runtime.json
agent-brain start --daemonSolution: Use auto-port (default): agent-brain start --daemon
Lock file prevents double-start. If blocked, run agent-brain status to discover existing instance.
agent-brain status # Recommended
cat .claude/doc-serve/runtime.json | jq '.port' # Direct read
agent-brain list # All instancesexport DOC_SERVE_URL="http://127.0.0.1:8000"
agent-brain query "search term"- Design-Architecture-Overview
- Design-Query-Architecture
- Design-Storage-Architecture
- Design-Class-Diagrams
- GraphRAG-Guide
- Agent-Skill-Hybrid-Search-Guide
- Agent-Skill-Graph-Search-Guide
- Agent-Skill-Vector-Search-Guide
- Agent-Skill-BM25-Search-Guide
Search
Server
Setup
- Pluggable-Providers-Spec
- GraphRAG-Integration-Spec
- Agent-Brain-Plugin-Spec
- Multi-Instance-Architecture-Spec