LLM-Driven SPARQL Generation with Streamable HTTP Transport 🚀
An intelligent MCP server that provides SPARQL query generation and execution capabilities for AGS (Anzo Graph Server) instances. This version uses the latest MCP SDK with Streamable HTTP transport (recommended for production) and eliminates the need for external API keys.
- Python 3.10+
- Access to an AGS instance with graphmart data
cd Altair_Graph_MCP_HTTP
pip install -r requirements.txtCreate a .env file with your AGS credentials:
ANZO_SERVER=your-ags-server
ANZO_PORT=443
ANZO_USERNAME=your-username
ANZO_PASSWORD=your-password
GRAPHMART_URI=http://your-graphmart-uripython src/ags_sparql_agent_server.pyExpected output:
🚀 Starting AGS SPARQL Agent MCP Server (Streamable HTTP Transport)
🔧 Configuration: HOST=0.0.0.0, PORT=8000
🔧 Mode: Stateless (recommended)
✅ FastMCP server created for Streamable HTTP transport
✅ 42 tools registered successfully
✅ 3 prompts registered successfully
📡 Starting MCP server with Streamable HTTP transport...
🌐 MCP endpoint: http://0.0.0.0:8000/mcp
The MCP endpoint is available at http://localhost:8000/mcp. Use POST requests to send MCP protocol messages.
Example with Claude Code:
claude mcp add --transport http my-ags-server http://localhost:8000/mcpget_sparql_generation_context- Get LLM-optimized ontology contextvalidate_sparql_syntax- Validate queries before executionget_sparql_examples- Get working query examples
- System & Monitoring (2 tools)
- SPARQL Query Execution (3 tools)
- Knowledge Discovery (5 tools)
- Ontology Management (10 tools)
- Graphmart Construction (10 tools)
- Graphmart Management (2 tools)
- Graphmart Diagnostics (2 tools)
generate_sparql_query- Step-by-step SPARQL generation guideimprove_sparql_query- Fix failed queries based on errorssparql_best_practices- AGS-specific best practices reference
User: "How many products are in the knowledge graph?"
Claude Response:
I'll help you query the knowledge graph:
1. Getting ontology context...
[Calls: get_sparql_generation_context]
Found: c:0 = Product (1,234 instances)
2. Generating SPARQL query:
SELECT (COUNT(?product) as ?count)
WHERE { ?product a c:0 }
3. Validating...
[Calls: validate_sparql_syntax]
✅ Valid query
4. Executing...
[Calls: execute_sparql_query]
Result: 1,234 products
Answer: There are 1,234 products in the knowledge graph.
User: "How many customers do we have?"
→ Generated SPARQL: SELECT (COUNT(?customer) as ?count) WHERE { ?customer a c:5 }
→ Result: 2,567 customers
User: "Find products with 'bike' in the name"
→ Generated SPARQL:
SELECT ?product ?name WHERE {
?product a c:0 ; p:0 ?name .
FILTER(CONTAINS(LCASE(?name), "bike"))
} LIMIT 20
→ Result: List of bike products
User: "Show me orders and their products"
→ First attempt fails (no results)
→ System uses improve_sparql_query prompt
→ Makes relationships OPTIONAL
→ Second attempt succeeds
→ Result: Orders with and without products
Start the server and verify the output:
python src/ags_sparql_agent_server.pyLook for these success indicators:
- ✅ FastMCP server created for Streamable HTTP transport
- ✅ 42 tools registered
- ✅ 3 prompts registered
- 🌐 MCP endpoint available at /mcp
Try these sample questions:
- "How many entities are in the graph?"
- "Find products containing 'bike'"
- "Which customers have placed orders?"
- "Show the average order value per customer"
Each query should follow this pattern:
- ✅ Get ontology context
- ✅ Generate SPARQL internally
- ✅ Validate before executing
- ✅ Execute successfully
- ✅ Return natural language response
This server is optimized for Railway deployment. The server automatically:
- Binds to
0.0.0.0for cloud accessibility - Uses the
PORTenvironment variable provided by Railway - Runs in stateless mode for optimal scalability
Deploy with:
railway upThe MCP endpoint will be available at: https://your-app.railway.app/mcp