# Startup Scripts Usage Guide
This project includes convenience scripts to simplify building and running the SmartSuite MCP server.
## Quick Reference
```bash
# Full build with all quality gates + start server
./scripts/build-and-run.sh
# Start server (loads .env automatically)
./scripts/start-server.sh
# Validation mode (verify configuration)
./scripts/start-server.sh --validate
# Development mode with auto-reload
./scripts/start-server.sh --dev
# Force rebuild before starting
./scripts/start-server.sh --build
```
## Scripts Overview
### `scripts/start-server.sh`
Starts the MCP server with automatic environment variable loading from `.env`.
**Features:**
- Automatically loads `.env` file
- Validates required environment variables (SMARTSUITE_API_KEY, SMARTSUITE_WORKSPACE_ID)
- Checks for build directory and builds if missing
- Supports multiple modes: normal, dev, validate
**Options:**
- `--validate` - Run validation mode and exit (for CI/CD)
- `--dev` - Run in development mode with auto-reload
- `--build` - Force rebuild before starting
- `--help` - Show help message
**Requirements:**
- `.env` file with SMARTSUITE_API_KEY and SMARTSUITE_WORKSPACE_ID
**Example:**
```bash
# Normal startup
./scripts/start-server.sh
# Validate configuration
./scripts/start-server.sh --validate
# Development mode
./scripts/start-server.sh --dev
```
### `scripts/build-and-run.sh`
Complete build process with all quality gates, then starts the server.
**Process:**
1. Runs `npm run lint` - ESLint checks
2. Runs `npm run typecheck` - TypeScript type checking
3. Runs `npm run test` - Full test suite
4. Runs `npm run build` - Compiles TypeScript
5. Starts server with `./scripts/start-server.sh`
**Use Case:**
- First-time setup
- After pulling changes
- Before committing changes
- Production deployments
**Example:**
```bash
./scripts/build-and-run.sh
```
## Environment Setup
Both scripts require a `.env` file in the project root:
```bash
# Copy example and configure
cp .env.example .env
# Edit .env and add your credentials
# SMARTSUITE_API_KEY=your-api-key-here
# SMARTSUITE_WORKSPACE_ID=your-workspace-id
```
## Troubleshooting
### "Error: .env file not found"
Create a `.env` file from `.env.example`:
```bash
cp .env.example .env
# Edit .env with your credentials
```
### "Error: SMARTSUITE_API_KEY not set in .env"
Open `.env` and add:
```bash
SMARTSUITE_API_KEY=your-actual-api-key
```
### "Build directory not found"
The script will automatically run `npm run build`. If this fails, run manually:
```bash
npm install
npm run build
```
### Permission denied
Make scripts executable:
```bash
chmod +x scripts/start-server.sh
chmod +x scripts/build-and-run.sh
```
## Manual Alternatives
If you prefer manual commands:
```bash
# Load environment and start
export SMARTSUITE_API_KEY=your-key
export SMARTSUITE_WORKSPACE_ID=your-workspace
node build/src/index.js
# Or use npm scripts
npm start # (requires env vars to be exported)
npm run dev # Development mode
```
## CI/CD Integration
For automated deployments, use validation mode:
```bash
# In CI pipeline
./scripts/start-server.sh --validate
# Or with npm
npm run build
MCP_VALIDATE_AND_EXIT=true npm start
```