Tanuj2005/KG-MCP-SERVER
If you are the rightful owner of KG-MCP-SERVER and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server providing seamless access to multiple freely available knowledge graphs including Wikidata, DBpedia, and ConceptNet.
Knowledge Graph MCP Server
A Model Context Protocol (MCP) server providing seamless access to multiple freely available knowledge graphs including Wikidata, DBpedia, and ConceptNet.
Overview
This server enables AI assistants and applications to query structured knowledge from some of the world's largest public knowledge bases. It provides a unified interface for executing SPARQL queries and searching entities across different knowledge graph platforms.
Features
- Multi-Graph Support: Query Wikidata, DBpedia, and ConceptNet through a single interface
- SPARQL Queries: Execute complex SPARQL queries against Wikidata and DBpedia endpoints
- ConceptNet Integration: Explore semantic relationships and common-sense knowledge
- Async Operations: Built with async/await for efficient concurrent requests
- Error Handling: Comprehensive error handling with timeout protection and detailed error messages
- MCP Protocol: Fully compatible with the Model Context Protocol for AI assistant integration
Supported Knowledge Graphs
Knowledge Graph | Type | Description |
---|---|---|
Wikidata | SPARQL + API | Collaborative knowledge base with 100M+ items from Wikipedia |
DBpedia | SPARQL | Structured information extracted from Wikipedia infoboxes |
ConceptNet | REST API | Multilingual knowledge graph of common-sense concepts and relationships |
Installation
Prerequisites
- Python 3.11 or higher
- uv (recommended) or pip
Setup
- Clone the repository:
git clone <your-repo-url>
cd KG_MCP_SERVER
- Install dependencies:
# Using uv (recommended)
uv sync
# Or using pip
pip install -e .
Usage
Running the Server
python main.py
The server will start and expose MCP tools for querying knowledge graphs.
Available Tools
1. list_knowledge_graphs()
List all available knowledge graphs and their capabilities.
Returns:
{
"available_graphs": {...},
"total_count": 3
}
2. query_wikidata_sparql(sparql_query: str)
Execute SPARQL queries against Wikidata.
Example:
query = """
SELECT ?item ?itemLabel WHERE {
?item wdt:P31 wd:Q5.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 10
"""
result = await query_wikidata_sparql(query)
3. query_dbpedia_sparql(sparql_query: str)
Execute SPARQL queries against DBpedia.
Example:
query = """
SELECT ?person ?name WHERE {
?person a dbo:Person .
?person foaf:name ?name .
}
LIMIT 10
"""
result = await query_dbpedia_sparql(query)
4. query_conceptnet(concept: str, limit: int = 10)
Query ConceptNet for relationships about a concept.
Example:
result = await query_conceptnet("dog", limit=10)
# Returns relationships like IsA(animal), UsedFor(companionship)
Configuration
Knowledge graph endpoints are configured in . You can add or modify endpoints by editing the KNOWLEDGE_GRAPHS
dictionary.
Example Queries
Find All Nobel Prize Winners (Wikidata)
SELECT ?person ?personLabel ?prizeLabel WHERE {
?person wdt:P166 ?prize.
?prize wdt:P31 wd:Q7191.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 20
Get Information About a City (DBpedia)
SELECT ?city ?population ?country WHERE {
?city a dbo:City ;
dbo:population ?population ;
dbo:country ?country .
FILTER(?population > 1000000)
}
LIMIT 10
Explore Concept Relationships (ConceptNet)
# Query for "coffee"
result = await query_conceptnet("coffee", limit=15)
# Returns edges like: UsedFor(staying awake), AtLocation(cafe), etc.
Error Handling
All tools return structured responses with success indicators:
{
"success": True,
"results": {...},
"query": "..."
}
Or on error:
{
"success": False,
"error": "Error type",
"message": "Detailed error message"
}