import { ApiClient } from './api-client.js';
const apiClient = new ApiClient();
/**
* Tool definitions for MCP server
*/
export const tools = [
{
name: 'create_city',
description: 'Create a new Italian city in the database',
inputSchema: {
type: 'object',
properties: {
nome: {
type: 'string',
description: 'Name of the Italian city to create',
},
},
required: ['nome'],
},
},
{
name: 'list_cities',
description: 'List all Italian cities in the database',
inputSchema: {
type: 'object',
properties: {},
},
},
{
name: 'get_city',
description: 'Get a specific Italian city by ID',
inputSchema: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'ID of the city to retrieve',
},
},
required: ['id'],
},
},
{
name: 'search_cities',
description: 'Search for Italian cities by name (supports fuzzy matching)',
inputSchema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Name or partial name of the city to search for',
},
},
required: ['name'],
},
},
{
name: 'update_city',
description: 'Update an existing Italian city name',
inputSchema: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'ID of the city to update',
},
nome: {
type: 'string',
description: 'New name for the city',
},
},
required: ['id', 'nome'],
},
},
{
name: 'delete_city',
description: 'Delete an Italian city from the database',
inputSchema: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'ID of the city to delete',
},
},
required: ['id'],
},
},
];
/**
* Tool handlers for MCP server
*/
export async function handleToolCall(name: string, args: any): Promise<any> {
try {
switch (name) {
case 'create_city': {
const city = await apiClient.createCity(args.nome);
return {
content: [
{
type: 'text',
text: `City created successfully: ${city.nome} (ID: ${city.id})`,
},
],
};
}
case 'list_cities': {
const cities = await apiClient.getAllCities();
const citiesList = cities.map(c => `- ${c.nome} (ID: ${c.id})`).join('\n');
return {
content: [
{
type: 'text',
text: `Found ${cities.length} cities:\n${citiesList}`,
},
],
};
}
case 'get_city': {
const city = await apiClient.getCityById(args.id);
return {
content: [
{
type: 'text',
text: `City: ${city.nome} (ID: ${city.id})`,
},
],
};
}
case 'search_cities': {
const cities = await apiClient.searchCities(args.name);
if (cities.length === 0) {
return {
content: [
{
type: 'text',
text: `No cities found matching "${args.name}"`,
},
],
};
}
const citiesList = cities.map(c => `- ${c.nome} (ID: ${c.id})`).join('\n');
return {
content: [
{
type: 'text',
text: `Found ${cities.length} cities matching "${args.name}":\n${citiesList}`,
},
],
};
}
case 'update_city': {
const city = await apiClient.updateCity(args.id, args.nome);
return {
content: [
{
type: 'text',
text: `City updated successfully: ${city.nome} (ID: ${city.id})`,
},
],
};
}
case 'delete_city': {
await apiClient.deleteCity(args.id);
return {
content: [
{
type: 'text',
text: `City deleted successfully (ID: ${args.id})`,
},
],
};
}
default:
throw new Error(`Unknown tool: ${name}`);
}
} catch (error: any) {
return {
content: [
{
type: 'text',
text: `Error: ${error.message}`,
},
],
isError: true,
};
}
}