ZVV-MCP

ZVV-MCP

An application that combines Spice.ai with ZVV (Zurich Public Transport) data from opendata.swiss, enabling natural language queries of public transport information through LLM integration.

Category
Visit Server

README

ZVV-MCP mit SpiceAI

Dieses Projekt demonstriert die Integration von SpiceAI in eine Next.js-Anwendung.

Lokale Entwicklung

  1. Installiere die Abhängigkeiten:
npm install
  1. Installiere die SpiceAI-Runtime:
curl https://install.spiceai.org | /bin/bash
  1. Starte die SpiceAI-Runtime:
spice run
  1. Starte den Entwicklungsserver:
npm run dev
  1. Öffne http://localhost:3000 im Browser

Vercel-Deployment

Für das Deployment auf Vercel benötigst du einen Spice.ai-API-Key:

  1. Erstelle einen Account auf spice.ai
  2. Erstelle eine App und generiere einen API-Key
  3. Verknüpfe dein GitHub-Repository mit Vercel
  4. Füge den API-Key als Umgebungsvariable SPICE_API_KEY in deinen Vercel-Projekteinstellungen hinzu
  5. Deploye dein Projekt

Funktionen

  • SQL-Abfragen an SpiceAI senden
  • Ergebnisse in einer Tabelle anzeigen
  • Fehlerbehandlung für fehlgeschlagene Abfragen

Technologien

  • Next.js 14
  • TypeScript
  • SpiceAI Client
  • Vercel Deployment

Übersicht

ZVV-MCP ist eine Anwendung, die Spice.ai mit Daten von opendata.swiss kombiniert, um öffentliche Verkehrsdaten des Zürcher Verkehrsverbunds (ZVV) mittels LLM abfragbar zu machen.

Features

  • Spice.ai Integration: Beschleunigte Datenabfragen für effiziente Verarbeitung großer Verkehrsdatensätze
  • opendata.swiss Anbindung: Zugriff auf offizielle ZVV-Daten
  • LLM-Abfragen: Natürlichsprachliche Abfrage von Verkehrsinformationen
  • Responsive Design: Optimale Nutzung auf allen Geräten

Projektstruktur

  • src/: Quellcode der Anwendung
    • components/: Wiederverwendbare UI-Komponenten
    • pages/: Next.js-Seiten und API-Routes
    • styles/: Globale CSS-Stile
  • public/: Statische Dateien
  • docs/: Dokumentation
  • zvv-data/: Spice.ai Konfiguration und Daten

Technische Architektur

Systemkomponenten

Die Anwendung besteht aus drei Hauptkomponenten:

  1. Next.js Frontend: React-basierte Benutzeroberfläche
  2. Spice.ai Engine: Verarbeitet und analysiert Verkehrsdaten
  3. OpenAI Service: Stellt LLM-Funktionalitäten für natürlichsprachliche Abfragen bereit

Datenfluss

┌─────────────┐    ┌─────────────┐    ┌─────────────┐    ┌──────────────┐
│ GTFS-Daten  │───>│ Spice.ai    │<───│ Next.js     │<───│ Benutzer-    │
│ (opendata)  │    │ Engine      │    │ Frontend    │    │ anfrage      │
└─────────────┘    └──────┬──────┘    └──────┬──────┘    └──────────────┘
                          │                   │
                          │                   │
                          │                   ▼
                          │           ┌─────────────┐
                          └──────────>│ OpenAI LLM  │
                                      │ (GPT-4o)    │
                                      └─────────────┘

Sequenzdiagramm für eine Benutzeranfrage

┌─────────┐          ┌─────────┐          ┌──────────┐          ┌────────┐
│ Benutzer│          │ Frontend│          │ OpenAI   │          │Spice.ai│
└────┬────┘          └────┬────┘          └─────┬────┘          └────┬───┘
     │                     │                     │                    │
     │ Stellt Frage        │                     │                    │
     │ zu ZVV-Linien       │                     │                    │
     │────────────────────>│                     │                    │
     │                     │                     │                    │
     │                     │ Verbindungsstatus   │                    │
     │                     │ abfragen            │                    │
     │                     │───────────────────────────────────────────>
     │                     │                     │                    │
     │                     │ Daten-Metadaten     │                    │
     │                     │<───────────────────────────────────────────
     │                     │                     │                    │
     │                     │ LLM-Anfrage mit     │                    │
     │                     │ Kontext & Frage     │                    │
     │                     │────────────────────>│                    │
     │                     │                     │                    │
     │                     │ LLM-Antwort         │                    │
     │                     │<────────────────────│                    │
     │                     │                     │                    │
     │ Antwort anzeigen    │                     │                    │
     │<────────────────────│                     │                    │
     │                     │                     │                    │
┌────┴────┐          ┌────┴────┐          ┌─────┴────┐          ┌────┴───┐
│ Benutzer│          │ Frontend│          │ OpenAI   │          │Spice.ai│
└─────────┘          └─────────┘          └──────────┘          └────────┘

Installation

Voraussetzungen

  • Node.js (>= 14.x)
  • npm oder yarn
  • Spice.ai CLI (siehe docs/installation.md)
  • Docker (optional, für Containerisierung)

Setup

# Projektabhängigkeiten installieren
npm install

# Spice.ai installieren (siehe docs/installation.md für Details)
curl -fsSL https://raw.githubusercontent.com/spiceai/spiceai/trunk/install/install.sh | bash

# Spice.ai Projekt initialisieren
spice init zvv-data

Entwicklung

# Next.js Entwicklungsserver starten
npm run dev

# In einem separaten Terminal: Spice.ai Runtime starten
cd zvv-data
spice run

Daten

ZVV GTFS-Daten

Das Projekt verwendet GTFS-Daten (General Transit Feed Specification) vom Zürcher Verkehrsverbund. Die Daten werden im data/-Verzeichnis erwartet und sind in der spicepod.yaml konfiguriert.

Hinweis: Die CSV-Datendateien sind sehr groß und werden nicht im Git-Repository gespeichert. Sie müssen separat heruntergeladen und im data/-Verzeichnis platziert werden.

Folgende Dateien werden benötigt:

  • stops.csv - Haltestellen (~5.791 Einträge)
  • routes.csv - Linien (~383 Einträge)
  • trips.csv - Fahrten (~205.526 Einträge)
  • stop_times.csv - Fahrplanzeiten (~3.456.460 Einträge)
  • calendar.csv - Betriebstage (~1.695 Einträge)
  • transfers.csv - Umsteigeverbindungen (~10.342 Einträge)
  • agency.csv - Verkehrsunternehmen
  • shapes.csv - Streckenverläufe
  • calendar_dates.csv - Zusätzliche Betriebstage/Ausnahmen

Die Daten können von opendata.swiss heruntergeladen werden.

Best Practices

Entwicklung

  • Komponenten-Design: Funktionale React-Komponenten mit Hooks verwenden
  • Typisierung: TypeScript für statische Typprüfung und bessere IDE-Unterstützung
  • State Management: React Context für geteilten Zustand zwischen Komponenten
  • CSS-Organisation: Tailwind-Klassen für konsistentes Design

Datenverarbeitung

  • Daten-Caching: Spice.ai Beschleunigung für schnelle Abfragen großer Datensätze
  • Inkrementelles Laden: Nur benötigte Daten laden, um Leistung zu optimieren
  • Error Handling: Robuste Fehlerbehandlung für API-Aufrufe und Datenverarbeitung

LLM-Integration

  • Prompt Engineering: Präzise System-Prompts für genaue Antworten
  • Kontext-Management: Relevante Daten ins LLM-Prompt aufnehmen
  • Antwort-Parsing: Strukturierte Verarbeitung der LLM-Antworten

Produktion

npm run build
npm start

Dokumentation

Technologie-Stack

  • Frontend: Next.js, React, TypeScript, Tailwind CSS
  • Datenverarbeitung: Spice.ai
  • Datenquellen: opendata.swiss (GTFS-Daten)
  • KI-Modelle: OpenAI GPT-4o für natürlichsprachliche Abfragen

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
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
Qdrant Server

Qdrant Server

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

Official
Featured