GET_VISA_INFO_BY_COUNTRY
Retrieve visa requirements and immigration details for specific countries to plan international travel with accurate, up-to-date information.
Instructions
Get visa information for a specific country.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| countryCode | Yes | ||
| currencyCode | No |
Implementation Reference
- The execute function implementing the core logic of the GET_VISA_INFO_BY_COUNTRY tool. It calls the visaService to fetch data and formats a detailed response with country info, news, FAQ, visa types, etc.execute: async (params: getVisaCountryParam) => { try { const visaInfoResponse = await visaService.getVisaInfoByCountry( params.countryCode, params.currencyCode, ); let formattedOutput = `š Visa information for ${params.countryCode}:\n`; if (visaInfoResponse && visaInfoResponse.data) { const { visaCountry, visaNews, visaFaq, visaTypes, bookingsCount } = visaInfoResponse.data; // Country Information if (visaCountry) { formattedOutput += `\nš Country: ${visaCountry.name} (${visaCountry.country_code})`; formattedOutput += `\nšø Image: ${visaCountry.image || "N/A"}`; formattedOutput += `\nš„ Banned Countries: ${visaCountry.banned?.join(", ") || "None"}`; formattedOutput += `\nāļø No Visa Required For: ${visaCountry.no_visa?.join(", ") || "None"}`; formattedOutput += `\nā ļø Status: ${visaCountry.status || "N/A"}`; } else { formattedOutput += "\nNo country details found."; } // Visa News if (visaNews && visaNews.length > 0) { formattedOutput += "\n\nš° Visa News:"; visaNews.forEach((news:any) => { formattedOutput += `\n - ${news.title || "No title"}: ${news.content || "No content"}`; }); } // Visa FAQ if (visaFaq && visaFaq.length > 0) { formattedOutput += "\n\nš Visa FAQ:"; visaFaq.forEach((faq:any) => { formattedOutput += `\n - š¬ Question: ${faq.question || "No question"}`; formattedOutput += `\n š¬ Answer: ${faq.answer || "No answer"}`; }); } // Visa Types if (visaTypes && visaTypes.length > 0) { formattedOutput += "\n\nšļø Visa Types:"; visaTypes.forEach((type:any) => { formattedOutput += `\nVisa Type: ${type.name || "N/A"}`; formattedOutput += `\nš Country Code: ${type.country_code || "N/A"}`; formattedOutput += `\n#ļøā£ Base Code: ${type.base_code || "N/A"}`; formattedOutput += `\nš° Total Price: $${type.total_price || "N/A"}`; formattedOutput += `\nš° Processing Fee: $${type.processing_fee || "N/A"}`; formattedOutput += `\nš° Government Fee: $${type.government_fee || "N/A"}`; formattedOutput += `\nš¼ Entry Type: ${type.entry_type || "N/A"}`; formattedOutput += `\nā° Validity Period: ${type.validity_period || "N/A"} days`; formattedOutput += `\nā Status: ${type.status || "N/A"}`; if (type.keyRequirements && type.keyRequirements.length > 0) { formattedOutput += "\nš Key Requirements:"; type.keyRequirements.forEach((req:any) => { formattedOutput += `\n - ${req.requirement || "N/A"}`; }); } if (type.benefits && type.benefits.length > 0) { formattedOutput += "\nā Benefits:"; type.benefits.forEach((benefit:any) => { formattedOutput += `\n - ${benefit.benefit || "N/A"}`; }); } if (type.additionalRequirements && type.additionalRequirements.length > 0) { formattedOutput += "\nā ļø Additional Requirements:"; type.additionalRequirements.forEach((additionalRequirement:any) => { formattedOutput += `\n - ${additionalRequirement.question || "N/A"}`; }); } formattedOutput += "\n---\n"; // Add separator between visa types }); } formattedOutput += `\nš Total Bookings: ${bookingsCount || 0}`; } else { formattedOutput += "Could not retrieve visa information."; } return dedent`${formattedOutput}`; } catch (error) { if (error instanceof Error) { return `Error fetching visa information for ${params.countryCode}: ${error.message}`; } return `An unknown error occurred while fetching visa information for ${params.countryCode}`; } }, };
- Zod schema for tool parameters: required countryCode (ISO alpha-3) and optional currencyCode.const getVisaCountryParam = z.object({ countryCode: z .string() .describe("The ISO 3166-1 alpha-3 country code (e.g., 'USA', 'GHA')."), currencyCode: z .string() .optional() .describe( "Optional currency code for the country, if applicable (e.g., 'USD', 'EUR').", ), });
- src/index.ts:14-15 (registration)Registration of the GET_VISA_INFO_BY_COUNTRY tool with the FastMCP server.// Add Visa tools server.addTool(getVisaInfoByCountry);
- src/services/visaService.ts:4-38 (helper)Helper service that fetches visa data from the external API, transforms it, and returns structured data used by the tool handler.getVisaInfoByCountry: async ( countryCode: string, currencyCode?: string, ): Promise<any> => { let url = `${config.visaApi.baseUrl}/visa/country/details/${countryCode}`; if (currencyCode) { url += `?currencyCode=${currencyCode}`; } try { const response = await fetch(url, { headers: { "x-api-key": config.visaApi.apiKey, }, }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const rawData = await response.json(); // Transform the raw data into the expected structure const formattedData = { data: { visaCountry: rawData.data?.visaCountry || null, // Assuming rawData.data.visaCountry contains the country details visaNews: rawData.data?.visaNews || [], visaFaq: rawData.data?.visaFaq || [], visaTypes: rawData.data?.visaTypes || [], bookingsCount: rawData.data?.bookingsCount || 0, }, }; return formattedData; } catch (error) { console.error("Error fetching visa info:", error); throw error; } },