Skip to content

feat: add MCP server for Neo4j graph queries#11

Merged
rysweet merged 2 commits intomainfrom
feature/mcp-server-10
Jul 30, 2025
Merged

feat: add MCP server for Neo4j graph queries#11
rysweet merged 2 commits intomainfrom
feature/mcp-server-10

Conversation

@rysweet
Copy link
Owner

@rysweet rysweet commented Jul 30, 2025

Summary

  • Implements MCP server for AI agents to query Blarify graphs
  • Provides three powerful tools for code understanding and change planning
  • Uses Neo4j for graph queries and Azure OpenAI for result formatting
  • Includes comprehensive integration tests with real Neo4j database

Details

This PR implements issue #10 to create an MCP (Model Context Protocol) server that provides AI coding agents with sophisticated tools to query and analyze Blarify graph databases.

Tools Implemented

  1. getContextForFiles

    • Retrieves comprehensive context for specified files
    • Traverses graph to find classes, functions, dependencies, imports
    • Includes LLM summaries and documentation links
    • Returns organized Markdown structure
  2. getContextForSymbol

    • Gets detailed context for any symbol (class, function, variable)
    • Finds definitions, usages, inheritance chains, and relationships
    • Supports fuzzy matching for symbol names
    • Shows callers, callees, and references
  3. buildPlanForChange

    • Analyzes codebase to create implementation plans
    • Extracts entities from change requests using LLM
    • Identifies affected files, dependencies, and tests
    • Generates step-by-step implementation guide

Architecture

mcp-blarify-server/
├── src/
│   ├── server.py              # Main MCP server
│   ├── config.py              # Configuration management
│   ├── tools/
│   │   ├── context_tools.py   # File and symbol context
│   │   ├── planning_tools.py  # Change planning
│   │   └── query_builder.py   # Cypher queries
│   └── processors/
│       ├── graph_traversal.py # Neo4j traversal
│       ├── context_builder.py # Context organization
│       └── llm_processor.py   # LLM integration
└── tests/                     # Comprehensive test suite

Testing

This PR includes comprehensive testing:

Unit Tests

  • Query builder tests
  • Context builder tests
  • LLM processor tests
  • MCP server tests

Integration Tests

  • Real Neo4j database with docker-compose
  • Test graph setup with realistic Blarify data
  • Full end-to-end testing of all MCP tools
  • Manual test script for interactive testing
  • CI/CD workflow for automated testing

Test Data

The test setup creates a realistic graph with:

  • Folder structure (src, tests, docs)
  • Code nodes (UserService, AuthService, UserController)
  • Relationships (inheritance, imports, calls, uses)
  • Documentation nodes with concepts
  • LLM descriptions
  • Filesystem nodes

Configuration

Environment variables:

  • NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD: Neo4j connection
  • AZURE_OPENAI_API_KEY, AZURE_OPENAI_ENDPOINT: LLM configuration
  • MAX_TRAVERSAL_DEPTH, MAX_CONTEXT_LENGTH: Performance tuning

Usage Example

# In Claude Desktop config
{
  "mcpServers": {
    "blarify": {
      "command": "python",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/mcp-blarify-server"
    }
  }
}

Test plan

  • Unit tests for all components
  • Integration tests with real Neo4j
  • Test data setup script
  • Manual testing script
  • Docker-compose environment
  • CI/CD workflow
  • Testing with Claude Desktop
  • Performance testing with large graphs

How to Test

  1. Run unit tests:

    cd mcp-blarify-server
    pytest tests/test_*.py -v
  2. Run integration tests:

    cd mcp-blarify-server
    ./run_integration_tests.sh
  3. Manual testing:

    cd mcp-blarify-server
    docker-compose up -d
    python tests/setup_test_graph.py
    python manual_test.py

🤖 Generated with Claude Code

rysweet and others added 2 commits July 30, 2025 01:07
This MCP server provides AI coding agents with sophisticated tools to query and analyze the Blarify graph database. It enables AI agents to understand codebases deeply by accessing the rich graph representations Blarify creates.

Key features:
- Three main tools: getContextForFiles, getContextForSymbol, buildPlanForChange
- Intelligent Cypher query building for complex graph traversals
- LLM integration to organize results into coherent Markdown
- Comprehensive context extraction with configurable depth
- Impact analysis for change planning
- Support for fuzzy symbol matching
- Error handling and performance optimization

Tools:
1. getContextForFiles: Retrieves comprehensive context for specified files
2. getContextForSymbol: Gets detailed context for symbols (classes, functions, etc.)
3. buildPlanForChange: Analyzes codebase and creates implementation plans

The server uses Neo4j for graph queries and Azure OpenAI for intelligent result formatting. It includes comprehensive tests, documentation, and usage examples.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added full integration testing suite that actually tests the MCP server with a real Neo4j database:

- Docker-compose setup for Neo4j test environment
- Test graph setup script that creates realistic Blarify data
- Integration tests that verify all MCP tools work with real data
- Manual test script for interactive testing
- CI/CD workflow for automated testing
- Convenience script for running integration tests

The test graph includes:
- Folder structure with src, tests, docs directories
- Code nodes: UserService, AuthService, UserController classes
- Relationships: inheritance, method calls, imports, usage
- Documentation nodes with concepts and links
- LLM descriptions for key classes
- Filesystem nodes
- Test file relationships

This ensures the MCP server is thoroughly tested with realistic data before deployment.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@rysweet rysweet merged commit 083ade0 into main Jul 30, 2025
rysweet pushed a commit that referenced this pull request Aug 3, 2025
rysweet added a commit that referenced this pull request Aug 3, 2025
feat: add MCP server for Neo4j graph queries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments