AgentTrust

AgentTrust is a pure MCP-only reputation and trust scoring server for AI agents.

AgentTrust

AgentTrust is a pure MCP-only reputation and trust scoring server for AI agents. It provides cryptographically-signed trust scores, interaction history, dispute resolution, and issuance attestation all via the Model Context Protocol. No REST API.

Quick Start

cp .env.example .env
uv sync
docker compose up -d postgres redis
uv run alembic upgrade head
uv run python scripts/generate_keypair.py   # first time only
uv run python scripts/register_scopes.py   # register trust.* scopes in AgentAuth

# Run server (stdio — for local testing with MCP Inspector)
uv run python -m agent_trust.server

# Run server (Streamable HTTP — for remote agents)
uv run python -m agent_trust.server --transport streamable-http --port 8000

# Run background workers (score recomputation, decay, expiry)
uv run python scripts/run_worker.py

# Test with MCP Inspector
uv run mcp dev src/agent_trust/server.py

Architecture

AgentTrust is a pure MCP server — all functionality is exposed as MCP tools, resources, and prompts. There are no HTTP endpoints beyond the MCP transport itself.

AI Agent
   │  (MCP client)
   ▼
AgentTrust MCP Server
   ├── Tools (actions)
   ├── Resources (read-only data)
   └── Prompts (LLM reasoning templates)
   │
   ├── PostgreSQL + TimescaleDB  (interactions, scores, disputes, attestations)
   ├── Redis                     (score cache, introspection cache, rate limits)
   ├── arq workers               (score recomputation, decay refresh, expiry)
   └── AgentAuth MCP             (token introspection, RBAC, trust levels)
        (agentauth.radi.pro/mcp)

Key design decisions:

  • All interactions are immutable append-only events
  • Scores are recomputed asynchronously via arq workers
  • AgentTrust connects to AgentAuth as an MCP client — dogfooding MCP-first philosophy
  • Token introspection results cached in Redis (SHA-256 key, TTL = min(token_expiry, 300s))
  • Attestations are portable Ed25519-signed JWTs

MCP Tools

Agent Management

ToolScope RequiredDescription
register_agentnoneRegister a new agent and get an agent_id
link_agentauthnoneLink an AgentAuth token to an existing agent
whoaminoneGet your own agent identity
get_agent_profilenoneGet public profile for any agent
search_agentsnoneSearch agents by name or description

Trust Scoring

ToolScope RequiredDescription
check_trustnone (optional auth)Get trust score for an agent
get_score_breakdowntrust.readDetailed score factor breakdown
compare_agentsnoneRank up to 10 agents by trust score

Interactions

ToolScope RequiredDescription
report_interactiontrust.reportSubmit an interaction report
get_interaction_historytrust.readGet interaction history for an agent

Disputes

ToolScope RequiredDescription
file_disputetrust.dispute.fileFile a dispute about an interaction
resolve_disputetrust.dispute.resolve + AgentAuth RBACResolve a dispute (arbitrators only)

Attestations

ToolScope RequiredDescription
issue_attestationtrust.attest.issueIssue a signed trust attestation
verify_attestationnoneVerify an attestation JWT

Safety & Admin

ToolScope RequiredDescription
sybil_checknoneRun sybil detection checks (ring/multi-hop reporting, burst registration across 1h/24h/7d windows, reporting velocity, delegation chain)
subscribe_alertstrust.adminSubscribe to score change notifications

MCP Resources

URIDescription
trust://agents/{id}/scoreCurrent trust scores for an agent
trust://agents/{id}/historyInteraction history
trust://agents/{id}/attestationsActive attestations
trust://leaderboard/{score_type}Top agents by score type
trust://disputes/{id}Dispute details
trust://healthServer health and connectivity

MCP Prompts

PromptDescription
evaluate_counterpartySystematic PROCEED/CAUTION/DECLINE trust assessment
explain_score_changeDiagnostic investigation of score changes
dispute_assessmentStructured arbitrator guide for evidence-based resolution

Score Algorithm

AgentTrust uses a Bayesian Beta distribution model:

  • Prior: α=2, β=2 → new agents start at 0.5 with low confidence
  • Time decay: weight = 0.5 ^ (age_days / half_life_days) (default half-life: 90 days)
  • Reporter credibility: (0.5 + reporter_trust × 0.5) × trust_level_weight × sybil_multiplier × interaction_count_penalty
  • Trust level weights: root=1.2×, delegated=1.0×, standalone=0.8×, ephemeral=0.7× — derived from auth_source/agentauth_linked, never from user-supplied metadata
  • Sybil multiplier: 0.3× (high risk), 0.6× (suspicious), 1.0× (clean) — via SybilDetector
  • New-reporter gate: interaction_count_penalty = 0.3 for reporters with < 3 recorded interactions
  • Mutual confirmation bonus: max(1.5 - 0.1 × (pair_count - 1), 1.0) — diminishing returns per pair (1st: 1.5×, 6th+: 1.0×)
  • Upheld dispute penalty: max(1.0 - n_upheld × 0.03, 0.50) (floor: 0.50)
  • Dismissed dispute penalty (filer): exponential max(1.0 - Σ(0.01 × 1.5ⁱ), 0.90) — floor reached at ~5–6 dismissals
  • Confidence: 1.0 - 1.0 / (1.0 + n × 0.1)

For a detailed walkthrough including role-aware scoring, Sybil detection, and worked examples, see docs/interaction-scoring.md.

Environment Variables

VariableDefaultDescription
DATABASE_URLPostgreSQL connection string (postgres+asyncpg://...)
REDIS_URLredis://localhost:6379/0Redis connection string
SIGNING_KEY_PATHkeys/signing_key.pemPath to Ed25519 private key
AUTH_PROVIDERbothagentauth | standalone | both
AGENTAUTH_MCP_URLhttps://agentauth.radi.pro/mcpAgentAuth MCP endpoint
AGENTAUTH_ACCESS_TOKENBearer token for AgentAuth MCP calls
SCORE_HALF_LIFE_DAYS90Score decay half-life in days
DISPUTE_PENALTY0.03Per-upheld-dispute score penalty
DISPUTE_FILER_DAILY_CAP10Max new disputes a single agent may file within any 24-hour window
DISPUTE_FILER_OPEN_CAP30Max open disputes a single agent may hold simultaneously across all targets
ATTESTATION_TTL_HOURS12Default attestation validity period
ATTESTATION_CUMULATIVE_REVOCATION_THRESHOLD0.10Cumulative score drop from attestation issuance score that triggers revocation
MCP_TRANSPORTstdiostdio | streamable-http
MCP_PORT8000Port for streamable-http transport
ENVIRONMENTdevelopmentdevelopment | production — binds to 0.0.0.0 in production (required when running behind a reverse proxy such as a Cloudflare tunnel)
LOG_LEVELINFOLogging level
JSON_LOGSfalseJSON log format (set true in production)
METRICS_ENABLEDtrueExpose /metrics Prometheus endpoint (streamable-http only)
SYBIL_BURST_24H_THRESHOLD20Agents registered in the same ±12-hour window to trigger medium Sybil alert
SYBIL_BURST_7D_THRESHOLD50Agents registered in the same ±84-hour window to trigger slow Sybil alert
SYBIL_REPORT_VELOCITY_THRESHOLD50Distinct negative reports by one agent in 24 hours to trigger velocity signal

Monitoring

AgentTrust exposes a Prometheus /metrics endpoint when running with streamable-http transport. The docker-compose stack includes Prometheus and Grafana with a pre-provisioned dashboard.

Metrics

MetricTypeLabelsDescription
agent_trust_tool_calls_totalCountertool_name, statusTotal MCP tool invocations (status: success | error)
agent_trust_tool_duration_secondsHistogramtool_nameEnd-to-end tool call latency
agent_trust_tool_errors_totalCountertool_name, error_typeTool errors by exception class

Access

URLService
http://localhost:3001Grafana (admin / $GRAFANA_PASSWORD)
http://localhost:9090Prometheus
http://localhost:8140/metricsRaw scrape endpoint

The Grafana dashboard (AgentTrust — MCP Tool Usage) is auto-provisioned and shows total calls, error rate, per-tool call rate, latency percentiles (p50/p95/p99), and an error breakdown table.

Set METRICS_ENABLED=false to disable the /metrics endpoint.

Rate Limits

Per-agent sliding window (60 seconds):

Trust LevelRequests/min
root300
delegated120
standalone60
ephemeral30
Unauthenticated10

Testing

# Run the full test suite
uv run pytest

# Quick summary (no verbose output)
uv run pytest --tb=short -q

# Run a specific test suite
uv run pytest tests/test_engine/ -v        # score algorithm (Bayesian model, decay, penalties)
uv run pytest tests/test_auth/ -v          # auth layer (AgentAuth, standalone Ed25519)
uv run pytest tests/test_tools/ -v         # MCP tool unit tests (all 15 tools)
uv run pytest tests/test_integration/ -v   # MCP protocol-level integration tests

# MCP protocol integration tests only (68 tests, no DB/Redis required)
uv run pytest tests/test_integration/test_mcp_protocol.py -v

# Run a single test class or test
uv run pytest tests/test_integration/test_mcp_protocol.py::TestRegisterAgentMCP -v
uv run pytest tests/test_tools/test_agent_tools.py::test_register_agent_standalone -v

# Show coverage
uv run pytest --cov=agent_trust --cov-report=term-missing

The MCP protocol integration tests (test_mcp_protocol.py) use an in-process MCP client/server pair — no running database or Redis instance is required. All external dependencies are mocked per-test.

Development

# Install dependencies
uv sync --extra dev

# Lint and format
uv run ruff check src/
uv run ruff format src/

# Create a new migration
uv run alembic revision --autogenerate -m "description"

# Seed test agents
uv run python scripts/seed_test_agents.py

CI/CD

Two GitHub Actions workflows automate testing and deployment.

CI (ci.yml)

Runs on every push and pull request:

  1. Starts PostgreSQL 16 (TimescaleDB) and Redis 7 as services
  2. Installs dependencies via uv sync
  3. Generates a signing keypair and runs Alembic migrations
  4. Lint: ruff check src/
  5. Format check: ruff format --check src/
  6. Tests: pytest --tb=short -q

CD (deploy.yml)

Triggers automatically when CI passes on main. Connects via SSH to the Hetzner server and runs:

git pull origin main
docker compose build
docker compose run --rm agent-trust uv run alembic upgrade head
docker compose up -d

The server is exposed to the internet via a Cloudflare tunnel running on the Hetzner host — no CI changes needed for routing.

Required GitHub Secrets

SecretDescription
HETZNER_HOSTServer IP or hostname
HETZNER_USERSSH username
HETZNER_SSH_KEYPrivate SSH key (PEM format)
HETZNER_APP_DIRAbsolute app path on server (e.g. /opt/agent-trust)

Deployment

For manual or first-time deployment:

# Full stack with docker compose (includes Prometheus + Grafana)
docker compose up -d

# Run migrations on first deploy
docker compose run --rm agent-trust uv run alembic upgrade head

# Generate signing keypair (first time only)
docker compose exec agent-trust uv run python scripts/generate_keypair.py

संबंधित सर्वर