GET_IMMIGRATION_INFO_BY_COUNTRY
Retrieve visa requirements and immigration details for international travel planning by specifying a country code.
Instructions
Get immigration information for a specific country.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| countryCode | Yes |
Implementation Reference
- The execute function implementing the core tool logic: fetches raw immigration data using the service, parses and formats it into a user-friendly string with emojis detailing services, descriptions, fees, requirements per country, and handles errors appropriately.execute: async (params: getImmigrationCountryParam) => { try { const immigrationInfo = await immigrationService.getImmigrationInfoByCountry( params.countryCode, ); let formattedImmigrationInfo = `š¼ Immigration information for ${params.countryCode}:\n`; if ( immigrationInfo && immigrationInfo.data && Array.isArray(immigrationInfo.data.data) ) { if (immigrationInfo.data.data.length > 0) { immigrationInfo.data.data.forEach((service:any) => { formattedImmigrationInfo += `\nšļø Service: ${service.name || "N/A"}`; formattedImmigrationInfo += `\nš Description: ${service.description || "N/A"}`; formattedImmigrationInfo += `\nš¬ Consultation Note: ${service.consultation_note || "N/A"}`; if (Array.isArray(service.countries) && service.countries.length > 0) { // Iterate through each country for this service service.countries.forEach((country:any) => { formattedImmigrationInfo += `\nš Country: ${country.country_code || "N/A"}`; formattedImmigrationInfo += `\nš° Consultation Fee: $${country.consultation_fee || "N/A"}`; formattedImmigrationInfo += `\nš° Service Fee: $${country.service_fee || "N/A"}`; if (Array.isArray(country.requirements) && country.requirements.length > 0) { formattedImmigrationInfo += "\nā Requirements:"; country.requirements.forEach((req:any) => { formattedImmigrationInfo += `\n - ${req.requirement || "N/A"} (${req.response_type || "N/A"})`; }); } else { formattedImmigrationInfo += "\nNo specific requirements listed for this country."; } formattedImmigrationInfo += "\n"; // Add spacing between countries }); } else { formattedImmigrationInfo += "\nNo country-specific information available."; } formattedImmigrationInfo += "\n---\n"; // Add separator between services }); } else { formattedImmigrationInfo += "No specific immigration information found for this country."; } } else { formattedImmigrationInfo += "Could not retrieve detailed immigration information."; } return dedent`${formattedImmigrationInfo}`; } catch (error) { // Rewriting error messages to be relevant to immigration information if (error instanceof Error) { return `Error fetching immigration information for ${params.countryCode}: ${error.message}`; } return `An unknown error occurred while fetching immigration information for ${params.countryCode}`; } },
- Zod schema defining the input parameters for the tool, specifically the required 'countryCode' string.const getImmigrationCountryParam = z.object({ countryCode: z .string() .describe("The ISO 3166-1 alpha-2 country code (e.g., 'US', 'GB')."), }); type getImmigrationCountryParam = z.infer<typeof getImmigrationCountryParam>;
- src/index.ts:17-18 (registration)Registers the GET_IMMIGRATION_INFO_BY_COUNTRY tool with the FastMCP server instance.//Add Immigration tools server.addTool(getImmigrationInfoByCountry);
- Helper service method that performs the actual API call to retrieve raw immigration data for the specified country using fetch and the configured API endpoint and key.getImmigrationInfoByCountry: async (countryCode: string): Promise<any> => { const url = `${config.immigrationApi.baseUrl}/immigration/service/country/${countryCode}?per_page=100`; try { const response = await fetch(url, { headers: { "x-api-key": config.immigrationApi.apiKey, }, }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error("Error fetching immigration info:", error); throw error; } },