Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Townhall Control Plane

Townhall is the HTTP control plane for Tinytown. It exposes all Tinytown operations via REST API and MCP (Model Context Protocol), enabling remote management from web clients, mobile apps, and AI tools.

Quick Start

# Start townhall daemon (REST API on port 8787)
townhall

# With verbose logging
townhall --verbose

# Custom port
townhall rest --port 9000

# For a specific town
townhall --town /path/to/project

Modes

Townhall supports three modes:

ModeCommandTransportUse Case
REST APItownhall restHTTP/JSONWeb/mobile clients, scripts
MCP stdiotownhall mcp-stdiostdin/stdoutIDE extensions, Claude Desktop
MCP HTTPtownhall mcp-httpHTTP/SSEBrowser MCP clients

REST API (Default)

townhall rest --bind 127.0.0.1 --port 8787

All CLI operations are available as HTTP endpoints:

# Get status
curl http://localhost:8787/v1/status

# List agents
curl http://localhost:8787/v1/agents

# Spawn agent
curl -X POST http://localhost:8787/v1/agents \
  -H "Content-Type: application/json" \
  -d '{"name": "worker-1", "cli": "claude"}'

# Assign task
curl -X POST http://localhost:8787/v1/tasks/assign \
  -H "Content-Type: application/json" \
  -d '{"agent": "worker-1", "task": "Fix the bug"}'

MCP Mode

For AI tool integration (Claude Desktop, VS Code, etc.):

# stdio transport (for Claude Desktop)
townhall mcp-stdio

# HTTP/SSE transport (for web clients)
townhall mcp-http --port 8788

See MCP Interface for detailed MCP documentation.

API Reference

Endpoints

EndpointMethodScopeDescription
/healthzGETpublicHealth check
/v1/townGETtown.readGet town info
/v1/statusGETtown.readGet full status
/v1/agentsGETtown.readList agents
/v1/agentsPOSTagent.manageSpawn agent
/v1/agents/{agent}/killPOSTagent.manageStop agent
/v1/agents/{agent}/restartPOSTagent.manageRestart agent
/v1/agents/prunePOSTagent.managePrune dead agents
/v1/tasks/assignPOSTtown.writeAssign task
/v1/tasks/pendingGETtown.readList pending tasks
/v1/backlogGETtown.readList backlog
/v1/backlogPOSTtown.writeAdd to backlog
/v1/backlog/{task_id}/claimPOSTtown.writeClaim backlog task
/v1/backlog/assign-allPOSTtown.writeAssign all backlog
/v1/backlog/{task_id}DELETEtown.writeRemove backlog task
/v1/messages/sendPOSTtown.writeSend message
/v1/agents/{agent}/inboxGETtown.readGet inbox
/v1/recoverPOSTagent.manageRecover orphaned agents
/v1/reclaimPOSTagent.manageReclaim tasks

See the OpenAPI spec for complete API documentation.

Error Handling

Errors follow RFC 7807 Problem Details:

{
  "type": "https://tinytown.dev/errors/404",
  "title": "Not Found",
  "status": 404,
  "detail": "Agent 'worker-99' not found"
}

Configuration

Configure townhall in tinytown.toml:

[townhall]
bind = "127.0.0.1"      # Bind address (default: 127.0.0.1)
rest_port = 8787        # REST API port (default: 8787)
request_timeout_ms = 30000  # Request timeout (default: 30s)

For production deployments, enable Authentication:

[townhall.auth]
mode = "api_key"
api_key_hash = "$argon2id$v=19$..."  # Use: tt generate-api-key

Security

Startup Safety Rules

Townhall enforces security by default:

  1. Non-loopback binding requires authentication - Cannot bind to 0.0.0.0 with auth.mode = "none"
  2. Warnings for API key on non-loopback - Recommends OIDC for production
  3. TLS/mTLS validation - Fails fast on invalid certificate configuration

Best Practices

  • Use 127.0.0.1 for local development
  • Enable API key or OIDC authentication for any network exposure
  • Enable TLS for production deployments
  • Use mTLS for service-to-service communication