// src/tools/api.ts
import axios from 'axios';
export const apiTools: Anthropic.Tool[] = [
{
name: "get_user",
description: "Get user details by ID",
input_schema: {
type: "object",
properties: {
user_id: { type: "string" }
},
required: ["user_id"]
}
},
{
name: "create_ticket",
description: "Create a support ticket",
input_schema: {
type: "object",
properties: {
subject: { type: "string" },
description: { type: "string" },
priority: { type: "string", enum: ["low", "medium", "high"] }
},
required: ["subject", "description"]
}
}
];
const api = axios.create({
baseURL: 'https://api.example.com',
headers: { 'Authorization': `Bearer ${process.env.API_TOKEN}` }
});
export async function executeApiTool(name: string, input: any): Promise<string> {
switch (name) {
case "get_user":
const user = await api.get(`/users/${input.user_id}`);
return JSON.stringify(user.data);
case "create_ticket":
const ticket = await api.post('/tickets', input);
return `Created ticket #${ticket.data.id}`;
default:
throw new Error(`Unknown tool: ${name}`);
}
}