A custom tools service for Optimizely Opal that exposes tools via HTTP endpoints using the @optimizely-opal/opal-tools-sdk.
- Node.js 18+
- Yarn 4.3.1
yarn install# Run in development mode with hot reload
yarn dev
# Build the project
yarn build
# Run the compiled application
yarn startThe server will start on port 3000 (or the PORT environment variable) and expose:
- Tools endpoints for each registered tool
- Discovery endpoint at
/discovery
Greets a person in a random language (English, Spanish, French).
Parameters:
name(required): Name of the person to greetlanguage(optional): Language for greeting (defaults to random)
Returns today's date in the specified format.
Parameters:
format(optional): Date format (defaults to ISO format)
HTTP client wrapper supporting various HTTP methods with custom headers.
Parameters:
url(required): The URL to make the request tomethod(optional): HTTP method (GET, POST, PUT, PATCH, DELETE). Defaults to GETheaders(optional): Custom headers as JSON stringbody(optional): Request body (for POST, PUT, PATCH methods)
Returns a Rick Roll GIF URL for fun interactions.
Parameters:
- No parameters required
Executes SQL queries against a SQLite database.
Parameters:
query(required): SQL query to executeparams(optional): Query parameters for prepared statements
This service uses Express.js with CORS enabled to serve tools. Each tool is implemented as a separate module in the src/tools/ directory and registered using the @tool decorator pattern from the Opal tools SDK.
The application is designed to work in both traditional server environments and serverless platforms (Vercel, Netlify) with automatic environment detection.
src/
main.ts # Main application entry point (exports app for serverless)
tools/ # Individual tool implementations
greeting.ts
todays-date.ts
api-call.ts
rick-roll.ts
sqlite-query.ts
vercel/
index.ts # Vercel serverless function entry point
netlify/
functions/
api.ts # Netlify Functions entry point
build/ # Compiled JavaScript output
docs/ # Deployment documentation
- Create a new file in
src/tools/directory - Define TypeScript interfaces for tool parameters
- Implement async function with typed parameters
- Register tool using
tool()decorator with parameter definitions - Import the tool file in
src/main.ts
- Runtime: Node.js
- Language: TypeScript (ES2022, NodeNext modules)
- Framework: Express.js
- Package Manager: Yarn 4.3.1
- SDK: @optimizely-opal/opal-tools-sdk
- Development: tsc-watch for hot reload
- Serverless: serverless-http wrapper for Netlify Functions
- Database: SQLite3 for local data storage
Ready to deploy your custom tools service? Choose your preferred platform:
- Deploy to Vercel -
⚠️ Currently not working due to Express middleware compatibility issues - Deploy to Netlify - ✅ Working - JAMstack deployment with edge functions
https://giphy.com/gifs/rick-astley-Ju7l5y9osyymQ