[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EWTBX8QTPKAJWTZZJVKCDM":3,"skill-same:01M6EWTBX8QTPKAJWTZZJVKCDM":73},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":49,"ownerHtmlUrl":50,"ownerBlogUrl":6,"ownerDescription":51,"updatedAt":52,"install":53,"resources":66},"01M6EWTBX8QTPKAJWTZZJVKCDM","clawdirect-dev",null,"Build agent-facing web experiences with ATXP-based authentication, following the ClawDirect pattern. Use this skill when building websites that AI agents interact with via MCP tools, implementing cookie-based agent auth, or creating agent skills for web apps. Provides templates using @longrun\u002Fturtle, Express, SQLite, and ATXP.","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fnapoleond\u002Fclawdirect-dev\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"clawdirect dev","dev","creating agent skills","with","build agent","via","apps","express","pattern","atxp","build","MCP","use","sqlite","Tools","templates","authentication","auth","web","ai agents","2026-11-10 10:12:30",false,"---\nname: clawdirect-dev\ndescription: Build agent-facing web experiences with ATXP-based authentication, following the ClawDirect pattern. Use this skill when building websites that AI agents interact with via MCP tools, implementing cookie-based agent auth, or creating agent skills for web apps. Provides templates using @longrun\u002Fturtle, Express, SQLite, and ATXP.\n---\n\n# ClawDirect-Dev\n\nBuild agent-facing web experiences with ATXP-based authentication.\n\n**Reference implementation**: https:\u002F\u002Fgithub.com\u002Fnapoleond\u002Fclawdirect\n\n## What is ATXP?\n\nATXP (Agent Transaction Protocol) enables AI agents to authenticate and pay for services. When building agent-facing websites, ATXP provides:\n\n- **Agent identity**: Know which agent is making requests\n- **Payments**: Charge for premium actions (optional)\n- **MCP integration**: Expose tools that agents can call programmatically\n\nFor full ATXP details: https:\u002F\u002Fskills.sh\u002Fatxp-dev\u002Fcli\u002Fatxp\n\n## How Agents Interact\n\nAgents interact with your site in two ways:\n\n1. **Browser**: Agents use browser automation tools to visit your website, click buttons, fill forms, and navigate—just like humans do\n2. **MCP tools**: Agents call your MCP endpoints directly for programmatic actions (authentication, payments, etc.)\n\nThe cookie-based auth pattern bridges these: agents get an auth cookie via MCP, then use it while browsing.\n\n**Important**: Agent browsers often cannot set HTTP-only cookies directly. The recommended pattern is for agents to pass the cookie value in the query string (e.g., `?myapp_cookie=XYZ`), and have the server set the cookie and redirect to a clean URL.\n\n## Architecture Overview\n\n```\n┌──────────────────────────────────────────────────────────────────┐\n│                         AI Agent                                 │\n│  ┌─────────────────────┐         ┌─────────────────────────┐    │\n│  │   Browser Tool      │         │   MCP Client            │    │\n│  │   (visits website)  │         │   (calls tools)         │    │\n│  └─────────┬───────────┘         └───────────┬─────────────┘    │\n└────────────┼─────────────────────────────────┼──────────────────┘\n             │                                 │\n             ▼                                 ▼\n┌────────────────────────────────────────────────────────────────┐\n│                    Your Application                             │\n│  ┌─────────────────────┐    ┌─────────────────────────┐        │\n│  │   Web Server        │    │   MCP Server            │        │\n│  │   (Express)         │    │   (@longrun\u002Fturtle)     │        │\n│  │                     │    │                         │        │\n│  │   - Serves UI       │    │   - yourapp_cookie      │        │\n│  │   - Cookie auth     │    │   - yourapp_action      │        │\n│  └─────────┬───────────┘    └───────────┬─────────────┘        │\n│            │                            │                       │\n│            └──────────┬─────────────────┘                       │\n│                       ▼                                         │\n│              ┌─────────────────┐                                │\n│              │     SQLite      │                                │\n│              │   auth_cookies  │                                │\n│              └─────────────────┘                                │\n└─────────────────────────────────────────────────────────────────┘\n```\n\n## Build Steps\n\n1. **Create MCP server** alongside your website\n2. **Implement cookie tool** in the MCP server\n3. **Use cookie for auth** in your web API\n4. **Publish an agent skill** for your site\n\n## Step 1: Project Setup\n\nInitialize a Node.js project with the required stack:\n\n```bash\nmkdir my-agent-app && cd my-agent-app\nnpm init -y\nnpm install @longrun\u002Fturtle @atxp\u002Fserver @atxp\u002Fexpress better-sqlite3 express cors dotenv zod\nnpm install -D typescript @types\u002Fnode @types\u002Fexpress @types\u002Fcors @types\u002Fbetter-sqlite3 tsx\n```\n\nCreate `tsconfig.json`:\n```json\n{\n  \"compilerOptions\": {\n    \"target\": \"ES2022\",\n    \"module\": \"NodeNext\",\n    \"moduleResolution\": \"NodeNext\",\n    \"outDir\": \"dist\",\n    \"rootDir\": \"src\",\n    \"strict\": true,\n    \"esModuleInterop\": true,\n    \"skipLibCheck\": true\n  },\n  \"include\": [\"src\u002F**\u002F*\"]\n}\n```\n\nCreate `.env`:\n```\nFUNDING_DESTINATION_ATXP=\u003Cyour_atxp_account>\nPORT=3001\n```\n\n## Step 2: Database with Cookie Auth\n\nCreate `src\u002Fdb.ts`:\n\n```typescript\nimport Database from 'better-sqlite3';\nimport crypto from 'crypto';\n\nconst DB_PATH = process.env.DB_PATH || '.\u002Fdata.db';\nlet db: Database.Database;\n\nexport function getDb(): Database.Database {\n  if (!db) {\n    db = new Database(DB_PATH);\n    db.pragma('journal_mode = WAL');\n\n    \u002F\u002F Auth cookies table - maps cookies to ATXP accounts\n    db.exec(`\n      CREATE TABLE IF NOT EXISTS auth_cookies (\n        cookie_value TEXT PRIMARY KEY,\n        atxp_account TEXT NOT NULL,\n        created_at DATETIME DEFAULT CURRENT_TIMESTAMP\n      )\n    `);\n\n    \u002F\u002F Add your app's tables here\n  }\n  return db;\n}\n\nexport function createAuthCookie(atxpAccount: string): string {\n  const cookieValue = crypto.randomBytes(32).toString('hex');\n  getDb().prepare(`\n    INSERT INTO auth_cookies (cookie_value, atxp_account)\n    VALUES (?, ?)\n  `).run(cookieValue, atxpAccount);\n  return cookieValue;\n}\n\nexport function getAtxpAccountFromCookie(cookieValue: string): string | null {\n  const result = getDb().prepare(`\n    SELECT atxp_account FROM auth_cookies WHERE cookie_value = ?\n  `).get(cookieValue) as { atxp_account: string } | undefined;\n  return result?.atxp_account || null;\n}\n```\n\n## Step 3: MCP Tools with Cookie Tool\n\nCreate `src\u002Ftools.ts`:\n\n```typescript\nimport { defineTool } from '@longrun\u002Fturtle';\nimport { z } from 'zod';\nimport { requirePayment, atxpAccountId } from '@atxp\u002Fserver';\nimport BigNumber from 'bignumber.js';\nimport { createAuthCookie } from '.\u002Fdb.js';\n\n\u002F\u002F Cookie tool - agents call this to get browser auth\nexport const cookieTool = defineTool(\n  'myapp_cookie',  \u002F\u002F Replace 'myapp' with your app name\n  'Get an authentication cookie for browser use. Set this cookie to authenticate when using the web interface.',\n  z.object({}),\n  async () => {\n    \u002F\u002F Free but requires ATXP auth\n    const accountId = atxpAccountId();\n    if (!accountId) {\n      throw new Error('Authentication required');\n    }\n\n    const cookie = createAuthCookie(accountId);\n\n    return JSON.stringify({\n      cookie,\n      instructions: 'To authenticate in a browser, navigate to https:\u002F\u002Fyour-domain.com?myapp_cookie=\u003Ccookie_value> - the server will set the HTTP-only cookie and redirect. Alternatively, set the cookie directly if your browser tool supports it.'\n    });\n  }\n);\n\n\u002F\u002F Example paid tool\nexport const paidActionTool = defineTool(\n  'myapp_action',\n  'Perform some action. Cost: $0.10',\n  z.object({\n    input: z.string().describe('Input for the action')\n  }),\n  async ({ input }) => {\n    await requirePayment({ price: new BigNumber(0.10) });\n\n    const accountId = atxpAccountId();\n    if (!accountId) {\n      throw new Error('Authentication required');\n    }\n\n    \u002F\u002F Your action logic here\n    return JSON.stringify({ success: true, input });\n  }\n);\n\nexport const allTools = [cookieTool, paidActionTool];\n```\n\n## Step 4: Express API with Cookie Validation\n\nCreate `src\u002Fapi.ts`:\n\n```typescript\nimport { Router, Request, Response } from 'express';\nimport { getAtxpAccountFromCookie } from '.\u002Fdb.js';\n\nexport const apiRouter = Router();\n\n\u002F\u002F Helper to extract cookie\nfunction getCookieValue(req: Request, cookieName: string): string | null {\n  const cookieHeader = req.headers.cookie;\n  if (!cookieHeader) return null;\n\n  const cookies = cookieHeader.split(';').map(c => c.trim());\n  for (const cookie of cookies) {\n    if (cookie.startsWith(`${cookieName}=`)) {\n      return cookie.substring(cookieName.length + 1);\n    }\n  }\n  return null;\n}\n\n\u002F\u002F Middleware to require cookie auth\nfunction requireCookieAuth(req: Request, res: Response, next: Function) {\n  const cookieValue = getCookieValue(req, 'myapp_cookie');\n\n  if (!cookieValue) {\n    res.status(401).json({\n      error: 'Authentication required',\n      message: 'Use the myapp_cookie MCP tool to get an authentication cookie'\n    });\n    return;\n  }\n\n  const atxpAccount = getAtxpAccountFromCookie(cookieValue);\n  if (!atxpAccount) {\n    res.status(401).json({\n      error: 'Invalid cookie',\n      message: 'Your cookie is invalid or expired. Get a new one via the MCP tool.'\n    });\n    return;\n  }\n\n  \u002F\u002F Attach account to request for use in handlers\n  (req as any).atxpAccount = atxpAccount;\n  next();\n}\n\n\u002F\u002F Public endpoint (no auth)\napiRouter.get('\u002Fapi\u002Fpublic', (_req: Request, res: Response) => {\n  res.json({ message: 'Public data' });\n});\n\n\u002F\u002F Protected endpoint (requires cookie auth)\napiRouter.post('\u002Fapi\u002Fprotected', requireCookieAuth, (req: Request, res: Response) => {\n  const account = (req as any).atxpAccount;\n  res.json({ message: 'Authenticated action', account });\n});\n```\n\n## Step 5: Server Entry Point\n\nCreate `src\u002Findex.ts`:\n\n```typescript\nimport 'dotenv\u002Fconfig';\nimport express from 'express';\nimport cors from 'cors';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\nimport { createServer } from '@longrun\u002Fturtle';\nimport { atxpExpress } from '@atxp\u002Fexpress';\nimport { getDb } from '.\u002Fdb.js';\nimport { allTools } from '.\u002Ftools.js';\nimport { apiRouter } from '.\u002Fapi.js';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\nconst FUNDING_DESTINATION = process.env.FUNDING_DESTINATION_ATXP;\nif (!FUNDING_DESTINATION) {\n  throw new Error('FUNDING_DESTINATION_ATXP is required');\n}\n\nconst PORT = process.env.PORT ? parseInt(process.env.PORT) : 3001;\n\nasync function main() {\n  \u002F\u002F Initialize database\n  getDb();\n\n  \u002F\u002F Create MCP server\n  const mcpServer = createServer({\n    name: 'myapp',\n    version: '1.0.0',\n    tools: allTools\n  });\n\n  \u002F\u002F Create Express app\n  const app = express();\n  app.use(cors());\n  app.use(express.json());\n\n  \u002F\u002F Cookie bootstrap middleware - handles ?myapp_cookie=XYZ for agent browsers\n  \u002F\u002F Agent browsers often can't set HTTP-only cookies directly, so they pass the cookie\n  \u002F\u002F value in the query string and the server sets it, then redirects to clean URL\n  app.use((req, res, next) => {\n    const cookieValue = req.query.myapp_cookie;\n    if (typeof cookieValue === 'string' && cookieValue.length > 0) {\n      res.cookie('myapp_cookie', cookieValue, {\n        httpOnly: true,\n        secure: process.env.NODE_ENV === 'production',\n        sameSite: 'lax',\n        path: '\u002F',\n        maxAge: 30 * 24 * 60 * 60 * 1000 \u002F\u002F 30 days\n      });\n      const url = new URL(req.originalUrl, `http:\u002F\u002F${req.headers.host}`);\n      url.searchParams.delete('myapp_cookie');\n      res.redirect(302, url.pathname + url.search || '\u002F');\n      return;\n    }\n    next();\n  });\n\n  \u002F\u002F Mount MCP server with ATXP at \u002Fmcp\n  app.use('\u002Fmcp', atxpExpress({\n    fundingDestination: FUNDING_DESTINATION,\n    handler: mcpServer.handler\n  }));\n\n  \u002F\u002F Mount API routes\n  app.use(apiRouter);\n\n  \u002F\u002F Serve static frontend (if you have one)\n  app.use(express.static(join(__dirname, '..', 'public')));\n\n  app.listen(PORT, () => {\n    console.log(`Server running on port ${PORT}`);\n    console.log(`  - MCP endpoint: http:\u002F\u002Flocalhost:${PORT}\u002Fmcp`);\n    console.log(`  - API endpoint: http:\u002F\u002Flocalhost:${PORT}\u002Fapi`);\n  });\n}\n\nmain().catch(console.error);\n```\n\n## Step 6: Create Agent Skill\n\nCreate a skill for agents to interact with your app. Structure:\n\n```\nmy-skill\u002F\n└── SKILL.md\n```\n\n**SKILL.md template**:\n\n```markdown\n---\nname: myapp\ndescription: Interact with MyApp. Use this skill to [describe what agents can do]. Requires ATXP authentication.\n---\n\n# MyApp\n\n[Brief description] at **https:\u002F\u002Fyour-domain.com**\n\n## Quick Start\n\n1. Install ATXP: `npx skills add atxp-dev\u002Fcli --skill atxp`\n2. Call MCP tools: `npx atxp-call https:\u002F\u002Fyour-domain.com\u002Fmcp \u003Ctool> [params]`\n\n## Authentication\n\nGet a cookie for browser use:\n\n\\`\\`\\`bash\nnpx atxp-call https:\u002F\u002Fyour-domain.com\u002Fmcp myapp_cookie '{}'\n\\`\\`\\`\n\nIf using a browser, navigate with the cookie in the query string:\n\n\\`\\`\\`\nhttps:\u002F\u002Fyour-domain.com?myapp_cookie=\u003Ccookie_value>\n\\`\\`\\`\n\nThe server will set the HTTP-only cookie and redirect to clean the URL.\n\n**Alternative** (if your browser tool supports direct cookie setting):\n- **Cookie name**: `myapp_cookie`\n- **Cookie value**: Value from tool response\n- **Domain**: `your-domain.com`\n- **Path**: `\u002F`\n- **HttpOnly**: `true`\n\n## MCP Tools\n\n| Tool | Description | Cost |\n|------|-------------|------|\n| `myapp_cookie` | Get auth cookie | Free |\n| `myapp_action` | Perform action | $0.10 |\n\nFor ATXP details: https:\u002F\u002Fskills.sh\u002Fatxp-dev\u002Fcli\u002Fatxp\n```\n\n## Deployment\n\nThis generates a standard Node.js application deployable to any hosting service:\n\n- [Render](https:\u002F\u002Frender.com) - Easy Node.js hosting with persistent disks\n- [Railway](https:\u002F\u002Frailway.app) - Simple deployments from Git\n- [Fly.io](https:\u002F\u002Ffly.io) - Global edge deployment\n- [DigitalOcean App Platform](https:\u002F\u002Fwww.digitalocean.com\u002Fproducts\u002Fapp-platform)\n- [Heroku](https:\u002F\u002Fheroku.com)\n\nEnsure your hosting provides:\n- Node.js 18+ runtime\n- Persistent storage for SQLite (or switch to PostgreSQL)\n- Environment variable configuration\n\n## Reference\n\nFull working example: https:\u002F\u002Fgithub.com\u002Fnapoleond\u002Fclawdirect\n\nKey files to study:\n- `src\u002Ftools.ts` - MCP tool definitions with ATXP payments\n- `src\u002Fdb.ts` - Cookie auth database schema\n- `src\u002Fapi.ts` - Express routes with cookie validation\n- `src\u002Findex.ts` - Server setup with turtle + ATXP\n- `docs\u002Fagent-cookie-auth.md` - Auth pattern documentation\n\nFor ATXP authentication details: https:\u002F\u002Fskills.sh\u002Fatxp-dev\u002Fcli\u002Fatxp\n\n## Adding Your Project to ClawDirect\n\nWhen your agent-facing site is ready, add it to the ClawDirect directory at https:\u002F\u002Fclaw.direct so other agents can discover it.\n\n### Add a New Entry\n\n```bash\nnpx atxp-call https:\u002F\u002Fclaw.direct\u002Fmcp clawdirect_add '{\n  \"url\": \"https:\u002F\u002Fyour-site.com\",\n  \"name\": \"Your Site Name\",\n  \"description\": \"Brief description of what your site does for agents\",\n  \"thumbnail\": \"\u003Cbase64_encoded_image>\",\n  \"thumbnailMime\": \"image\u002Fpng\"\n}'\n```\n\n**Cost**: $0.50 USD\n\n**Parameters**:\n- `url` (required): Unique URL for the site\n- `name` (required): Display name (max 100 chars)\n- `description` (required): What the site does (max 500 chars)\n- `thumbnail` (required): Base64-encoded image\n- `thumbnailMime` (required): One of `image\u002Fpng`, `image\u002Fjpeg`, `image\u002Fgif`, `image\u002Fwebp`\n\n### Edit Your Entry\n\nEdit an entry you own:\n\n```bash\nnpx atxp-call https:\u002F\u002Fclaw.direct\u002Fmcp clawdirect_edit '{\n  \"url\": \"https:\u002F\u002Fyour-site.com\",\n  \"description\": \"Updated description\"\n}'\n```\n\n**Cost**: $0.10 USD\n\n**Parameters**:\n- `url` (required): URL of entry to edit (must be owner)\n- `description` (optional): New description\n- `thumbnail` (optional): New base64-encoded image\n- `thumbnailMime` (optional): New MIME type\n\n### Delete Your Entry\n\nDelete an entry you own:\n\n```bash\nnpx atxp-call https:\u002F\u002Fclaw.direct\u002Fmcp clawdirect_delete '{\n  \"url\": \"https:\u002F\u002Fyour-site.com\"\n}'\n```\n\n**Cost**: Free\n\n**Parameters**:\n- `url` (required): URL of entry to delete (must be owner)\n\n**Warning**: This action is irreversible.\n","# ClawDirect-Dev\n\nBuild agent-facing web experiences with ATXP-based authentication.\n\n**Reference implementation**: https:\u002F\u002Fgithub.com\u002Fnapoleond\u002Fclawdirect\n\n## What is ATXP?\n\nATXP (Agent Transaction Protocol) enables AI agents to authenticate and pay for services. When building agent-facing websites, ATXP provides:\n\n- **Agent identity**: Know which agent is making requests\n- **Payments**: Charge for premium actions (optional)\n- **MCP integration**: Expose tools that agents can call programmatically\n\nFor full ATXP details: https:\u002F\u002Fskills.sh\u002Fatxp-dev\u002Fcli\u002Fatxp\n\n## How Agents Interact\n\nAgents interact with your site in two ways:\n\n1. **Browser**: Agents use browser automation tools to visit your website, click buttons, fill forms, and navigate—just like humans do\n2. **MCP tools**: Agents call your MCP endpoints directly for programmatic actions (authentication, payments, etc.)\n\nThe cookie-based auth pattern bridges these: agents get an auth cookie via MCP, then use it while browsing.\n\n**Important**: Agent browsers often cannot set HTTP-only cookies directly. The recommended pattern is for agents to pass the cookie value in the query string (e.g., `?myapp_cookie=XYZ`), and have the server set the cookie and redirect to a clean URL.\n\n## Architecture Overview\n\n```\n┌──────────────────────────────────────────────────────────────────┐\n│                         AI Agent                                 │\n│  ┌─────────────────────┐         ┌─────────────────────────┐    │\n│  │   Browser Tool      │         │   MCP Client            │    │\n│  │   (visits website)  │         │   (calls tools)         │    │\n│  └─────────┬───────────┘         └───────────┬─────────────┘    │\n└────────────┼─────────────────────────────────┼──────────────────┘\n             │                                 │\n             ▼                                 ▼\n┌────────────────────────────────────────────────────────────────┐\n│                    Your Application                             │\n│  ┌─────────────────────┐    ┌─────────────────────────┐        │\n│  │   Web Server        │    │   MCP Server            │        │\n│  │   (Express)         │    │   (@longrun\u002Fturtle)     │        │\n│  │                     │    │                         │        │\n│  │   - Serves UI       │    │   - yourapp_cookie      │        │\n│  │   - Cookie auth     │    │   - yourapp_action      │        │\n│  └─────────┬───────────┘    └───────────┬─────────────┘        │\n│            │                            │                       │\n│            └──────────┬─────────────────┘                       │\n│                       ▼                                         │\n│              ┌─────────────────┐                                │\n│              │     SQLite      │                                │\n│              │   auth_cookies  │                                │\n│              └─────────────────┘                                │\n└─────────────────────────────────────────────────────────────────┘\n```\n\n## Build Steps\n\n1. **Create MCP server** alongside your website\n2. **Implement cookie tool** in the MCP server\n3. **Use cookie for auth** in your web API\n4. **Publish an agent skill** for your site\n\n## Step 1: Project Setup\n\nInitialize a Node.js project with the required stack:\n\n```bash\nmkdir my-agent-app && cd my-agent-app\nnpm init -y\nnpm install @longrun\u002Fturtle @atxp\u002Fserver @atxp\u002Fexpress better-sqlite3 express cors dotenv zod\nnpm install -D typescript @types\u002Fnode @types\u002Fexpress @types\u002Fcors @types\u002Fbetter-sqlite3 tsx\n```\n\nCreate `tsconfig.json`:\n```json\n{\n  \"compilerOptions\": {\n    \"target\": \"ES2022\",\n    \"module\": \"NodeNext\",\n    \"moduleResolution\": \"NodeNext\",\n    \"outDir\": \"dist\",\n    \"rootDir\": \"src\",\n    \"strict\": true,\n    \"esModuleInterop\": true,\n    \"skipLibCheck\": true\n  },\n  \"include\": [\"src\u002F**\u002F*\"]\n}\n```\n\nCreate `.env`:\n```\nFUNDING_DESTINATION_ATXP=\u003Cyour_atxp_account>\nPORT=3001\n```\n\n## Step 2: Database with Cookie Auth\n\nCreate `src\u002Fdb.ts`:\n\n```typescript\nimport Database from 'better-sqlite3';\nimport crypto from 'crypto';\n\nconst DB_PATH = process.env.DB_PATH || '.\u002Fdata.db';\nlet db: Database.Database;\n\nexport function getDb(): Database.Database {\n  if (!db) {\n    db = new Database(DB_PATH);\n    db.pragma('journal_mode = WAL');\n\n    \u002F\u002F Auth cookies table - maps cookies to ATXP accounts\n    db.exec(`\n      CREATE TABLE IF NOT EXISTS auth_cookies (\n        cookie_value TEXT PRIMARY KEY,\n        atxp_account TEXT NOT NULL,\n        created_at DATETIME DEFAULT CURRENT_TIMESTAMP\n      )\n    `);\n\n    \u002F\u002F Add your app's tables here\n  }\n  return db;\n}\n\nexport function createAuthCookie(atxpAccount: string): string {\n  const cookieValue = crypto.randomBytes(32).toString('hex');\n  getDb().prepare(`\n    INSERT INTO auth_cookies (cookie_value, atxp_account)\n    VALUES (?, ?)\n  `).run(cookieValue, atxpAccount);\n  return cookieValue;\n}\n\nexport function getAtxpAccountFromCookie(cookieValue: string): string | null {\n  const result = getDb().prepare(`\n    SELECT atxp_account FROM auth_cookies WHERE cookie_value = ?\n  `).get(cookieValue) as { atxp_account: string } | undefined;\n  return result?.atxp_account || null;\n}\n```\n\n## Step 3: MCP Tools with Cookie Tool\n\nCreate `src\u002Ftools.ts`:\n\n```typescript\nimport { defineTool } from '@longrun\u002Fturtle';\nimport { z } from 'zod';\nimport { requirePayment, atxpAccountId } from '@atxp\u002Fserver';\nimport BigNumber from 'bignumber.js';\nimport { createAuthCookie } from '.\u002Fdb.js';\n\n\u002F\u002F Cookie tool - agents call this to get browser auth\nexport const cookieTool = defineTool(\n  'myapp_cookie',  \u002F\u002F Replace 'myapp' with your app name\n  'Get an authentication cookie for browser use. Set this cookie to authenticate when using the web interface.',\n  z.object({}),\n  async () => {\n    \u002F\u002F Free but requires ATXP auth\n    const accountId = atxpAccountId();\n    if (!accountId) {\n      throw new Error('Authentication required');\n    }\n\n    const cookie = createAuthCookie(accountId);\n\n    return JSON.stringify({\n      cookie,\n      instructions: 'To authenticate in a browser, navigate to https:\u002F\u002Fyour-domain.com?myapp_cookie=\u003Ccookie_value> - the server will set the HTTP-only cookie and redirect. Alternatively, set the cookie directly if your browser tool supports it.'\n    });\n  }\n);\n\n\u002F\u002F Example paid tool\nexport const paidActionTool = defineTool(\n  'myapp_action',\n  'Perform some action. Cost: $0.10',\n  z.object({\n    input: z.string().describe('Input for the action')\n  }),\n  async ({ input }) => {\n    await requirePayment({ price: new BigNumber(0.10) });\n\n    const accountId = atxpAccountId();\n    if (!accountId) {\n      throw new Error('Authentication required');\n    }\n\n    \u002F\u002F Your action logic here\n    return JSON.stringify({ success: true, input });\n  }\n);\n\nexport const allTools = [cookieTool, paidActionTool];\n```\n\n## Step 4: Express API with Cookie Validation\n\nCreate `src\u002Fapi.ts`:\n\n```typescript\nimport { Router, Request, Response } from 'express';\nimport { getAtxpAccountFromCookie } from '.\u002Fdb.js';\n\nexport const apiRouter = Router();\n\n\u002F\u002F Helper to extract cookie\nfunction getCookieValue(req: Request, cookieName: string): string | null {\n  const cookieHeader = req.headers.cookie;\n  if (!cookieHeader) return null;\n\n  const cookies = cookieHeader.split(';').map(c => c.trim());\n  for (const cookie of cookies) {\n    if (cookie.startsWith(`${cookieName}=`)) {\n      return cookie.substring(cookieName.length + 1);\n    }\n  }\n  return null;\n}\n\n\u002F\u002F Middleware to require cookie auth\nfunction requireCookieAuth(req: Request, res: Response, next: Function) {\n  const cookieValue = getCookieValue(req, 'myapp_cookie');\n\n  if (!cookieValue) {\n    res.status(401).json({\n      error: 'Authentication required',\n      message: 'Use the myapp_cookie MCP tool to get an authentication cookie'\n    });\n    return;\n  }\n\n  const atxpAccount = getAtxpAccountFromCookie(cookieValue);\n  if (!atxpAccount) {\n    res.status(401).json({\n      error: 'Invalid cookie',\n      message: 'Your cookie is invalid or expired. Get a new one via the MCP tool.'\n    });\n    return;\n  }\n\n  \u002F\u002F Attach account to request for use in handlers\n  (req as any).atxpAccount = atxpAccount;\n  next();\n}\n\n\u002F\u002F Public endpoint (no auth)\napiRouter.get('\u002Fapi\u002Fpublic', (_req: Request, res: Response) => {\n  res.json({ message: 'Public data' });\n});\n\n\u002F\u002F Protected endpoint (requires cookie auth)\napiRouter.post('\u002Fapi\u002Fprotected', requireCookieAuth, (req: Request, res: Response) => {\n  const account = (req as any).atxpAccount;\n  res.json({ message: 'Authenticated action', account });\n});\n```\n\n## Step 5: Server Entry Point\n\nCreate `src\u002Findex.ts`:\n\n```typescript\nimport 'dotenv\u002Fconfig';\nimport express from 'express';\nimport cors from 'cors';\nimport { fileURLToPath } from 'url';\nimport { dirname, join } from 'path';\nimport { createServer } from '@longrun\u002Fturtle';\nimport { atxpExpress } from '@atxp\u002Fexpress';\nimport { getDb } from '.\u002Fdb.js';\nimport { allTools } from '.\u002Ftools.js';\nimport { apiRouter } from '.\u002Fapi.js';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = dirname(__filename);\n\nconst FUNDING_DESTINATION = process.env.FUNDING_DESTINATION_ATXP;\nif (!FUNDING_DESTINATION) {\n  throw new Error('FUNDING_DESTINATION_ATXP is required');\n}\n\nconst PORT = process.env.PORT ? parseInt(process.env.PORT) : 3001;\n\nasync function main() {\n  \u002F\u002F Initialize database\n  getDb();\n\n  \u002F\u002F Create MCP server\n  const mcpServer = createServer({\n    name: 'myapp',\n    version: '1.0.0',\n    tools: allTools\n  });\n\n  \u002F\u002F Create Express app\n  const app = express();\n  app.use(cors());\n  app.use(express.json());\n\n  \u002F\u002F Cookie bootstrap middleware - handles ?myapp_cookie=XYZ for agent browsers\n  \u002F\u002F Agent browsers often can't set HTTP-only cookies directly, so they pass the cookie\n  \u002F\u002F value in the query string and the server sets it, then redirects to clean URL\n  app.use((req, res, next) => {\n    const cookieValue = req.query.myapp_cookie;\n    if (typeof cookieValue === 'string' && cookieValue.length > 0) {\n      res.cookie('myapp_cookie', cookieValue, {\n        httpOnly: true,\n        secure: process.env.NODE_ENV === 'production',\n        sameSite: 'lax',\n        path: '\u002F',\n        maxAge: 30 * 24 * 60 * 60 * 1000 \u002F\u002F 30 days\n      });\n      const url = new URL(req.originalUrl, `http:\u002F\u002F${req.headers.host}`);\n      url.searchParams.delete('myapp_cookie');\n      res.redirect(302, url.pathname + url.search || '\u002F');\n      return;\n    }\n    next();\n  });\n\n  \u002F\u002F Mount MCP server with ATXP at \u002Fmcp\n  app.use('\u002Fmcp', atxpExpress({\n    fundingDestination: FUNDING_DESTINATION,\n    handler: mcpServer.handler\n  }));\n\n  \u002F\u002F Mount API routes\n  app.use(apiRouter);\n\n  \u002F\u002F Serve static frontend (if you have one)\n  app.use(express.static(join(__dirname, '..', 'public')));\n\n  app.listen(PORT, () => {\n    console.log(`Server running on port ${PORT}`);\n    console.log(`  - MCP endpoint: http:\u002F\u002Flocalhost:${PORT}\u002Fmcp`);\n    console.log(`  - API endpoint: http:\u002F\u002Flocalhost:${PORT}\u002Fapi`);\n  });\n}\n\nmain().catch(console.error);\n```\n\n## Step 6: Create Agent Skill\n\nCreate a skill for agents to interact with your app. Structure:\n\n```\nmy-skill\u002F\n└── SKILL.md\n```\n\n**SKILL.md template**:\n\n```markdown\n---\nname: myapp\ndescription: Interact with MyApp. Use this skill to [describe what agents can do]. Requires ATXP authentication.\n---\n\n# MyApp\n\n[Brief description] at **https:\u002F\u002Fyour-domain.com**\n\n## Quick Start\n\n1. Install ATXP: `npx skills add atxp-dev\u002Fcli --skill atxp`\n2. Call MCP tools: `npx atxp-call https:\u002F\u002Fyour-domain.com\u002Fmcp \u003Ctool> [params]`\n\n## Authentication\n\nGet a cookie for browser use:\n\n\\`\\`\\`bash\nnpx atxp-call https:\u002F\u002Fyour-domain.com\u002Fmcp myapp_cookie '{}'\n\\`\\`\\`\n\nIf using a browser, navigate with the cookie in the query string:\n\n\\`\\`\\`\nhttps:\u002F\u002Fyour-domain.com?myapp_cookie=\u003Ccookie_value>\n\\`\\`\\`\n\nThe server will set the HTTP-only cookie and redirect to clean the URL.\n\n**Alternative** (if your browser tool supports direct cookie setting):\n- **Cookie name**: `myapp_cookie`\n- **Cookie value**: Value from tool response\n- **Domain**: `your-domain.com`\n- **Path**: `\u002F`\n- **HttpOnly**: `true`\n\n## MCP Tools\n\n| Tool | Description | Cost |\n|------|-------------|------|\n| `myapp_cookie` | Get auth cookie | Free |\n| `myapp_action` | Perform action | $0.10 |\n\nFor ATXP details: https:\u002F\u002Fskills.sh\u002Fatxp-dev\u002Fcli\u002Fatxp\n```\n\n## Deployment\n\nThis generates a standard Node.js application deployable to any hosting service:\n\n- [Render](https:\u002F\u002Frender.com) - Easy Node.js hosting with persistent disks\n- [Railway](https:\u002F\u002Frailway.app) - Simple deployments from Git\n- [Fly.io](https:\u002F\u002Ffly.io) - Global edge deployment\n- [DigitalOcean App Platform](https:\u002F\u002Fwww.digitalocean.com\u002Fproducts\u002Fapp-platform)\n- [Heroku](https:\u002F\u002Fheroku.com)\n\nEnsure your hosting provides:\n- Node.js 18+ runtime\n- Persistent storage for SQLite (or switch to PostgreSQL)\n- Environment variable configuration\n\n## Reference\n\nFull working example: https:\u002F\u002Fgithub.com\u002Fnapoleond\u002Fclawdirect\n\nKey files to study:\n- `src\u002Ftools.ts` - MCP tool definitions with ATXP payments\n- `src\u002Fdb.ts` - Cookie auth database schema\n- `src\u002Fapi.ts` - Express routes with cookie validation\n- `src\u002Findex.ts` - Server setup with turtle + ATXP\n- `docs\u002Fagent-cookie-auth.md` - Auth pattern documentation\n\nFor ATXP authentication details: https:\u002F\u002Fskills.sh\u002Fatxp-dev\u002Fcli\u002Fatxp\n\n## Adding Your Project to ClawDirect\n\nWhen your agent-facing site is ready, add it to the ClawDirect directory at https:\u002F\u002Fclaw.direct so other agents can discover it.\n\n### Add a New Entry\n\n```bash\nnpx atxp-call https:\u002F\u002Fclaw.direct\u002Fmcp clawdirect_add '{\n  \"url\": \"https:\u002F\u002Fyour-site.com\",\n  \"name\": \"Your Site Name\",\n  \"description\": \"Brief description of what your site does for agents\",\n  \"thumbnail\": \"\u003Cbase64_encoded_image>\",\n  \"thumbnailMime\": \"image\u002Fpng\"\n}'\n```\n\n**Cost**: $0.50 USD\n\n**Parameters**:\n- `url` (required): Unique URL for the site\n- `name` (required): Display name (max 100 chars)\n- `description` (required): What the site does (max 500 chars)\n- `thumbnail` (required): Base64-encoded image\n- `thumbnailMime` (required): One of `image\u002Fpng`, `image\u002Fjpeg`, `image\u002Fgif`, `image\u002Fwebp`\n\n### Edit Your Entry\n\nEdit an entry you own:\n\n```bash\nnpx atxp-call https:\u002F\u002Fclaw.direct\u002Fmcp clawdirect_edit '{\n  \"url\": \"https:\u002F\u002Fyour-site.com\",\n  \"description\": \"Updated description\"\n}'\n```\n\n**Cost**: $0.10 USD\n\n**Parameters**:\n- `url` (required): URL of entry to edit (must be owner)\n- `description` (optional): New description\n- `thumbnail` (optional): New base64-encoded image\n- `thumbnailMime` (optional): New MIME type\n\n### Delete Your Entry\n\nDelete an entry you own:\n\n```bash\nnpx atxp-call https:\u002F\u002Fclaw.direct\u002Fmcp clawdirect_delete '{\n  \"url\": \"https:\u002F\u002Fyour-site.com\"\n}'\n```\n\n**Cost**: Free\n\n**Parameters**:\n- `url` (required): URL of entry to delete (must be owner)\n\n**Warning**: This action is irreversible.\n",{"name":5,"description":7},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002Fnapoleond\u002Fclawdirect-dev",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":54,"prompt":64,"zipAvailable":65},[55,58,61],{"tool":56,"command":57},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill clawdirect-dev",{"tool":59,"command":60},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill clawdirect-dev",{"tool":62,"command":63},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill clawdirect-dev","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fnapoleond\u002Fclawdirect-dev\u002FSKILL.md",true,[67],{"path":68,"resourceType":69,"resourceTypeDesc":70,"sizeBytes":71,"sourceHtmlUrl":72},"skill-report.json","REFERENCE","参考文档",34748,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fnapoleond\u002Fclawdirect-dev\u002Fskill-report.json",[74,83,91,99,105,111],{"skillNo":75,"name":76,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":39},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[80,81,82],"model","model hierarchy","model hierarchy skill",{"skillNo":84,"name":85,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":39},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[30,89,90],"zoom","zoom mcp",{"skillNo":92,"name":93,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":39},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[97,98,25,89],"sdk","zoom apps sdk",{"skillNo":100,"name":101,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":39},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[101],{"skillNo":106,"name":107,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":39},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[107],{"skillNo":112,"name":113,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":39},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[113]]