Skip to main content
Glama
Pedrohmlara

Countries MCP Server

by Pedrohmlara
tools.ts2.1 kB
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp"; import axios from "axios"; import { z } from "zod"; export interface Country { cioc?: string; cca2?: string; ccn3?: string; name: { common: string; official: string; }; flags: { alt?: string; }; } export function setTools(server: McpServer) { server.tool( "get_flag_details_by_country", "Returns a country's flag description based on its name, formatted as: [CIOC-CCA2-CCN3 (Common Name/Official Name)] Flag Description", { country_name: z.string() }, async ({ country_name }) => { const flag_data = await axios.get( `https://restcountries.com/v3.1/name/${country_name}` ).then((res) => { if (!res.data || !Array.isArray(res.data) || res.data.length === 0) { return 'No country data found!'; } return res.data.map((country: Country) => { const codes = [ country.cioc, country.cca2, country.ccn3 ].filter(Boolean).join('-'); const names = [ country.name.common, country.name.official ].filter(Boolean).join('/'); return `[${codes} (${names})]: ${country.flags.alt || 'No flag description available'} \n`; }).join('\n'); }).catch((error) => { if (axios.isAxiosError(error)) { if (error.response?.status === 404) { return 'Country not found!'; } return `Error fetching country data: ${error.message}`; } return `An unexpected error occurred: ${error.message}`; }); return { content: [{ type: "text", text: flag_data }] }; } ) }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Pedrohmlara/countries-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server