About geonames-mcp-server
geonames-mcp-server provides access to GeoNames place and geographic reference data for developers and location-based research. Its tools cover place search, administrative hierarchies, reverse geocoding, postal codes, and country facts.
Key features
- 01Search places with geographic filters
- 02Retrieve detailed place records
- 03Browse parent and child hierarchies
- 04Reverse geocode coordinates
- 05Find postal codes and country facts
Use cases
- 01Find places within a country or bounding box
- 02Identify administrative areas for coordinates
- 03Explore a place's parent or child areas
- 04Look up postal codes or country details
MCP support
Exposes eight GeoNames tools to MCP clients through STDIO or Streamable HTTP. A public hosted MCP server is also available.
Configuration
Remote servers need no local install. Pick your client, then copy the config or install in one click.
https://geonames.caseyjhand.com/mcpclaude mcp add --transport http cyanheads-geonames https://geonames.caseyjhand.com/mcp{"mcpServers":{"cyanheads-geonames":{"type":"http","url":"https://geonames.caseyjhand.com/mcp"}}}Open in Cursor{"servers":{"cyanheads-geonames":{"type":"http","url":"https://geonames.caseyjhand.com/mcp"}}}Open in VS Code{"mcpServers":{"cyanheads-geonames":{"type":"http","url":"https://geonames.caseyjhand.com/mcp"}}}{"mcpServers":{"cyanheads-geonames":{"serverUrl":"https://geonames.caseyjhand.com/mcp"}}}Run commands in a terminal; paste JSON into the client’s MCP config and restart. Servers that need sign-in will prompt on first connect.
Tools
8| Parameter | Type | Required | Description |
|---|---|---|---|
| limit | integer | No | Maximum entries to return, 1 to 100. Default 10. |
| match | enum | No | How query is matched. name_required (the default) needs at least one query term in the place name while other terms may match the country or admin names; any_field lets every term match any of those fields; exact_name matches the whole name exactly, alternate and historical names included; name_prefix matches names that start with query. Needs query. Case-insensitive.name_required | any_field | exact_name | name_prefix |
| query | string | No | Place name to search for, such as Springfield or "Berlin, Germany", up to 200 characters. match sets how it is compared. Omit it to search by filters alone, which then needs at least one of countries, featureClasses, featureCodes, or boundingBox (cities alone is not enough). |
| cities | enum | No | Keep only populated places (class P) with a population of at least 1,000 (cities1000), 5,000 (cities5000), or 15,000 (cities15000), plus seats of admin divisions: GeoNames' cities tiers. Beside featureClasses or featureCodes, list only class P or class-P codes such as PPLC. Case-insensitive.cities1000 | cities5000 | cities15000 |
| offset | integer | No | Entries to skip before the first one returned, for paging, 0 to 5000. Default 0. |
| orderBy | enum | No | Result order: relevance (GeoNames' default) or population, largest first. Case-insensitive.relevance | population |
| countries | array | No | ISO 3166-1 country codes, up to 10, as a list or a comma-separated string: alpha-2 (US, GB, DE), alpha-3 (USA, GBR, DEU), or three-digit numeric (840, 826, 276), each sent to GeoNames as alpha-2. Case-insensitive; UK is accepted for GB. |
| boundingBox | object | No | Keep only places inside this box. The box cannot cross the 180° meridian: split such an area into two searches. |
| boundingBox.east | number | Yes | Eastern longitude bound, decimal degrees, -180 to 180. |
| boundingBox.west | number | Yes | Western longitude bound, decimal degrees, -180 to 180; below east. |
| boundingBox.north | number | Yes | Northern latitude bound, decimal degrees, -90 to 90. |
| boundingBox.south | number | Yes | Southern latitude bound, decimal degrees, -90 to 90; below north. |
| featureCodes | array | No | GeoNames feature codes (PPLC capital, ADM1 state, MT mountain, AIRP airport), up to 20, as a list or a comma-separated string. Case-insensitive; a class prefix (P.PPLC) is dropped. Each code implies its class; with featureClasses too, the two lists intersect, so featureClasses must list exactly these codes' classes. geonames_list_reference topic feature_codes lists every code. |
| featureClasses | array | No | GeoNames feature classes: A admin divisions, H water, L areas, P populated places, R roads, S spots and buildings, T terrain, U undersea, V vegetation. A list or a comma-separated string; case-insensitive. With featureCodes too, the two lists intersect: list exactly the classes of those codes, or pass featureCodes alone. |
| geonamesUsername | string | No | Your own GeoNames username, so the call spends that account's free credits instead of the server's. Omit it to use the server's account. The account needs free web services enabled on its geonames.org account page. |
Details
From the project README@cyanheads/geonames-mcp-server
Search GeoNames places, walk admin hierarchies, reverse geocode, get postal codes and country info via MCP. STDIO or Streamable HTTP.
Public Hosted Server: https://geonames.caseyjhand.com/mcp
Overview
The GeoNames gazetteer: 13M+ places worldwide, linked into an administrative tree from continent to neighborhood. Search places, read full records, walk the admin hierarchy, reverse geocode coordinates, look up postal codes, and read country facts.
Tools
| Tool | Description |
|---|---|
geonames_search_places | Search places by name, country, admin division code, feature class or code, population tier, and bounding box |
geonames_get_place | Full record for one geonameId: admin chain, timezone, elevation, alternate names, postal codes, external identifiers |
geonames_get_hierarchy | Parent chain from Earth and the continent down to the feature |
geonames_get_children | Direct children of a feature in the administrative, tourism, or dependency tree |
geonames_reverse_geocode | Country and admin subdivisions (or the ocean) for a coordinate, plus the nearest places or features and an optional timezone |
geonames_find_postal_codes | Postal codes by code, by place name, or near a coordinate |
geonames_get_countries | Country facts: ISO and FIPS codes, geonameId, capital, population, area, languages, currency, postal-code format |
geonames_list_reference | Feature classes, feature codes, and the countries with postal-code data |
Capability reference
geonames_search_places tool
query(up to 200 characters) compared permatch:name_required(default),any_field,exact_name, orname_prefix; filterscountries(up to 10, by ISO alpha-2, alpha-3, or numeric code),adminCode1–adminCode4,featureClasses,featureCodes(up to 20),cities(cities1000/cities5000/cities15000), andboundingBox. A call needsqueryor one ofcountries,featureClasses,featureCodes,boundingBox- A listed country also returns the territories GeoNames files under it (
GBalso returns IM, GG, JE, and GS), each place under its owncountryCode; the notice names any country on the page thatcountriesdoes not list adminCode1–adminCode4search inside an admin division by its GeoNames code, asgeonames_get_placeandgeonames_reverse_geocodereturn it inadminLevels(countries: ["US"], adminCode1: "TX", featureCodes: ["AIRP"]lists Texas airports). Codes are case-insensitive and zero padding counts (02, not2); they are not ISO 3166-2 or postal codes (Bavaria is02, notBY). Each needs exactly one country, and levels 2–4 needadminCode1limit1–1,000 (default 10), held to 100 per call with a notice when more remain;offset0–5000,orderByrelevanceorpopulation(omitted, GeoNames' own order); returnstotalCount,effectiveQuery, andnextOffsetfeatureClasses,featureCodes, andcities(class P only) intersect: with both lists set, each code's class must be listed and each listed class needs a code; besidecities, only class P and its codes. Anything else fails asfeature_filter_mismatch- Fails before any request with
query_or_filter_required,query_required,unknown_country_code,unknown_feature_code,admin_code_unscoped,feature_filter_mismatch, orinvalid_bounding_box
geonames_get_place tool
- One
geonameId; an unknown id returnsfound: falsewithguidance - Returns
adminLevels1–5 (code, name,geonameId), timezone (UTC offsets on 1 January and 1 July), bounding box, recorded and DEM elevation, population, Wikipedia URL,alternateNames,postalCodes,links, andidentifiers(IATA, ICAO, FAA, Transport Canada, UN/LOCODE, Wikidata) nameLanguages(up to 20 tags;zhalso matcheszh-CN) filtersalternateNamesonly
geonames_get_hierarchy tool
- One
geonameId;chainruns from Earth and its continent through the country and admin divisions down to the feature, skipping levels it does not sit under - Each level carries
geonameId, feature class and code, country and first-level codes, coordinates, and population; an unknown id returnsfound: false
geonames_get_children tool
hierarchy:administrative(default),tourism(islands, coasts, and their municipalities; almost all in Spain), ordependency(a country's dependent territories). Children are mostly admin divisions (class A) and populated places (class P); continents and coasts are class L, islands class T- GeoNames answers a
tourismordependencyrequest with the administrative children when the feature has no such tree. The tool compares the two lists and setssameAsAdministrative, with a notice, when they match; the rows stay, since a real tree can match too - Fetches up to 1,000 children per parent once and caches them, so
nameContains,limit(1–1,000, default 100, held to 500 per call with a notice when more remain), andoffsetcost no extra credits; a notice says when GeoNames lists more - An unknown id returns
found: false; a leaf returns an emptychildrenlist with a notice
geonames_reverse_geocode tool
lat/lngresolve tocountryandadminLevels(down to ADM5, each with itsgeonameIdand ISO 3166-2 subdivision code where one exists) or, offshore, theoceancoastalBufferKm(0–50, default 0) matches the nearest country within that distance when none contains the point, for harbor, pier, and shoreline fixes; a buffered match carriescountry.distanceInKm, and the nearby and timezone lookups keep the exact pointnearbylists the nearest populated places (nearbyLimit0–1,000, default 5, held to 50 per call with a notice when more lie within the radius;radiusKmup to 300, default 20; optionalcitiestier) or, whenfeatureClasses/featureCodesis set, the nearest features of that type;nearbyKindsays which.featureClassesandfeatureCodesintersect- Fails before any request with
conflicting_filters(citieswith a feature filter),unknown_feature_code, orfeature_filter_mismatch(a code whose class is not listed, or a listed class with no code) includeTimezoneadds the IANA id, UTC offsets, local time, sunrise, and sunset (offsets only offshore, where both dates are reported at the standard offset)
geonames_find_postal_codes tool
mode:code(needspostalCode),place_name(needsplaceName), ornearby(needslatandlng;radiusKmup to 30, default 10); a missing field, orcountriesor anoffsetabove 0 innearby, fails asmode_fields_mismatchcountriesfilter forcodeandplace_name, by ISO alpha-2, alpha-3, or numeric code (the 250 country codes plus the retiredAN,CS, andYU; any other, such asELorZZZ, fails asunknown_country_code)- A listed country also returns the territories GeoNames files under it (
GBalso returns IM, JE, and GG), each postal code under its owncountryCode; the notice names any country on the page thatcountriesdoes not list limit1–1,000 (default 10), held to 100 per call with a notice when more remain;codeandplace_namepage withoffset0–5000 and returnnextOffsetwhile more rows remain below offset 5000; GeoNames reports no total, sotruncatedsays whether more rows exist, never how many- Covers 122 countries; Ireland returns only Eircode routing keys and Malta only letter prefixes
geonames_get_countries tool
- Up to 250
countriesby ISO alpha-2, alpha-3, or numeric code, acontinent,nameContains, or no filter for all 250;limit1–1,000 (default 50), held to 250 per call, withoffset - Rows carry ISO and FIPS codes,
geonameId(the starting point forgeonames_get_children), capital, population, area, continent, languages, currency, postal-code format, and mainland bounding box; unknown codes land innotFound
geonames_list_reference tool
topic:feature_classes(9),feature_codes(684, filterable byfeatureClass), orpostal_countries(122, with each country's code range and count);featureClasswith another topic fails asfilter_not_applicablenameContains,limit1–1,000 (default 100, held to 700 per call, which fits every topic), andoffset; feature classes and codes are bundled and spend no credits
Features
Built on @cyanheads/mcp-ts-core: stdio and Streamable HTTP transports, pluggable auth (none / jwt / oauth), swappable storage (in-memory, filesystem, Supabase, Cloudflare KV/R2/D1), structured logging with optional OpenTelemetry tracing.
GeoNames-specific:
- Data from GeoNames, licensed CC BY 4.0: results you pass on must credit GeoNames. This server is independent of GeoNames.
- Per-account pacing at 1,000 requests an hour, with a cooldown after a quota error that holds only that account
- Responses are cached across callers: searches for 1 hour, timezones never, every other lookup for 24 hours. A cache hit spends no credit
- Forgiving inputs: alpha-3 and numeric country codes,
UKforGB, andFLforLI. The server also accepts forms its advertised schemas leave out (a comma-joined string for a list, other casings of enums and codes, aP.PPLCclass prefix, a geonames.org URL or a JSON integer for ageonameId, extra spaces in a postal code,usernameforgeonamesUsername), but the tool descriptions offer only the canonical forms, since a client that validates arguments refuses the rest
Agent-friendly output:
- Typed failure reasons separate the caller's account (
caller_account_rejected) from the operator's (server_account_rejected), a spent quota (quota_exhausted, withdata.windowofhour,day,week, orlocal), and a value GeoNames rejected (upstream_rejected_parameter) - Unknown ids return
found: falsewithguidancerather than an error; empty or partial pages carry anoticenaming the nextoffsetor the filter to loosen - GeoNames placeholders for "none" (
population: 0, empty admin names,geonameId: 0) are dropped rather than reported as facts
Known limitations:
- Shared quota on a shared deployment. All callers without their own username share the server account's 1,000 credits an hour. A burst of reverse geocodes (up to 7 credits each) can exhaust it, and GeoNames does not say when the window resets.
- Search and postal searches reach only offset 5000 on the free tier, and a page holds at most 100 rows, so a result set is reachable up to its 5,100th row. Nearby postal lookups do not page.
- Children cap at 1,000 per parent.
- Postal data covers 122 countries. Ireland and Malta return only code prefixes. US nearby lookups place the first row at the query point rather than the ZIP centroid.
- Nearby radius tops out at 300 km for places and features and 30 km for postal codes, GeoNames' free-tier ceilings.
- Bounding boxes cannot cross the 180° meridian. Split such an area into two searches.
- Coastal points can resolve to the ocean without a buffer. By default only a country that contains the point matches, so a harbor or shoreline point just outside the outline returns the sea while its nearby places are on land. Set
coastalBufferKm(up to 50) to match the nearest country instead; in a strait that can be either shore. - Microstates and enclaves can resolve to the surrounding country. A point inside Vatican City returns Italy.
- Nearest populated places include sections and historical places. In a dense city the nearest rows are often
PPLXquarters orPPLHformer districts; each row'sfeatureCodesays which, andcitiesrestricts to places above a population tier. - Offshore timezones are offsets only. No IANA id, local time, sunrise, or sunset is available at sea, and both dated offsets are the standard offset (open water has no DST).
exact_namematches alternate and historical names, so a result'snamecan differ from the query: "Springfield" can return Plattsburg or Palmyra, MO.- Data is community-edited and provided "as is". Many features have no recorded population or elevation.
Getting started
Public Hosted Instance
A public instance is available at https://geonames.caseyjhand.com/mcp — no installation required. Point any MCP client at it via Streamable HTTP:
{
"mcpServers": {
"geonames-mcp-server": {
"type": "streamable-http",
"url": "https://geonames.caseyjhand.com/mcp"
}
}
}
A call that passes no geonamesUsername spends the hosted instance's GeoNames account, whose 1,000 credits an hour are shared by every such caller. Pass your own geonamesUsername to spend your account's quota instead.
Self-Hosted / Local
Add the following to your MCP client configuration file, with your GeoNames username in place of the placeholder.
{
"mcpServers": {
"geonames-mcp-server": {
"type": "stdio",
"command": "bunx",
"args": ["@cyanheads/geonames-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info",
"GEONAMES_USERNAME": "your_geonames_username"
}
}
}
}
Or with npx (no Bun required):
{
"mcpServers": {
"geonames-mcp-server": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@cyanheads/geonames-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info",
"GEONAMES_USERNAME": "your_geonames_username"
}
}
}
}
Or with Docker:
{
"mcpServers": {
"geonames-mcp-server": {
"type": "stdio",
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MCP_TRANSPORT_TYPE=stdio",
"-e", "GEONAMES_USERNAME=your_geonames_username",
"ghcr.io/cyanheads/geonames-mcp-server:latest"
]
}
}
}
For Streamable HTTP, set the transport and start the server:
MCP_TRANSPORT_TYPE=http MCP_HTTP_PORT=3010 GEONAMES_USERNAME=your_geonames_username bun run start:http
# Server listens at http://localhost:3010/mcp
Prerequisites
- Bun v1.4.0 or higher (or Node.js v24+).
- A free GeoNames account with free web services enabled on its account page. GeoNames rejects calls from an account until they are enabled.
Installation
- Clone the repository:
git clone https://github.com/cyanheads/geonames-mcp-server.git
- Navigate into the directory:
cd geonames-mcp-server
- Install dependencies:
bun install
- Configure environment:
cp .env.example .env
# edit .env and set GEONAMES_USERNAME
Configuration
Every GeoNames call spends credits from a GeoNames account. GEONAMES_USERNAME is the server's account: a free GeoNames account with free web services enabled on its account page. Every tool also takes geonamesUsername, so a caller on a shared deployment can spend their own account instead of the server's. When neither is set, calls fail with username_required; only the bundled feature_classes and feature_codes topics of geonames_list_reference work without an account.
A free account gets 1,000 credits an hour and 10,000 a day. Cached lookups spend nothing.
| Tool | Credits per call |
|---|---|
geonames_search_places, geonames_get_place, geonames_get_hierarchy | 1 |
geonames_get_children | 1; 2 for tourism or dependency when the parent's administrative list is not cached |
geonames_find_postal_codes | 1 (code, place_name; a miss with countries adds 1 for the postal coverage list unless it is cached); 2 (nearby) |
geonames_reverse_geocode | 1 for containment (with or without coastalBufferKm), plus 3 for nearest populated places or 4 for nearest features, 1 for the ocean when no country contains the point or lies within the buffer, and 1 for the timezone |
geonames_get_countries | 1 a day; the country table is cached |
geonames_list_reference | 0 for feature_classes and feature_codes; 1 a day for postal_countries |
| Variable | Description | Default |
|---|---|---|
GEONAMES_USERNAME | GeoNames account used when a call passes no geonamesUsername. Free at geonames.org; enable free web services on its account page. | none |
MCP_TRANSPORT_TYPE | Transport: stdio or http. | stdio |
MCP_HTTP_PORT | HTTP server port. | 3010 |
MCP_SESSION_MODE | HTTP session mode: stateless, stateful, or auto. .env.example and the Docker image set stateless. | auto |
MCP_AUTH_MODE | Authentication: none, jwt, or oauth. | none |
MCP_LOG_LEVEL | Log level (debug, info, warning, error, etc.). | info |
LOGS_DIR | Directory for log files (Node.js only). | <app-root>/logs |
LOG_TOOL_FAILURE_PAYLOADS | Log each failed tool call's arguments and result, redacted by key name: a GeoNames username is removed under geonamesUsername, username, or any near-miss key with a user or account word. | false |
STORAGE_PROVIDER_TYPE | Storage backend: in-memory, filesystem, supabase, cloudflare-kv/r2/d1. | in-memory |
OTEL_ENABLED | Enable OpenTelemetry. | false |
See .env.example for the full list of optional overrides.
Running the server
Local development
-
Build and run the production version:
# One-time build bun run rebuild # Run the built server bun run start:http # or bun run start:stdio -
Run checks and tests:
bun run devcheck # Lints, formats, type-checks, and more bun run test # Runs the test suite
Project structure
| Directory | Purpose |
|---|---|
src/index.ts | createApp() entry point: server instructions, tool registration, GeoNames service setup and teardown. |
src/config | GEONAMES_USERNAME parsing and validation with Zod. |
src/mcp-server/tools | The eight tool definitions (*.tool.ts) and the inputs they share (shared-inputs.ts). |
src/services/geonames | GeoNames service: fetch boundary, status mapping, retry, per-account pacing, response cache, parsers, and the bundled feature-code and country-code tables. |
src/utils | Inline-text sanitizer for GeoNames-authored and caller-echoed text in format() output and the enrichment trailer renders. |
tests/ | Unit and integration tests, mirroring the src/ structure. |
docs/design.md | Design notes: tool surface, credential model, upstream behavior. |
Development guide
See CLAUDE.md for development guidelines and architectural rules. The short version:
- Handlers throw, framework catches — no
try/catchin tool logic - Use
ctx.logfor logging,ctx.statefor storage - Register new tools in
src/mcp-server/tools/definitions/index.ts - Wrap external API calls: validate raw → normalize to domain type → return output schema; never fabricate missing fields
Contributing
Issues are welcome. Run checks and tests before submitting:
bun run devcheck
bun run test
License
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.