stock-bot/scripts/setup-mcp.sh
2025-06-17 23:19:12 -04:00

83 lines
No EOL
2.9 KiB
Bash
Executable file

#!/bin/bash
# Setup MCP Servers for Stock Bot
# This script helps set up Model Context Protocol servers for PostgreSQL and MongoDB
set -e
echo "🚀 Setting up MCP servers for Stock Bot..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if infrastructure is running
echo -e "\n${YELLOW}📊 Checking infrastructure status...${NC}"
# Check PostgreSQL
if nc -z localhost 5432; then
echo -e "${GREEN}✅ PostgreSQL is running on port 5432${NC}"
PG_RUNNING=true
else
echo -e "${RED}❌ PostgreSQL is not running on port 5432${NC}"
PG_RUNNING=false
fi
# Check MongoDB
if nc -z localhost 27017; then
echo -e "${GREEN}✅ MongoDB is running on port 27017${NC}"
MONGO_RUNNING=true
else
echo -e "${RED}❌ MongoDB is not running on port 27017${NC}"
MONGO_RUNNING=false
fi
# Start infrastructure if needed
if [ "$PG_RUNNING" = false ] || [ "$MONGO_RUNNING" = false ]; then
echo -e "\n${YELLOW}🔧 Starting required infrastructure...${NC}"
bun run infra:up
echo -e "${GREEN}✅ Infrastructure started${NC}"
# Wait a moment for services to be ready
echo -e "${YELLOW}⏳ Waiting for services to be ready...${NC}"
sleep 5
fi
echo -e "\n${YELLOW}🔧 Testing MCP server connections...${NC}"
# Get project paths
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# Test PostgreSQL MCP server
echo -e "\n${YELLOW}Testing PostgreSQL MCP server...${NC}"
if npm list @modelcontextprotocol/server-postgres --prefix "$PROJECT_ROOT" >/dev/null 2>&1; then
echo -e "${GREEN}✅ PostgreSQL MCP server package is installed${NC}"
echo -e "${YELLOW} Package: @modelcontextprotocol/server-postgres v0.6.2${NC}"
else
echo -e "${RED}❌ PostgreSQL MCP server package not found${NC}"
fi
# Test MongoDB MCP server
echo -e "\n${YELLOW}Testing MongoDB MCP server...${NC}"
if npm list mongodb-mcp-server --prefix "$PROJECT_ROOT" >/dev/null 2>&1; then
echo -e "${GREEN}✅ MongoDB MCP server package is installed${NC}"
echo -e "${YELLOW} Package: mongodb-mcp-server v0.1.1 (official MongoDB team)${NC}"
else
echo -e "${RED}❌ MongoDB MCP server package not found${NC}"
fi
echo -e "\n${GREEN}🎉 MCP setup complete!${NC}"
echo -e "\n${YELLOW}📋 Configuration saved to: .vscode/mcp.json${NC}"
echo -e "\n${YELLOW}🔗 Connection details:${NC}"
echo -e " PostgreSQL: postgresql://trading_user:trading_pass_dev@localhost:5432/trading_bot"
echo -e " MongoDB: mongodb://trading_admin:trading_mongo_dev@localhost:27017/stock?authSource=admin"
echo -e "\n${YELLOW}📖 Usage:${NC}"
echo -e " - The MCP servers are configured in .vscode/mcp.json"
echo -e " - Claude Code will automatically use these servers when they're available"
echo -e " - Make sure your infrastructure is running with: bun run infra:up"
echo -e "\n${GREEN}✨ Ready to use MCP with PostgreSQL and MongoDB!${NC}"