#!/bin/bash
# Setup script for creating Temporal namespaces and Nexus endpoints
# This script sets up the required Temporal infrastructure for the calculator MCP application
set -e
echo "Setting up Temporal infrastructure for Nexus MCP Calculator..."
# Default values
HANDLER_NAMESPACE="my-handler-namespace"
CALLER_NAMESPACE="my-caller-namespace"
ENDPOINT_NAME="mcp-gateway"
TASK_QUEUE="mcp"
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--handler-namespace)
HANDLER_NAMESPACE="$2"
shift 2
;;
--caller-namespace)
CALLER_NAMESPACE="$2"
shift 2
;;
--endpoint-name)
ENDPOINT_NAME="$2"
shift 2
;;
--task-queue)
TASK_QUEUE="$2"
shift 2
;;
-h|--help)
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --handler-namespace NAME Handler namespace (default: my-handler-namespace)"
echo " --caller-namespace NAME Caller namespace (default: my-caller-namespace)"
echo " --endpoint-name NAME Nexus endpoint name (default: mcp-gateway)"
echo " --task-queue NAME Task queue name (default: mcp)"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
echo "Configuration:"
echo " Handler namespace: $HANDLER_NAMESPACE"
echo " Caller namespace: $CALLER_NAMESPACE"
echo " Endpoint name: $ENDPOINT_NAME"
echo " Task queue: $TASK_QUEUE"
echo ""
# Check if temporal CLI is available
if ! command -v temporal &> /dev/null; then
echo "Error: temporal CLI is not installed or not in PATH"
echo "Please install the Temporal CLI: https://docs.temporal.io/cli"
exit 1
fi
# Create handler namespace (where the worker runs)
echo "Creating handler namespace: $HANDLER_NAMESPACE"
temporal operator namespace create --namespace "$HANDLER_NAMESPACE" || {
echo "Note: Handler namespace may already exist, continuing..."
}
# Create caller namespace (where the MCP gateway runs)
echo "Creating caller namespace: $CALLER_NAMESPACE"
temporal operator namespace create --namespace "$CALLER_NAMESPACE" || {
echo "Note: Caller namespace may already exist, continuing..."
}
# Create Nexus endpoint
echo "Creating Nexus endpoint: $ENDPOINT_NAME"
temporal operator nexus endpoint create \
--name "$ENDPOINT_NAME" \
--target-namespace "$HANDLER_NAMESPACE" \
--target-task-queue "$TASK_QUEUE" || {
echo "Note: Nexus endpoint may already exist, continuing..."
}
echo ""
echo "✅ Temporal infrastructure setup complete!"
echo ""
echo "Next steps:"
echo "1. Start the calculator worker:"
echo " cd nexus-mcp-calculator"
echo " uv run python -m nexus_mcp_calculator.worker --namespace $HANDLER_NAMESPACE --task-queue $TASK_QUEUE"
echo ""
echo "2. Start the MCP server:"
echo " uv run python -m nexus_mcp_calculator.mcp_server --namespace $CALLER_NAMESPACE --endpoint $ENDPOINT_NAME"
echo ""
echo "3. Configure your MCP client to connect to the server"