From 56aca5db36d7909371a1864b0aa4365dbb3a8bc2 Mon Sep 17 00:00:00 2001 From: "kmsh.dev" Date: Wed, 23 Jul 2025 21:29:55 +0530 Subject: [PATCH] Simplify project structure and unify extension configuration --- .github/workflows/release.yml | 6 - Cargo.lock | 2 +- Cargo.toml | 28 ++- build.sh | 90 -------- configuration/default_settings.jsonc | 11 +- configuration/installation_instructions.md | 30 +-- crates/bridge/Cargo.toml | 13 +- crates/extension/Cargo.toml | 25 --- .../configuration/default_settings.jsonc | 11 - .../installation_instructions.md | 89 -------- extension.toml | 2 +- scripts/deepwiki-mcp-proxy.sh | 192 ------------------ {crates/extension/src => src}/lib.rs | 5 +- {crates/extension/src => src}/tests.rs | 0 14 files changed, 28 insertions(+), 476 deletions(-) delete mode 100755 build.sh delete mode 100644 crates/extension/Cargo.toml delete mode 100644 crates/extension/configuration/default_settings.jsonc delete mode 100644 crates/extension/configuration/installation_instructions.md delete mode 100755 scripts/deepwiki-mcp-proxy.sh rename {crates/extension/src => src}/lib.rs (98%) rename {crates/extension/src => src}/tests.rs (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f97d02a..7253b68 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -210,9 +210,3 @@ jobs: exit 1 fi echo "✅ extension.toml found" - - - name: Test extension build script - run: | - echo "🔧 Testing build script..." - chmod +x build.sh - ./build.sh diff --git a/Cargo.lock b/Cargo.lock index 15c1a0b..b10d6ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,7 +233,7 @@ dependencies = [ ] [[package]] -name = "deepwiki-mcp-server-extension" +name = "deepwiki-mcp-server" version = "0.1.0" dependencies = [ "schemars", diff --git a/Cargo.toml b/Cargo.toml index 0d93784..784c72d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,22 +1,20 @@ -[workspace] -members = ["crates/extension", "crates/bridge"] -resolver = "2" - -[workspace.package] +[package] +name = "deepwiki-mcp-server" version = "0.1.0" edition = "2021" authors = ["Keshav Mishra "] repository = "https://github.com/keshav1998/deepwiki-mcp-server" license = "MIT" -[workspace.lints.rust] -unsafe_code = "forbid" +[lib] +crate-type = ["cdylib"] +path = "src/lib.rs" -[workspace.lints.clippy] -# Enable pedantic clippy checks -pedantic = { level = "warn", priority = -1 } -# Specific lint configurations -module_name_repetitions = "allow" -missing_errors_doc = "allow" -missing_panics_doc = "allow" -must_use_candidate = "allow" +[dependencies] +zed_extension_api = "0.6.0" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +schemars = { version = "0.8", features = ["derive"] } + +[workspace] +members = ["crates/bridge"] diff --git a/build.sh b/build.sh deleted file mode 100755 index 349632e..0000000 --- a/build.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash - -# DeepWiki MCP Server Build Script -# This script builds both the Zed extension (WASM) and the native bridge binary - -set -e - -echo "🚀 Building DeepWiki MCP Server Extension" -echo "==========================================" - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -# Function to print colored output -print_status() { - echo -e "${GREEN}[INFO]${NC} $1" -} - -print_warning() { - echo -e "${YELLOW}[WARN]${NC} $1" -} - -print_error() { - echo -e "${RED}[ERROR]${NC} $1" -} - -# Check if we're in the right directory -if [ ! -f "extension.toml" ]; then - print_error "extension.toml not found. Please run this script from the project root." - exit 1 -fi - -# Clean previous builds -print_status "Cleaning previous builds..." -cargo clean - -# Build the minimal proxy binary first (native) -print_status "Building minimal rust-sdk proxy binary..." -if cargo build --release --manifest-path crates/bridge/Cargo.toml; then - print_status "✅ Proxy binary built successfully" -else - print_error "❌ Failed to build proxy binary" - exit 1 -fi - -# Build the extension (WASM) -print_status "Building WASM extension..." -if cargo build --release --manifest-path crates/extension/Cargo.toml --target wasm32-wasip1; then - print_status "✅ Extension WASM built successfully" -else - print_error "❌ Failed to build extension WASM" - exit 1 -fi - -# Create distribution directory -print_status "Creating distribution package..." -mkdir -p dist/bin - -# Copy the proxy binary -cp target/release/deepwiki-mcp-bridge dist/bin/ - -# Copy the extension WASM -cp target/wasm32-wasip1/release/deepwiki_mcp_server_extension.wasm dist/ - -# Copy configuration files -cp extension.toml dist/ -cp -r crates/extension/configuration dist/ - -# Copy documentation -cp README.md dist/ 2>/dev/null || echo "README.md not found, skipping" -cp LICENSE dist/ 2>/dev/null || echo "LICENSE not found, skipping" - -print_status "📦 Distribution package created in 'dist/' directory" -echo -echo "Contents:" -echo " - dist/bin/deepwiki-mcp-bridge (minimal rust-sdk proxy)" -echo " - dist/deepwiki_mcp_server_extension.wasm (Zed extension)" -echo " - dist/extension.toml (extension manifest)" -echo " - dist/configuration/ (extension configuration)" -echo - -print_status "🎉 Build completed successfully!" -echo -echo "Next steps:" -echo " 1. Install the proxy binary: cp dist/bin/deepwiki-mcp-bridge ~/.local/bin/" -echo " 2. Install the extension in Zed extensions directory" -echo " 3. Or use: zed --install-extension ./dist" diff --git a/configuration/default_settings.jsonc b/configuration/default_settings.jsonc index 1f3b849..7da8413 100644 --- a/configuration/default_settings.jsonc +++ b/configuration/default_settings.jsonc @@ -3,14 +3,9 @@ // Endpoint URL - choose one: // - "https://mcp.deepwiki.com" for free public repositories only - // - "https://mcp.devin.ai" for authenticated access to public and private repositories + // - "https://mcp.devin.ai" for authenticated access (OAuth2 handled automatically) "endpoint": "https://mcp.deepwiki.com", - // Wire protocol to use (sse or mcp) - "protocol": "mcp", - - // Optional: Devin API key for authenticated access to private repositories - // Required when using "https://mcp.devin.ai" endpoint - // Get your API key from https://devin.ai account settings - // "devin_api_key": "YOUR_DEVIN_API_KEY" + // Note: Transport type (HTTP/SSE) is auto-detected based on URL patterns + // Note: Authentication for Devin endpoints is handled automatically via OAuth2 } diff --git a/configuration/installation_instructions.md b/configuration/installation_instructions.md index 028b335..c2f984e 100644 --- a/configuration/installation_instructions.md +++ b/configuration/installation_instructions.md @@ -2,8 +2,11 @@ This extension provides access to DeepWiki's documentation search capabilities through the Model Context Protocol (MCP). + ## Configuration +The extension will automatically download the appropriate bridge binary for your platform (Linux, macOS, or Windows) from GitHub releases. + ### Basic Setup (Free - Public Repositories Only) For access to public repositories only, no authentication is required: @@ -38,30 +41,3 @@ For access to both public and private repositories, you'll need a Devin API key: } } ``` - -## Available Tools - -The DeepWiki MCP server provides three main tools: - -- **`read_wiki_structure`** - Get a list of documentation topics for a GitHub repository -- **`read_wiki_contents`** - View documentation about a GitHub repository -- **`ask_question`** - Ask any question about a GitHub repository and get an AI-powered, context-grounded response - -## Wire Protocols - -The server supports two wire protocols: - -- **SSE (Server-Sent Events)** - Recommended for most integrations (`/sse` endpoint) -- **Streamable HTTP** - Alternative protocol (`/mcp` endpoint) - -For maximum compatibility, the SSE protocol is used by default. - -## Troubleshooting - -- Ensure your Devin API key is valid if using the authenticated endpoint -- Check that the endpoint URL is correct for your chosen service -- Verify that the protocol setting matches your client's capabilities - -For more information, visit: -- [DeepWiki MCP Documentation](https://docs.devin.ai/work-with-devin/deepwiki-mcp) -- [Devin MCP Documentation](https://docs.devin.ai/work-with-devin/devin-mcp) diff --git a/crates/bridge/Cargo.toml b/crates/bridge/Cargo.toml index f191680..22cc3b7 100644 --- a/crates/bridge/Cargo.toml +++ b/crates/bridge/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "deepwiki-mcp-bridge" -version.workspace = true -edition.workspace = true -authors.workspace = true +version = "0.1.0" +edition = "2021" +authors = ["Keshav Mishra "] description = "DeepWiki MCP Proxy - Minimal proxy using official rust-sdk for Zed context servers" -repository.workspace = true -license.workspace = true +repository = "https://github.com/keshav1998/deepwiki-mcp-server" +license = "MIT" [[bin]] name = "deepwiki-mcp-bridge" @@ -37,6 +37,3 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } [features] default = [] - -[lints] -workspace = true diff --git a/crates/extension/Cargo.toml b/crates/extension/Cargo.toml deleted file mode 100644 index 0c839f2..0000000 --- a/crates/extension/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "deepwiki-mcp-server-extension" -version.workspace = true -edition.workspace = true -authors.workspace = true -description = "DeepWiki MCP Server Extension for Zed" -repository.workspace = true -license.workspace = true - -[lib] -crate-type = ["cdylib"] - -[dependencies] -# Zed Extension API -zed_extension_api = "0.6.0" -schemars = { version = "0.8", features = ["derive"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" - -[features] -default = [] -test-support = [] - -[lints] -workspace = true diff --git a/crates/extension/configuration/default_settings.jsonc b/crates/extension/configuration/default_settings.jsonc deleted file mode 100644 index 7da8413..0000000 --- a/crates/extension/configuration/default_settings.jsonc +++ /dev/null @@ -1,11 +0,0 @@ -{ - // DeepWiki MCP Server Configuration - - // Endpoint URL - choose one: - // - "https://mcp.deepwiki.com" for free public repositories only - // - "https://mcp.devin.ai" for authenticated access (OAuth2 handled automatically) - "endpoint": "https://mcp.deepwiki.com", - - // Note: Transport type (HTTP/SSE) is auto-detected based on URL patterns - // Note: Authentication for Devin endpoints is handled automatically via OAuth2 -} diff --git a/crates/extension/configuration/installation_instructions.md b/crates/extension/configuration/installation_instructions.md deleted file mode 100644 index d5b22a7..0000000 --- a/crates/extension/configuration/installation_instructions.md +++ /dev/null @@ -1,89 +0,0 @@ -# DeepWiki MCP Server Extension Installation - -This extension provides access to DeepWiki's documentation search capabilities through the Model Context Protocol (MCP). - -## Automatic Setup - -The extension automatically downloads and configures the required bridge binary when first used. No manual installation of additional components is required! - -## Configuration - -The extension will automatically download the appropriate bridge binary for your platform (Linux, macOS, or Windows) from GitHub releases. - -### Basic Setup (Free - Public Repositories Only) - -For access to public repositories only, no authentication is required: - -```json -{ - "context_servers": { - "deepwiki-mcp-server-extension": { - "endpoint": "https://mcp.deepwiki.com", - "protocol": "sse" - } - } -} -``` - -### Advanced Setup (Authenticated - Public & Private Repositories) - -For access to both public and private repositories, you'll need a Devin API key: - -1. Sign up for a Devin account at [Devin.ai](https://devin.ai) -2. Generate an API key from your account settings -3. Configure the extension with your API key: - -```json -{ - "context_servers": { - "deepwiki-mcp-server-extension": { - "endpoint": "https://mcp.devin.ai", - "protocol": "sse", - "devin_api_key": "YOUR_DEVIN_API_KEY" - } - } -} -``` - -## Available Tools - -The DeepWiki MCP server provides three main tools: - -- **`read_wiki_structure`** - Get a list of documentation topics for a GitHub repository -- **`read_wiki_contents`** - View documentation about a GitHub repository -- **`ask_question`** - Ask any question about a GitHub repository and get an AI-powered, context-grounded response - -## Wire Protocols - -The server supports two wire protocols: - -- **SSE (Server-Sent Events)** - Recommended for most integrations (`/sse` endpoint) -- **Streamable HTTP** - Alternative protocol (`/mcp` endpoint) - -For maximum compatibility, the SSE protocol is used by default. - -## Troubleshooting - -### Common Issues - -- **Binary Download Failed**: Ensure you have internet connectivity and GitHub is accessible -- **Permission Denied**: The extension automatically handles file permissions, but check if your system allows file downloads -- **Wrong Architecture**: The extension automatically detects your platform, but you can check the logs if there are issues - -### Configuration Issues - -- Ensure your Devin API key is valid if using the authenticated endpoint -- Check that the endpoint URL is correct for your chosen service -- Verify that the protocol setting matches your client's capabilities - -### Manual Installation (Advanced) - -If automatic download fails, you can manually install the bridge binary: - -1. Download the appropriate binary from [GitHub Releases](https://github.com/keshav1998/deepwiki-mcp-server/releases) -2. Extract and place it in your extension's `bin/` directory -3. Make it executable (Unix systems): `chmod +x bin/deepwiki-mcp-bridge` - -For more information, visit: -- [DeepWiki MCP Documentation](https://docs.devin.ai/work-with-devin/deepwiki-mcp) -- [Devin MCP Documentation](https://docs.devin.ai/work-with-devin/devin-mcp) diff --git a/extension.toml b/extension.toml index 9832613..ff2e191 100644 --- a/extension.toml +++ b/extension.toml @@ -5,7 +5,7 @@ schema_version = 1 authors = ["Keshav Mishra "] description = "DeepWiki - Repository Documentation and AI Q&A" repository = "https://github.com/keshav1998/deepwiki-mcp-server" -lib = { path = "crates/extension/Cargo.toml" } + [context_servers.deepwiki-mcp-server] name = "DeepWiki MCP Server" diff --git a/scripts/deepwiki-mcp-proxy.sh b/scripts/deepwiki-mcp-proxy.sh deleted file mode 100755 index bc02b4e..0000000 --- a/scripts/deepwiki-mcp-proxy.sh +++ /dev/null @@ -1,192 +0,0 @@ -#!/bin/bash - -# DeepWiki MCP Proxy Script -# This script acts as a simple proxy between Zed and the DeepWiki MCP server -# It forwards JSON-RPC requests from stdin to the DeepWiki server and returns responses - -# Enable debug logging -DEBUG=${DEBUG:-0} -debug_log() { - if [ "$DEBUG" = "1" ]; then - echo "DEBUG: $1" >&2 - fi -} - -# Get configuration from environment variables -DEEPWIKI_ENDPOINT="${DEEPWIKI_ENDPOINT:-https://mcp.deepwiki.com}" -DEEPWIKI_PROTOCOL="${DEEPWIKI_PROTOCOL:-mcp}" -DEEPWIKI_URL="${DEEPWIKI_ENDPOINT}/${DEEPWIKI_PROTOCOL}" - -# Session management - use a temporary file to persist state -SESSION_FILE=$(mktemp) -echo "" > "$SESSION_FILE" -INITIALIZED=false - -# Function to get session ID -get_session_id() { - cat "$SESSION_FILE" 2>/dev/null || echo "" -} - -# Function to set session ID -set_session_id() { - echo "$1" > "$SESSION_FILE" - debug_log "Session ID set to: $1" -} - -# Function to make HTTP request to DeepWiki -make_request() { - local json_data="$1" - local current_session_id=$(get_session_id) - - debug_log "Making request to $DEEPWIKI_URL" - debug_log "Request data: $json_data" - debug_log "Current session ID: '$current_session_id'" - - local headers=(-H "Content-Type: application/json" -H "Accept: application/json, text/event-stream") - - # Add session ID header if we have one - if [ -n "$current_session_id" ]; then - headers+=(-H "Mcp-Session-Id: $current_session_id") - debug_log "Using session ID header" - else - debug_log "No session ID header" - fi - - # Make the request and capture both headers and body - local temp_headers=$(mktemp) - local response=$(curl -s -D "$temp_headers" "${headers[@]}" -d "$json_data" "$DEEPWIKI_URL") - - debug_log "Raw response: $response" - - # Extract session ID from headers if present - local new_session_id=$(grep -i "mcp-session-id:" "$temp_headers" | cut -d' ' -f2- | tr -d '\r\n') - if [ -n "$new_session_id" ]; then - set_session_id "$new_session_id" - debug_log "Updated session ID: $new_session_id" - fi - - rm "$temp_headers" - - # Parse SSE response to extract JSON - local json_response=$(echo "$response" | grep "^data: " | sed 's/^data: //' | grep -v "^ping$" | head -1) - debug_log "Parsed JSON: $json_response" - echo "$json_response" -} - -# Function to handle initialization -handle_initialize() { - local request_id="$1" - debug_log "Handling initialize with request ID: $request_id" - - local init_request='{ - "jsonrpc": "2.0", - "id": 1, - "method": "initialize", - "params": { - "protocolVersion": "2024-11-05", - "capabilities": {"tools": {}}, - "clientInfo": {"name": "deepwiki-mcp-server-zed", "version": "0.1.0"} - } - }' - - local response=$(make_request "$init_request") - if [ $? -eq 0 ] && [ -n "$response" ] && [ "$response" != "null" ]; then - INITIALIZED=true - debug_log "Initialization successful" - echo "$response" | jq -c --arg id "$request_id" '.id = ($id | tonumber)' - else - debug_log "Initialization failed" - echo "{\"jsonrpc\":\"2.0\",\"id\":$request_id,\"error\":{\"code\":-32603,\"message\":\"Failed to initialize DeepWiki session\"}}" - fi -} - -# Function to forward requests to DeepWiki -forward_request() { - local method="$1" - local params="$2" - local request_id="$3" - local session_id=$(get_session_id) - - debug_log "Forwarding request: method=$method, params=$params, id=$request_id" - debug_log "Current session ID: '$session_id'" - debug_log "Initialized flag: '$INITIALIZED'" - - if [ "$INITIALIZED" != "true" ]; then - debug_log "Session not initialized" - echo "{\"jsonrpc\":\"2.0\",\"id\":$request_id,\"error\":{\"code\":-32603,\"message\":\"Session not initialized\"}}" - return - fi - - if [ -z "$session_id" ]; then - debug_log "No session ID available" - echo "{\"jsonrpc\":\"2.0\",\"id\":$request_id,\"error\":{\"code\":-32603,\"message\":\"No session ID available\"}}" - return - fi - - local forward_request - if [ "$params" = "null" ] || [ -z "$params" ]; then - forward_request="{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"$method\"}" - else - forward_request="{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"$method\",\"params\":$params}" - fi - - debug_log "Forward request JSON: $forward_request" - - local response=$(make_request "$forward_request") - debug_log "Forward response: $response" - - if [ $? -eq 0 ] && [ -n "$response" ] && [ "$response" != "null" ]; then - echo "$response" | jq -c --arg id "$request_id" '.id = ($id | tonumber)' - else - debug_log "Failed to get valid response" - echo "{\"jsonrpc\":\"2.0\",\"id\":$request_id,\"error\":{\"code\":-32603,\"message\":\"Failed to forward request to DeepWiki\"}}" - fi -} - -# Cleanup function -cleanup() { - debug_log "Cleaning up temporary files" - rm -f "$SESSION_FILE" -} - -# Set up cleanup trap -trap cleanup EXIT - -# Main loop - read JSON-RPC requests from stdin -while IFS= read -r line; do - if [ -z "$line" ]; then - continue - fi - - debug_log "Received request: $line" - - # Parse the JSON-RPC request - method=$(echo "$line" | jq -r '.method // empty') - params=$(echo "$line" | jq -c '.params // null') - request_id=$(echo "$line" | jq -r '.id // null') - - debug_log "Parsed: method=$method, params=$params, id=$request_id" - - case "$method" in - "initialize") - handle_initialize "$request_id" - ;; - "initialized") - # Notification - no response needed - debug_log "Received initialized notification" - ;; - "notifications/message") - # Handle logging/debugging messages - no response needed - debug_log "Received notification message" - ;; - "tools/list"|"tools/call") - forward_request "$method" "$params" "$request_id" - ;; - *) - if [ "$request_id" != "null" ]; then - debug_log "Unknown method: $method" - echo "{\"jsonrpc\":\"2.0\",\"id\":$request_id,\"error\":{\"code\":-32601,\"message\":\"Method '$method' not found\"}}" - fi - ;; - esac -done diff --git a/crates/extension/src/lib.rs b/src/lib.rs similarity index 98% rename from crates/extension/src/lib.rs rename to src/lib.rs index 23d3974..8076801 100644 --- a/crates/extension/src/lib.rs +++ b/src/lib.rs @@ -37,8 +37,7 @@ impl zed::Extension for DeepWikiMcpExtension { let bridge_path = self.ensure_bridge_binary()?; // Get user settings or use defaults - let settings = - ContextServerSettings::for_project("deepwiki-mcp-server-extension", project)?; + let settings = ContextServerSettings::for_project("deepwiki-mcp-server", project)?; let config = settings.settings.map_or_else( || DeepWikiContextServerSettings { @@ -70,7 +69,7 @@ impl zed::Extension for DeepWikiMcpExtension { let installation_instructions = include_str!("../configuration/installation_instructions.md").to_string(); - let settings = ContextServerSettings::for_project("deepwiki-mcp-server-extension", project); + let settings = ContextServerSettings::for_project("deepwiki-mcp-server", project); let mut default_settings = include_str!("../configuration/default_settings.jsonc").to_string(); diff --git a/crates/extension/src/tests.rs b/src/tests.rs similarity index 100% rename from crates/extension/src/tests.rs rename to src/tests.rs