PostGIS Yukon MCP

PostGIS Yukon MCP

Enables natural language and geospatial queries on PostGIS databases, with 32 tools for spatial analysis, geometry operations, and database management.

Category
Visit Server

README

PostGIS MCP Server

基于 fastMCP 框架的 PostGIS 工具 MCP 服务器实现。

🌟 新功能: Text-to-SQL

现在支持使用自然语言查询PostGIS数据库!无需编写复杂的SQL语句,只需用中文或英文描述您的查询需求。

示例:

  • "查询表:buildings 坐标120.5,30.2 附近500米的建筑"
  • "为表:roads创建100米缓冲区"
  • "计算表:parks的面积"

详细信息请查看 Text-to-SQL文档

项目简介

本项目使用 fastMCP 框架封装 PostGIS 地理空间数据库工具,通过 MCP (Model Context Protocol) 协议提供标准化的工具接口。

项目结构

yukon_mcp_service/
├── src/
│   ├── __init__.py           # 包初始化
│   ├── server.py             # MCP 服务器主入口
│   ├── tools/                # 工具模块
│   │   ├── __init__.py
│   │   ├── spatial_query.py  # 空间查询工具
│   │   ├── geometry.py       # 几何操作工具
│   │   └── analysis.py       # 空间分析工具
│   └── config/
│       ├── __init__.py
│       └── database.py       # 数据库配置
├── tests/                    # 测试文件
│   ├── __init__.py
│   └── test_tools.py
├── pyproject.toml            # 项目配置
├── requirements.txt          # 依赖列表
└── README.md                 # 项目说明

功能特性

空间查询工具(3个)

  • query_nearby - 根据坐标查询附近的地理要素
  • query_bbox - 空间范围查询
  • query_attribute - 根据属性查询要素

几何操作工具(5个)

  • buffer_geometry - 创建几何缓冲区
  • get_area - 计算几何面积
  • get_length - 计算几何长度
  • transform_coords - 坐标系统转换
  • simplify_geom - 简化几何对象

空间分析工具(5个)

  • measure_distance - 计算两个几何对象之间的距离
  • test_intersection - 检查几何对象相交关系
  • test_containment - 检查几何对象包含关系
  • union_geoms - 合并多个几何对象
  • get_centroid - 计算几何对象质心

数据库管理工具(9个)

  • postgis_version - 获取 PostGIS 版本信息
  • list_extensions - 列出已安装的数据库扩展
  • discover_spatial_tables - 发现包含空间字段的表
  • table_info - 获取表的详细空间信息
  • create_index - 为空间列创建 GIST 索引
  • analyze - 分析表以更新统计信息
  • vacuum - 清理表以回收空间
  • spatial_extent - 获取表的空间范围
  • validate_geometries - 检查几何对象有效性

高级空间分析工具(8个)

  • join_spatial - 执行空间连接操作
  • find_nearest - 查找最近的K个邻居
  • cluster_spatial - 使用 DBSCAN 进行空间聚类
  • compute_convex_hull - 计算凸包
  • generate_voronoi - 生成 Voronoi 多边形
  • interpolate_line - 沿线段插值点
  • snap_geometry - 将几何对象捕捉到网格
  • split_line - 使用点分割线段

Text-to-SQL 工具(2个)

  • nl_to_sql - 将自然语言转换为PostGIS SQL语句
  • execute_sql - 安全执行SQL查询(需用户确认)

共计 32 个专业 PostGIS 工具

安装依赖

pip install -r requirements.txt

配置说明

在使用前需要配置 PostGIS 数据库连接信息:

# src/config/database.py
DB_CONFIG = {
    "host": "localhost",
    "port": 5432,
    "database": "your_database",
    "user": "your_user",
    "password": "your_password"
}

运行服务

python -m src.server

使用示例

通过 MCP 协议调用工具:

# 查询指定坐标附近的要素
result = await mcp_client.call_tool(
    "query_nearby",
    {
        "longitude": 120.123,
        "latitude": 30.456,
        "radius": 1000
    }
)

开发指南

添加新工具

  1. src/tools/ 目录下创建新的工具模块
  2. 使用 @mcp.tool() 装饰器定义工具函数
  3. server.py 中注册新工具

示例:

@mcp.tool()
async def my_spatial_tool(param1: str, param2: float) -> dict:
    """工具描述"""
    # 实现逻辑
    return {"result": "data"}

技术栈

  • Python 3.8+
  • fastMCP
  • PostGIS
  • psycopg2
  • asyncio

许可证

MIT License

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured