Edge / CDN · Zero-Cold-Start Edge

Serving /.well-known/* Agent Discovery Endpoints on Cloudflare Workers & Pages

Deploy /.well-known/agent-card.json, /.well-known/mcp/server.json, and /.well-known/oauth-protected-resource on Cloudflare Workers and Cloudflare Pages with strict JSON MIME types and CORS.

Manifest Parameters

Zero Telemetry · Strict CSP
Authentication & OAuth Scopes
A2A Agent Card (v0.3) Options
Exact Well-Known Endpoint URL application/json
https://agent.example.com/.well-known/agent-card.json
/.well-known/agent-card.json
{
  "protocolVersion": "0.3.0",
  "name": "Acme Cloud Assistant",
  "description": "Autonomous API diagnostics, billing lookups, and workflow execution via A2A and MCP.",
  "url": "https://agent.example.com/a2a",
  "preferredTransport": "JSONRPC",
  "version": "1.0.0",
  "provider": {
    "organization": "Acme Corp",
    "url": "https://agent.example.com"
  },
  "documentationUrl": "https://docs.example.com/agents",
  "capabilities": {
    "streaming": true,
    "pushNotifications": false,
    "stateTransitionHistory": true
  },
  "defaultInputModes": [
    "text/plain",
    "application/json"
  ],
  "defaultOutputModes": [
    "application/json",
    "text/plain"
  ],
  "securitySchemes": {
    "oauth2": {
      "type": "oauth2",
      "flows": {
        "authorizationCode": {
          "authorizationUrl": "https://auth.example.com/oauth/authorize",
          "tokenUrl": "https://auth.example.com/oauth/token",
          "scopes": {
            "agent:invoke": "Authorize agent:invoke access",
            "mcp:tools": "Authorize mcp:tools access",
            "mcp:read": "Authorize mcp:read access"
          }
        }
      }
    }
  },
  "security": [
    {
      "oauth2": [
        "agent:invoke",
        "mcp:tools",
        "mcp:read"
      ]
    }
  ],
  "skills": [
    {
      "id": "diagnose-api",
      "name": "Diagnose API Errors",
      "description": "Inspect trace IDs, rate limits, and webhook delivery status.",
      "tags": [
        "diagnostics",
        "support"
      ],
      "examples": [
        "Run Diagnose API Errors for the current workspace"
      ]
    },
    {
      "id": "lookup-usage",
      "name": "Query Account Usage",
      "description": "Return bounded billing-period token and quota usage metrics.",
      "tags": [
        "billing",
        "analytics"
      ],
      "examples": [
        "Run Query Account Usage for the current workspace"
      ]
    }
  ]
}
curl Verification Command
curl -fsSL -D - "https://agent.example.com/.well-known/agent-card.json" | head -n 40
HTTP 401 WWW-Authenticate Header (RFC 9728 / MCP-PRO-002)
WWW-Authenticate: Bearer resource_metadata="https://agent.example.com/.well-known/oauth-protected-resource", scope="agent:invoke mcp:tools mcp:read"
Live Well-Known Audit 98.4% Lack Agent Cards

Verify live A2A, MCP, OAuth & AEO discovery in production

In RungLab's N=140 B2B SaaS Readiness Benchmark, 98.4% (62/63) of full-telemetry domains lacked agent-card.json. Audit your live domain with ReadyCheck, cut MCP schema token tax with MCPDiet, or automate fleet discovery checks via Apify & RapidAPI.

Required Endpoints, Paths & MIME Types

Path / Endpoint Purpose Required Content-Type
public/.well-known/agent-card.json Static Cloudflare Pages asset path (copied to dist/.well-known/) application/json; charset=utf-8
dist/_headers Cloudflare Pages header rules forcing JSON MIME & CORS on extensionless RFC 9728 paths text/plain (edge config)

Cloudflare Worker Router for /.well-known/* + 401 Challenge

worker-well-known.ts
export interface Env {
  AGENT_ORIGIN: string;
}

const CORS_HEADERS = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Methods": "GET, HEAD, OPTIONS",
  "Access-Control-Allow-Headers": "Content-Type, Authorization",
  "Cache-Control": "public, max-age=300",
  "Content-Type": "application/json; charset=utf-8",
  "X-Content-Type-Options": "nosniff"
};

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const url = new URL(request.url);

    if (request.method === "OPTIONS" && url.pathname.startsWith("/.well-known/")) {
      return new Response(null, { status: 204, headers: CORS_HEADERS });
    }

    if (url.pathname === "/.well-known/oauth-protected-resource") {
      return Response.json(
        {
          resource: `${url.origin}/mcp`,
          authorization_servers: ["https://auth.example.com"],
          scopes_supported: ["mcp:read", "mcp:tools"],
          bearer_methods_supported: ["header"]
        },
        { headers: CORS_HEADERS }
      );
    }

    if (url.pathname === "/mcp" && !request.headers.get("Authorization")) {
      return new Response(JSON.stringify({ error: "unauthorized" }), {
        status: 401,
        headers: {
          "Content-Type": "application/json",
          "WWW-Authenticate": `Bearer resource_metadata="${url.origin}/.well-known/oauth-protected-resource", scope="mcp:read mcp:tools"`
        }
      });
    }

    return new Response("Not Found", { status: 404 });
  }
};

Cloudflare Pages dist/_headers for Static /.well-known/* Files

_headers
/.well-known/*
  Content-Type: application/json; charset=utf-8
  Access-Control-Allow-Origin: *
  Cache-Control: public, max-age=300
  X-Content-Type-Options: nosniff

Key Empirical & Architectural Takeaways

  • Cloudflare Pages serves static files inside dist/.well-known/* automatically without Workers billing, making static agent-card.json and server.json hosting $0/mo.
  • Extensionless files like /.well-known/oauth-protected-resource require an explicit Content-Type: application/json; charset=utf-8 rule in _headers or a Worker response header.
  • Always test with a non-browser User-Agent (curl) to ensure Cloudflare WAF / Bot Fight Mode does not challenge automated A2A or MCP OAuth discovery fetches.

Common Production Pitfalls to Avoid

  • SPA frameworks on Cloudflare Pages rewrite unknown routes to /index.html (200 OK) if a file is missing — verify /.well-known/* files exist in the final dist/ directory.
  • Setting Cache-Control: immutable on agent-card.json traps outdated skill or auth server URLs at the edge.
  • Forgetting OPTIONS preflight handling on dynamic Worker /.well-known/* routes blocks browser-based inspectors.

More Agent Discovery Specifications & Framework Guides

Backend Framework Route Handlers + Middleware

Next.js App Router /.well-known/* Route Handlers & Headers

Serve /.well-known/agent-card.json, /.well-known/mcp/server.json, and /.well-known/oauth-protected-resource cleanly in Next.js App Router without middleware auth redirects or trailing-slash loops.

← Back to AI Agent Discovery Generator & Validator Hub

Frequently Asked Questions

Does Cloudflare Pages serve dotfiles inside /.well-known/ by default?

Yes, Cloudflare Pages deploys files placed under dist/.well-known/ directly. Just ensure your build script copies public/.well-known/ into your output folder and sets Content-Type: application/json in _headers for extensionless files.

How do I prevent Cloudflare Bot Fight Mode from blocking agent discovery?

Add a Cloudflare WAF Skip / Custom Rule for URI Path starts with /.well-known/ (GET/HEAD/OPTIONS) so automated A2A, MCP, and ReadyCheck crawlers receive clean 200 JSON.

Can I combine _headers security rules with /.well-known/ CORS?

Yes — keep Cross-Origin-Resource-Policy: cross-origin (or omit restrictive CORP) specifically on /.well-known/* if third-party web inspectors read it, while keeping strict CSP and HSTS on /*.