Football Knowledge Graph RAG MCP Server

Football Knowledge Graph RAG MCP Server

Enables natural language querying of a football knowledge graph via Neo4j, generating Cypher queries and answers using LLMs, and also provides tools to build the graph from text.

Category
Visit Server

README

Football Knowledge Graph RAG with MCP

Overview

Football Knowledge Graph RAG is a Graph Retrieval-Augmented Generation (Graph RAG) system built using Neo4j, Large Language Models (LLMs), and the Model Context Protocol (MCP).

The system allows users to query a football knowledge graph using natural language. Questions are automatically translated into Cypher queries, executed against Neo4j, and transformed into human-readable answers using an LLM.

In addition, the system provides a Graph Builder that can automatically construct a knowledge graph from natural language text.


System Architecture

Graph RAG Pipeline

User Question
      │
      ▼
Text-to-Cypher (LLM)
      │
      ▼
Cypher Query
      │
      ▼
Neo4j Knowledge Graph
      │
      ▼
Retrieved Data
      │
      ▼
Answer Generation (LLM)
      │
      ▼
Final Response

Graph Builder Pipeline

Natural Language Text
      │
      ▼
Entity & Relationship Extraction (LLM)
      │
      ▼
Structured Graph Data
      │
      ▼
Neo4j Knowledge Graph

Technologies Used

  • Python
  • Neo4j Graph Database
  • OpenRouter API
  • Google Gemini 2.5 Flash
  • MCP (Model Context Protocol)
  • FastMCP

Project Structure

football-knowledge-graph-rag/

├── football_mcp.py
├── graph_rag.py
├── test.py
├── requirements.txt
├── .env.example
├── claude_desktop_config.example.json
└── README.md

Code Documentation

graph_rag.py

This module implements the Graph Retrieval-Augmented Generation (Graph RAG) workflow.

Main Functions

test_connection()

Verifies the connection to the Neo4j database.

generate_cypher(question)

Converts a natural language question into a Cypher query using an LLM.

Example:

Input:

Who are the players of Chelsea?

Generated Cypher:

MATCH (a:Athlete)-[:PLAYS_FOR]->(c:Club)
WHERE c.name = "Chelsea F.C."
RETURN a.name AS athlete
LIMIT 20

execute_cypher(cypher)

Executes a Cypher query against Neo4j and returns the results.


generate_answer(question, data)

Converts retrieved graph data into a natural language response.


graph_rag(question)

Main Graph RAG pipeline:

Question
   ↓
Generate Cypher
   ↓
Execute Cypher
   ↓
Retrieve Graph Data
   ↓
Generate Answer

football_mcp.py

This module implements the MCP server and exposes multiple tools for interacting with the knowledge graph.

Available Tools

ask_graph()

Query the football knowledge graph using natural language.

preview_graph()

Preview entities and relationships before insertion into Neo4j.

build_graph()

Automatically construct a knowledge graph from natural language text.

run_cypher()

Execute custom Cypher queries directly on Neo4j.

project_info()

Display project information.


test.py

Used for testing, experimentation, and development purposes.


Knowledge Graph Schema

Entities

Athlete

Represents football players.

Examples:

Cole Palmer
Bukayo Saka
Bruno Fernandes

Club

Represents football clubs.

Examples:

Chelsea F.C.
Arsenal F.C.
Manchester United F.C.

Country

Represents player nationality or country of origin.

Examples:

England
Germany
Brazil

Relationships

PLAYS_FOR

(Athlete)-[:PLAYS_FOR]->(Club)

Example:

Cole Palmer
    │
PLAYS_FOR
    ▼
Chelsea F.C.

FROM

(Athlete)-[:FROM]->(Country)

Example:

Cole Palmer
    │
FROM
    ▼
England

Cypher Query Logic

The system uses a Text-to-Cypher approach.

Example Question:

Who are the players of Chelsea?

Generated Cypher:

MATCH (a:Athlete)-[:PLAYS_FOR]->(c:Club)
WHERE c.name = "Chelsea F.C."
RETURN a.name AS athlete
LIMIT 20

Example Question:

Which country contributes the most players to Arsenal?

Generated Cypher:

MATCH (a:Athlete)-[:PLAYS_FOR]->(c:Club),
      (a)-[:FROM]->(country:Country)
WHERE c.name = "Arsenal F.C."
RETURN country.name AS country,
       count(*) AS total
ORDER BY total DESC
LIMIT 10

AI Pipeline Explanation

The AI workflow consists of three main stages.

Stage 1 — Natural Language to Cypher

User question:

Who plays for Chelsea?

The LLM translates the question into a valid Cypher query based on the graph schema.


Stage 2 — Graph Retrieval

The generated Cypher query is executed against Neo4j.

Example result:

[
  {
    "athlete": "Cole Palmer"
  },
  {
    "athlete": "Enzo Fernandez"
  }
]

Stage 3 — Natural Language Answer Generation

The retrieved graph data is passed back to the LLM to generate a human-readable response.

Example:

The players currently associated with Chelsea in the knowledge graph are Cole Palmer and Enzo Fernandez.

Installation

Clone the repository:

git clone https://github.com/Fachreza28/football-knowledge-graph-rag.git

cd football-knowledge-graph-rag

Install dependencies:

pip install -r requirements.txt

Configuration

Create a .env file:

NEO4J_URI=neo4j://127.0.0.1:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_password

OPENROUTER_API_KEY=your_api_key

MODEL_NAME=google/gemini-2.5-flash

Running the Project

Start the MCP server:

python football_mcp.py

Expected output:

STARTING MCP SERVER...

Example Queries

Who plays for Chelsea?

Who plays for Arsenal?

Which country contributes the most players to Arsenal?

Which players are from England?

Which club does Cole Palmer play for?


Author

Fachreza Aptadhi Kurniawan

Co-Author

Sultan Alamsyah Mubarok

Football Knowledge Graph RAG Project using Neo4j, MCP, Graph RAG, and Large Language Models.

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