justfile•5.73 kB
cdk_dir := "cdk"
# Default API configuration (can be overridden via environment variables or profile)
api_name := env_var_or_default('API_NAME', 'PetstoreAPI')
api_base_url := env_var_or_default('API_BASE_URL', 'https://petstore3.swagger.io/api/v3')
api_spec_url := env_var_or_default('API_SPEC_URL', 'https://petstore3.swagger.io/api/v3/openapi.json')
auth_type := env_var_or_default('AUTH_TYPE', 'none')
auth_token := env_var_or_default('AUTH_TOKEN', '')
local_port := env_var_or_default('LOCAL_PORT', '8080')
# Helper to load profile and export environment variables
_load_profile profile:
@uv run python3 scripts/load_profile.py "{{profile}}"
# Helper function to compute stack name
_get_stack_name:
@python3 {{cdk_dir}}/stack_naming.py "{{api_name}}"
# Helper function to compute container name (same as stack but with 'local-' prefix)
_get_container_name:
@echo "local-$(just _get_stack_name)"
# List available profiles
list-profiles:
@echo "Available profiles:"
@ls -1 profiles/*.yaml 2>/dev/null | sed 's|profiles/||' | sed 's|.yaml||' || echo " No profiles found in profiles/"
cdk *args:
#!/usr/bin/env bash
export API_NAME={{api_name}}
export API_BASE_URL={{api_base_url}}
export API_SPEC_URL={{api_spec_url}}
export AUTH_TYPE={{auth_type}}
export AUTH_TOKEN={{auth_token}}
cd {{cdk_dir}} && cdk {{args}}
# Deploy with current API configuration
# Usage: just deploy [args] OR just PROFILE=zoho-crm deploy [args]
deploy *args:
#!/usr/bin/env bash
STACK_NAME=$(just _get_stack_name)
just cdk deploy "$STACK_NAME" --require-approval never \
--parameters ApiName={{api_name}} \
--parameters ApiBaseUrl={{api_base_url}} \
--parameters ApiSpecUrl={{api_spec_url}} \
--parameters AuthType={{auth_type}} {{args}}
# Deploy using a profile
# Usage: just deploy-profile zoho-crm [args]
deploy-profile profile *args:
#!/usr/bin/env bash
eval $(just _load_profile "{{profile}}")
just deploy {{args}}
# Deploy Petstore API (convenience command)
deploy-pet *args:
@API_NAME=PetstoreAPI \
API_BASE_URL=https://petstore3.swagger.io/api/v3 \
API_SPEC_URL=https://petstore3.swagger.io/api/v3/openapi.json \
AUTH_TYPE=none \
just deploy {{args}}
bootstrap *args:
@just cdk bootstrap {{args}}
destroy *args:
#!/usr/bin/env bash
STACK_NAME=$(just _get_stack_name)
just cdk destroy "$STACK_NAME" {{args}}
status:
@aws cloudformation describe-stacks --query 'Stacks[?starts_with(StackName, `openapi-mcp-`)].{Name:StackName,Status:StackStatus,Updated:LastUpdatedTime}' --output table
logs:
#!/usr/bin/env bash
STACK_NAME=$(just _get_stack_name)
FUNCTION_NAME=$(aws cloudformation describe-stack-resources --stack-name "$STACK_NAME" --query 'StackResources[?ResourceType==`AWS::Lambda::Function`].PhysicalResourceId' --output text)
if [ -z "$FUNCTION_NAME" ]; then
echo "Error: Could not find Lambda function in stack $STACK_NAME"
exit 1
fi
aws logs tail "/aws/lambda/$FUNCTION_NAME" --follow --format short
test:
uv run pytest tests/ --mcp-url=http://localhost:{{local_port}}/ -v
# Test locally with a profile (builds, runs, tests, and cleans up)
# Usage: just test-local-profile petstore
test-local-profile profile:
#!/usr/bin/env bash
set -e
echo "Testing profile: {{profile}}"
eval $(just _load_profile "{{profile}}")
just docker-stop
just docker-build
just docker-run
sleep 3
just test
EXIT_CODE=$?
just docker-stop
exit $EXIT_CODE
test-deployed:
#!/usr/bin/env bash
STACK_NAME=$(just _get_stack_name)
API_URL=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[0].Outputs[?OutputKey==`ApiUrl`].OutputValue' --output text)
if [ -z "$API_URL" ]; then
echo "Error: Could not find API URL in stack $STACK_NAME"
exit 1
fi
uv run pytest tests/ --mcp-url="$API_URL" -v
# Test deployed Lambda with a profile
# Usage: just test-profile zoho-crm
test-profile profile:
#!/usr/bin/env bash
eval $(just _load_profile "{{profile}}")
just test-deployed
docker-build:
docker build -t mcp-openapi-local -f Dockerfile .
docker-run:
#!/usr/bin/env bash
CONTAINER_NAME=$(just _get_container_name)
docker run --rm -d -p {{local_port}}:8080 \
-e API_NAME={{api_name}} \
-e API_BASE_URL={{api_base_url}} \
-e API_SPEC_URL={{api_spec_url}} \
-e AUTH_TYPE={{auth_type}} \
-e AUTH_TOKEN={{auth_token}} \
--name "$CONTAINER_NAME" \
mcp-openapi-local
echo "Started container: $CONTAINER_NAME on port {{local_port}}"
# Run Docker container with a profile
# Usage: just docker-run-profile zoho-crm
docker-run-profile profile:
#!/usr/bin/env bash
eval $(just _load_profile "{{profile}}")
just docker-run
docker-stop:
#!/usr/bin/env bash
CONTAINER_NAME=$(just _get_container_name)
echo "Stopping container: $CONTAINER_NAME"
docker stop "$CONTAINER_NAME" 2>/dev/null || true
# List running MCP containers
docker-list:
@echo "Running MCP containers:"
@docker ps --filter "name=local-openapi-mcp-" --format "table {{{{.Names}}\t{{{{.Ports}}\t{{{{.Status}}" || echo "No containers running"
# Stop all running MCP containers
docker-stop-all:
#!/usr/bin/env bash
echo "Stopping all MCP containers..."
CONTAINERS=$(docker ps -q --filter "name=local-openapi-mcp-")
if [ -z "$CONTAINERS" ]; then
echo "No containers to stop"
else
docker stop $CONTAINERS
echo "Stopped all containers"
fi
synth:
@just cdk synth
diff:
@just cdk diff
install:
uv sync --all-extras