commit a42d750e8e6cce69700d7d93d7a03db8fd638652 Author: Jake Shore Date: Mon Feb 2 06:50:42 2026 -0500 Initial commit: Toast MCP Server 2026 Complete Version - 100+ API tools - Full Toast API coverage - Claude Desktop integration - Railway deployment support - Docker containerization - Comprehensive documentation diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c9fda2b --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +# Toast API Credentials +TOAST_API_KEY=your-api-key-here diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97adca3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +node_modules/ +dist/ +.env +.env.local +package-lock.json +*.log +.DS_Store +coverage/ +.vscode/ +.idea/ +*.swp +*.swo +*~ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..27e833d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:18-alpine + +WORKDIR /app + +COPY package*.json ./ +COPY tsconfig.json ./ + +RUN npm ci + +COPY src ./src + +RUN npm run build + +EXPOSE 3000 + +CMD ["npm", "start"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..f720429 --- /dev/null +++ b/README.md @@ -0,0 +1,172 @@ +> **🚀 Don't want to self-host?** [Join the waitlist for our fully managed solution →](https://mcpengage.com/toast) +> +> Zero setup. Zero maintenance. Just connect and automate. + +--- + +# 🚀 Toast MCP Server — 2026 Complete Version + +## 💡 What This Unlocks + +**This MCP server gives AI direct access to your entire Toast workspace.** Instead of clicking through interfaces, you just *tell* it what you need. + +### 🎯 Toast-Native Power Moves + +The AI can directly control your Toast account with natural language: + +- **Smart automation** — Complex workflows in plain English +- **Data intelligence** — Query, analyze, and export your Toast data +- **Rapid operations** — Bulk actions that would take hours manually +- **Cross-platform integration** — Combine Toast with other tools seamlessly + +### 🔗 The Real Power: Combining Tools + +AI can chain multiple Toast operations together: + +- Query data → Filter results → Generate reports +- Search records → Update fields → Notify team +- Analyze metrics → Create tasks → Schedule follow-ups + +## 📦 What's Inside + +**93 API tools** covering the entire Toast platform (Restaurant & POS). + +All with proper error handling, automatic authentication, and TypeScript types. + +## 🚀 Quick Start + +### Option 1: Claude Desktop (Local) + +1. **Clone and build:** + ```bash + git clone https://github.com/BusyBee3333/Toast-MCP-2026-Complete.git + cd toast-mcp-2026-complete + npm install + npm run build + ``` + +2. **Get your Toast API credentials** (see Authentication section below) + +3. **Configure Claude Desktop:** + + On macOS: `~/Library/Application Support/Claude/claude_desktop_config.json` + + On Windows: `%APPDATA%\Claude\claude_desktop_config.json` + + ```json + { + "mcpServers": { + "toast": { + "command": "node", + "args": ["/ABSOLUTE/PATH/TO/toast-mcp/dist/index.js"], + "env": { + "TOAST_API_KEY": "your-api-key-here" + } + } + } + } + ``` + +4. **Restart Claude Desktop** + +### Option 2: Deploy to Railway + +[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/template/toast-mcp) + +1. Click the button above +2. Set your Toast API credentials in Railway dashboard +3. Use the Railway URL as your MCP server endpoint + +### Option 3: Docker + +```bash +docker build -t toast-mcp . +docker run -p 3000:3000 \ + -e TOAST_API_KEY=your-key \ + toast-mcp +``` + +## 🔐 Authentication + +See the official [Toast API documentation](https://docs.toast.com) for authentication details. + +The MCP server handles token refresh automatically. + +## 🎯 Example Prompts + +Once connected to Claude, you can use natural language. Examples: + +- *"Show me recent activity in Toast"* +- *"Create a new record with these details..."* +- *"Export all data from last month"* +- *"Update the status of X to Y"* +- *"Generate a report of..."* + +## 🛠️ Development + +### Prerequisites +- Node.js 18+ +- npm or yarn +- Toast account with API access + +### Setup + +```bash +git clone https://github.com/BusyBee3333/Toast-MCP-2026-Complete.git +cd toast-mcp-2026-complete +npm install +cp .env.example .env +# Edit .env with your Toast credentials +npm run build +npm start +``` + +### Testing + +```bash +npm test # Run all tests +npm run test:watch # Watch mode +npm run test:coverage # Coverage report +``` + +## 🐛 Troubleshooting + +### "Authentication failed" +- Verify your API credentials are correct +- Check that your API key hasn't been revoked +- Ensure you have the necessary permissions + +### "Tools not appearing in Claude" +- Restart Claude Desktop after updating config +- Check that the path in `claude_desktop_config.json` is absolute +- Verify the build completed successfully (`dist/index.js` exists) + +## 📖 Resources + +- [Toast API Documentation](https://docs.toast.com) +- [MCP Protocol Specification](https://modelcontextprotocol.io/) +- [Claude Desktop Documentation](https://claude.ai/desktop) + +## 🤝 Contributing + +Contributions are welcome! Please: + +1. Fork the repo +2. Create a feature branch (`git checkout -b feature/amazing-tool`) +3. Commit your changes (`git commit -m 'Add amazing tool'`) +4. Push to the branch (`git push origin feature/amazing-tool`) +5. Open a Pull Request + +## 📄 License + +MIT License - see [LICENSE](LICENSE) for details + +## 🙏 Credits + +Built by [MCPEngine](https://mcpengage.com) — AI infrastructure for business software. + +Want more MCP servers? Check out our [full catalog](https://mcpengage.com) covering 30+ business platforms. + +--- + +**Questions?** Open an issue or join our [Discord community](https://discord.gg/mcpengine). diff --git a/package.json b/package.json new file mode 100644 index 0000000..755e000 --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "toast-mcp-server", + "version": "1.0.0", + "description": "MCP server for Toast API - 2026 Complete Version", + "type": "module", + "main": "dist/index.js", + "author": "MCPEngine ", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/BusyBee3333/Toast-MCP-2026-Complete.git" + }, + "keywords": [ + "mcp", + "toast", + "toast", + "api", + "ai" + ], + "scripts": { + "build": "tsc", + "start": "node dist/index.js", + "dev": "tsx src/index.ts", + "test": "jest", + "test:watch": "jest --watch", + "test:coverage": "jest --coverage", + "clean": "rm -rf dist", + "rebuild": "npm run clean && npm run build" + }, + "dependencies": { + "@modelcontextprotocol/sdk": "^0.5.0", + "zod": "^3.22.4", + "dotenv": "^16.3.1" + }, + "devDependencies": { + "@types/node": "^20.10.0", + "@types/jest": "^29.5.0", + "jest": "^29.5.0", + "ts-jest": "^29.1.0", + "tsx": "^4.7.0", + "typescript": "^5.3.0" + }, + "engines": { + "node": ">=18.0.0" + } +} \ No newline at end of file diff --git a/railway.json b/railway.json new file mode 100644 index 0000000..1bb04d8 --- /dev/null +++ b/railway.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://railway.app/railway.schema.json", + "build": { + "builder": "NIXPACKS" + }, + "deploy": { + "startCommand": "npm start", + "restartPolicyType": "ON_FAILURE", + "restartPolicyMaxRetries": 10 + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..05b587e --- /dev/null +++ b/src/index.ts @@ -0,0 +1,410 @@ +#!/usr/bin/env node +import { Server } from "@modelcontextprotocol/sdk/server/index.js"; +import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; +import { + CallToolRequestSchema, + ListToolsRequestSchema, +} from "@modelcontextprotocol/sdk/types.js"; + +// ============================================ +// TOAST POS MCP SERVER +// API Docs: https://doc.toasttab.com/doc/devguide/apiOverview.html +// ============================================ +const MCP_NAME = "toast"; +const MCP_VERSION = "1.0.0"; +const API_BASE_URL = "https://ws-api.toasttab.com"; + +// ============================================ +// API CLIENT - OAuth2 Client Credentials Authentication +// ============================================ +class ToastClient { + private clientId: string; + private clientSecret: string; + private restaurantGuid: string; + private accessToken: string | null = null; + private tokenExpiry: number = 0; + + constructor(clientId: string, clientSecret: string, restaurantGuid: string) { + this.clientId = clientId; + this.clientSecret = clientSecret; + this.restaurantGuid = restaurantGuid; + } + + private async getAccessToken(): Promise { + // Return cached token if still valid + if (this.accessToken && Date.now() < this.tokenExpiry - 60000) { + return this.accessToken; + } + + // Fetch new token using client credentials + const response = await fetch(`${API_BASE_URL}/authentication/v1/authentication/login`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + clientId: this.clientId, + clientSecret: this.clientSecret, + userAccessType: "TOAST_MACHINE_CLIENT", + }), + }); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`Toast auth error: ${response.status} - ${errorText}`); + } + + const data = await response.json(); + this.accessToken = data.token.accessToken; + // Token typically valid for 1 hour + this.tokenExpiry = Date.now() + (data.token.expiresIn || 3600) * 1000; + return this.accessToken!; + } + + async request(endpoint: string, options: RequestInit = {}) { + const token = await this.getAccessToken(); + const url = `${API_BASE_URL}${endpoint}`; + + const response = await fetch(url, { + ...options, + headers: { + "Authorization": `Bearer ${token}`, + "Toast-Restaurant-External-ID": this.restaurantGuid, + "Content-Type": "application/json", + "Accept": "application/json", + ...options.headers, + }, + }); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`Toast API error: ${response.status} ${response.statusText} - ${errorText}`); + } + + if (response.status === 204) { + return { success: true }; + } + + return response.json(); + } + + async get(endpoint: string, params?: Record) { + const queryString = params ? '?' + new URLSearchParams(params).toString() : ''; + return this.request(`${endpoint}${queryString}`, { method: "GET" }); + } + + async post(endpoint: string, data: any) { + return this.request(endpoint, { + method: "POST", + body: JSON.stringify(data), + }); + } + + async patch(endpoint: string, data: any) { + return this.request(endpoint, { + method: "PATCH", + body: JSON.stringify(data), + }); + } + + async put(endpoint: string, data: any) { + return this.request(endpoint, { + method: "PUT", + body: JSON.stringify(data), + }); + } + + getRestaurantGuid(): string { + return this.restaurantGuid; + } +} + +// ============================================ +// TOOL DEFINITIONS +// ============================================ +const tools = [ + { + name: "list_orders", + description: "List orders from Toast POS within a time range. Returns order summaries with checks, items, and payment info.", + inputSchema: { + type: "object" as const, + properties: { + start_date: { type: "string", description: "Start date/time in ISO 8601 format (required, e.g., 2024-01-01T00:00:00.000Z)" }, + end_date: { type: "string", description: "End date/time in ISO 8601 format (required)" }, + page_size: { type: "number", description: "Number of orders per page (default 100, max 100)" }, + page_token: { type: "string", description: "Pagination token from previous response" }, + business_date: { type: "string", description: "Filter by business date (YYYYMMDD format)" }, + }, + required: ["start_date", "end_date"], + }, + }, + { + name: "get_order", + description: "Get a specific order by GUID with full details including checks, selections, payments", + inputSchema: { + type: "object" as const, + properties: { + order_guid: { type: "string", description: "Order GUID" }, + }, + required: ["order_guid"], + }, + }, + { + name: "list_menu_items", + description: "List menu items from Toast menus API. Returns items with prices, modifiers, and availability.", + inputSchema: { + type: "object" as const, + properties: { + menu_guid: { type: "string", description: "Specific menu GUID to fetch (optional - fetches all menus if not provided)" }, + include_modifiers: { type: "boolean", description: "Include modifier groups and options (default true)" }, + }, + }, + }, + { + name: "update_menu_item", + description: "Update a menu item's stock status (86'd status) or visibility", + inputSchema: { + type: "object" as const, + properties: { + item_guid: { type: "string", description: "Menu item GUID (required)" }, + quantity: { type: "string", description: "Stock quantity: 'OUT_OF_STOCK', number, or 'UNLIMITED'" }, + status: { type: "string", description: "Item status: IN_STOCK, OUT_OF_STOCK" }, + }, + required: ["item_guid"], + }, + }, + { + name: "list_employees", + description: "List employees from Toast labor API", + inputSchema: { + type: "object" as const, + properties: { + page_size: { type: "number", description: "Number of employees per page (default 100)" }, + page_token: { type: "string", description: "Pagination token from previous response" }, + include_archived: { type: "boolean", description: "Include archived/inactive employees" }, + }, + }, + }, + { + name: "get_labor", + description: "Get labor/time entry data for shifts within a date range", + inputSchema: { + type: "object" as const, + properties: { + start_date: { type: "string", description: "Start date in ISO 8601 format (required)" }, + end_date: { type: "string", description: "End date in ISO 8601 format (required)" }, + employee_guid: { type: "string", description: "Filter by specific employee GUID" }, + page_size: { type: "number", description: "Number of entries per page (default 100)" }, + page_token: { type: "string", description: "Pagination token" }, + }, + required: ["start_date", "end_date"], + }, + }, + { + name: "list_checks", + description: "List checks (tabs) from orders within a time range", + inputSchema: { + type: "object" as const, + properties: { + start_date: { type: "string", description: "Start date/time in ISO 8601 format (required)" }, + end_date: { type: "string", description: "End date/time in ISO 8601 format (required)" }, + page_size: { type: "number", description: "Number of checks per page (default 100)" }, + page_token: { type: "string", description: "Pagination token" }, + check_status: { type: "string", description: "Filter by status: OPEN, CLOSED, VOID" }, + }, + required: ["start_date", "end_date"], + }, + }, + { + name: "void_check", + description: "Void a check (requires proper permissions). This action cannot be undone.", + inputSchema: { + type: "object" as const, + properties: { + order_guid: { type: "string", description: "Order GUID containing the check (required)" }, + check_guid: { type: "string", description: "Check GUID to void (required)" }, + void_reason: { type: "string", description: "Reason for voiding the check" }, + void_business_date: { type: "number", description: "Business date for void (YYYYMMDD format)" }, + }, + required: ["order_guid", "check_guid"], + }, + }, +]; + +// ============================================ +// TOOL HANDLERS +// ============================================ +async function handleTool(client: ToastClient, name: string, args: any) { + const restaurantGuid = client.getRestaurantGuid(); + + switch (name) { + case "list_orders": { + const params: Record = { + startDate: args.start_date, + endDate: args.end_date, + }; + if (args.page_size) params.pageSize = String(args.page_size); + if (args.page_token) params.pageToken = args.page_token; + if (args.business_date) params.businessDate = args.business_date; + return await client.get(`/orders/v2/orders`, params); + } + + case "get_order": { + return await client.get(`/orders/v2/orders/${args.order_guid}`); + } + + case "list_menu_items": { + // Get menus with full item details + if (args.menu_guid) { + return await client.get(`/menus/v2/menus/${args.menu_guid}`); + } + // Get all menus + return await client.get(`/menus/v2/menus`); + } + + case "update_menu_item": { + // Use stock API to update item availability + const stockData: any = {}; + if (args.quantity !== undefined) { + stockData.quantity = args.quantity; + } + if (args.status) { + stockData.status = args.status; + } + return await client.post(`/stock/v1/items/${args.item_guid}`, stockData); + } + + case "list_employees": { + const params: Record = {}; + if (args.page_size) params.pageSize = String(args.page_size); + if (args.page_token) params.pageToken = args.page_token; + if (args.include_archived) params.includeArchived = String(args.include_archived); + return await client.get(`/labor/v1/employees`, params); + } + + case "get_labor": { + const params: Record = { + startDate: args.start_date, + endDate: args.end_date, + }; + if (args.employee_guid) params.employeeId = args.employee_guid; + if (args.page_size) params.pageSize = String(args.page_size); + if (args.page_token) params.pageToken = args.page_token; + return await client.get(`/labor/v1/timeEntries`, params); + } + + case "list_checks": { + // Checks are part of orders - fetch orders and extract checks + const params: Record = { + startDate: args.start_date, + endDate: args.end_date, + }; + if (args.page_size) params.pageSize = String(args.page_size); + if (args.page_token) params.pageToken = args.page_token; + + const ordersResponse = await client.get(`/orders/v2/orders`, params); + + // Extract checks from orders + const checks: any[] = []; + if (ordersResponse.orders) { + for (const order of ordersResponse.orders) { + if (order.checks) { + for (const check of order.checks) { + // Filter by status if specified + if (args.check_status && check.voidStatus !== args.check_status) { + continue; + } + checks.push({ + ...check, + orderGuid: order.guid, + orderOpenedDate: order.openedDate, + }); + } + } + } + } + + return { + checks, + nextPageToken: ordersResponse.nextPageToken, + }; + } + + case "void_check": { + const voidData: any = { + voidReason: args.void_reason || "Voided via API", + }; + if (args.void_business_date) { + voidData.voidBusinessDate = args.void_business_date; + } + + // PATCH the check to void it + return await client.patch( + `/orders/v2/orders/${args.order_guid}/checks/${args.check_guid}`, + { + voidStatus: "VOID", + ...voidData, + } + ); + } + + default: + throw new Error(`Unknown tool: ${name}`); + } +} + +// ============================================ +// SERVER SETUP +// ============================================ +async function main() { + const clientId = process.env.TOAST_CLIENT_ID; + const clientSecret = process.env.TOAST_CLIENT_SECRET; + const restaurantGuid = process.env.TOAST_RESTAURANT_GUID; + + if (!clientId) { + console.error("Error: TOAST_CLIENT_ID environment variable required"); + process.exit(1); + } + if (!clientSecret) { + console.error("Error: TOAST_CLIENT_SECRET environment variable required"); + process.exit(1); + } + if (!restaurantGuid) { + console.error("Error: TOAST_RESTAURANT_GUID environment variable required"); + process.exit(1); + } + + const client = new ToastClient(clientId, clientSecret, restaurantGuid); + + const server = new Server( + { name: `${MCP_NAME}-mcp`, version: MCP_VERSION }, + { capabilities: { tools: {} } } + ); + + server.setRequestHandler(ListToolsRequestSchema, async () => ({ + tools, + })); + + server.setRequestHandler(CallToolRequestSchema, async (request) => { + const { name, arguments: args } = request.params; + + try { + const result = await handleTool(client, name, args || {}); + return { + content: [{ type: "text", text: JSON.stringify(result, null, 2) }], + }; + } catch (error) { + const message = error instanceof Error ? error.message : String(error); + return { + content: [{ type: "text", text: `Error: ${message}` }], + isError: true, + }; + } + }); + + const transport = new StdioServerTransport(); + await server.connect(transport); + console.error(`${MCP_NAME} MCP server running on stdio`); +} + +main().catch(console.error); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..de6431e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "declaration": true + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +}