trafikverket-mcp

trafikverket-mcp

Provides real-time access to Swedish road weather, traffic cameras, road conditions, and traffic flow data from Trafikverket (Swedish Transport Administration). Enables users to query weather stations, cameras, traffic situations, and flow data through natural language.

Category
访问服务器

README

Trafikverket MCP Server

A Model Context Protocol (MCP) server providing real-time access to Swedish road weather, traffic cameras, road conditions, and traffic flow data from Trafikverket (Swedish Transport Administration).

Features

  • Real-time weather data from 850+ Swedish road weather stations
  • Traffic camera access with live images and geographic search
  • Traffic situations including accidents, roadwork, and closures
  • Traffic flow data with vehicle counts and average speeds
  • Road surface conditions including ice, snow, and water depth
  • Geographic proximity search for cameras and weather stations
  • County-based filtering for regional queries

Available Tools

Weather Tools

get_weather_station

Get current weather data for a specific station by name.

Parameter Type Required Description
stationName string Yes Station name (e.g., "Kiruna", "Stockholm")

Returns: Air/road temperatures, humidity, visibility, wind, precipitation, road conditions.

list_weather_stations

List available weather stations with optional filtering.

Parameter Type Required Default Description
namePattern string No - Substring filter (case-insensitive)
limit number No 100 Maximum stations to return (1-1000)

get_weather_stations_near_location

Find weather stations near geographic coordinates.

Parameter Type Required Default Description
latitude number Yes - WGS84 latitude (-90 to 90)
longitude number Yes - WGS84 longitude (-180 to 180)
radiusKm number No 30 Search radius in kilometers
limit number No 50 Maximum stations to return

get_weather_observations

Get historical weather observations for trend analysis.

Parameter Type Required Default Description
measurepointId number Yes - Measurement point ID
limit number No 10 Maximum observations (1-100)

Camera Tools

get_cameras

Get traffic cameras with optional filtering.

Parameter Type Required Default Description
namePattern string No - Substring filter (e.g., "E4")
county number No - Swedish county code (1-25)
limit number No 10 Maximum cameras (1-100)

Returns: Camera locations, GPS coordinates, bearings, photo URLs.

get_cameras_near_location

Find cameras near geographic coordinates.

Parameter Type Required Default Description
latitude number Yes - WGS84 latitude
longitude number Yes - WGS84 longitude
radiusKm number No 30 Search radius in kilometers
county number No - County filter for efficiency
limit number No 50 Maximum cameras (1-1000)

get_camera_image

Fetch the actual image from a traffic camera.

Parameter Type Required Description
photoUrl string Yes Photo URL from get_cameras

Returns: Base64-encoded camera image.

Traffic Tools

get_traffic_situations

Get current traffic incidents, accidents, roadwork, and closures.

Parameter Type Required Default Description
roadNumber string No - Road filter (e.g., "E4", "väg 862")
county number No - County code (1-25)
limit number No 50 Maximum situations

Supports SQL-style wildcards: E% matches E4, E20, etc.

get_traffic_flow

Get real-time traffic density and speed data.

Parameter Type Required Default Description
county number No - County code (1-25)
region number No - Trafikverket region (1-6)
dataQuality string No - Filter: "good", "degraded", "bad"
limit number No 50 Maximum measurements

get_road_conditions

Get road surface conditions including ice, snow, and water.

Parameter Type Required Default Description
roadNumber string No - Road filter (e.g., "E4")
limit number No 50 Maximum conditions

Swedish County Reference

Code County Code County
1 Stockholm 14 Västra Götaland
3 Uppsala 17 Värmland
4 Södermanland 18 Örebro
5 Östergötland 19 Västmanland
6 Jönköping 20 Dalarna
7 Kronoberg 21 Gävleborg
8 Kalmar 22 Västernorrland
9 Gotland 23 Jämtland
10 Blekinge 24 Västerbotten
12 Skåne 25 Norrbotten
13 Halland

Installation

Prerequisites

Setup

# Clone the repository
git clone https://github.com/hniska/trafikverket-mcp.git
cd trafikverket-mcp

# Install dependencies
npm install

# Build
npm run build

Configuration

Claude Desktop / Claude Code

Add to your MCP configuration (use absolute paths):

Production (compiled JavaScript):

{
  "mcpServers": {
    "trafikverket": {
      "command": "node",
      "args": ["/path/to/trafikverket-mcp/dist/index.js"],
      "env": {
        "TRAFIKVERKET_API_KEY": "YOUR_API_KEY"
      }
    }
  }
}

Development (TypeScript):

{
  "mcpServers": {
    "trafikverket": {
      "command": "npx",
      "args": ["tsx", "/path/to/trafikverket-mcp/src/index.ts"],
      "env": {
        "TRAFIKVERKET_API_KEY": "YOUR_API_KEY"
      }
    }
  }
}

Restart Claude after updating configuration.

Usage Examples

# Weather queries
"What's the current weather at Kiruna?"
"List weather stations near Stockholm"
"Find weather stations within 50km of Gothenburg"

# Camera queries
"Show traffic cameras on E4"
"Get cameras near Skellefteå"
"Fetch the image from camera X"

# Traffic queries
"Any traffic incidents on E4?"
"Check road conditions in Norrbotten"
"What's the traffic flow like in Stockholm county?"

Development

Scripts

Command Description
npm run dev Run with tsx (development)
npm run build Compile TypeScript
npm start Run compiled server
npm test Run unit tests
npm run test:integration Run E2E tests against real API
npm run lint Lint code
npm run format Format with Prettier

Project Structure

trafikverket-mcp/
├── src/
│   ├── index.ts                 # Entry point (STDIO transport)
│   ├── server.ts                # MCP server (tool handlers)
│   ├── lib/
│   │   ├── trafikverket-client.ts  # API client with caching
│   │   ├── xml-builder.ts          # XML query construction
│   │   ├── xml-parser.ts           # Response parsing
│   │   └── county-mapping.ts       # County code lookup
│   └── types/
│       └── trafikverket.ts      # TypeScript interfaces
├── design/
│   └── schemas/                 # Official Trafikverket XML schemas
└── dist/                        # Compiled output

Architecture

Claude (MCP Client)
    ↓ JSON-RPC over STDIO
MCP Server
    ↓ XML Request
Trafikverket API
    ↓ XML Response
Parser → TypeScript Types
    ↓ Formatted Response
Claude

Error Handling

  • Invalid API key: Clear message with registration link
  • Network errors: Timeout (10s) and connection failures
  • API errors: Trafikverket error messages forwarded
  • Validation errors: Zod schema validation with details
  • Not found: Graceful handling for missing stations/cameras

Resources

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选