@clawnet/template-minimal 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/skills/claude-agent-sdk/.claude-plugin/plugin.json +13 -0
- package/.agents/skills/claude-agent-sdk/SKILL.md +954 -0
- package/.agents/skills/claude-agent-sdk/references/mcp-servers-guide.md +387 -0
- package/.agents/skills/claude-agent-sdk/references/permissions-guide.md +429 -0
- package/.agents/skills/claude-agent-sdk/references/query-api-reference.md +437 -0
- package/.agents/skills/claude-agent-sdk/references/session-management.md +419 -0
- package/.agents/skills/claude-agent-sdk/references/subagents-patterns.md +464 -0
- package/.agents/skills/claude-agent-sdk/references/top-errors.md +503 -0
- package/.agents/skills/claude-agent-sdk/rules/claude-agent-sdk.md +96 -0
- package/.agents/skills/claude-agent-sdk/scripts/check-versions.sh +55 -0
- package/.agents/skills/claude-agent-sdk/templates/basic-query.ts +55 -0
- package/.agents/skills/claude-agent-sdk/templates/custom-mcp-server.ts +161 -0
- package/.agents/skills/claude-agent-sdk/templates/error-handling.ts +283 -0
- package/.agents/skills/claude-agent-sdk/templates/filesystem-settings.ts +211 -0
- package/.agents/skills/claude-agent-sdk/templates/multi-agent-workflow.ts +318 -0
- package/.agents/skills/claude-agent-sdk/templates/package.json +30 -0
- package/.agents/skills/claude-agent-sdk/templates/permission-control.ts +211 -0
- package/.agents/skills/claude-agent-sdk/templates/query-with-tools.ts +54 -0
- package/.agents/skills/claude-agent-sdk/templates/session-management.ts +151 -0
- package/.agents/skills/claude-agent-sdk/templates/subagents-orchestration.ts +166 -0
- package/.agents/skills/claude-agent-sdk/templates/tsconfig.json +22 -0
- package/.claude/settings.local.json +70 -0
- package/.claude/skills/moltbook-example/SKILL.md +79 -0
- package/.claude/skills/post/SKILL.md +130 -0
- package/.env.example +4 -0
- package/.vercel/README.txt +11 -0
- package/.vercel/project.json +1 -0
- package/AGENTS.md +114 -0
- package/CLAUDE.md +532 -0
- package/README.md +44 -0
- package/api/index.ts +3 -0
- package/biome.json +14 -0
- package/clark_avatar.jpeg +0 -0
- package/package.json +21 -0
- package/scripts/wake.ts +38 -0
- package/skills/clawbook/HEARTBEAT.md +142 -0
- package/skills/clawbook/SKILL.md +219 -0
- package/skills/moltbook-example/SKILL.md +79 -0
- package/skills/moltbook-example/bot/index.ts +61 -0
- package/src/agent/prompts.ts +98 -0
- package/src/agent/runner.ts +526 -0
- package/src/agent/tool-definitions.ts +1151 -0
- package/src/agent-options.ts +14 -0
- package/src/bot-identity.ts +41 -0
- package/src/constants.ts +15 -0
- package/src/handlers/heartbeat.ts +21 -0
- package/src/handlers/openai-compat.ts +95 -0
- package/src/handlers/post.ts +21 -0
- package/src/identity.ts +83 -0
- package/src/index.ts +30 -0
- package/src/middleware/cron-auth.ts +53 -0
- package/src/middleware/sigma-auth.ts +147 -0
- package/src/runs.ts +49 -0
- package/tests/agent/prompts.test.ts +172 -0
- package/tests/agent/runner.test.ts +353 -0
- package/tests/agent/tool-definitions.test.ts +171 -0
- package/tests/constants.test.ts +24 -0
- package/tests/handlers/openai-compat.test.ts +128 -0
- package/tests/handlers.test.ts +133 -0
- package/tests/identity.test.ts +66 -0
- package/tests/index.test.ts +108 -0
- package/tests/middleware/cron-auth.test.ts +99 -0
- package/tests/middleware/sigma-auth.test.ts +198 -0
- package/tests/runs.test.ts +56 -0
- package/tests/skill.test.ts +71 -0
- package/tsconfig.json +14 -0
- package/vercel.json +9 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
# MCP Servers Guide
|
|
2
|
+
|
|
3
|
+
Complete guide to creating and using Model Context Protocol (MCP) servers with Claude Agent SDK.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## What Are MCP Servers?
|
|
8
|
+
|
|
9
|
+
MCP servers extend agent capabilities with custom tools. Think of them as plugins that give your agent new abilities.
|
|
10
|
+
|
|
11
|
+
**Use Cases**:
|
|
12
|
+
- Database access
|
|
13
|
+
- API integrations
|
|
14
|
+
- Custom calculations
|
|
15
|
+
- External service interactions
|
|
16
|
+
- File system operations
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Creating In-Process MCP Servers
|
|
21
|
+
|
|
22
|
+
### Basic Server
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { createSdkMcpServer, tool } from "@anthropic-ai/claude-agent-sdk";
|
|
26
|
+
import { z } from "zod";
|
|
27
|
+
|
|
28
|
+
const myServer = createSdkMcpServer({
|
|
29
|
+
name: "my-service",
|
|
30
|
+
version: "1.0.0",
|
|
31
|
+
tools: [
|
|
32
|
+
tool(
|
|
33
|
+
"tool_name",
|
|
34
|
+
"Tool description",
|
|
35
|
+
{ /* Zod schema */ },
|
|
36
|
+
async (args) => {
|
|
37
|
+
// Implementation
|
|
38
|
+
return {
|
|
39
|
+
content: [{ type: "text", text: "Result" }]
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Tool Definition Pattern
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
tool(
|
|
51
|
+
name: string, // Tool identifier
|
|
52
|
+
description: string, // What it does
|
|
53
|
+
inputSchema: ZodSchema, // Input validation
|
|
54
|
+
handler: Handler // Implementation
|
|
55
|
+
)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Zod Schemas
|
|
61
|
+
|
|
62
|
+
### Common Patterns
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { z } from "zod";
|
|
66
|
+
|
|
67
|
+
// String
|
|
68
|
+
z.string()
|
|
69
|
+
z.string().email()
|
|
70
|
+
z.string().url()
|
|
71
|
+
z.string().min(5).max(100)
|
|
72
|
+
z.string().describe("Description for AI")
|
|
73
|
+
|
|
74
|
+
// Number
|
|
75
|
+
z.number()
|
|
76
|
+
z.number().int()
|
|
77
|
+
z.number().positive()
|
|
78
|
+
z.number().min(0).max(100)
|
|
79
|
+
|
|
80
|
+
// Boolean
|
|
81
|
+
z.boolean()
|
|
82
|
+
z.boolean().default(false)
|
|
83
|
+
|
|
84
|
+
// Enum
|
|
85
|
+
z.enum(["option1", "option2", "option3"])
|
|
86
|
+
z.union([z.literal("a"), z.literal("b")])
|
|
87
|
+
|
|
88
|
+
// Optional
|
|
89
|
+
z.string().optional()
|
|
90
|
+
z.number().default(10)
|
|
91
|
+
|
|
92
|
+
// Object
|
|
93
|
+
z.object({
|
|
94
|
+
name: z.string(),
|
|
95
|
+
age: z.number(),
|
|
96
|
+
email: z.string().email().optional()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// Array
|
|
100
|
+
z.array(z.string())
|
|
101
|
+
z.array(z.number()).min(1).max(10)
|
|
102
|
+
|
|
103
|
+
// Complex nested
|
|
104
|
+
z.object({
|
|
105
|
+
user: z.object({
|
|
106
|
+
id: z.string().uuid(),
|
|
107
|
+
name: z.string(),
|
|
108
|
+
roles: z.array(z.enum(["admin", "user", "guest"]))
|
|
109
|
+
}),
|
|
110
|
+
metadata: z.record(z.any()).optional()
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Best Practices
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// ✅ Good: Clear descriptions
|
|
118
|
+
{
|
|
119
|
+
location: z.string().describe("City name or coordinates (e.g., 'San Francisco, CA')"),
|
|
120
|
+
radius: z.number().min(1).max(100).describe("Search radius in kilometers")
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ❌ Bad: No descriptions
|
|
124
|
+
{
|
|
125
|
+
location: z.string(),
|
|
126
|
+
radius: z.number()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ✅ Good: Validation constraints
|
|
130
|
+
{
|
|
131
|
+
email: z.string().email(),
|
|
132
|
+
age: z.number().int().min(0).max(120),
|
|
133
|
+
role: z.enum(["admin", "user", "guest"])
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ❌ Bad: No validation
|
|
137
|
+
{
|
|
138
|
+
email: z.string(),
|
|
139
|
+
age: z.number(),
|
|
140
|
+
role: z.string()
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Handler Implementation
|
|
147
|
+
|
|
148
|
+
### Success Response
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
async (args) => {
|
|
152
|
+
const result = await performOperation(args);
|
|
153
|
+
return {
|
|
154
|
+
content: [{
|
|
155
|
+
type: "text",
|
|
156
|
+
text: JSON.stringify(result, null, 2)
|
|
157
|
+
}]
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Error Response
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
async (args) => {
|
|
166
|
+
try {
|
|
167
|
+
const result = await riskyOperation(args);
|
|
168
|
+
return {
|
|
169
|
+
content: [{ type: "text", text: result }]
|
|
170
|
+
};
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return {
|
|
173
|
+
content: [{
|
|
174
|
+
type: "text",
|
|
175
|
+
text: `Error: ${error.message}`
|
|
176
|
+
}],
|
|
177
|
+
isError: true // Mark as error
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Complete Examples
|
|
186
|
+
|
|
187
|
+
### Weather Service
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
const weatherServer = createSdkMcpServer({
|
|
191
|
+
name: "weather",
|
|
192
|
+
version: "1.0.0",
|
|
193
|
+
tools: [
|
|
194
|
+
tool(
|
|
195
|
+
"get_weather",
|
|
196
|
+
"Get current weather for a location",
|
|
197
|
+
{
|
|
198
|
+
location: z.string().describe("City name"),
|
|
199
|
+
units: z.enum(["celsius", "fahrenheit"]).default("celsius")
|
|
200
|
+
},
|
|
201
|
+
async (args) => {
|
|
202
|
+
const response = await fetch(
|
|
203
|
+
`https://api.weather.com/v1/current?location=${args.location}&units=${args.units}`
|
|
204
|
+
);
|
|
205
|
+
const data = await response.json();
|
|
206
|
+
return {
|
|
207
|
+
content: [{
|
|
208
|
+
type: "text",
|
|
209
|
+
text: `Temp: ${data.temp}° ${args.units}\nConditions: ${data.conditions}`
|
|
210
|
+
}]
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
),
|
|
214
|
+
tool(
|
|
215
|
+
"get_forecast",
|
|
216
|
+
"Get 7-day forecast",
|
|
217
|
+
{
|
|
218
|
+
location: z.string(),
|
|
219
|
+
days: z.number().min(1).max(7).default(7)
|
|
220
|
+
},
|
|
221
|
+
async (args) => {
|
|
222
|
+
const forecast = await fetchForecast(args.location, args.days);
|
|
223
|
+
return {
|
|
224
|
+
content: [{ type: "text", text: JSON.stringify(forecast, null, 2) }]
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
)
|
|
228
|
+
]
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Database Service
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
const databaseServer = createSdkMcpServer({
|
|
236
|
+
name: "database",
|
|
237
|
+
version: "1.0.0",
|
|
238
|
+
tools: [
|
|
239
|
+
tool(
|
|
240
|
+
"query",
|
|
241
|
+
"Execute SQL query",
|
|
242
|
+
{
|
|
243
|
+
sql: z.string().describe("SQL query to execute"),
|
|
244
|
+
params: z.array(z.any()).optional().describe("Query parameters")
|
|
245
|
+
},
|
|
246
|
+
async (args) => {
|
|
247
|
+
try {
|
|
248
|
+
const results = await db.query(args.sql, args.params);
|
|
249
|
+
return {
|
|
250
|
+
content: [{ type: "text", text: JSON.stringify(results, null, 2) }]
|
|
251
|
+
};
|
|
252
|
+
} catch (error) {
|
|
253
|
+
return {
|
|
254
|
+
content: [{ type: "text", text: `SQL Error: ${error.message}` }],
|
|
255
|
+
isError: true
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
)
|
|
260
|
+
]
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Using MCP Servers
|
|
267
|
+
|
|
268
|
+
### In Query Options
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
const response = query({
|
|
272
|
+
prompt: "What's the weather in NYC?",
|
|
273
|
+
options: {
|
|
274
|
+
mcpServers: {
|
|
275
|
+
"weather": weatherServer,
|
|
276
|
+
"database": databaseServer
|
|
277
|
+
},
|
|
278
|
+
allowedTools: [
|
|
279
|
+
"mcp__weather__get_weather",
|
|
280
|
+
"mcp__database__query"
|
|
281
|
+
]
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Tool Naming Convention
|
|
287
|
+
|
|
288
|
+
**Format**: `mcp__<server-name>__<tool-name>`
|
|
289
|
+
|
|
290
|
+
Examples:
|
|
291
|
+
- `mcp__weather__get_weather`
|
|
292
|
+
- `mcp__database__query`
|
|
293
|
+
- `mcp__filesystem__read_file`
|
|
294
|
+
|
|
295
|
+
**CRITICAL**: Server and tool names must match exactly.
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## External MCP Servers
|
|
300
|
+
|
|
301
|
+
### Stdio Servers
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
options: {
|
|
305
|
+
mcpServers: {
|
|
306
|
+
"filesystem": {
|
|
307
|
+
command: "npx",
|
|
308
|
+
args: ["@modelcontextprotocol/server-filesystem"],
|
|
309
|
+
env: {
|
|
310
|
+
ALLOWED_PATHS: "/path/to/allowed/dir"
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### HTTP/SSE Servers
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
options: {
|
|
321
|
+
mcpServers: {
|
|
322
|
+
"remote": {
|
|
323
|
+
url: "https://api.example.com/mcp",
|
|
324
|
+
headers: {
|
|
325
|
+
"Authorization": "Bearer token",
|
|
326
|
+
"Content-Type": "application/json"
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## Best Practices
|
|
336
|
+
|
|
337
|
+
### ✅ Do
|
|
338
|
+
|
|
339
|
+
- Use clear tool names and descriptions
|
|
340
|
+
- Add `.describe()` to all Zod fields
|
|
341
|
+
- Implement error handling in handlers
|
|
342
|
+
- Validate inputs with Zod constraints
|
|
343
|
+
- Return clear, formatted responses
|
|
344
|
+
- Test tools independently before integration
|
|
345
|
+
- Use unique tool names across servers
|
|
346
|
+
- Version your servers
|
|
347
|
+
|
|
348
|
+
### ❌ Don't
|
|
349
|
+
|
|
350
|
+
- Use generic names like "process" or "run"
|
|
351
|
+
- Skip input validation
|
|
352
|
+
- Return raw error objects
|
|
353
|
+
- Forget `isError: true` on errors
|
|
354
|
+
- Use duplicate tool names
|
|
355
|
+
- Expose sensitive operations without checks
|
|
356
|
+
- Skip testing in isolation
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## Troubleshooting
|
|
361
|
+
|
|
362
|
+
### Tool Not Found
|
|
363
|
+
|
|
364
|
+
**Problem**: `"Tool mcp__server__tool not found"`
|
|
365
|
+
|
|
366
|
+
**Solution**:
|
|
367
|
+
1. Check server name matches
|
|
368
|
+
2. Check tool name matches
|
|
369
|
+
3. Include in `allowedTools` array
|
|
370
|
+
4. Verify server added to `mcpServers`
|
|
371
|
+
|
|
372
|
+
### Tool Name Collision
|
|
373
|
+
|
|
374
|
+
**Problem**: Two tools with same name
|
|
375
|
+
|
|
376
|
+
**Solution**: Use unique names or prefix with server name
|
|
377
|
+
|
|
378
|
+
### Validation Errors
|
|
379
|
+
|
|
380
|
+
**Problem**: Invalid input to tool
|
|
381
|
+
|
|
382
|
+
**Solution**: Add descriptive Zod schemas with constraints
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
**For more details**: See SKILL.md
|
|
387
|
+
**Official MCP docs**: https://modelcontextprotocol.io/
|