Skip to content

Instantly share code, notes, and snippets.

@giehlman
Created January 20, 2026 12:56
Show Gist options
  • Select an option

  • Save giehlman/2595a38f82170fd4590607d51a7ba166 to your computer and use it in GitHub Desktop.

Select an option

Save giehlman/2595a38f82170fd4590607d51a7ba166 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# KnowledgeCP Installation Script
# Installs and configures the KnowledgeCP MCP server for Claude Code
#
# Usage: curl -fsSL https://knowledgecp.com/install.sh | bash
#
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
KNOWLEDGECP_VERSION="1.0.0"
KNOWLEDGECP_SERVER_URL="${KNOWLEDGECP_SERVER_URL:-https://knowledgecp.com/sse}"
CLAUDE_CONFIG_DIR="$HOME/.claude"
KNOWLEDGECP_DIR="$CLAUDE_CONFIG_DIR/knowledgecp"
# Print colored message
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[OK]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if jq is installed
check_jq() {
if ! command -v jq &> /dev/null; then
print_warning "jq is not installed. Attempting to install..."
if [[ "$OSTYPE" == "darwin"* ]]; then
if command -v brew &> /dev/null; then
brew install jq
else
print_error "Please install jq: brew install jq"
exit 1
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt-get &> /dev/null; then
sudo apt-get update && sudo apt-get install -y jq
elif command -v yum &> /dev/null; then
sudo yum install -y jq
else
print_error "Please install jq manually"
exit 1
fi
else
print_error "Please install jq manually"
exit 1
fi
fi
}
# Create directories
setup_directories() {
print_info "Setting up directories..."
mkdir -p "$CLAUDE_CONFIG_DIR"
mkdir -p "$KNOWLEDGECP_DIR"
mkdir -p "$KNOWLEDGECP_DIR/context"
mkdir -p "$KNOWLEDGECP_DIR/instructions"
print_success "Directories created"
}
# Create or update MCP config
setup_mcp_config() {
print_info "Configuring MCP server..."
local MCP_CONFIG="$CLAUDE_CONFIG_DIR/mcp.json"
# Create new config if doesn't exist
if [ ! -f "$MCP_CONFIG" ]; then
echo '{"mcpServers":{}}' > "$MCP_CONFIG"
fi
# Add/update knowledgecp server config
local TEMP_FILE=$(mktemp)
jq --arg url "$KNOWLEDGECP_SERVER_URL" \
'.mcpServers.knowledgecp = {
"type": "sse",
"url": $url,
"description": "KnowledgeCP - Team Knowledge Base"
}' "$MCP_CONFIG" > "$TEMP_FILE"
mv "$TEMP_FILE" "$MCP_CONFIG"
print_success "MCP config updated: $MCP_CONFIG"
}
# Create or update CLAUDE.md
setup_claude_md() {
print_info "Setting up CLAUDE.md..."
local CLAUDE_MD="$CLAUDE_CONFIG_DIR/CLAUDE.md"
local KNOWLEDGECP_SECTION="
## KnowledgeCP
KnowledgeCP is configured for team knowledge management.
### Automatic Actions (Session Start)
1. Check for knowledge updates: \`kb_check_update()\`
2. If updates available, ask user if they want to sync
3. Load knowledge from \`~/.claude/knowledgecp/\`:
- \`context/*.md\` - Business knowledge, APIs, conventions
- \`instructions/*.md\` - MCP usage guides
### User Commands
When the user says any of these phrases, use the corresponding tool:
| User Says | Action |
|-----------|--------|
| \"speichere was wir besprochen haben\" | \`kb_remember(key, content)\` |
| \"remember this session\" | \`kb_remember(key, content)\` |
| \"persist to knowledgecp\" | \`kb_remember(key, content)\` |
| \"zeige Knowledge-Status\" | Show version and last sync info |
### Tools Available
- \`kb_login(email, password)\` - Login to KnowledgeCP
- \`kb_pull()\` - Pull latest knowledge
- \`kb_check_update()\` - Check for updates
- \`kb_remember(key, content)\` - Save new knowledge (as draft)
- \`kb_submit_review(knowledge_id)\` - Submit draft for review
- \`kb_logout()\` - Logout
### Roles
- **Member**: Can read published knowledge
- **Maintainer**: Can create drafts
- **Admin**: Can approve/reject drafts
"
# Create CLAUDE.md if doesn't exist
if [ ! -f "$CLAUDE_MD" ]; then
echo "# Claude Configuration" > "$CLAUDE_MD"
echo "" >> "$CLAUDE_MD"
echo "This file contains global instructions for Claude Code." >> "$CLAUDE_MD"
fi
# Check if KnowledgeCP section already exists
if grep -q "## KnowledgeCP" "$CLAUDE_MD"; then
print_warning "KnowledgeCP section already exists in CLAUDE.md"
print_info "To update, manually edit: $CLAUDE_MD"
else
echo "$KNOWLEDGECP_SECTION" >> "$CLAUDE_MD"
print_success "CLAUDE.md updated with KnowledgeCP section"
fi
}
# Create config file
setup_knowledgecp_config() {
print_info "Creating KnowledgeCP config..."
local CONFIG_FILE="$KNOWLEDGECP_DIR/config.json"
if [ ! -f "$CONFIG_FILE" ]; then
cat > "$CONFIG_FILE" << EOF
{
"version": "$KNOWLEDGECP_VERSION",
"serverUrl": "$KNOWLEDGECP_SERVER_URL",
"isFirstRun": true,
"lastSync": null,
"workspaceId": null
}
EOF
print_success "Config created: $CONFIG_FILE"
else
print_warning "Config already exists: $CONFIG_FILE"
fi
}
# Create version file
setup_version_file() {
echo "0.0.0" > "$KNOWLEDGECP_DIR/.version"
print_success "Version file created"
}
# Create sample knowledge files
setup_sample_files() {
print_info "Creating sample knowledge files..."
# Sample context file
if [ ! -f "$KNOWLEDGECP_DIR/context/welcome.md" ]; then
cat > "$KNOWLEDGECP_DIR/context/welcome.md" << 'EOF'
# Welcome to KnowledgeCP
This is your team's shared knowledge base. Knowledge stored here will be
available to all team members using Claude Code.
## How to Use
1. **Login**: Use `kb_login(email, password)` to authenticate
2. **Pull Knowledge**: Knowledge is automatically pulled after login
3. **Save Knowledge**: Say "speichere was wir besprochen haben" to save session context
## Getting Started
Ask your team admin for login credentials, or visit the admin panel to create your account.
EOF
print_success "Sample context file created"
fi
# Sample instructions file
if [ ! -f "$KNOWLEDGECP_DIR/instructions/example-mcp.md" ]; then
cat > "$KNOWLEDGECP_DIR/instructions/example-mcp.md" << 'EOF'
# Example MCP Server Instructions
This is a template for documenting MCP server usage.
## Server Name: example-mcp
### When to Use
- When the user asks about [specific domain]
- When the user wants to [specific action]
### Available Tools
| Tool | Description |
|------|-------------|
| `example_tool()` | Does something useful |
### Examples
- "Show me X" → `example_tool(type: "X")`
EOF
print_success "Sample instructions file created"
fi
}
# Setup hooks (placeholder for future implementation)
setup_hooks() {
print_info "Hooks setup is pending (requires Claude Code hook support)"
# TODO: Implement when Claude Code hooks API is available
}
# Print completion message
print_completion() {
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} KnowledgeCP Installation Complete!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo "Next steps:"
echo " 1. Restart Claude Code"
echo " 2. Login with: kb_login(email, password)"
echo " 3. Your knowledge will be automatically pulled"
echo ""
echo "Configuration files:"
echo " - MCP Config: $CLAUDE_CONFIG_DIR/mcp.json"
echo " - CLAUDE.md: $CLAUDE_CONFIG_DIR/CLAUDE.md"
echo " - Knowledge: $KNOWLEDGECP_DIR/"
echo ""
echo "Need help? Visit: https://knowledgecp.com/docs"
echo ""
}
# Main installation
main() {
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} KnowledgeCP Installer v$KNOWLEDGECP_VERSION${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
check_jq
setup_directories
setup_mcp_config
setup_claude_md
setup_knowledgecp_config
setup_version_file
setup_sample_files
setup_hooks
print_completion
}
# Run main
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment