Skip to main content

MCP Server Generator CLI - Analyze codebases and generate production-ready MCP servers via gRPC backend

Project description

Synapse - Agentic MCP Server Generator

An intelligent CLI tool that analyzes any codebase and automatically generates production-ready MCP (Model Context Protocol) servers

Overview

Synapse enables seamless integration between AI assistants and existing codebases by automatically generating MCP servers. Simply point Synapse at your codebase, describe what you need, and it will create a fully functional MCP server with tools, resources, and proper error handling.

Features

  • ๐Ÿš€ Quick Setup: Initialize with a single command
  • ๐Ÿค– Multi-Model Support: Works with Claude, GPT-4, Groq, and Gemini
  • ๐Ÿ” Smart Analysis: Automatically analyzes your codebase structure
  • ๐Ÿ—๏ธ Agentic Generation: Uses CrewAI for intelligent MCP server generation
  • ๐Ÿ”’ Secure Configuration: Encrypted API key storage
  • โœ… MCP Compliant: Generates servers that follow MCP specifications

System Architecture

The build process uses a two-agent flow: Planner Agent โ†’ Generator Agent, both powered by an intelligent codebase context search system.

flowchart TB
    subgraph Input
        UQ[User Query]
        CB[User's Codebase]
    end

    subgraph "Planner Agent"
        P1[Receive User Query]
        P2{Need More Context?}
        P3[Call Context Search Tool]
        P4[Analyze Search Results]
        P5[Extract Function Signatures]
        P6[Identify Relevant Code]
        P7[Create Markdown To-Do List]
        P8[Write to .synapse/todo_list.md]
    end

    subgraph "Codebase Context Search Tool"
        CS1[Parse Query Keywords]
        CS2[Grep Search Codebase]
        CS3[AST Parse Python Files]
        CS4[Extract Function Signatures]
        CS5[Follow Imports Recursively]
        CS6[Track Visited Files]
        CS7[Score Relevance]
        CS8[Return Structured Context]
    end

    subgraph "Generator Agent"
        G1[Read To-Do List Markdown]
        G2[Get Next Unchecked Task]
        G3{Task Available?}
        G4{Need Context?}
        G5[Call Context Search Tool]
        G6[Check Function Signatures]
        G7[Read Current MCP Server File]
        G8[Write/Update MCP Server Code]
        G9[Use insert_file / replace_file]
        G10[Check Off Task in Markdown]
        G11[MCP Server Complete]
    end

    subgraph "File Editing Tools"
        FE1[read_file_tool]
        FE2[insert_file_tool]
        FE3[replace_file_tool]
        FE4[write_file_tool]
    end

    subgraph Output
        TODO[".synapse/todo_list.md"]
        MCP["mcp_server.py"]
    end

    %% Input flows
    UQ --> P1
    CB --> CS2

    %% Planner flow
    P1 --> P2
    P2 -->|Yes| P3
    P3 --> CS1
    CS1 --> CS2
    CS2 --> CS3
    CS3 --> CS4
    CS4 --> CS5
    CS5 --> CS6
    CS6 --> CS7
    CS7 --> CS8
    CS8 --> P4
    P4 --> P5
    P5 --> P6
    P6 --> P2
    P2 -->|No, Enough Context| P7
    P7 --> P8
    P8 --> TODO

    %% Generator flow
    TODO --> G1
    G1 --> G2
    G2 --> G3
    G3 -->|Yes| G4
    G4 -->|Yes| G5
    G5 --> CS1
    CS8 --> G6
    G6 --> G7
    G4 -->|No| G7
    G7 --> FE1
    FE1 --> G8
    G8 --> G9
    G9 --> FE2
    G9 --> FE3
    FE2 --> G10
    FE3 --> G10
    G10 --> FE3
    G10 --> G2
    G3 -->|No, All Done| G11
    G11 --> MCP

    %% Styling
    style UQ fill:#e1f5fe
    style CB fill:#e1f5fe
    style TODO fill:#fff9c4
    style MCP fill:#c8e6c9

Flow Description

Planner Agent (Iterative Context Gathering)

  1. Receives user query describing MCP server requirements
  2. Iteratively searches codebase using the context search tool:
    • Calls search multiple times to gather comprehensive context
    • Follows imports and references across files
    • Extracts exact function signatures and parameter patterns
  3. Creates markdown to-do list with checkboxes at .synapse/todo_list.md
  4. Each task includes: description, required files/functions, dependencies, expected output

Codebase Context Search Tool

  • Text-based search: Uses grep patterns to find relevant code
  • AST parsing: Extracts function signatures, classes, and methods
  • Import following: Recursively follows import statements to gather related context
  • Relevance scoring: Ranks results by relevance to the query
  • Returns: Structured context with file paths, line numbers, and code snippets

Generator Agent (Sequential Task Execution)

  1. Reads the markdown to-do list from the planner
  2. For each unchecked task (sequentially):
    • Uses context search to verify function signatures and argument patterns
    • Reads current MCP server file (if exists)
    • Writes/updates MCP server code using file editing tools
    • Uses only existing code from user's codebase
    • Follows exact positional argument patterns from user's functions
    • Checks off completed task in markdown (- [ ] โ†’ - [x])
  3. Continues until all tasks are complete

To-Do List Format

The planner creates a markdown file with this structure:

# MCP Server Generation Tasks

- [ ] Task 1: Create MCP server boilerplate
  - Description: Initialize FastMCP server with imports and main execution
  - Expected Output: Basic server structure with FastMCP

- [ ] Task 2: Implement tool for function_name
  - Description: Create MCP tool that exposes function_name
  - Required Files: module/file.py
  - Function Signature: def function_name(param1: str, param2: int) -> dict
  - Dependencies: from module.file import function_name

- [x] Task 1: Create MCP server boilerplate  (checked when complete)

Installation

From PyPI (Recommended - Coming Soon)

pip install synapse-cli

From Source

# Clone the repository
cd /path/to/synapse

# Install in development mode
pip install -e .

# Verify installation
synapse --version

For Development

# Install with development dependencies
pip install -e ".[dev]"

# Or install from requirements.txt
pip install -r requirements.txt

Quick Start

1. Initialize Synapse

# Navigate to your project directory
cd /path/to/your/project

# Initialize Synapse
synapse init

This will:

  • Create a .synapse directory
  • Prompt you to select an AI model (Claude, GPT-4, Groq, or Gemini)
  • Securely store your API key
  • Set up the configuration

2. Check Status

synapse status

Commands

synapse init

Initialize Synapse in the current directory.

synapse init          # Initialize with interactive prompts
synapse init --force  # Re-initialize if already exists

What it does:

  • Creates .synapse configuration directory
  • Configures AI model and API key
  • Sets up encrypted configuration storage

Example output:

๐Ÿš€ Synapse Initialization
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

Select your AI model:
  1. Anthropic Claude
  2. Groq
  3. OpenAI
  4. Gemini

Your choice: 1

โœ“ Selected: Anthropic Claude
Enter your API key: ********************************
โœ“ Validating API key...
โœ“ Connection successful!
โœ“ Configuration saved securely

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐ŸŽ‰ Welcome to Synapse!

Available Commands:
  synapse config       View or update configuration
  synapse analyze      Analyze your codebase structure
  synapse build        Generate MCP server from requirements

Get started: synapse analyze
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

synapse status

Show current Synapse status and project information.

synapse status

What it shows:

  • Initialization status
  • Configuration status
  • Analysis status
  • Next steps

synapse config

View or update configuration. API keys are shown as first 5 characters + ****.

synapse config                    # View current config (project + global API key display)
synapse config --key <API_KEY>    # Set project API key (and global if not set)
synapse config --global --key <API_KEY>  # Set global API key only

synapse analyze

Analyze codebase structure (Coming in Phase 2).

synapse analyze
synapse analyze --verbose
synapse analyze --output ./custom_output

synapse build

Generate MCP server from requirements (Coming in Phase 2).

synapse build
synapse build --query "Create tools for database operations"
synapse build --output custom_server.py

Project Structure

synapse/
โ”œโ”€โ”€ cli.py                  # Main CLI entry point
โ”œโ”€โ”€ pyproject.toml          # Modern Python package configuration (PEP 621)
โ”œโ”€โ”€ setup.py                # Minimal setup for backward compatibility
โ”œโ”€โ”€ MANIFEST.in             # Package file inclusion rules
โ”œโ”€โ”€ commands/               # Command implementations
โ”‚   โ”œโ”€โ”€ init_command.py    # synapse init
โ”‚   โ”œโ”€โ”€ config_command.py  # synapse config (Phase 2)
โ”‚   โ”œโ”€โ”€ analyze_command.py # synapse analyze (Phase 2)
โ”‚   โ””โ”€โ”€ build_command.py   # synapse build (Phase 2)
โ”œโ”€โ”€ utils/                  # Utility functions
โ”‚   โ”œโ”€โ”€ cli_utils.py       # CLI interaction helpers
โ”‚   โ”œโ”€โ”€ config_manager.py  # Configuration management
โ”‚   โ”œโ”€โ”€ call_llm.py        # LLM API integration
โ”‚   โ””โ”€โ”€ ...                # Other utilities
โ”œโ”€โ”€ crews/                  # CrewAI crews (Phase 2+)
โ”œโ”€โ”€ agents/                 # Agent definitions (Phase 2+)
โ”œโ”€โ”€ tools/                  # Tool wrappers (Phase 2+)
โ”œโ”€โ”€ nodes/                  # Node implementations (Phase 2+)
โ”œโ”€โ”€ templates/              # MCP server templates (Phase 2+)
โ””โ”€โ”€ tests/                  # Test files

Packaging

Synapse uses modern Python packaging standards:

  • pyproject.toml: Main configuration file (PEP 621 compliant)
  • setup.py: Minimal compatibility shim
  • Ready for PyPI publishing

See PUBLISHING.md for detailed instructions on building and publishing to PyPI.

Configuration

Synapse uses two config locations:

  • Global: ~/.synapse/config.json โ€” shared across projects (API key stored encrypted).
  • Project: PROJECT_ROOT/.synapse/config.json โ€” per-project config and API key override.

API key precedence (for backend gRPC auth): SYNAPSE_API_KEY env > project API key > global API key.

Set API key:

synapse init                    # Prompts for API key if no global key; sets both project and global
synapse config --key <API_KEY>  # Set project key (and global if global not set)
synapse config --global --key <API_KEY>  # Set global key only

View config (API key shown as first 5 chars + ****): synapse config.

Project directory layout:

.synapse/
โ”œโ”€โ”€ config.json            # Encrypted API key + project config
โ”œโ”€โ”€ project_schema.txt     # Generated by analyze
โ””โ”€โ”€ statistics.json        # Generated by analyze

Testing API key ("Invalid or expired API key")

The backend validates keys against the database (and Redis cache). The key you set in the CLI must be a key that exists in the backend's api_keys table.

  • Production / UI flow: Create an API key in the Synapse web app (Settings or API Keys). Copy the key (shown only once) and set it in the CLI: synapse config --key <that_exact_key>.

  • Local / dev testing: Seed a test key into the same DB the gRPC backend uses, then use that key in the CLI:

    # From repo root; set DB_PASSWORD (and CLOUD_SQL_CONNECTION_NAME if using Cloud SQL)
    python infrastructure/seed_test_api_key.py
    # Copy the printed key, then:
    synapse config --key <printed_key>
    synapse build
    
  • Verify what the CLI is using: Run synapse config and check the "API Key" line (first 5 chars + ****). Ensure it matches the key you created (e.g. syn-api-... from the UI or seed script). If you set SYNAPSE_API_KEY in the environment, that overrides project/global config.

Supported AI Models

Model Provider API Key Format
Claude 3.5 Sonnet Anthropic sk-ant-...
Llama 3.3 70B Groq gsk_...
GPT-4 OpenAI sk-...
Gemini 1.5 Pro Google AIza...

Security

  • API keys are encrypted using Fernet symmetric encryption
  • Encryption keys are machine-specific
  • Configuration files are stored locally in .synapse/
  • Never commit .synapse/ to version control

Development Status

โœ… Phase 1: CLI Tool & Init (Current)

  • Project structure
  • CLI framework with Click
  • Configuration management with encryption
  • synapse init command
  • synapse status command
  • Documentation

๐Ÿšง Phase 2: Config & Analysis (Next)

  • synapse config command
  • Codebase analyzer
  • synapse analyze command
  • Project schema generation

๐Ÿ“‹ Phase 3: MCP Generation

  • CrewAI integration
  • Agent definitions
  • synapse build command
  • MCP server templates
  • Validation

Requirements

  • Python 3.9+
  • API key for at least one supported AI model
  • Internet connection for API calls

Troubleshooting

"Synapse not initialized"

Run synapse init in your project directory first.

"Invalid API key"

Ensure your API key:

  • Starts with the correct prefix for your chosen model
  • Has no extra spaces or characters
  • Is valid and active

Re-initialization

Use synapse init --force to re-initialize if needed.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details

Support

For issues, questions, or contributions, please visit:


Built with โค๏ธ using CrewAI and the Model Context Protocol

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synapse_cli-0.1.3.tar.gz (115.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synapse_cli-0.1.3-py3-none-any.whl (122.5 kB view details)

Uploaded Python 3

File details

Details for the file synapse_cli-0.1.3.tar.gz.

File metadata

  • Download URL: synapse_cli-0.1.3.tar.gz
  • Upload date:
  • Size: 115.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for synapse_cli-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7b930e961c739c58871785e0b61873b870683f25abd0a60d999b12b3a29fa006
MD5 f02e51dbd4a3a0d50badfc2320e32a86
BLAKE2b-256 8449ed84dd8ef869cbd337cfe59ff255b8f2bfb070d3fcccd7c72fd8e21ac43c

See more details on using hashes here.

File details

Details for the file synapse_cli-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: synapse_cli-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 122.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for synapse_cli-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 35c3191fe1bbd6103a7546d56480451cb43f5d9a0d1a138a782c795b085fb61d
MD5 80abb81ba8eed44f4c246450a04aab4a
BLAKE2b-256 ecd5ac85c58df8c311528b9ab14d0d2fa18c04300c4af770b4e8136364923bec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page