Qgistoolmcp
Q

Qgistoolmcp

2.5 points
4.8K

Installation

Copy the following command to your Client for configuration
Note: Your key is sensitive information, do not share it with anyone.

๐Ÿš€ QGIS MCP Services - LLM-Powered Geospatial Processing Framework

A comprehensive framework for constructing LLM-powered QGIS agents, equipped with 333 geospatial processing tools across 14 specialized MCP services.

Leverage AI agents to convert natural language into automated QGIS workflows, with intelligent selection and execution of appropriate geospatial tools.

๐Ÿš€ Quick Start

1. Prerequisites

  • Python 3.10 - 3.11
  • QGIS 3.22+ with Python bindings installed
  • Virtual environment (recommended)

2. Installation

# Clone the repository
git clone <repository-url>
cd qgisToolMCP

# Create and activate virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install all services
pip install -e services/qgis-vector-geometry-buffer-mcp/
pip install -e services/qgis-vector-analysis-overlay-mcp/
# ... install other services as needed

# Install client demo dependencies
pip install openai mcp python-dotenv

3. Configure Environment

# Create environment file
cp .env.example .env

# Edit .env and set your OpenAI API key
# OPENAI_API_KEY=your-api-key-here
# OPENAI_API_BASE_URL=https://api.openai.com/v1

4. Start Services

# Start all 14 services in the background
cd services
./run.sh

# Check service status
./status.sh

# View logs for a specific service
tail -f logs/qgis-vector-geometry-buffer-mcp.log

5. Run the Demo Agent

# Run the LLM-powered agent demo
python client_demo/agent.py http://localhost:32821/sse http://localhost:32822/sse

# Or run the test script
python client_demo/test_agent.py

โœจ Features

  • ๐Ÿค– LLM-Powered Agent: Translate natural language into QGIS operations with intelligent tool selection.
  • ๐ŸŽฏ 333 QGIS Tools: Access a complete QGIS processing toolkit via the Model Context Protocol (MCP).
  • ๐Ÿ”ง 14 Specialized Services: Cover vector, raster, GDAL, cartography, and more.
  • ๐ŸŒ HTTP SSE Communication: All services are accessible via Server-Sent Events.
  • ๐Ÿ“ฆ Modular Architecture: Load only the services you need.
  • ๐Ÿ› ๏ธ Simple Python API: Facilitate easy integration for custom agent development.
  • ๐Ÿ”Œ Background Service Management: Use scripts to start, stop, and check the status of all services.

๐Ÿ”ง Technical Details

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          LLM-Powered QGIS Agent                 โ”‚
โ”‚      (Natural Language โ†’ Tool Selection)        โ”‚
โ”‚              (client_demo/agent.py)             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚ HTTP SSE
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚   14 Independent Services   โ”‚
    โ”‚  (services/qgis-*-mcp/)     โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚ Each service runs on its    โ”‚
    โ”‚ own port (32821-32834)      โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
         QGIS Processing Engine
          (via shared executor)

๐Ÿ’ป Usage Examples

Basic Usage

Example 1: Using the LLM-Powered Agent

import asyncio
from client_demo.agent import QGISAgent

async def main():
    # Create agent connected to multiple services
    agent = QGISAgent(
        service_urls=[
            "http://localhost:32821/sse",  # buffer service
            "http://localhost:32822/sse",  # hull-bounds service
            "http://localhost:32824/sse",  # analysis-overlay service
        ],
        model="gpt-4-turbo-preview"
    )

    # Connect to services
    await agent.connect()

    # Use natural language to describe the task
    task = """
    I have a shapefile at /path/to/input.shp with point features.
    Please create a 500 meter buffer around each point and save
    the result to /path/to/output.shp
    """

    # Agent will intelligently select and execute the right tool
    async for update in agent.process_task(task):
        print(update, end='', flush=True)

    await agent.disconnect()

asyncio.run(main())

Advanced Usage

Example 2: Direct Tool Execution

import asyncio
from client_demo.agent import QGISAgent

async def main():
    agent = QGISAgent(
        service_urls="http://localhost:32821/sse"
    )

    await agent.connect()

    # Execute a specific tool directly
    result = await agent.execute_tool('buffer', {
        'INPUT': '/path/to/input.shp',
        'DISTANCE': 500,
        'OUTPUT': '/path/to/output.shp'
    })

    print(f"Result: {result}")

    await agent.disconnect()

asyncio.run(main())

Example 3: Interactive Mode

# Run the agent in interactive mode
python client_demo/agent.py http://localhost:32821/sse

# Then type natural language queries:
# > Create a 1km buffer around the features in my_layer.shp
# > Simplify the geometries with tolerance 0.5
# > Calculate the area of each polygon

๐Ÿ“ฆ Available Services

Service Port Tools Category Description
qgis-vector-geometry-buffer-mcp 32821 10 Vector Geometry Buffer and offset operations
qgis-vector-geometry-hull-bounds-mcp 32822 18 Vector Geometry Convex hulls, bounding boxes
qgis-vector-geometry-vertex-mcp 32823 19 Vector Geometry Vertex manipulation
qgis-vector-analysis-overlay-mcp 32824 24 Vector Analysis Spatial analysis, overlay ops
qgis-vector-general-creation-mcp 32825 47 Vector Creation Create features, grids, points
qgis-vector-geometry-transform-mcp 32826 34 Vector Geometry Transformations, projections
qgis-vector-polygon-line-mcp 32827 27 Vector Operations Polygon/line operations
qgis-vector-table-selection-mcp 32828 44 Vector Table Attributes, selection, queries
qgis-raster-analysis-mcp 32829 20 Raster Analysis Raster analysis tools
qgis-raster-tools-creation-mcp 32830 18 Raster Tools Raster creation, conversion
qgis-gdal-raster-mcp 32831 28 GDAL GDAL raster processing
qgis-gdal-vector-mcp 32832 21 GDAL GDAL vector processing
qgis-cartography-plots-mcp 32833 9 Cartography Cartography and plotting
qgis-database-network-mcp 32834 14 Database/Network Database and network analysis

Total: 333 tools across 14 services

๐Ÿ“š Documentation

Service Management

Start All Services

cd services
./run.sh

This starts all 14 services in the background with logging.

Check Service Status

cd services
./status.sh

Output example:

Service: qgis-vector-geometry-buffer-mcp    Status: RUNNING  PID: 12345  Port: 32821
Service: qgis-vector-geometry-hull-bounds-mcp  Status: RUNNING  PID: 12346  Port: 32822
...

Stop All Services

cd services
./stop.sh

View Logs

# View logs for a specific service
tail -f services/logs/qgis-vector-geometry-buffer-mcp.log

# View all logs
tail -f services/logs/*.log

# Search for errors
grep -i error services/logs/*.log

Client Demo API

The client_demo/agent.py provides a powerful agent framework:

QGISAgent Class

agent = QGISAgent(
    service_urls: List[str] | str,  # Service URL(s) to connect to
    openai_api_key: Optional[str] = None,  # OpenAI API key
    base_url: Optional[str] = None,  # API base URL
    model: str = "gpt-4-turbo-preview",  # LLM model to use
    max_retries: int = 3,  # Retry attempts for failed operations
    verbose: bool = True  # Enable detailed logging
)

Key Methods

  • await agent.connect(): Connect to all services
  • await agent.disconnect(): Disconnect from services
  • agent.list_tools(): Get list of all available tools
  • agent.list_services(): Get list of connected services
  • agent.list_tools_by_service(): Get tools grouped by service
  • await agent.execute_tool(name, params): Execute a specific tool
  • async for update in agent.process_task(description): Process natural language task

Project Structure

qgisToolMCP/
โ”œโ”€โ”€ client_demo/              # LLM-powered agent demo
โ”‚   โ”œโ”€โ”€ agent.py             # Main QGISAgent class
โ”‚   โ”œโ”€โ”€ test_agent.py        # Test script
โ”‚   โ”œโ”€โ”€ test_direct_call.py  # Direct call example
โ”‚   โ””โ”€โ”€ data/                # Test data
โ”œโ”€โ”€ services/                 # 14 independent MCP services
โ”‚   โ”œโ”€โ”€ run.sh               # Start all services
โ”‚   โ”œโ”€โ”€ stop.sh              # Stop all services
โ”‚   โ”œโ”€โ”€ status.sh            # Check service status
โ”‚   โ”œโ”€โ”€ logs/                # Service logs (created at runtime)
โ”‚   โ”œโ”€โ”€ pids/                # Service PID files (created at runtime)
โ”‚   โ””โ”€โ”€ qgis-*-mcp/          # Individual services
โ”‚       โ”œโ”€โ”€ src/             # Service source code
โ”‚       โ”œโ”€โ”€ docs/            # Service documentation
โ”‚       โ”œโ”€โ”€ pyproject.toml   # Service configuration
โ”‚       โ””โ”€โ”€ README.md        # Service-specific docs
โ”œโ”€โ”€ shared/                   # Shared code across services
โ”‚   โ”œโ”€โ”€ executor.py          # QGIS algorithm executor
โ”‚   โ””โ”€โ”€ qgis_runner.py       # QGIS Python runner script
โ”œโ”€โ”€ documentation/            # Project documentation
โ”‚   โ”œโ”€โ”€ DEVELOPMENT.md       # Development guide
โ”‚   โ”œโ”€โ”€ PROJECT_TRANSFORMATION.md  # Architecture overview
โ”‚   โ””โ”€โ”€ README.md            # Documentation index
โ”œโ”€โ”€ scripts/                  # Utility scripts
โ”œโ”€โ”€ manage.py                 # Service management CLI
โ”œโ”€โ”€ Makefile                  # Build automation
โ””โ”€โ”€ README.md                 # This file

Development

Adding a New Tool to a Service

  1. Navigate to the service directory:
cd services/qgis-vector-geometry-buffer-mcp/src/qgis_vector_geometry_buffer_mcp/tools/
  1. Add your tool function:
@mcp.tool()
def my_new_tool(
    input_layer: str,
    parameter: float,
    output: str
) -> dict:
    """Tool description"""
    params = {
        'INPUT': input_layer,
        'PARAMETER': parameter,
        'OUTPUT': output
    }
    result = executor.run_algorithm('native:algorithm_id', params)
    return {
        "output": result.get('OUTPUT'),
        "status": "success"
    }
  1. Register the tool in tools/__init__.py

  2. Restart the service:

cd services
./stop.sh
./run.sh

See DEVELOPMENT.md for detailed development guide.

Configuration

Environment Variables

Create a .env file in the project root:

# OpenAI API Configuration
OPENAI_API_KEY=your-api-key-here
OPENAI_API_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-4-turbo-preview

# QGIS Configuration (for services)
QGIS_PYTHON_PATH=/usr/bin/python3
QGIS_PREFIX_PATH=/usr

Service Configuration

Each service can have its own .env file in its directory for service-specific configuration.

Requirements

For Running Services

  • Python 3.10 - 3.11
  • QGIS 3.22+ with Python bindings
  • Required Python packages (installed automatically):
    • fastmcp
    • python-dotenv

For Using the Agent

  • Python 3.10+
  • OpenAI API key (or compatible API)
  • Required Python packages:
    • openai
    • mcp
    • python-dotenv

Troubleshooting

Services Won't Start

  1. Check if QGIS is properly installed:
python3 -c "from qgis.core import QgsApplication; print('QGIS OK')"
  1. Check service logs:
tail -f services/logs/<service-name>.log
  1. Verify virtual environment:
which python
# Should point to .venv/bin/python

Port Conflicts

If you get "port already in use" errors, you can:

  1. Check what's using the port:
lsof -i :32821
  1. Kill the process or change the port in services/run.sh

Agent Can't Connect to Services

  1. Verify services are running:
cd services
./status.sh
  1. Check if ports are accessible:
curl http://localhost:32821/sse
  1. Verify service URLs in your agent code match the running services

Other Documentation

  • Development Guide: How to develop new services and tools
  • Project Transformation: Architecture and design decisions
  • Service Management: Detailed service management documentation
  • Client Demo: Agent usage and examples
  • Shared Code: Shared utilities documentation

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. Add New Tools: Implement additional QGIS algorithms
  2. Improve Documentation: Enhance guides and examples
  3. Fix Bugs: Report and fix issues
  4. Optimize Performance: Improve execution speed
  5. Add Tests: Increase test coverage

See DEVELOPMENT.md for contribution guidelines.

๐Ÿ“„ License

MIT License - See LICENSE file for details

๐Ÿ™ Acknowledgments

๐Ÿ› ๏ธ Support


Built with โค๏ธ for the geospatial AI community

Alternatives

P
Paperbanana
Python
7.6K
5 points
F
Finlab Ai
FinLab AI is a quantitative financial analysis platform that helps users discover excess returns (alpha) in investment strategies through AI technology. It provides a rich dataset, backtesting framework, and strategy examples, supporting automated installation and integration into mainstream AI programming assistants.
7.7K
4 points
A
Assistant Ui
assistant - ui is an open - source TypeScript/React library for quickly building production - grade AI chat interfaces, providing composable UI components, streaming responses, accessibility, etc., and supporting multiple AI backends and models.
TypeScript
7.2K
5 points
A
Apify MCP Server
The Apify MCP Server is a tool based on the Model Context Protocol (MCP) that allows AI assistants to extract data from websites such as social media, search engines, and e-commerce through thousands of ready-to-use crawlers, scrapers, and automation tools (Apify Actors). It supports OAuth and Skyfire proxy payment and can be integrated into MCP clients such as Claude and VS Code through HTTPS endpoints or local stdio.
TypeScript
7.3K
5 points
N
Next Devtools MCP
The Next.js development tools MCP server provides Next.js development tools and utilities for AI programming assistants such as Claude and Cursor, including runtime diagnostics, development automation, and document access functions.
TypeScript
16.9K
5 points
P
Praisonai
PraisonAI is a production-ready multi-AI agent framework with self-reflection capabilities, designed to create AI agents to automate the solution of various problems from simple tasks to complex challenges. It simplifies the construction and management of multi-agent LLM systems by integrating PraisonAI agents, AG2, and CrewAI into a low-code solution, emphasizing simplicity, customization, and effective human-machine collaboration.
Python
15.9K
5 points
M
Maverick MCP
MaverickMCP is a personal stock analysis server based on FastMCP 2.0, providing professional level financial data analysis, technical indicator calculation, and investment portfolio optimization tools for MCP clients such as Claude Desktop. It comes pre-set with 520 S&P 500 stock data, supports multiple technical analysis strategies and parallel processing, and can run locally without complex authentication.
Python
11.8K
4 points
B
Blueprint MCP
Blueprint MCP is a chart generation tool based on the Arcade ecosystem. It uses technologies such as Nano Banana Pro to automatically generate visual charts such as architecture diagrams and flowcharts by analyzing codebases and system architectures, helping developers understand complex systems.
Python
11.1K
4 points
N
Notion Api MCP
Certified
A Python-based MCP Server that provides advanced to-do list management and content organization functions through the Notion API, enabling seamless integration between AI models and Notion.
Python
22.8K
4.5 points
D
Duckduckgo MCP Server
Certified
The DuckDuckGo Search MCP Server provides web search and content scraping services for LLMs such as Claude.
Python
74.9K
4.3 points
M
Markdownify MCP
Markdownify is a multi-functional file conversion service that supports converting multiple formats such as PDFs, images, audio, and web page content into Markdown format.
TypeScript
36.5K
5 points
G
Gitlab MCP Server
Certified
The GitLab MCP server is a project based on the Model Context Protocol that provides a comprehensive toolset for interacting with GitLab accounts, including code review, merge request management, CI/CD configuration, and other functions.
TypeScript
26.0K
4.3 points
U
Unity
Certified
UnityMCP is a Unity editor plugin that implements the Model Context Protocol (MCP), providing seamless integration between Unity and AI assistants, including real - time state monitoring, remote command execution, and log functions.
C#
35.5K
5 points
F
Figma Context MCP
Framelink Figma MCP Server is a server that provides access to Figma design data for AI programming tools (such as Cursor). By simplifying the Figma API response, it helps AI more accurately achieve one - click conversion from design to code.
TypeScript
68.4K
4.5 points
G
Gmail MCP Server
A Gmail automatic authentication MCP server designed for Claude Desktop, supporting Gmail management through natural language interaction, including complete functions such as sending emails, label management, and batch operations.
TypeScript
22.3K
4.5 points
M
Minimax MCP Server
The MiniMax Model Context Protocol (MCP) is an official server that supports interaction with powerful text-to-speech, video/image generation APIs, and is suitable for various client tools such as Claude Desktop and Cursor.
Python
51.5K
4.8 points