
Neptune Graph Analytics using Strands Agent
Graph Database Analytics using Agentic AI built based on Strands SDK Authors: Seshadri Senthamaraikannan (seshasen) , Mohan Gowda Purushothama (purumoha)
Graph databases excel at representing complex relationships in data, but extracting meaningful insights often requires specialized query knowledge and technical expertise. What if you could simply ask natural language questions about your graph data and get intelligent, contextual responses? In this post, we'll explore how to combine Amazon Neptune with Strands Agents SDK using the Model Context Protocol (MCP) to create powerful, conversational analytics experiences.
Challenge: Making Graph Data Accessible
Organizations store vast amounts of interconnected data in graph databases like Amazon Neptune, from customer purchase patterns to complex network topologies. However, extracting insights typically requires:
- Deep knowledge of query languages like Gremlin or openCypher
- Understanding of the underlying graph schema
- Technical expertise to interpret complex relationships
This creates a barrier between business users and valuable graph insights, limiting the democratization of data analytics across organizations.
Solution: Model Context Protocol (MCP)
The Model Context Protocol (MCP) is an open standard that enables Large Language Models (LLMs) to seamlessly integrate with external tools and services. By combining Amazon Neptune with Strands AI agents through MCP, we can create intelligent systems that:
- Accept natural language queries about graph data
- Automatically generate appropriate database queries
- Analyze results and provide contextual summaries
- Make graph analytics accessible to non-technical users
Architecture Overview
Our solution leverages a multi-component architecture that bridges natural language processing with graph database operations:

The implementation consists of:
- Strands Agents SDK: Serves as the primary orchestrator, managing the conversation flow and tool interactions. More info: https://strandsagents.com/latest/
- Amazon Bedrock LLM: Powers the natural language understanding and response generation
- Neptune MCP Server: Provides standardized tools for Neptune database operations. More info: https://awslabs.github.io/mcp/servers/amazon-neptune-mcp-server/
- Amazon Neptune: Stores and processes the graph data with high performance
This architecture is an experiment based providing developers capability to set up Strands Agent SDK and run analytics on Amazon Neptune which can also be deployed as an production application at scale. The implementation leverages the Strands Agents SDK in conjunction with the Model Context Protocol (MCP) tools to establish a seamless interaction framework between users, Amazon Bedrock LLM, and Neptune DB. Within this architecture, the Strands Agents SDK serves as the primary intermediary, facilitating connections to the Neptune database through MCP tools. The system utilizes Amazon Bedrock LLM to formulate appropriate queries and execute them against the Neptune DB instance. Following successful data retrieval, the solution employs Anthropic Claude Sonnet 4.5 from Amazon Bedrock to synthesize the information and deliver a comprehensive, user-friendly summary to the end user. This integrated approach enhances data accessibility while maintaining robust processing workflows across all system components.
These tools are organized into three distinct functional components:
- Run Queries Tool: This component executes OpenCypher or Gremlin queries against the Neptune database. It handles the complete query lifecycle from formation to execution and result retrieval. The tool abstracts the complexity of direct database interaction, allowing the Agent to focus on generating appropriate query syntax based on user requirements.
- Get Schema Tool: This tool retrieves comprehensive schema information from the Neptune database. It provides the Agent with detailed knowledge about node labels, edge relationships, property keys, and the overall graph structure. This schema awareness is critical for the Agent to understand the data model before constructing relevant queries.
- Get Status Tool: This component performs availability checks to determine if the Neptune graph instance is operational. It verifies connectivity and readiness before the Agent attempts any data operations, ensuring reliability and providing appropriate feedback when the database is unavailable.
The architecture also includes a Utility Function component that facilitates data loading operations into the Neptune database. This enables the preparation and population of graph data that the Agent can subsequently query and analyze.
Implementation Walkthrough
In this example we will show you the following:-
- How to use Amazon Neptune MCP tools on your Strands SDK.
- How to load Sample customer purchase data into Neptune DB using Utility.
- Connecting with Neptune DB, analysing and providing the summary based on user question.
Prerequisites
Before getting started, ensure you have:
- Python 3.10+
- AWS account with appropriate permissions
- Anthropic Claude 3.7 enabled on Amazon Bedrock
- Neptune DB Cluster configured and available
- Required Python packages installed
requirements.txt
uvstrands-agentsstrands-agents-toolsmcpicecreampandasnumpylangchain-communityawscurlInstall Required Libraries
pip install -r requirements.txt
Loading Sample Customer Purchase data into Neptune DB
We have used a sample customer purchase retail dataset from kaggle . Download this file into a /data folder. This dataset is in CSV format and we have used a python utility neptune_loader/gremlin_csv_generator.py to convert these CSV files into Gremlin standard CSV files. This utility requires comprehensive schema information regarding the Nodes and their connecting edges based on the Source file to be processed. This essential information must be provided through the completion of the configuration JSON file. Once executed it provides the list of gremlin standard csv files which is ready to be loaded in Neptune DB.
Below configuration is used by the utility to convert the CSV files into Gremlin standard Nodes and Edges files.
"nodes": [ { "label": "Customer Purchase", -- Node Label "file_name": "customer_purchase", -- Gremlin CSV filename for Node "node_cols": [ "CustomerID:string" -- Source Column To be used for creating Nodes ], "properties": { -- Additional Properties to be part of the Node (can be from source data or text field "Country of Residence": "Country:string", "context_type": "Customer details", "description": "Customer Purchase history Tree", "tree_name": "Customer Purchase history", "effectiveFrom": "20250401120000" } } "edges": [ { "label": "Purchased", -- Edge label "file_name": "customer_products", -- Filename for edge files "from_cols": [ "CustomerID:string" -- Edge connecting From nodelColumn name (must match with node cols above) ], "to_cols": [ -- Edge connection to node column name "InvoiceNo:string", "StockCode:string" ], "from_label": "customer_purchase", --- Edge connecting from Node Label "to_label": "product_purchased", --- Edge connecting to Node label "properties": {} }Using the above configuration mapping file, generate gremlin standard Nodes and Edges files.
import pandas as pdimport numpy as npfrom neptune_loader.gremlin_csv_generator import generate_gremlin_files
# Source data to the loadedsrc_data_location = 'data/customer_data.csv' -- Source datasrc_format_location = 'neptune_loader/customer_data.json' -- Source data configuration mapping file
# Create gremlin standard files using neptune utility# Note: It always needs the json file to be created to map the relationship between nodes
generate_gremlin_files(src_data_location,src_format_location)Upload the generated gremlin standard files to S3 bucket for processing into Neptune
# Provide the bucket name you want the data to be copied. # Ensure the Notebook Instance has necessary S3 permissions to read and write files.bucket_name = "neptune-strands-store-poc"
# Copy the created gremlin files to S3 bucketprefix_name = "customer-data"
!aws s3 cp nodes/ s3://{bucket_name}/gremlin/{prefix_name}/nodes/ --recursive!aws s3 cp edges/ s3://{bucket_name}/gremlin/{prefix_name}/edges/ --recursive
# Loading Nodes into Neptune DB using Curl command# Provide the Host name of Neptune DBHOST='HOST'
!awscurl --service neptune-db --region us-west-2 -X POST \ -H 'Content-Type: application/json' \ $HOST:8182/loader -d \ '{"source" : "s3://<bucket>/gremlin/customer-data/nodes/","format" : "csv","iamRoleArn" : "arn:aws:iam::<Account>:role/NeptuneLoadFromS3","region" : "us-west-2","failOnError" : "TRUE","parallelism" : "MEDIUM","updateSingleCardinalityProperties" : "FALSE","queueRequest" : "TRUE"}'
!awscurl --service neptune-db --region us-west-2 -X POST \ -H 'Content-Type: application/json' \ $HOST:8182/loader -d \ '{"source" : "s3://<bucket>/gremlin/customer-data/edges/","format" : "csv","iamRoleArn" : "arn:aws:iam::<Account>:role/NeptuneLoadFromS3","region" : "us-west-2","failOnError" : "TRUE","parallelism" : "MEDIUM","updateSingleCardinalityProperties" : "FALSE","queueRequest" : "TRUE"}'Strands Agent SDK Set up
import threadingimport timefrom datetime import timedelta
from mcp import StdioServerParameters, stdio_clientfrom mcp.client.streamable_http import streamablehttp_clientfrom mcp.server import FastMCPfrom strands import Agentfrom strands.tools.mcp import MCPClient
# Connect to an Neptune MCP server using stdio transportneptune_mcp_client = MCPClient(lambda: stdio_client( StdioServerParameters( command="uvx", args=["awslabs.amazon-neptune-mcp-server@latest"], env = {"NEPTUNE_ENDPOINT":"neptune-db://db-neptune-1.cluster-chow2sm86ya0.us-west-2.neptune.amazonaws.com"} ) ))
Perform Analytics on Customer Purchase data in Neptune
with neptune_mcp_client: # Get the tools from the MCP server tools = neptune_mcp_client.list_tools_sync()
# Create an agent with these tools agent = Agent(tools=tools, max_parallel_tools=1)
response = agent( "Summarize the purchase details in america and get me what was purchased the most?" ) Output:I'll help you analyze the purchase details in America and find out what was purchased the most. Let me first check the graph schema to understand what data we're working with.Tool #8: get_graph_schemaNow I'll run a query to analyze purchases in America and find the most purchased product:Tool #9: run_opencypher_queryLet me try a slightly different approach since I need to make sure I'm capturing data for America correctly:Tool #10: run_opencypher_queryGreat! Now I'll use "USA" as the country identifier to find the most purchased products:Tool #11: run_opencypher_queryLet me also get some additional information about the total purchase volume and number of unique products:Tool #12: run_opencypher_query## Purchase Details in America - Summary
Based on the data analysis of purchases made in the USA, here's a summary of the purchase details:
### Most Purchased Products in America1. **SET 12 COLOURING PENCILS DOILY** - 88 units purchased2. **12 PENCILS SMALL TUBE RED RETROSPOT** - 72 units purchased3. Several tied products with 48 units each: - SET 6 SCHOOL MILK BOTTLES IN CRATE - SET/10 PINK POLKADOT PARTY CANDLES - SET/10 IVORY POLKADOT PARTY CANDLES - SET/10 RED POLKADOT PARTY CANDLES - SET/10 BLUE POLKADOT PARTY CANDLES4. **PACK OF 20 NAPKINS PANTRY DESIGN** - 36 units purchased5. **PARTY CONES CANDY TREE DECORATION** - 36 units purchased...- Total number of unique products purchased: 163- Total quantity of items purchased: 1,034
### ConclusionThe most purchased product in America was the **SET 12 COLOURING PENCILS DOILY** with 88 units purchased. There appears to be a strong preference for stationery items and party supplies among American customers.Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...Conclusion
Dataset in Neptune Graph DB contains around 500k entries of customer purchase details across different countries. Using Neptune MCP tools with Strands Agent SDK within few line of code we have got an excellent summary with detailed analysis of UK's Purchase details in real time. This also illustrates that by leveraging these relationship-centric data models in Neptune DB, AI agents can perform more sophisticated analytical operations, drawing deeper insights from multidimensional data connections and delivering more contextually relevant results to users. This relational intelligence significantly enhances the analytical precision and contexual awareness of the system.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article