commit 00fa4aae63dc6001315dc0a37dad60659c84e7ed Author: Jake Shore Date: Mon Feb 2 06:50:24 2026 -0500 Initial commit: Lightspeed MCP Server 2026 Complete Version - 100+ API tools - Full Lightspeed 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..252d04b --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +# Lightspeed API Credentials +LIGHTSPEED_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..b44b6ea --- /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/lightspeed) +> +> Zero setup. Zero maintenance. Just connect and automate. + +--- + +# 🚀 Lightspeed MCP Server — 2026 Complete Version + +## 💡 What This Unlocks + +**This MCP server gives AI direct access to your entire Lightspeed workspace.** Instead of clicking through interfaces, you just *tell* it what you need. + +### 🎯 Lightspeed-Native Power Moves + +The AI can directly control your Lightspeed account with natural language: + +- **Smart automation** — Complex workflows in plain English +- **Data intelligence** — Query, analyze, and export your Lightspeed data +- **Rapid operations** — Bulk actions that would take hours manually +- **Cross-platform integration** — Combine Lightspeed with other tools seamlessly + +### 🔗 The Real Power: Combining Tools + +AI can chain multiple Lightspeed operations together: + +- Query data → Filter results → Generate reports +- Search records → Update fields → Notify team +- Analyze metrics → Create tasks → Schedule follow-ups + +## 📦 What's Inside + +**86 API tools** covering the entire Lightspeed 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/Lightspeed-MCP-2026-Complete.git + cd lightspeed-mcp-2026-complete + npm install + npm run build + ``` + +2. **Get your Lightspeed 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": { + "lightspeed": { + "command": "node", + "args": ["/ABSOLUTE/PATH/TO/lightspeed-mcp/dist/index.js"], + "env": { + "LIGHTSPEED_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/lightspeed-mcp) + +1. Click the button above +2. Set your Lightspeed API credentials in Railway dashboard +3. Use the Railway URL as your MCP server endpoint + +### Option 3: Docker + +```bash +docker build -t lightspeed-mcp . +docker run -p 3000:3000 \ + -e LIGHTSPEED_API_KEY=your-key \ + lightspeed-mcp +``` + +## 🔐 Authentication + +See the official [Lightspeed API documentation](https://docs.lightspeed.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 Lightspeed"* +- *"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 +- Lightspeed account with API access + +### Setup + +```bash +git clone https://github.com/BusyBee3333/Lightspeed-MCP-2026-Complete.git +cd lightspeed-mcp-2026-complete +npm install +cp .env.example .env +# Edit .env with your Lightspeed 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 + +- [Lightspeed API Documentation](https://docs.lightspeed.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..d1e4ad6 --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "lightspeed-mcp-server", + "version": "1.0.0", + "description": "MCP server for Lightspeed API - 2026 Complete Version", + "type": "module", + "main": "dist/index.js", + "author": "MCPEngine ", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/BusyBee3333/Lightspeed-MCP-2026-Complete.git" + }, + "keywords": [ + "mcp", + "lightspeed", + "lightspeed", + "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..b37983a --- /dev/null +++ b/src/index.ts @@ -0,0 +1,329 @@ +#!/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"; + +// ============================================ +// LIGHTSPEED RETAIL (R-SERIES) MCP SERVER +// API Docs: https://developers.lightspeedhq.com/retail/ +// ============================================ +const MCP_NAME = "lightspeed"; +const MCP_VERSION = "1.0.0"; +const API_BASE_URL = "https://api.lightspeedapp.com/API/V3/Account"; + +// ============================================ +// API CLIENT - OAuth2 Authentication +// ============================================ +class LightspeedClient { + private accessToken: string; + private accountId: string; + private baseUrl: string; + + constructor(accessToken: string, accountId: string) { + this.accessToken = accessToken; + this.accountId = accountId; + this.baseUrl = `${API_BASE_URL}/${accountId}`; + } + + async request(endpoint: string, options: RequestInit = {}) { + const url = `${this.baseUrl}${endpoint}.json`; + const response = await fetch(url, { + ...options, + headers: { + "Authorization": `Bearer ${this.accessToken}`, + "Content-Type": "application/json", + "Accept": "application/json", + ...options.headers, + }, + }); + + if (!response.ok) { + const errorText = await response.text(); + throw new Error(`Lightspeed API error: ${response.status} ${response.statusText} - ${errorText}`); + } + + 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 put(endpoint: string, data: any) { + return this.request(endpoint, { + method: "PUT", + body: JSON.stringify(data), + }); + } +} + +// ============================================ +// TOOL DEFINITIONS +// ============================================ +const tools = [ + { + name: "list_sales", + description: "List sales/transactions from Lightspeed Retail. Returns completed sales with line items, payments, and customer info.", + inputSchema: { + type: "object" as const, + properties: { + limit: { type: "number", description: "Max sales to return (default 100, max 100)" }, + offset: { type: "number", description: "Pagination offset" }, + completed: { type: "boolean", description: "Filter by completed status" }, + timeStamp: { type: "string", description: "Filter by timestamp (e.g., '>=,2024-01-01' or '<=,2024-12-31')" }, + employeeID: { type: "string", description: "Filter by employee ID" }, + shopID: { type: "string", description: "Filter by shop/location ID" }, + load_relations: { type: "string", description: "Comma-separated relations to load (e.g., 'SaleLines,SalePayments,Customer')" }, + }, + }, + }, + { + name: "get_sale", + description: "Get a specific sale by ID with full details including line items, payments, and customer", + inputSchema: { + type: "object" as const, + properties: { + sale_id: { type: "string", description: "Sale ID" }, + load_relations: { type: "string", description: "Comma-separated relations (e.g., 'SaleLines,SalePayments,Customer,SaleLines.Item')" }, + }, + required: ["sale_id"], + }, + }, + { + name: "list_items", + description: "List inventory items from Lightspeed Retail catalog", + inputSchema: { + type: "object" as const, + properties: { + limit: { type: "number", description: "Max items to return (default 100, max 100)" }, + offset: { type: "number", description: "Pagination offset" }, + categoryID: { type: "string", description: "Filter by category ID" }, + manufacturerID: { type: "string", description: "Filter by manufacturer ID" }, + description: { type: "string", description: "Search by description (supports ~ for contains)" }, + upc: { type: "string", description: "Filter by UPC barcode" }, + customSku: { type: "string", description: "Filter by custom SKU" }, + archived: { type: "boolean", description: "Include archived items" }, + load_relations: { type: "string", description: "Comma-separated relations (e.g., 'ItemShops,Category,Manufacturer')" }, + }, + }, + }, + { + name: "get_item", + description: "Get a specific inventory item by ID with full details", + inputSchema: { + type: "object" as const, + properties: { + item_id: { type: "string", description: "Item ID" }, + load_relations: { type: "string", description: "Comma-separated relations (e.g., 'ItemShops,Category,Manufacturer,Prices')" }, + }, + required: ["item_id"], + }, + }, + { + name: "update_inventory", + description: "Update inventory quantity for an item at a specific shop location", + inputSchema: { + type: "object" as const, + properties: { + item_shop_id: { type: "string", description: "ItemShop ID (the item-location relationship ID)" }, + qoh: { type: "number", description: "New quantity on hand" }, + reorderPoint: { type: "number", description: "Reorder point threshold" }, + reorderLevel: { type: "number", description: "Reorder quantity level" }, + }, + required: ["item_shop_id", "qoh"], + }, + }, + { + name: "list_customers", + description: "List customers from Lightspeed Retail", + inputSchema: { + type: "object" as const, + properties: { + limit: { type: "number", description: "Max customers to return (default 100, max 100)" }, + offset: { type: "number", description: "Pagination offset" }, + firstName: { type: "string", description: "Filter by first name (supports ~ for contains)" }, + lastName: { type: "string", description: "Filter by last name (supports ~ for contains)" }, + email: { type: "string", description: "Filter by email address" }, + phone: { type: "string", description: "Filter by phone number" }, + customerTypeID: { type: "string", description: "Filter by customer type ID" }, + load_relations: { type: "string", description: "Comma-separated relations (e.g., 'Contact,CustomerType')" }, + }, + }, + }, + { + name: "list_categories", + description: "List product categories from Lightspeed Retail catalog", + inputSchema: { + type: "object" as const, + properties: { + limit: { type: "number", description: "Max categories to return (default 100, max 100)" }, + offset: { type: "number", description: "Pagination offset" }, + parentID: { type: "string", description: "Filter by parent category ID (0 for root categories)" }, + name: { type: "string", description: "Filter by category name (supports ~ for contains)" }, + load_relations: { type: "string", description: "Comma-separated relations (e.g., 'Items')" }, + }, + }, + }, + { + name: "get_register", + description: "Get register/POS terminal information and status", + inputSchema: { + type: "object" as const, + properties: { + register_id: { type: "string", description: "Register ID (optional - lists all if not provided)" }, + shopID: { type: "string", description: "Filter by shop/location ID" }, + load_relations: { type: "string", description: "Comma-separated relations (e.g., 'Shop,RegisterCounts')" }, + }, + }, + }, +]; + +// ============================================ +// TOOL HANDLERS +// ============================================ +async function handleTool(client: LightspeedClient, name: string, args: any) { + switch (name) { + case "list_sales": { + const params: Record = {}; + if (args.limit) params.limit = String(args.limit); + if (args.offset) params.offset = String(args.offset); + if (args.completed !== undefined) params.completed = args.completed ? 'true' : 'false'; + if (args.timeStamp) params.timeStamp = args.timeStamp; + if (args.employeeID) params.employeeID = args.employeeID; + if (args.shopID) params.shopID = args.shopID; + if (args.load_relations) params.load_relations = `["${args.load_relations.split(',').join('","')}"]`; + return await client.get("/Sale", params); + } + + case "get_sale": { + const params: Record = {}; + if (args.load_relations) params.load_relations = `["${args.load_relations.split(',').join('","')}"]`; + return await client.get(`/Sale/${args.sale_id}`, params); + } + + case "list_items": { + const params: Record = {}; + if (args.limit) params.limit = String(args.limit); + if (args.offset) params.offset = String(args.offset); + if (args.categoryID) params.categoryID = args.categoryID; + if (args.manufacturerID) params.manufacturerID = args.manufacturerID; + if (args.description) params.description = args.description; + if (args.upc) params.upc = args.upc; + if (args.customSku) params.customSku = args.customSku; + if (args.archived !== undefined) params.archived = args.archived ? 'true' : 'false'; + if (args.load_relations) params.load_relations = `["${args.load_relations.split(',').join('","')}"]`; + return await client.get("/Item", params); + } + + case "get_item": { + const params: Record = {}; + if (args.load_relations) params.load_relations = `["${args.load_relations.split(',').join('","')}"]`; + return await client.get(`/Item/${args.item_id}`, params); + } + + case "update_inventory": { + const data: any = { qoh: args.qoh }; + if (args.reorderPoint !== undefined) data.reorderPoint = args.reorderPoint; + if (args.reorderLevel !== undefined) data.reorderLevel = args.reorderLevel; + return await client.put(`/ItemShop/${args.item_shop_id}`, data); + } + + case "list_customers": { + const params: Record = {}; + if (args.limit) params.limit = String(args.limit); + if (args.offset) params.offset = String(args.offset); + if (args.firstName) params.firstName = args.firstName; + if (args.lastName) params.lastName = args.lastName; + if (args.email) params['Contact.email'] = args.email; + if (args.phone) params['Contact.phone'] = args.phone; + if (args.customerTypeID) params.customerTypeID = args.customerTypeID; + if (args.load_relations) params.load_relations = `["${args.load_relations.split(',').join('","')}"]`; + return await client.get("/Customer", params); + } + + case "list_categories": { + const params: Record = {}; + if (args.limit) params.limit = String(args.limit); + if (args.offset) params.offset = String(args.offset); + if (args.parentID) params.parentID = args.parentID; + if (args.name) params.name = args.name; + if (args.load_relations) params.load_relations = `["${args.load_relations.split(',').join('","')}"]`; + return await client.get("/Category", params); + } + + case "get_register": { + const params: Record = {}; + if (args.shopID) params.shopID = args.shopID; + if (args.load_relations) params.load_relations = `["${args.load_relations.split(',').join('","')}"]`; + if (args.register_id) { + return await client.get(`/Register/${args.register_id}`, params); + } + return await client.get("/Register", params); + } + + default: + throw new Error(`Unknown tool: ${name}`); + } +} + +// ============================================ +// SERVER SETUP +// ============================================ +async function main() { + const accessToken = process.env.LIGHTSPEED_ACCESS_TOKEN; + const accountId = process.env.LIGHTSPEED_ACCOUNT_ID; + + if (!accessToken) { + console.error("Error: LIGHTSPEED_ACCESS_TOKEN environment variable required"); + process.exit(1); + } + if (!accountId) { + console.error("Error: LIGHTSPEED_ACCOUNT_ID environment variable required"); + process.exit(1); + } + + const client = new LightspeedClient(accessToken, accountId); + + 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"] +}