Labsco
kpritam logo

Gremlin

โ˜… 9

from kpritam

Interact with any Gremlin-compatible graph database using natural language, with support for schema discovery, complex queries, and data import/export.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

Gremlin MCP Server

Connect AI agents like Claude, Cursor, and Windsurf to your graph databases!

An MCP (Model Context Protocol) server that enables AI assistants to interact with any Gremlin-compatible graph database through natural language. Query your data, discover schemas, analyze relationships, and manage graph data using simple conversations.

โœจ What You Can Do

Talk to your graph database naturally:

  • ๐Ÿ” "What's the structure of my graph?" - Automatic schema discovery
  • ๐Ÿ“Š "Show me all users over 30 and their connections" - Complex graph queries
  • ๐Ÿ”— "Find the shortest path between Alice and Bob" - Relationship analysis
  • ๐Ÿ“ˆ "Give me graph statistics and metrics" - Data insights
  • ๐Ÿ“ฅ "Import this GraphSON data" - Data loading
  • ๐Ÿ“ค "Export user data as CSV" - Data extraction
  • ๐Ÿง  Smart enum discovery - AI learns your data's valid values automatically

๐Ÿ› ๏ธ Available Tools

Your AI assistant gets access to these powerful tools:

ToolPurposeWhat It Does
๐Ÿ” get_graph_statusHealth CheckVerify database connectivity and server status
๐Ÿ“‹ get_graph_schemaSchema DiscoveryGet complete graph structure with nodes, edges, and relationships
โšก run_gremlin_queryQuery ExecutionExecute any Gremlin traversal query with full syntax support
๐Ÿ”„ refresh_schema_cacheCache ManagementForce immediate refresh of cached schema information
๐Ÿ“ฅ import_graph_dataData ImportLoad data from GraphSON, CSV, or JSON with batch processing
๐Ÿ“ค export_subgraphData ExportExtract subgraphs to JSON, GraphSON, or CSV formats

๐Ÿง  Automatic Enum Discovery

Why this matters: AI agents work best when they know the exact valid values for properties. Instead of guessing or making invalid queries, they can use precise, real values from your data.

One of the most powerful features of this MCP server is Automatic Enum Discovery - it intelligently analyzes your graph data to discover valid property values and provides them as enums to AI agents.

๐Ÿค” The Problem It Solves

Without Enum Discovery:

AI: "I see this vertex has a 'status' property of type 'string'...
     Let me try querying with status='active'"
Result: โŒ No results (actual values are 'CONFIRMED', 'PENDING', 'CANCELLED')

With Enum Discovery:

AI: "I can see the 'status' property has these exact values:
     ['CONFIRMED', 'PENDING', 'CANCELLED', 'WAITLISTED']
     Let me query with status='CONFIRMED'"
Result: โœ… Perfect results using real data values

๐Ÿ’ก How It Works

The server automatically scans your graph properties and:

  1. Identifies Low-Cardinality Properties - Properties with a reasonable number of distinct values
  2. Extracts Real Values - Samples actual data from your graph
  3. Provides as Enums - Includes valid values in the schema for AI agents

Example Output:

{
  "name": "bookingStatus",
  "type": ["string"],
  "cardinality": "single",
  "enum": ["CONFIRMED", "PENDING", "CANCELLED", "WAITLISTED"],
  "sample_values": ["CONFIRMED", "PENDING"]
}

๐ŸŽฏ Benefits for AI Agents

  • ๐ŸŽฏ Accurate Queries - AI uses real values instead of guessing
  • โšก Faster Results - No trial-and-error with invalid values
  • ๐Ÿง  Better Understanding - AI learns your data vocabulary
  • ๐Ÿ“Š Smarter Analytics - Enables grouping and filtering with actual categories

โš™๏ธ Configuration Options

Fine-tune enum discovery to match your data:

# Enable/disable enum discovery
GREMLIN_ENUM_DISCOVERY_ENABLED="true"         # Default: true

# Control what gets detected as enum
GREMLIN_ENUM_CARDINALITY_THRESHOLD="10"       # Max distinct values for enum (default: 10)

# Exclude specific properties
GREMLIN_ENUM_PROPERTY_BLACKLIST="id,uuid,timestamp,createdAt,updatedAt"

# Schema optimization
GREMLIN_SCHEMA_MAX_ENUM_VALUES="10"           # Limit enum values shown (default: 10)
GREMLIN_SCHEMA_INCLUDE_SAMPLE_VALUES="false"  # Reduce schema size (default: false)

๐Ÿšซ Property Blacklist

Some properties should never be treated as enums:

Automatically Excluded:

  • High-cardinality properties (> threshold unique values)
  • Numeric IDs and UUIDs
  • Timestamps and dates
  • Long text fields

Manual Exclusion:

# Exclude specific properties by name
GREMLIN_ENUM_PROPERTY_BLACKLIST="userId,sessionId,description,notes,content"

Common Blacklist Patterns:

  • id,uuid,guid - Unique identifiers
  • timestamp,createdAt,updatedAt,lastModified - Time fields
  • description,notes,comment,content,text - Free text fields
  • email,url,phone,address - Personal/contact data
  • hash,token,key,secret - Security-related fields

๐Ÿ› ๏ธ Real-World Examples

E-commerce Graph:

{
  "orderStatus": {
    "enum": ["PENDING", "PROCESSING", "SHIPPED", "DELIVERED", "CANCELLED"]
  },
  "productCategory": {
    "enum": ["ELECTRONICS", "CLOTHING", "BOOKS", "HOME", "SPORTS"]
  },
  "paymentMethod": {
    "enum": ["CREDIT_CARD", "PAYPAL", "BANK_TRANSFER", "CRYPTO"]
  }
}

Social Network Graph:

{
  "relationshipType": {
    "enum": ["FRIEND", "FAMILY", "COLLEAGUE", "ACQUAINTANCE"]
  },
  "privacyLevel": {
    "enum": ["PUBLIC", "FRIENDS", "PRIVATE"]
  },
  "accountStatus": {
    "enum": ["ACTIVE", "SUSPENDED", "DEACTIVATED"]
  }
}

๐Ÿ”ง Tuning for Your Data

For Large Datasets:

GREMLIN_ENUM_CARDINALITY_THRESHOLD="5"     # Stricter enum detection
GREMLIN_SCHEMA_MAX_ENUM_VALUES="5"         # Fewer values in schema

For Rich Categorical Data:

GREMLIN_ENUM_CARDINALITY_THRESHOLD="25"    # More permissive detection
GREMLIN_SCHEMA_MAX_ENUM_VALUES="20"        # Show more enum values

For Performance-Critical Environments:

GREMLIN_ENUM_DISCOVERY_ENABLED="false"     # Disable for faster schema loading
GREMLIN_SCHEMA_INCLUDE_SAMPLE_VALUES="false" # Minimal schema size

This intelligent enum discovery transforms how AI agents interact with your graph data, making queries more accurate and insights more meaningful! ๐ŸŽฏ

๐Ÿ—„๏ธ Supported Databases

Works with any Gremlin-compatible graph database:

DatabaseStatusNotes
๐ŸŸข Apache TinkerPopโœ… TestedLocal development and CI testing
๐ŸŸก Amazon Neptune๐Ÿ”ง CompatibleDesigned for, not yet tested
๐ŸŸก JanusGraph๐Ÿ”ง CompatibleDesigned for, not yet tested
๐ŸŸก Azure Cosmos DB๐Ÿ”ง CompatibleWith Gremlin API
๐ŸŸก ArcadeDB๐Ÿ”ง CompatibleWith Gremlin support

๐Ÿ” Security Considerations

โš ๏ธ Important: This server is designed for development and trusted environments.

Current Limitations

  • Basic input sanitization (advanced injection protection in development)
  • No connection pooling or rate limiting
  • All Gremlin syntax is permitted
  • No audit logging for security monitoring
  • ๐Ÿ”’ Use behind a firewall in production
  • ๐Ÿ”‘ Enable strong authentication on your Gremlin server
  • ๐Ÿ“Š Monitor query patterns and resource usage
  • ๐Ÿ›ก๏ธ Consider a query proxy for additional security controls
  • ๐Ÿ”„ Keep dependencies updated

๐Ÿ”ง Developer Documentation

The following sections are for developers who want to contribute to or modify the server.

Development Setup

# Clone and install
git clone https://github.com/kpritam/gremlin-mcp.git
cd gremlin-mcp
npm install

# Development with hot reload
npm run dev

# Run tests
npm test
npm run test:coverage
npm run test:watch

# Integration tests (requires running Gremlin server)
GREMLIN_ENDPOINT=localhost:8182/g npm run test:it

# All tests together (unit + integration)
npm test && npm run test:it

Architecture

  • Full Type Safety: TypeScript + Effect functional programming patterns
  • Effect-based Architecture: Uses Effect.ts for composable, type-safe operations
  • Service-Oriented Design: Dependencies managed through Effect's Context.Tag patterns
  • Layer-Based Composition: Application built using Effect.Layer for dependency resolution
  • Comprehensive Testing: Unit + Integration tests with Effect testing patterns
  • Error Handling: Effect-based error management with custom error types

Project Structure

src/
โ”œโ”€โ”€ server.ts              # Effect-based MCP server with graceful startup/shutdown
โ”œโ”€โ”€ config.ts              # Effect.Config-based configuration validation
โ”œโ”€โ”€ constants.ts           # Application constants integrated with Effect configuration
โ”œโ”€โ”€ gremlin/
โ”‚   โ”œโ”€โ”€ service.ts         # GremlinService using Effect.Context.Tag pattern
โ”‚   โ”œโ”€โ”€ schema-service.ts  # SchemaService with Effect dependency injection
โ”‚   โ””โ”€โ”€ types.ts           # TypeScript types and schemas
โ”œโ”€โ”€ handlers/              # Effect-based MCP request handlers
โ”‚   โ”œโ”€โ”€ tools.ts           # Effect-based tool handlers
โ”‚   โ”œโ”€โ”€ resources.ts       # Effect-based resource handlers
โ”‚   โ””โ”€โ”€ effect-runtime-bridge.ts # ManagedRuntime container for Effect execution
โ””โ”€โ”€ utils/                 # Effect-based utility modules
    โ”œโ”€โ”€ data-operations.ts # Effect-based graph data import/export operations
    โ”œโ”€โ”€ result-parser.ts   # Gremlin result parsing with metadata extraction
    โ””โ”€โ”€ type-guards.ts     # Runtime type checking functions

Available Scripts

CommandPurpose
npm run buildCompile TypeScript to JavaScript
npm run devDevelopment mode with hot reload
npm testRun unit test suite
npm run lintCode linting with ESLint
npm run formatCode formatting with Prettier
npm run validateRun all checks (format, lint, type-check, test)

Smart Schema Discovery

The server implements intelligent schema discovery with enumeration detection:

// Property with detected enum values
{
  "name": "status",
  "type": ["string"],
  "cardinality": "single",
  "enum": ["Confirmed", "Pending", "Cancelled", "Waitlisted"]
}

Contributing

  1. Follow the rules in RULES.md
  2. Run npm run validate before committing
  3. Add tests for new functionality
  4. Update documentation for user-facing changes
  5. Ensure all tests pass

Testing Strategy

  • Unit Tests (tests/): Individual component testing
    • Component isolation with comprehensive mocking
    • Type safety validation with Zod schemas
    • Fast execution without external dependencies
  • Integration Tests (tests/integration/): Full workflow testing
    • Real Gremlin server connections via Docker
    • End-to-end MCP protocol validation
    • Database operations and query execution
  • CI Testing: Automated testing in GitHub Actions
    • Unit tests run on every commit
    • Integration tests run with Docker Gremlin server
    • Both required for releases

๐Ÿ“„ License

MIT License - feel free to use in your projects!


Questions? Check the troubleshooting guide or open an issue.