ts-agent-sdk by jezweb/claude-skills
npx skills add https://github.com/jezweb/claude-skills --skill ts-agent-sdk此技能用于生成类型化的 TypeScript SDK,使 AI 代理(主要是 Claude Code)能够通过 MCP 服务器与 Web 应用程序交互。它用简洁的函数调用取代了冗长的 JSON-RPC curl 命令。
核心 SDK 模板文件随此技能打包在:templates/
将这些文件复制到目标项目的 scripts/sdk/ 目录作为起点:
cp -r ~/.claude/skills/ts-agent-sdk/templates/* ./scripts/sdk/
扫描项目中的 MCP 服务器模块:
src/server/modules/mcp*/server.ts
每个 server.ts 文件都包含使用以下模式定义的工具:
server.tool(
'tool_name',
'Tool description',
zodInputSchema,
async (params) => { ... }
)
为每个工具提取:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
将 Zod 模式转换为 TypeScript 接口:
// From: z.object({ name: z.string(), email: z.string().email() })
// To:
export interface CreateEnquiryInput {
name: string;
email: string;
}
为每个工具创建一个包含方法的客户端类:
// scripts/sdk/docs/client.ts
import { MCPClient, defaultClient } from '../client';
import type { CreateDocumentInput, CreateDocumentOutput } from './types';
const ENDPOINT = '/api/mcp-docs/message';
export class DocsClient {
private mcp: MCPClient;
constructor(client?: MCPClient) {
this.mcp = client || defaultClient;
}
async createDocument(input: CreateDocumentInput): Promise<CreateDocumentOutput> {
return this.mcp.callTool(ENDPOINT, 'create_document', input);
}
async listDocuments(input: ListDocumentsInput): Promise<ListDocumentsOutput> {
return this.mcp.callTool(ENDPOINT, 'list_documents', input);
}
// ... one method per tool
}
export const docs = new DocsClient();
在 scripts/sdk/examples/ 中创建可运行的示例:
#!/usr/bin/env npx tsx
// scripts/sdk/examples/create-doc.ts
import { docs } from '../';
async function main() {
const result = await docs.createDocument({
spaceId: 'wiki',
title: 'Getting Started',
content: '# Welcome\n\nThis is the intro.',
});
console.log(`Created document: ${result.document.id}`);
}
main().catch(console.error);
将模块导出添加到 scripts/sdk/index.ts:
export { docs } from './docs';
export { enquiries } from './enquiries';
project/
└── scripts/sdk/
├── index.ts # 主导出文件
├── config.ts # 环境配置
├── errors.ts # 错误类
├── client.ts # MCP 客户端
│
├── docs/ # 生成的模块
│ ├── types.ts # TypeScript 接口
│ ├── client.ts # 类型化方法
│ └── index.ts # 模块导出
│
├── enquiries/ # 另一个模块
│ ├── types.ts
│ ├── client.ts
│ └── index.ts
│
└── examples/ # 可运行脚本
├── create-doc.ts
├── list-spaces.ts
└── create-enquiry.ts
SDK 使用以下环境变量:
| 变量 | 描述 | 默认值 |
|---|---|---|
SDK_MODE | 执行模式:'local'、'remote'、'auto' | 'auto' |
SDK_BASE_URL | 目标 Worker URL | http://localhost:8787 |
SDK_API_TOKEN | 用于身份验证的 Bearer 令牌 | (无) |
使用以下命令运行生成的脚本:
SDK_API_TOKEN="your-token" SDK_BASE_URL="https://app.workers.dev" npx tsx scripts/sdk/examples/create-doc.ts
SDK 提供类型化的错误:
AuthError - 401,令牌无效ValidationError - 输入无效NotFoundError - 资源未找到RateLimitError - 429,请求过多MCPError - MCP 协议错误NetworkError - 连接失败当 MCP 工具发生变化时,重新生成 SDK:
src/server/modules/mcp*/server.ts周安装量
317
仓库
GitHub 星标数
652
首次出现
2026年1月20日
安全审计
安装于
claude-code264
gemini-cli211
opencode208
cursor200
antigravity196
codex182
This skill generates typed TypeScript SDKs that allow AI agents (primarily Claude Code) to interact with web applications via MCP servers. It replaces verbose JSON-RPC curl commands with clean function calls.
The core SDK template files are bundled with this skill at: templates/
Copy these files to the target project's scripts/sdk/ directory as a starting point:
cp -r ~/.claude/skills/ts-agent-sdk/templates/* ./scripts/sdk/
Scan the project for MCP server modules:
src/server/modules/mcp*/server.ts
Each server.ts file contains tool definitions using the pattern:
server.tool(
'tool_name',
'Tool description',
zodInputSchema,
async (params) => { ... }
)
For each tool, extract:
Convert Zod schemas to TypeScript interfaces:
// From: z.object({ name: z.string(), email: z.string().email() })
// To:
export interface CreateEnquiryInput {
name: string;
email: string;
}
Create a client class with methods for each tool:
// scripts/sdk/docs/client.ts
import { MCPClient, defaultClient } from '../client';
import type { CreateDocumentInput, CreateDocumentOutput } from './types';
const ENDPOINT = '/api/mcp-docs/message';
export class DocsClient {
private mcp: MCPClient;
constructor(client?: MCPClient) {
this.mcp = client || defaultClient;
}
async createDocument(input: CreateDocumentInput): Promise<CreateDocumentOutput> {
return this.mcp.callTool(ENDPOINT, 'create_document', input);
}
async listDocuments(input: ListDocumentsInput): Promise<ListDocumentsOutput> {
return this.mcp.callTool(ENDPOINT, 'list_documents', input);
}
// ... one method per tool
}
export const docs = new DocsClient();
Create runnable examples in scripts/sdk/examples/:
#!/usr/bin/env npx tsx
// scripts/sdk/examples/create-doc.ts
import { docs } from '../';
async function main() {
const result = await docs.createDocument({
spaceId: 'wiki',
title: 'Getting Started',
content: '# Welcome\n\nThis is the intro.',
});
console.log(`Created document: ${result.document.id}`);
}
main().catch(console.error);
Add module exports to scripts/sdk/index.ts:
export { docs } from './docs';
export { enquiries } from './enquiries';
project/
└── scripts/sdk/
├── index.ts # Main exports
├── config.ts # Environment config
├── errors.ts # Error classes
├── client.ts # MCP client
│
├── docs/ # Generated module
│ ├── types.ts # TypeScript interfaces
│ ├── client.ts # Typed methods
│ └── index.ts # Module exports
│
├── enquiries/ # Another module
│ ├── types.ts
│ ├── client.ts
│ └── index.ts
│
└── examples/ # Runnable scripts
├── create-doc.ts
├── list-spaces.ts
└── create-enquiry.ts
The SDK uses these environment variables:
| Variable | Description | Default |
|---|---|---|
SDK_MODE | Execution mode: 'local', 'remote', 'auto' | 'auto' |
SDK_BASE_URL | Target Worker URL | http://localhost:8787 |
SDK_API_TOKEN | Bearer token for auth | (none) |
Run generated scripts with:
SDK_API_TOKEN="your-token" SDK_BASE_URL="https://app.workers.dev" npx tsx scripts/sdk/examples/create-doc.ts
The SDK provides typed errors:
AuthError - 401, invalid tokenValidationError - Invalid inputNotFoundError - Resource not foundRateLimitError - 429, too many requestsMCPError - MCP protocol errorsNetworkError - Connection failuresWhen MCP tools change, regenerate the SDK:
src/server/modules/mcp*/server.tsWeekly Installs
317
Repository
GitHub Stars
652
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykWarn
Installed on
claude-code264
gemini-cli211
opencode208
cursor200
antigravity196
codex182
AI Elements:基于shadcn/ui的AI原生应用组件库,快速构建对话界面
54,900 周安装
Botchan:Base区块链智能体消息层,实现无需许可的链上通信
308 周安装
Worktrunk CLI 工具:高效管理 Git Worktree,自动化开发工作流
308 周安装
viem 集成指南:为 TypeScript/JavaScript 应用连接 EVM 区块链
308 周安装
Appwrite TypeScript SDK 使用指南 - 客户端与服务器端开发教程
309 周安装
React Native 棕地迁移指南:逐步集成到原生应用(Expo/裸RN)
309 周安装
best-minds:基于专家模拟的AI提问框架,提升LLM回答质量与专业性
309 周安装