Loading...
Loading...
Compare original and translation side by side
templates/scripts/sdk/cp -r ~/.claude/skills/ts-agent-sdk/templates/* ./scripts/sdk/templates/scripts/sdk/cp -r ~/.claude/skills/ts-agent-sdk/templates/* ./scripts/sdk/src/server/modules/mcp*/server.tsserver.tool(
'tool_name',
'Tool description',
zodInputSchema,
async (params) => { ... }
)src/server/modules/mcp*/server.tsserver.tool(
'tool_name',
'Tool description',
zodInputSchema,
async (params) => { ... }
)// From: z.object({ name: z.string(), email: z.string().email() })
// To:
export interface CreateEnquiryInput {
name: string;
email: string;
}// 原代码:z.object({ name: z.string(), email: z.string().email() })
// 转换后:
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/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);
}
// ... 每个工具对应一个方法
}
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/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.tsexport { docs } from './docs';
export { enquiries } from './enquiries';scripts/sdk/index.tsexport { 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.tsproject/
└── 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| Variable | Description | Default |
|---|---|---|
| Execution mode: 'local', 'remote', 'auto' | 'auto' |
| Target Worker URL | http://localhost:8787 |
| Bearer token for auth | (none) |
| 变量名 | 描述 | 默认值 |
|---|---|---|
| 执行模式:'local'、'remote'、'auto' | 'auto' |
| 目标Worker URL | http://localhost:8787 |
| 用于认证的Bearer令牌 | (无) |
SDK_API_TOKEN="your-token" SDK_BASE_URL="https://app.workers.dev" npx tsx scripts/sdk/examples/create-doc.tsSDK_API_TOKEN="your-token" SDK_BASE_URL="https://app.workers.dev" npx tsx scripts/sdk/examples/create-doc.tsAuthErrorValidationErrorNotFoundErrorRateLimitErrorMCPErrorNetworkErrorAuthErrorValidationErrorNotFoundErrorRateLimitErrorMCPErrorNetworkErrorsrc/server/modules/mcp*/server.tssrc/server/modules/mcp*/server.ts