Valhalla MCP Server

Valhalla MCP Server

Integrates Claude Desktop with the Valhalla routing engine to provide OpenStreetMap-based routing and isochrone capabilities. It enables users to calculate travel paths and reachability polygons for various transportation modes using natural language.

Category
访问服务器

README

Valhalla MCP Server

A Model Context Protocol (MCP) server that provides seamless integration between Claude Desktop and the Valhalla Open-Street-Map routing engine. Access professional routing and isochrone capabilities directly from your AI conversations without complex APIs.

License Node.js Docker

Example Usage

Claude Desktop Integration

Claude Desktop showing a route calculation between two points with detailed GeoJSON response from Valhalla MCP Server

Features

Currently Supported Valhalla Services

MCP Tool/Resource Valhalla Service Description
route tool /route Single origin → destination routing with alternatives
isochrone tool /isochrone Travel time polygons showing reachable areas
health resource /status Server status and version information
tile resource /tile/{z}/{x}/{y} Vector tiles for client-side rendering

Valhalla Services - Coming Soon

Service Description Use Cases
Matrix Distance/time matrices for multiple origins/destinations Delivery optimization, logistics planning
Map-matching Match GPS coordinates to road network GPS trace cleaning, route correction
Elevation Elevation profiles along routes or at points Hiking routes, difficulty analysis
Expansion Graph traversal visualization Network analysis, reachability studies
Locate Detailed metadata about nodes and edges Address geocoding, road attributes
Centroid Optimal convergence point from multiple locations Meeting point optimization
Optimized Route Multi-stop delivery routing with constraints Logistics, delivery services

Transportation Modes

  • auto - Car routing
  • bicycle - Bicycle routing
  • pedestrian - Walking routes
  • taxi - Taxi routing
  • bus - Public transit routing

Quick Start

Prerequisites

  • Node.js 18+
  • Claude Desktop
  • NPM or Yarn package manager

Option 1: Local Valhalla Server

For production use or custom datasets:

# Prerequisites: Docker and Docker Compose
./start-mcp.sh

This script will:

  • Build the MCP server
  • Start local Valhalla with Monaco OSM data
  • Wait for services to be ready
  • Run integration tests
  • Provide Claude Desktop configuration

Option 2: Use Your Pre-existing Valhalla Server

If you already have a Valhalla server running elsewhere:

# Clone and setup
git clone <repository-url>
cd valhalla-mcp
npm install
npm run build

# Configure environment variables
cp env.example .env
# Edit .env file and set VALHALLA_BASE_URL=http://your-valhalla-server:8002

Claude Desktop Integration

  1. Open Claude Desktop settings
  2. Add to your MCP configuration:

For Demo API (recommended for testing):

{
  "mcpServers": {
    "valhalla-mcp": {
      "command": "node",
      "args": ["dist/index.js"],
      "cwd": "/YOUR/PATH/TO/valhalla-mcp",
      "env": {
        "VALHALLA_BASE_URL": "https://valhalla1.openstreetmap.de"
      }
    }
  }
}

For Local Valhalla Server:

{
  "mcpServers": {
    "valhalla-mcp": {
      "command": "node",
      "args": ["dist/index.js"],
      "cwd": "/YOUR/PATH/TO/valhalla-mcp",
      "env": {
        "VALHALLA_BASE_URL": "http://localhost:8002"
      }
    }
  }
}
  1. Update the cwd path to your actual project location

  2. Restart Claude Desktop

Test Your Installation

Try these commands in Claude Desktop to verify everything works:

Basic routing:

  • "Calculate route from Monaco-Ville to Monte Carlo"
  • "Get driving directions from 43.7384,7.4246 to 43.7396,7.4263"
  • "Calculate bicycle route from 43.7350,7.4200 to 43.7450,7.4300"

Travel time analysis:

  • "Show 10-minute drive isochrone from Monaco center"
  • "Generate 15-minute bicycle travel polygon from 43.7311,7.4197"

You should receive detailed GeoJSON responses with route geometries and travel statistics!

Development Mode

For development with auto-reload:

npm run dev

Configuration

Environment Variables

The server uses environment variables for configuration. Create a .env file from the template:

cp env.example .env

Available environment variables:

  • VALHALLA_BASE_URL - Base URL for Valhalla service (default: http://localhost:8002)
  • DEBUG - Enable debug logging (default: false)
  • LOG_LEVEL - Log level: error, warn, info, debug (default: info)
  • MCP_SERVER_NAME - MCP server name (default: valhalla-mcp-server)
  • MCP_SERVER_VERSION - MCP server version (default: 0.1.0)

Common Valhalla endpoints:

  • http://localhost:8002 - Local Docker instance (recommended)
  • https://valhalla1.openstreetmap.de - Public demo API (✅ tested and working)
  • https://your-server.com:8002 - Custom deployment

Note: The main demo URL https://valhalla.openstreetmap.de serves a web interface. Use https://valhalla1.openstreetmap.de for API access.

Docker Deployment

The complete stack can be deployed using Docker Compose:

# Build and start all services
docker-compose up -d

# View logs
docker-compose logs -f valhalla-mcp

# Stop services
docker-compose down

Usage Examples

Route Calculation

Request a route between two points:

{
  "tool": "route",
  "arguments": {
    "origin": { "lat": 52.5200, "lon": 13.4050 },
    "destination": { "lat": 52.5170, "lon": 13.3888 },
    "mode": "bicycle",
    "alternatives": 2,
    "units": "kilometers"
  }
}

Response includes GeoJSON LineString with route geometry and summary statistics:

{
  "type": "FeatureCollection",
  "features": [{
    "type": "Feature",
    "geometry": {
      "type": "LineString",
      "coordinates": [[13.4050, 52.5200], [13.3888, 52.5170]]
    },
    "properties": {
      "distance_km": 2.1,
      "duration_seconds": 420,
      "duration_minutes": 7,
      "mode": "bicycle"
    }
  }]
}

Isochrone Generation

Generate a 15-minute travel time polygon:

{
  "tool": "isochrone",
  "arguments": {
    "origin": { "lat": 52.5200, "lon": 13.4050 },
    "minutes": 15,
    "mode": "pedestrian"
  }
}

Health Check

Access server health information:

{
  "resource": "health://status"
}

Integration with MCP Clients

Claude Desktop

Add to your Claude Desktop configuration:

{
  "mcpServers": {
    "valhalla": {
      "command": "node",
      "args": ["/path/to/valhalla-mcp/dist/index.js"],
      "env": {
        "VALHALLA_BASE_URL": "https://valhalla1.openstreetmap.de"
      }
    }
  }
}

Note: Environment variables in Claude Desktop config override .env file values.

Other MCP Clients

The server implements the standard MCP protocol and works with any compliant client. Use stdio transport for local integration.

Architecture

┌─────────────────┐     MCP Protocol     ┌─────────────────┐
│   MCP Client    │ ◄─────────────────► │ Valhalla MCP    │
│ (Claude, etc.)  │    (stdio/HTTP)      │     Server      │
└─────────────────┘                      └─────────┬───────┘
                                                   │ HTTP REST
                                         ┌─────────▼───────┐
                                         │   Valhalla      │
                                         │  Routing Engine │
                                         └─────────────────┘

Development

Installation

# Install dependencies
npm install

# Build the project
npm run build

Key dependencies:

  • @modelcontextprotocol/sdk - Official MCP SDK
  • axios - HTTP client for Valhalla API calls
  • zod - Runtime type validation
  • geojson - GeoJSON type definitions
  • dotenv - Environment variable management

Testing

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Run linting
npm run lint

# Fix linting issues
npm run lint:fix

Type Checking

The project uses strict TypeScript configuration:

# Type check
npx tsc --noEmit

Performance

  • Route calculation: < 200ms (local Valhalla instance)
  • Isochrone generation: < 300ms
  • Tile serving: < 30ms
  • Health check: < 5ms

Performance depends on Valhalla configuration and available OSM data.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Acknowledgments

For issues and questions:

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选