Common issues and solutions when working with Claude Agent Template.
Symptoms:
- Agent cannot find or use your custom tool
- Error messages about missing tools
Solutions:
- Verify tool is exported from
lib/mcp-tools/your-tool.ts - Check it's imported in
lib/mcp-tools.ts - Ensure it's added to
allowedToolswithmcp__0__prefix inapp/api/agent/route.ts
Example:
// lib/mcp-tools/my-tool.ts
export const myTool = tool(...);
// lib/mcp-tools.ts
import { myTool } from "./mcp-tools/my-tool";
export const customMcpServer = createSdkMcpServer({
tools: [myTool],
});
// app/api/agent/route.ts
allowedTools: ["mcp__0__my-tool"],Symptoms:
- No real-time updates in the UI
- Messages appear all at once
- Console errors about EventSource
Solutions:
- Verify
Content-Type: text/event-streamheader is set - Check browser console for errors
- Ensure SSE format is correct:
data: {...}\n\n - Check network tab for proper streaming response
Debugging:
// Check response headers
const response = await fetch('/api/agent', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
});
console.log(response.headers.get('Content-Type')); // Should be 'text/event-stream'Symptoms:
- TypeScript errors in tool definitions
- Runtime errors when tool is called
- Zod validation failures
Solutions:
- Match Zod schemas to parameter types exactly
- Return correct structure:
{ content: [...] }or{ content: [...], isError: true } - Use proper type assertions:
type: "text" as const
Example:
// Correct
return {
content: [{
type: "text" as const, // Use 'as const'
text: "Result",
}],
};
// Incorrect
return {
content: [{
type: "text", // Missing 'as const'
text: "Result",
}],
};Symptoms:
- 401 Unauthorized errors
- "Missing API key" messages
- Agent cannot connect to Claude
Solutions:
- Verify
.envfile exists and containsANTHROPIC_API_KEY - Restart development server after changing
.env - Check
.envis not committed to git (should be in.gitignore) - Ensure no extra spaces around the API key
Example .env:
ANTHROPIC_API_KEY=sk-ant-api03-xxxxx
Symptoms:
- Long wait times for agent responses
- Timeout errors
- UI freezing
Solutions:
- Optimize tool implementations (reduce database queries, cache results)
- Reduce
maxTurnsif agent is taking too many steps - Use streaming to show progress incrementally
- Check network latency to Anthropic API
Symptoms:
- "Cannot connect to database" errors
- Timeout when querying data
- SSL/TLS errors
Solutions:
- Verify
DATABASE_URLin.envis correct - Check database is accessible from your network
- For SSL connections, add
?sslmode=requireto connection string - Run
npx prisma generateafter schema changes
Example connection string:
DATABASE_URL="postgresql://user:pass@host:5432/db?sslmode=require"
Symptoms:
pnpm buildfails- Type errors during build
- Module not found errors
Solutions:
- Run
pnpm installto ensure all dependencies are installed - Clear
.nextfolder:rm -rf .next - Check for TypeScript errors:
pnpm tsc --noEmit - Ensure all imports are correct and files exist
If you're still experiencing issues:
- Check the GitHub Issues
- Review Claude Agent SDK Documentation
- Verify your setup matches the Quick Start guide
- Check for updates:
pnpm update