鱼皮AI导航
鱼皮AI导航
  • 主页
  • 社区
  • AI工具
  • AI知识库
  • AI提示词
  • MCP
  • Skills
  • AI学习资源
  • AI资讯
  • GitHub开源
登录/注册

ts-agent-sdk

为 AI代理提供面向 MCP 服务器的强类型 TypeScript SDK 生成能力,自动将工具定义转换为带完整类型声明的客户端方法、接口和可执行示例脚本,支持本地开发与远程调用双模式,并内置标准化错误处理和模块化组织结构。

生活方式
访问 GitHub
文档Skills.MD
name
ts-agent-sdk
description
Generate typed TypeScript SDKs for AI agents to interact with MCP servers. Converts JSON-RPC curl commands to clean function calls. Auto-generates types, client methods, and example scripts from MCP tool definitions. Use when building MCP-enabled applications, need typed programmatic access to MCP tools, or creating reusable agent automation scripts.
user-invocabletrue

ts-agent-sdk

Overview

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.

Template Location

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:

▼
bash
复制代码
cp -r ~/.claude/skills/ts-agent-sdk/templates/* ./scripts/sdk/

SDK Generation Workflow

Step 1: Detect MCP Servers

Scan the project for MCP server modules:

▼
text
复制代码
src/server/modules/mcp*/server.ts

Each server.ts file contains tool definitions using the pattern:

▼
typescript
复制代码
server.tool( 'tool_name', 'Tool description', zodInputSchema, async (params) => { ... } )

Step 2: Extract Tool Definitions

For each tool, extract:

  1. name: The tool identifier (e.g., 'create_document')
  2. description: Tool description for JSDoc
  3. inputSchema: Zod schema defining input parameters
  4. endpoint: The MCP endpoint path (e.g., '/api/mcp-docs/message')

Step 3: Generate TypeScript Interfaces

Convert Zod schemas to TypeScript interfaces:

▼
typescript
复制代码
// From: z.object({ name: z.string(), email: z.string().email() }) // To: export interface CreateEnquiryInput { name: string; email: string; }

Step 4: Generate Module Client

Create a client class with methods for each tool:

▼
typescript
复制代码
// 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();

Step 5: Generate Example Scripts

Create runnable examples in scripts/sdk/examples/:

▼
typescript
复制代码
#!/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);

Step 6: Update Index Exports

Add module exports to scripts/sdk/index.ts:

▼
typescript
复制代码
export { docs } from './docs'; export { enquiries } from './enquiries';

Output Structure

▼
text
复制代码
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

Environment Variables

The SDK uses these environment variables:

VariableDescriptionDefault
SDK_MODEExecution mode: 'local', 'remote', 'auto''auto'
SDK_BASE_URLTarget Worker URLhttp://localhost:8787
SDK_API_TOKENBearer token for auth(none)

Execution

Run generated scripts with:

▼
bash
复制代码
SDK_API_TOKEN="your-token" SDK_BASE_URL="https://app.workers.dev" npx tsx scripts/sdk/examples/create-doc.ts

Naming Conventions

  • Module names: Lowercase, from MCP server name (e.g., 'mcp-docs' → 'docs')
  • Method names: camelCase from tool name (e.g., 'create_document' → 'createDocument')
  • Type names: PascalCase (e.g., 'CreateDocumentInput', 'CreateDocumentOutput')

Error Handling

The SDK provides typed errors:

  • AuthError - 401, invalid token
  • ValidationError - Invalid input
  • NotFoundError - Resource not found
  • RateLimitError - 429, too many requests
  • MCPError - MCP protocol errors
  • NetworkError - Connection failures

Regeneration

When MCP tools change, regenerate the SDK:

  1. Re-scan src/server/modules/mcp*/server.ts
  2. Update types.ts with new/changed schemas
  3. Update client.ts with new/changed methods
  4. Preserve any custom code in examples/
生活方式

快捷安装

复制到终端去安装 Skill

npxskillsaddjezweb/claude-skills--skill"ts-agent-sdk"
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
站长:程序员鱼皮 老鱼简历 商务合作 增值电信业务经营许可证
2026 鱼皮AI导航 | 沪ICP备19026706号-6
🔥热门工具
朱雀AI检测朱雀AI检测
朱雀AI检测助手朱雀AI检测助手
LovartLovart
老鱼简历老鱼简历
WritePass官网WritePass官网
面多多面多多
CursorCursor
星月写作星月写作
朱雀AI检测助手朱雀AI检测助手
零感AI零感AI
Skills 推荐
explicit-identity
在跨进程或异步边界时确保身份可追溯,通过全程显式传递唯一标识符(如 UUID)来避免依赖隐式状态或“最新”概念引发的竞争条件,严格区分不同语义的 ID 类型并各自独立管理。
sympy
提供符号数学计算能力,支持代数方程求解、微积分运算、表达式化简、符号矩阵运算、物理建模、数论分析、几何推导及公式转代码等功能,适用于需要精确解析解而非数值近似的所有数学场景。
secret-scanner
自动识别和检测代码或配置文件中可能泄露的敏感信息,如密钥、令牌、密码等,并提供修复建议与安全配置方案,支持开发流程中的早期风险防控。
propositional-logic
通过形式化方法分析命题逻辑结构,利用真值表枚举、自然演绎推理与语义 tableau 构造判断公式性质,实现对可满足性、永真性及逻辑蕴涵的系统性判定,适用于数学逻辑中的命题推理问题求解。
chinese-writing
掌握现代简体中文内容创作的核心方法,专注于生成温暖自然、清晰易读的周刊、博客与科技资讯类文章,强调以读者为中心的表达、简洁有力的句式、合理的结构排版及中英文混排规范,适用于需要专业语感与传播效果的内容生产场景。