#!/bin/bash
# FedMCP One-Click Installer for Claude Code
# Usage: curl -fsSL https://raw.githubusercontent.com/northernvariables/CanadaGPT/main/packages/fedmcp/scripts/install-claude-code.sh | bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ 🍁 FedMCP Installer ║"
echo "║ Canadian Federal Government Data for Claude Code ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo -e "${NC}"
# Check for required dependencies
check_dependency() {
if ! command -v "$1" &> /dev/null; then
echo -e "${RED}Error: $1 is required but not installed.${NC}"
exit 1
fi
}
echo -e "${YELLOW}Checking dependencies...${NC}"
check_dependency python3
check_dependency pip3
check_dependency claude
PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
REQUIRED_VERSION="3.10"
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$PYTHON_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then
echo -e "${RED}Error: Python 3.10+ is required (found $PYTHON_VERSION)${NC}"
exit 1
fi
echo -e "${GREEN}✓ All dependencies satisfied${NC}"
# Install FedMCP in a virtual environment
echo ""
echo -e "${YELLOW}Installing FedMCP...${NC}"
# Create dedicated venv for fedmcp
FEDMCP_VENV="$HOME/.fedmcp/venv"
mkdir -p "$HOME/.fedmcp"
if [ -d "$FEDMCP_VENV" ]; then
echo -e "${YELLOW}Existing FedMCP venv found, upgrading...${NC}"
else
echo -e "${YELLOW}Creating virtual environment...${NC}"
python3 -m venv "$FEDMCP_VENV"
fi
# Activate and install
source "$FEDMCP_VENV/bin/activate"
# Upgrade pip first
pip install --upgrade pip --quiet
# Install fedmcp
pip install --upgrade git+https://github.com/northernvariables/CanadaGPT.git#subdirectory=packages/fedmcp
deactivate
echo -e "${GREEN}✓ FedMCP installed${NC}"
# Get the Python path from the venv
PYTHON_PATH="$FEDMCP_VENV/bin/python"
# Add MCP server to Claude Code
echo ""
echo -e "${YELLOW}Adding FedMCP to Claude Code...${NC}"
# Remove existing fedmcp server if present (ignore errors)
claude mcp remove fedmcp 2>/dev/null || true
# Add the MCP server with user scope (available across all projects)
claude mcp add --transport stdio --scope user fedmcp -- "$PYTHON_PATH" -m fedmcp.server
echo -e "${GREEN}✓ FedMCP added to Claude Code${NC}"
# Configure permissions for auto-approval
echo ""
echo -e "${YELLOW}Configuring permissions...${NC}"
CLAUDE_CONFIG_DIR="$HOME/.claude"
SETTINGS_FILE="$CLAUDE_CONFIG_DIR/settings.json"
# Create config directory if needed
mkdir -p "$CLAUDE_CONFIG_DIR"
# Create or update settings.json with FedMCP permissions
if [ -f "$SETTINGS_FILE" ]; then
# Check if settings.json exists and is valid JSON
if python3 -c "import json; json.load(open('$SETTINGS_FILE'))" 2>/dev/null; then
# Update existing settings
python3 << 'PYTHON_SCRIPT'
import json
import os
settings_file = os.path.expanduser("~/.claude/settings.json")
with open(settings_file, 'r') as f:
settings = json.load(f)
# Ensure permissions structure exists
if 'permissions' not in settings:
settings['permissions'] = {}
if 'allow' not in settings['permissions']:
settings['permissions']['allow'] = []
# Add FedMCP permission pattern if not present
fedmcp_pattern = "mcp__fedmcp__*"
if fedmcp_pattern not in settings['permissions']['allow']:
settings['permissions']['allow'].append(fedmcp_pattern)
print(f"Added permission: {fedmcp_pattern}")
else:
print(f"Permission already exists: {fedmcp_pattern}")
with open(settings_file, 'w') as f:
json.dump(settings, f, indent=2)
PYTHON_SCRIPT
else
echo -e "${YELLOW}Existing settings.json is invalid, backing up and creating new...${NC}"
mv "$SETTINGS_FILE" "$SETTINGS_FILE.backup"
echo '{"permissions":{"allow":["mcp__fedmcp__*"]}}' > "$SETTINGS_FILE"
fi
else
# Create new settings file
echo '{"permissions":{"allow":["mcp__fedmcp__*"]}}' > "$SETTINGS_FILE"
fi
echo -e "${GREEN}✓ Permissions configured (auto-approve all FedMCP tools)${NC}"
# Optional: CanadaGPT PRO API key setup
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW}Optional: CanadaGPT PRO API Key${NC}"
echo ""
echo "PRO subscribers get 10,000 requests/hour (vs 100/hr free)."
echo "Generate your API key at: https://canadagpt.ca/settings#fedmcp-keys"
echo ""
read -p "Enter your CanadaGPT API key (or press Enter to skip): " FEDMCP_API_KEY
# Optional: CanLII API key setup
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW}Optional: CanLII API Key${NC}"
echo ""
echo "For Canadian legal case search, get a free API key from:"
echo "https://www.canlii.org/en/feedback/feedback.html"
echo ""
read -p "Enter your CanLII API key (or press Enter to skip): " CANLII_KEY
# Configure MCP server with API keys
ENV_ARGS=""
if [ -n "$FEDMCP_API_KEY" ]; then
ENV_ARGS="--env FEDMCP_API_KEY=$FEDMCP_API_KEY"
echo -e "${GREEN}✓ CanadaGPT PRO API key will be configured${NC}"
fi
if [ -n "$CANLII_KEY" ]; then
ENV_ARGS="$ENV_ARGS --env CANLII_API_KEY=$CANLII_KEY"
echo -e "${GREEN}✓ CanLII API key will be configured${NC}"
fi
if [ -n "$ENV_ARGS" ]; then
# Update the MCP server with the API keys
claude mcp remove fedmcp 2>/dev/null || true
claude mcp add --transport stdio --scope user $ENV_ARGS fedmcp -- "$PYTHON_PATH" -m fedmcp.server
fi
# Success message
echo ""
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN} 🎉 FedMCP Installation Complete! 🎉${NC}"
echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo "FedMCP is now available in Claude Code with 75+ tools including:"
echo " • Parliamentary debates and Hansard transcripts"
echo " • MP voting records and expenses"
echo " • Bill tracking and legislative progress"
echo " • Lobbying registrations and communications"
echo " • Federal contracts and grants"
echo " • Political contributions"
echo " • Canadian case law (if CanLII key provided)"
echo ""
echo -e "${BLUE}Try these commands in Claude Code:${NC}"
echo ' > "What bills are currently being debated in Parliament?"'
echo ' > "Show me the voting record for MP X"'
echo ' > "Who is lobbying the government on AI?"'
echo ""
echo -e "${YELLOW}To verify installation:${NC}"
echo " claude mcp list"
echo " /mcp (inside Claude Code)"
echo ""