返回顶部
c

clawdirect-devClawDirect开发

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/turtle, Express, SQLite, and ATXP.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
1,952
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

clawdirect-dev

ClawDirect-Dev

构建基于ATXP认证的面向代理的Web体验。

参考实现: https://github.com/napoleond/clawdirect

什么是ATXP?

ATXP(代理交易协议)使AI代理能够进行身份认证并为服务付费。在构建面向代理的网站时,ATXP提供:

  • - 代理身份:识别哪个代理正在发起请求
  • 支付:对高级操作收费(可选)
  • MCP集成:暴露代理可以编程调用的工具

完整ATXP详情:https://skills.sh/atxp-dev/cli/atxp

代理如何交互

代理通过两种方式与您的网站交互:

  1. 1. 浏览器:代理使用浏览器自动化工具访问您的网站、点击按钮、填写表单和导航——就像人类一样
  2. MCP工具:代理直接调用您的MCP端点进行编程操作(认证、支付等)

基于Cookie的认证模式连接了这两种方式:代理通过MCP获取认证Cookie,然后在浏览时使用它。

重要提示:代理浏览器通常无法直接设置HTTP-only Cookie。推荐模式是代理在查询字符串中传递Cookie值(例如,?myapp_cookie=XYZ),然后由服务器设置Cookie并重定向到干净的URL。

架构概览

┌──────────────────────────────────────────────────────────────────┐
│ AI代理 │
│ ┌─────────────────────┐ ┌─────────────────────────┐ │
│ │ 浏览器工具 │ │ MCP客户端 │ │
│ │ (访问网站) │ │ (调用工具) │ │
│ └─────────┬───────────┘ └───────────┬─────────────┘ │
└────────────┼─────────────────────────────────┼──────────────────┘
│ │
▼ ▼
┌────────────────────────────────────────────────────────────────┐
│ 您的应用程序 │
│ ┌─────────────────────┐ ┌─────────────────────────┐ │
│ │ Web服务器 │ │ MCP服务器 │ │
│ │ (Express) │ │ (@longrun/turtle) │ │
│ │ │ │ │ │
│ │ - 提供UI │ │ - yourapp_cookie │ │
│ │ - Cookie认证 │ │ - yourapp_action │ │
│ └─────────┬───────────┘ └───────────┬─────────────┘ │
│ │ │ │
│ └──────────┬─────────────────┘ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ SQLite │ │
│ │ auth_cookies │ │
│ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘

构建步骤

  1. 1. 创建MCP服务器,与您的网站并行
  2. 在MCP服务器中实现Cookie工具
  3. 在您的Web API中使用Cookie进行认证
  4. 为您的网站发布代理技能

步骤1:项目设置

使用所需技术栈初始化Node.js项目:

bash
mkdir my-agent-app && cd my-agent-app
npm init -y
npm install @longrun/turtle @atxp/server @atxp/express better-sqlite3 express cors dotenv zod
npm install -D typescript @types/node @types/express @types/cors @types/better-sqlite3 tsx

创建 tsconfig.json:
json
{
compilerOptions: {
target: ES2022,
module: NodeNext,
moduleResolution: NodeNext,
outDir: dist,
rootDir: src,
strict: true,
esModuleInterop: true,
skipLibCheck: true
},
include: [src//*]
}

创建 .env:

FUNDINGDESTINATIONATXP=<您的atxp账户>
PORT=3001

步骤2:带Cookie认证的数据库

创建 src/db.ts:

typescript
import Database from better-sqlite3;
import crypto from crypto;

const DBPATH = process.env.DBPATH || ./data.db;
let db: Database.Database;

export function getDb(): Database.Database {
if (!db) {
db = new Database(DB_PATH);
db.pragma(journal_mode = WAL);

// 认证Cookie表 - 将Cookie映射到ATXP账户
db.exec(
CREATE TABLE IF NOT EXISTS auth_cookies (
cookie_value TEXT PRIMARY KEY,
atxp_account TEXT NOT NULL,
createdat DATETIME DEFAULT CURRENTTIMESTAMP
)
);

// 在此添加您的应用表
}
return db;
}

export function createAuthCookie(atxpAccount: string): string {
const cookieValue = crypto.randomBytes(32).toString(hex);
getDb().prepare(
INSERT INTO authcookies (cookievalue, atxp_account)
VALUES (?, ?)
).run(cookieValue, atxpAccount);
return cookieValue;
}

export function getAtxpAccountFromCookie(cookieValue: string): string | null {
const result = getDb().prepare(
SELECT atxpaccount FROM authcookies WHERE cookie_value = ?
).get(cookieValue) as { atxp_account: string } | undefined;
return result?.atxp_account || null;
}

步骤3:带Cookie工具的MCP工具

创建 src/tools.ts:

typescript
import { defineTool } from @longrun/turtle;
import { z } from zod;
import { requirePayment, atxpAccountId } from @atxp/server;
import BigNumber from bignumber.js;
import { createAuthCookie } from ./db.js;

// Cookie工具 - 代理调用此工具获取浏览器认证
export const cookieTool = defineTool(
myapp_cookie, // 将myapp替换为您的应用名称
获取用于浏览器使用的认证Cookie。设置此Cookie以在使用Web界面时进行认证。,
z.object({}),
async () => {
// 免费但需要ATXP认证
const accountId = atxpAccountId();
if (!accountId) {
throw new Error(需要认证);
}

const cookie = createAuthCookie(accountId);

return JSON.stringify({
cookie,
instructions: 要在浏览器中认证,请导航到 https://your-domain.com?myappcookie=value> - 服务器将设置HTTP-only Cookie并重定向。或者,如果您的浏览器工具支持,可以直接设置Cookie。
});
}
);

// 示例付费工具
export const paidActionTool = defineTool(
myapp_action,
执行某个操作。费用:$0.10,
z.object({
input: z.string().describe(操作的输入)
}),
async ({ input }) => {
await requirePayment({ price: new BigNumber(0.10) });

const accountId = atxpAccountId();
if (!accountId) {
throw new Error(需要认证);
}

// 您的操作逻辑在此
return JSON.stringify({ success: true, input });
}
);

export const allTools = [cookieTool, paidActionTool];

步骤4:带Cookie验证的Express API

创建 src/api.ts:

typescript
import { Router, Request, Response } from express;
import { getAtxpAccountFromCookie } from ./db.js;

export const apiRouter = Router();

// 提取Cookie的辅助函数
function getCookieValue(req: Request, cookieName: string): string | null {
const cookieHeader = req.headers.cookie;
if (!cookieHeader) return null;

const cookies = cookieHeader.split(;).map(c => c.trim());
for (const cookie of cookies) {
if (cookie.startsWith(${cookieName}=)) {
return cookie.substring(cookieName.length + 1);
}
}
return null;
}

// 需要Cookie认证的中间件
function requireCookieAuth(req: Request, res: Response, next: Function) {
const cookieValue = getCookieValue(req, myapp_cookie);

if (!cookieValue) {
res.status(401).json({
error: 需要认证,
message: 使用myapp_cookie MCP工具获取认证Cookie
});
return;
}

const atxpAccount = getAtxpAccountFromCookie(cookieValue);
if (!atxpAccount) {
res.status(401).json({
error: 无效的Cookie,
message: 您的Cookie无效或已过期。请通过MCP工具获取新的Cookie。
});
return;
}

// 将账户附加到请求中供处理程序使用
(req as any).atxpAccount = atxpAccount;
next();
}

// 公共端点(无需认证)
api

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 clawdirect-dev-1776377932 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 clawdirect-dev-1776377932 技能

通过命令行安装

skillhub install clawdirect-dev-1776377932

下载

⬇ 下载 clawdirect-dev v1.0.0(免费)

文件大小: 5.83 KB | 发布时间: 2026-4-17 14:40

v1.0.0 最新 2026-4-17 14:40
ClawDirect-Dev v1.0.0

- Initial release providing templates and guidance for building agent-facing web apps with ATXP-based authentication.
- Supports cookie-based auth, MCP tool integration, and payment-enabled endpoints.
- Includes setup instructions for a Node.js stack using Express, @longrun/turtle, SQLite, and ATXP.
- Provides ready-to-use database code, agent authentication patterns, and examples for agent skill creation.
- Reference implementation and further documentation links included.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部