Skip to main content
Glama
Geo MCP Server

Geo MCP Server

by aabbas77-web

image alt

AliSoft Geo MCP Ollama

By Dr. Ali Abbas aabbas7@gmail.com

Programming Language: Python

Geo MCP Ollama

Connecting GIS & Local LLMs: Geo MCP with Ollama Tutorial

Embroidery Tools

A fully local AI assistant that answers GIS questions by calling real geospatial tools. A small LLM running in Ollama decides which tool to use, a FastMCP server executes it with Shapely, and the LLM explains the result. No cloud service and no API keys.

Python MCP Ollama Platform License

Why this project

Language models are unreliable at precise geometry and distance maths. Instead of letting the model guess, this project gives it a toolbox of exact functions exposed through the Model Context Protocol (MCP). The same server can be reused by any MCP-capable client.

Related MCP server: ArcGIS Pro Local MCP

Architecture

sequenceDiagram
    participant U as User
    participant C as ollama_client.py (MCP client)
    participant L as Ollama (qwen3:4b)
    participant S as geo_server.py (MCP server)

    U->>C: Question
    C->>S: Start subprocess (stdio) and list_tools()
    S-->>C: Tool names + JSON schemas
    loop Agent loop (max 5 turns)
        C->>L: chat(messages, tools)
        L-->>C: tool_calls or final answer
        C->>S: call_tool(name, args)
        S-->>C: JSON result
    end
    C-->>U: Final answer

Component

File

Role

MCP server

geo_server.py

Exposes three GIS tools over stdio (FastMCP + Shapely)

MCP client / agent

ollama_client.py

Discovers tools, passes them to the LLM, executes tool calls, loops until an answer

LLM runtime

Ollama

Serves qwen3:4b at http://127.0.0.1:11434

Available tools

Tool

Inputs

Output

buffer_point

latitude, longitude, distance_km

Buffer polygon as WKT and its area in km²

distance_between_points

lat1, lon1, lat2, lon2

Haversine distance in km

point_in_polygon

latitude, longitude, polygon_wkt

{"inside": true/false}

WKT uses longitude first, then latitude: POLYGON ((lon lat, lon lat, ...)).

Requirements

  • Python 3.10 or newer

  • Ollama installed

  • About 4 to 6 GB of free RAM for the 4B model

  • Windows for the provided .bat launchers (the Python code itself is cross-platform)

Quick start (Windows)

:: 1. One-time setup: creates .venv and installs dependencies
01_setup.bat

:: 2. Start Ollama (skip if the Ollama app is already running)
02_start_ollama.bat

:: 3. Download the model (one time, in a new terminal)
ollama pull qwen3:4b

:: 4. Run the client; it starts the GIS server automatically
03_start_ai_geo_server_ollama_client.bat

Linux / macOS

python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
ollama serve &                 # if not already running
ollama pull qwen3:4b
export NO_PROXY=localhost,127.0.0.1,::1
python ollama_client.py geo_server.py

Usage

ollama_client.py runs two demo questions. Edit the queries list in main() to ask your own:

queries = [
    "What is the distance between Seattle (47.6062, -122.3321) and Portland (45.5152, -122.6784)?",
]

Expected console output for a tool-using question:

[Client] Discovered 3 tools: ['buffer_point', 'distance_between_points', 'point_in_polygon']
[Client] LLM requested tool: distance_between_points({'lat1': 47.6062, 'lon1': -122.3321, ...})
[Client] Tool result: {"distance_km": 234.011}
[Client] Final answer (turn 2)
Assistant: The geodesic distance ... is 234.01 kilometers.

Test the tools without any LLM:

import asyncio
from fastmcp import Client
from geo_server import mcp

async def main():
    async with Client(mcp) as c:
        print(await c.call_tool("distance_between_points", {
            "lat1": 47.6062, "lon1": -122.3321, "lat2": 45.5152, "lon2": -122.6784}))

asyncio.run(main())

Project structure

geo-mcp-ollama/
├── geo_server.py                              # MCP server with the GIS tools
├── ollama_client.py                           # MCP client + Ollama agent loop
├── requirements.txt                           # Pinned dependencies
├── 01_setup.bat                               # Create .venv and install packages
├── 02_start_ollama.bat                        # ollama serve
└── 03_start_ai_geo_server_ollama_client.bat   # Run client (spawns the server)

Configuration

Setting

Where

Default

Model

ollama_model in main()

qwen3:4b

Ollama URL

ollama_url in OllamaMCPClient

http://127.0.0.1:11434

Max agent turns

max_turns

5

Proxy bypass

NO_PROXY in script 03 and trust_env=False in the client

enabled

Force CPU

OLLAMA_LLM_LIBRARY=cpu (commented in script 03)

off

Adding a new tool

Add a typed, documented function to geo_server.py. FastMCP turns the signature and docstring into the schema the LLM sees, so write clear docstrings (units, coordinate order).

@mcp.tool
def bounding_box(polygon_wkt: str) -> str:
    """Return the bounding box (min_lon, min_lat, max_lon, max_lat) of a WKT geometry."""
    try:
        return json.dumps({"bbox": shapely_wkt.loads(polygon_wkt).bounds})
    except Exception as e:
        return json.dumps({"error": str(e)})

Do not use print() in the server: stdout is the MCP transport. Log to stderr instead.

Known limitations

  • buffer_point accuracy. It converts km to degrees with the longitude factor on both axes, so the buffer is stretched north-south by 1/cos(latitude) and the area is overstated (116.4 km² instead of about 78.4 km² for a 5 km buffer at 47.65°N). Fix: build the buffer geodesically with pyproj.Geod (already listed in requirements.txt but not yet used).

  • Small models may skip tools. In testing, qwen3:4b answered a buffer-area question by itself instead of calling buffer_point. Use a strict system prompt ("you MUST call the matching tool"), temperature: 0, or a larger model.

  • Speed on CPU. qwen3:4b resolves to a reasoning ("Thinking") build. On a CPU-only laptop it generated 5 to 7 tokens/s and one question took several minutes. An instruct (non-thinking) model is much faster.

  • Haversine assumes a spherical Earth (about 0.5% error); use pyproj.Geod for ellipsoidal accuracy.

  • A new server process is started for every question.

Troubleshooting

Symptom

Fix

Python not found in setup

Install Python 3.10+ and add it to PATH

Connection refused on 127.0.0.1:11434

Start Ollama (02_start_ollama.bat)

model "qwen3:4b" not found

Run ollama pull qwen3:4b

address already in use on ollama serve

Ollama is already running; skip that step

Proxy-related errors to localhost

Launch through script 03 (sets NO_PROXY), keep trust_env=False

Ollama crash 0xc0000005

Uncomment set OLLAMA_LLM_LIBRARY=cpu in script 03

Max turns reached without a final answer

Rephrase the question, raise max_turns, or use a stronger model

Roadmap

  • Geodesic buffer_point using pyproj.Geod

  • Input validation and error feedback to the LLM on failed tool calls

  • Interactive chat mode with one persistent MCP session

  • More tools: polygon area, centroid, reprojection, nearest neighbour, GeoJSON layers

  • Automated tests with a scripted fake LLM

Documentation

A detailed step-by-step guide with diagrams is available in docs/Geo_MCP_Ollama_Project_Guide.docx.

Author

Dr. Ali Abbas Software engineer and researcher (Computer Vision, GIS, UAV systems, embedded and Android development)

Questions, bug reports and collaboration ideas are welcome. Please open an issue or get in touch by email.

License

This project is licensed under the MIT License. Copyright (c) 2026 Dr. Ali Abbas.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Enables LLMs to geocode and reverse geocode places, find nearby points of interest, search categories within an area, get turn-by-turn routing, suggest meeting points, and analyze neighborhoods, commutes, schools, EV charging, and parking through OpenStreetMap data services. It also serves place and map tile resources over stdio, SSE, or Streamable HTTP transports.
      12
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI clients to inspect and modify maps and scenes open in a locally running desktop GIS session through natural language, exposing 38 fixed tools for session and layer queries, fields, selection, visibility and renaming, symbology, transparency, camera and elevation, map switching, raster, layout export, whitelisted geoprocessing, and attribute editing. It routes stdio MCP calls through a Windows named pipe to a C# add-in, with no network ports and no arbitrary code execution.
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables agents to perform local Houston retail site-selection analysis by calling ArcPy/numpy tools over stdio for geocoding, hex profiling, overlay suitability, embedding similarity, hot-spot detection, and validation, with sources, checks, and caveats included.
      6
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to inspect geospatial vector and raster metadata and run bounded analysis on administrator-registered datasets, including planar buffering, clipping, spatial joins, and PNG map rendering delivered as checksummed artifacts. All data access is read-only and controlled through a curated dataset catalog.
      Apache 2.0