summaryrefslogtreecommitdiff
path: root/mcp-servers/simple-mcp-server/.claude/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'mcp-servers/simple-mcp-server/.claude/hooks')
-rwxr-xr-xmcp-servers/simple-mcp-server/.claude/hooks/dev-watch.sh93
-rwxr-xr-xmcp-servers/simple-mcp-server/.claude/hooks/pre-build.sh144
-rwxr-xr-xmcp-servers/simple-mcp-server/.claude/hooks/test-runner.sh198
3 files changed, 435 insertions, 0 deletions
diff --git a/mcp-servers/simple-mcp-server/.claude/hooks/dev-watch.sh b/mcp-servers/simple-mcp-server/.claude/hooks/dev-watch.sh
new file mode 100755
index 0000000..1d2b5fc
--- /dev/null
+++ b/mcp-servers/simple-mcp-server/.claude/hooks/dev-watch.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+
+# Development Watch Hook for Simple MCP Server
+# Automatically triggered on TypeScript file changes
+
+set -e
+
+# Colors for output
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[1;33m'
+NC='\033[0m' # No Color
+
+echo -e "${GREEN}๐Ÿ”„ Development Watch Hook Triggered${NC}"
+
+# Get the modified file
+MODIFIED_FILE="$1"
+
+# Skip if not a TypeScript file
+if [[ ! "$MODIFIED_FILE" =~ \.ts$ ]]; then
+ exit 0
+fi
+
+# Skip node_modules and dist
+if [[ "$MODIFIED_FILE" =~ node_modules|dist|coverage ]]; then
+ exit 0
+fi
+
+echo "๐Ÿ“ File changed: $MODIFIED_FILE"
+
+# Type checking
+echo -e "${YELLOW}โœ… Running type check...${NC}"
+if npx tsc --noEmit 2>/dev/null; then
+ echo -e "${GREEN} โœ“ Type checking passed${NC}"
+else
+ echo -e "${RED} โœ— Type checking failed${NC}"
+ exit 1
+fi
+
+# Format with prettier
+if command -v prettier &> /dev/null; then
+ echo -e "${YELLOW}๐ŸŽจ Formatting with Prettier...${NC}"
+ npx prettier --write "$MODIFIED_FILE" 2>/dev/null || true
+ echo -e "${GREEN} โœ“ Formatted${NC}"
+fi
+
+# Lint with ESLint
+if [ -f .eslintrc.json ] || [ -f .eslintrc.js ]; then
+ echo -e "${YELLOW}๐Ÿ” Linting with ESLint...${NC}"
+ if npx eslint "$MODIFIED_FILE" --fix 2>/dev/null; then
+ echo -e "${GREEN} โœ“ Linting passed${NC}"
+ else
+ echo -e "${YELLOW} โš  Linting warnings${NC}"
+ fi
+fi
+
+# Run tests if it's a test file or if the corresponding test exists
+if [[ "$MODIFIED_FILE" =~ \.test\.ts$ ]] || [[ "$MODIFIED_FILE" =~ \.spec\.ts$ ]]; then
+ echo -e "${YELLOW}๐Ÿงช Running tests for $MODIFIED_FILE...${NC}"
+ if npx vitest run "$MODIFIED_FILE" 2>/dev/null; then
+ echo -e "${GREEN} โœ“ Tests passed${NC}"
+ else
+ echo -e "${RED} โœ— Tests failed${NC}"
+ exit 1
+ fi
+else
+ # Check if corresponding test file exists
+ TEST_FILE="${MODIFIED_FILE%.ts}.test.ts"
+ TEST_FILE_SPEC="${MODIFIED_FILE%.ts}.spec.ts"
+
+ if [ -f "$TEST_FILE" ]; then
+ echo -e "${YELLOW}๐Ÿงช Running related tests...${NC}"
+ npx vitest run "$TEST_FILE" 2>/dev/null || true
+ elif [ -f "$TEST_FILE_SPEC" ]; then
+ echo -e "${YELLOW}๐Ÿงช Running related tests...${NC}"
+ npx vitest run "$TEST_FILE_SPEC" 2>/dev/null || true
+ fi
+fi
+
+# Update tool/resource counts if applicable
+if [[ "$MODIFIED_FILE" =~ src/tools/ ]] || [[ "$MODIFIED_FILE" =~ src/resources/ ]] || [[ "$MODIFIED_FILE" =~ src/prompts/ ]]; then
+ echo -e "${YELLOW}๐Ÿ“Š Updating capability counts...${NC}"
+
+ TOOL_COUNT=$(find src/tools -name "*.ts" -not -name "index.ts" 2>/dev/null | wc -l || echo 0)
+ RESOURCE_COUNT=$(find src/resources -name "*.ts" -not -name "index.ts" 2>/dev/null | wc -l || echo 0)
+ PROMPT_COUNT=$(find src/prompts -name "*.ts" -not -name "index.ts" 2>/dev/null | wc -l || echo 0)
+
+ echo " Tools: $TOOL_COUNT"
+ echo " Resources: $RESOURCE_COUNT"
+ echo " Prompts: $PROMPT_COUNT"
+fi
+
+echo -e "${GREEN}โœ… Development checks complete${NC}"
diff --git a/mcp-servers/simple-mcp-server/.claude/hooks/pre-build.sh b/mcp-servers/simple-mcp-server/.claude/hooks/pre-build.sh
new file mode 100755
index 0000000..a72ff45
--- /dev/null
+++ b/mcp-servers/simple-mcp-server/.claude/hooks/pre-build.sh
@@ -0,0 +1,144 @@
+#!/bin/bash
+
+# Pre-Build Hook for Simple MCP Server
+# Runs before building for production
+
+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
+
+echo -e "${BLUE}๐Ÿ”จ Pre-Build Hook${NC}"
+echo "======================================"
+
+# Check for uncommitted changes
+if git diff --quiet && git diff --staged --quiet; then
+ echo -e "${GREEN}โœ“ Working directory clean${NC}"
+else
+ echo -e "${YELLOW}โš  Warning: Uncommitted changes detected${NC}"
+ git status --short
+fi
+
+# Lint check
+echo -e "\n${YELLOW}๐Ÿ” Running lint check...${NC}"
+if npx eslint src --ext .ts 2>/dev/null; then
+ echo -e "${GREEN} โœ“ Linting passed${NC}"
+else
+ echo -e "${RED} โœ— Linting failed${NC}"
+ echo " Run 'npm run lint:fix' to fix issues"
+ exit 1
+fi
+
+# Type validation
+echo -e "\n${YELLOW}๐Ÿ“ Running type check...${NC}"
+if npx tsc --noEmit; then
+ echo -e "${GREEN} โœ“ Type checking passed${NC}"
+else
+ echo -e "${RED} โœ— Type checking failed${NC}"
+ exit 1
+fi
+
+# Test suite
+echo -e "\n${YELLOW}๐Ÿงช Running tests...${NC}"
+if npm test 2>/dev/null; then
+ echo -e "${GREEN} โœ“ All tests passed${NC}"
+else
+ echo -e "${RED} โœ— Tests failed${NC}"
+ exit 1
+fi
+
+# Dependency audit
+echo -e "\n${YELLOW}๐Ÿ”’ Checking dependencies...${NC}"
+AUDIT_RESULT=$(npm audit --production 2>&1)
+if echo "$AUDIT_RESULT" | grep -q "found 0 vulnerabilities"; then
+ echo -e "${GREEN} โœ“ No vulnerabilities found${NC}"
+else
+ echo -e "${YELLOW} โš  Security vulnerabilities detected${NC}"
+ echo " Run 'npm audit fix' to resolve"
+fi
+
+# Version validation
+echo -e "\n${YELLOW}๐Ÿท๏ธ Checking version...${NC}"
+PACKAGE_VERSION=$(node -p "require('./package.json').version")
+echo " Current version: $PACKAGE_VERSION"
+
+# Check if version tag exists
+if git rev-parse "v$PACKAGE_VERSION" >/dev/null 2>&1; then
+ echo -e "${GREEN} โœ“ Version tag exists${NC}"
+else
+ echo -e "${YELLOW} โš  Version tag v$PACKAGE_VERSION not found${NC}"
+ echo " Create with: git tag v$PACKAGE_VERSION"
+fi
+
+# Check package.json required fields
+echo -e "\n${YELLOW}๐Ÿ“ฆ Validating package.json...${NC}"
+NAME=$(node -p "require('./package.json').name" 2>/dev/null)
+DESCRIPTION=$(node -p "require('./package.json').description" 2>/dev/null)
+MAIN=$(node -p "require('./package.json').main" 2>/dev/null)
+
+if [ -z "$NAME" ]; then
+ echo -e "${RED} โœ— Missing 'name' field${NC}"
+ exit 1
+fi
+
+if [ -z "$DESCRIPTION" ]; then
+ echo -e "${YELLOW} โš  Missing 'description' field${NC}"
+fi
+
+if [ -z "$MAIN" ]; then
+ echo -e "${YELLOW} โš  Missing 'main' field${NC}"
+fi
+
+echo -e "${GREEN} โœ“ Package metadata valid${NC}"
+
+# MCP specific checks
+echo -e "\n${YELLOW}๐Ÿ”Œ Checking MCP implementation...${NC}"
+
+# Check for required MCP files
+if [ -f "src/index.ts" ]; then
+ echo -e "${GREEN} โœ“ Entry point exists${NC}"
+else
+ echo -e "${RED} โœ— Missing src/index.ts${NC}"
+ exit 1
+fi
+
+# Count capabilities
+TOOL_COUNT=0
+RESOURCE_COUNT=0
+PROMPT_COUNT=0
+
+if [ -d "src/tools" ]; then
+ TOOL_COUNT=$(find src/tools -name "*.ts" -not -name "index.ts" | wc -l)
+fi
+
+if [ -d "src/resources" ]; then
+ RESOURCE_COUNT=$(find src/resources -name "*.ts" -not -name "index.ts" | wc -l)
+fi
+
+if [ -d "src/prompts" ]; then
+ PROMPT_COUNT=$(find src/prompts -name "*.ts" -not -name "index.ts" | wc -l)
+fi
+
+echo " Capabilities:"
+echo " - Tools: $TOOL_COUNT"
+echo " - Resources: $RESOURCE_COUNT"
+echo " - Prompts: $PROMPT_COUNT"
+
+if [ $TOOL_COUNT -eq 0 ] && [ $RESOURCE_COUNT -eq 0 ] && [ $PROMPT_COUNT -eq 0 ]; then
+ echo -e "${YELLOW} โš  No MCP capabilities implemented${NC}"
+fi
+
+# Final summary
+echo ""
+echo "======================================"
+echo -e "${GREEN}โœ… Pre-build checks complete${NC}"
+echo "Ready to build for production!"
+echo ""
+echo "Next steps:"
+echo " 1. npm run build"
+echo " 2. npm test"
+echo " 3. npm publish (if deploying to npm)"
diff --git a/mcp-servers/simple-mcp-server/.claude/hooks/test-runner.sh b/mcp-servers/simple-mcp-server/.claude/hooks/test-runner.sh
new file mode 100755
index 0000000..964f80c
--- /dev/null
+++ b/mcp-servers/simple-mcp-server/.claude/hooks/test-runner.sh
@@ -0,0 +1,198 @@
+#!/bin/bash
+
+# Test Runner Hook for Simple MCP Server
+# Enhanced test execution with coverage and protocol validation
+
+set -e
+
+# Colors for output
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[1;33m'
+BLUE='\033[0;34m'
+MAGENTA='\033[0;35m'
+NC='\033[0m' # No Color
+
+echo -e "${BLUE}๐Ÿงช Test Runner Hook${NC}"
+echo "======================================"
+
+# Parse test type from arguments
+TEST_TYPE="${1:-all}"
+WATCH_MODE="${2:-false}"
+
+# Function to run tests
+run_tests() {
+ local type=$1
+ local title=$2
+
+ echo -e "\n${YELLOW}Running $title...${NC}"
+
+ if [ "$type" = "unit" ]; then
+ TEST_CMD="npx vitest run tests/unit"
+ elif [ "$type" = "integration" ]; then
+ TEST_CMD="npx vitest run tests/integration"
+ else
+ TEST_CMD="npx vitest run"
+ fi
+
+ if [ "$WATCH_MODE" = "true" ]; then
+ TEST_CMD="${TEST_CMD/run/}"
+ fi
+
+ if $TEST_CMD; then
+ echo -e "${GREEN} โœ“ $title passed${NC}"
+ return 0
+ else
+ echo -e "${RED} โœ— $title failed${NC}"
+ return 1
+ fi
+}
+
+# Function to check MCP protocol compliance
+check_protocol_compliance() {
+ echo -e "\n${YELLOW}๐Ÿ”Œ Checking MCP Protocol Compliance...${NC}"
+
+ # Check server initialization
+ echo " Checking server initialization..."
+ if node -e "require('./dist/index.js')" 2>/dev/null; then
+ echo -e "${GREEN} โœ“ Server module loads${NC}"
+ else
+ echo -e "${YELLOW} โš  Server not built (run 'npm run build')${NC}"
+ fi
+
+ # Check for required handlers
+ echo " Checking protocol handlers..."
+
+ # This would normally check the actual implementation
+ # For now, we'll check if the files exist
+ if [ -f "src/index.ts" ]; then
+ if grep -q "ListToolsRequestSchema\|ListResourcesRequestSchema\|ListPromptsRequestSchema" src/index.ts 2>/dev/null; then
+ echo -e "${GREEN} โœ“ Protocol handlers found${NC}"
+ else
+ echo -e "${YELLOW} โš  Some protocol handlers may be missing${NC}"
+ fi
+ fi
+
+ # Check capabilities
+ echo " Checking capabilities..."
+ local has_capability=false
+
+ if [ -d "src/tools" ] && [ "$(ls -A src/tools 2>/dev/null)" ]; then
+ echo -e "${GREEN} โœ“ Tools capability${NC}"
+ has_capability=true
+ fi
+
+ if [ -d "src/resources" ] && [ "$(ls -A src/resources 2>/dev/null)" ]; then
+ echo -e "${GREEN} โœ“ Resources capability${NC}"
+ has_capability=true
+ fi
+
+ if [ -d "src/prompts" ] && [ "$(ls -A src/prompts 2>/dev/null)" ]; then
+ echo -e "${GREEN} โœ“ Prompts capability${NC}"
+ has_capability=true
+ fi
+
+ if [ "$has_capability" = false ]; then
+ echo -e "${YELLOW} โš  No capabilities implemented yet${NC}"
+ fi
+}
+
+# Function to generate coverage report
+generate_coverage() {
+ echo -e "\n${YELLOW}๐Ÿ“Š Generating Coverage Report...${NC}"
+
+ if npx vitest run --coverage 2>/dev/null; then
+ echo -e "${GREEN} โœ“ Coverage report generated${NC}"
+
+ # Parse coverage summary if available
+ if [ -f "coverage/coverage-summary.json" ]; then
+ echo " Coverage Summary:"
+ node -e "
+ const coverage = require('./coverage/coverage-summary.json');
+ const total = coverage.total;
+ const metrics = ['statements', 'branches', 'functions', 'lines'];
+ metrics.forEach(metric => {
+ const pct = total[metric].pct;
+ const color = pct >= 80 ? '\\033[0;32m' : pct >= 60 ? '\\033[1;33m' : '\\033[0;31m';
+ console.log(' ' + metric + ': ' + color + pct.toFixed(1) + '%\\033[0m');
+ });
+ " 2>/dev/null || echo " (Could not parse coverage summary)"
+ fi
+
+ echo " View detailed report: coverage/index.html"
+ else
+ echo -e "${YELLOW} โš  Coverage generation failed${NC}"
+ fi
+}
+
+# Main execution
+echo "Test configuration:"
+echo " Type: $TEST_TYPE"
+echo " Watch: $WATCH_MODE"
+
+# Pre-test checks
+echo -e "\n${YELLOW}๐Ÿ“‹ Pre-test checks...${NC}"
+
+# Check if test framework is installed
+if ! command -v vitest &> /dev/null && ! npx vitest --version &> /dev/null; then
+ echo -e "${RED} โœ— Vitest not installed${NC}"
+ echo " Install with: npm install -D vitest"
+ exit 1
+fi
+
+# Check if test directory exists
+if [ ! -d "tests" ] && [ ! -d "src/__tests__" ]; then
+ echo -e "${YELLOW} โš  No test directory found${NC}"
+ echo " Create tests in 'tests/' directory"
+fi
+
+# Run appropriate tests
+case $TEST_TYPE in
+ unit)
+ run_tests "unit" "Unit Tests"
+ ;;
+ integration)
+ run_tests "integration" "Integration Tests"
+ ;;
+ coverage)
+ generate_coverage
+ ;;
+ protocol)
+ check_protocol_compliance
+ ;;
+ all)
+ FAILED=false
+
+ run_tests "unit" "Unit Tests" || FAILED=true
+ run_tests "integration" "Integration Tests" || FAILED=true
+ check_protocol_compliance
+
+ if [ "$FAILED" = true ]; then
+ echo -e "\n${RED}โŒ Some tests failed${NC}"
+ exit 1
+ fi
+ ;;
+ *)
+ echo -e "${RED}Unknown test type: $TEST_TYPE${NC}"
+ echo "Valid options: unit, integration, coverage, protocol, all"
+ exit 1
+ ;;
+esac
+
+# Test summary
+echo ""
+echo "======================================"
+
+if [ "$WATCH_MODE" = "true" ]; then
+ echo -e "${BLUE}๐Ÿ‘๏ธ Watching for changes...${NC}"
+ echo "Press Ctrl+C to stop"
+else
+ echo -e "${GREEN}โœ… Test run complete${NC}"
+
+ # Provide helpful next steps
+ echo ""
+ echo "Next steps:"
+ echo " โ€ข Fix any failing tests"
+ echo " โ€ข Run with coverage: npm test -- coverage"
+ echo " โ€ข Test with MCP Inspector: npx @modelcontextprotocol/inspector"
+fi