@getcheddar/cheddar-mcp 1.0.5 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +56 -330
  2. package/bin/cheddar-mcp.mjs +5 -0
  3. package/dist/core.d.ts +17 -0
  4. package/dist/core.d.ts.map +1 -0
  5. package/dist/core.js +79 -0
  6. package/dist/core.js.map +1 -0
  7. package/dist/http.d.ts +6 -0
  8. package/dist/http.d.ts.map +1 -0
  9. package/dist/http.js +65 -0
  10. package/dist/http.js.map +1 -0
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +24 -75
  14. package/dist/index.js.map +1 -1
  15. package/dist/lib/legacy-client.d.ts +44 -0
  16. package/dist/lib/legacy-client.d.ts.map +1 -0
  17. package/dist/lib/legacy-client.js +149 -0
  18. package/dist/lib/legacy-client.js.map +1 -0
  19. package/dist/tools/customers.d.ts +2 -2
  20. package/dist/tools/customers.d.ts.map +1 -1
  21. package/dist/tools/customers.js +103 -103
  22. package/dist/tools/customers.js.map +1 -1
  23. package/dist/tools/plans.d.ts +10 -0
  24. package/dist/tools/plans.d.ts.map +1 -0
  25. package/dist/tools/plans.js +26 -0
  26. package/dist/tools/plans.js.map +1 -0
  27. package/package.json +10 -7
  28. package/dist/lib/cheddar-client.d.ts +0 -111
  29. package/dist/lib/cheddar-client.d.ts.map +0 -1
  30. package/dist/lib/cheddar-client.js +0 -101
  31. package/dist/lib/cheddar-client.js.map +0 -1
  32. package/dist/tools/checkout.d.ts +0 -10
  33. package/dist/tools/checkout.d.ts.map +0 -1
  34. package/dist/tools/checkout.js +0 -641
  35. package/dist/tools/checkout.js.map +0 -1
  36. package/dist/tools/payment-methods.d.ts +0 -10
  37. package/dist/tools/payment-methods.d.ts.map +0 -1
  38. package/dist/tools/payment-methods.js +0 -162
  39. package/dist/tools/payment-methods.js.map +0 -1
  40. package/dist/tools/subscriptions.d.ts +0 -10
  41. package/dist/tools/subscriptions.d.ts.map +0 -1
  42. package/dist/tools/subscriptions.js +0 -191
  43. package/dist/tools/subscriptions.js.map +0 -1
package/README.md CHANGED
@@ -1,379 +1,105 @@
1
- # Cheddar MCP Server
1
+ # Cheddar MCP Server (legacy API)
2
2
 
3
- A Model Context Protocol (MCP) server for integrating with the Cheddar Payment Platform. This server provides AI assistants with tools to generate payment integration code and manage Cheddar resources.
3
+ Model Context Protocol server that calls the **legacy Cheddar merchant API** documented at [https://docs.getcheddar.com/](https://docs.getcheddar.com/) using **HTTP Basic** authentication (`Authorization: Basic …`).
4
4
 
5
- **Package:** `@getcheddar/cheddar-mcp`
6
- **Version:** 1.0.5
7
-
8
- ---
9
-
10
- ## Two Modes of Operation
11
-
12
- The MCP server works in two modes depending on whether you provide API credentials:
13
-
14
- ### Mode A: Code Generation Only (No Auth Required)
15
-
16
- **Use this mode to:**
17
-
18
- - Generate integration code (React, Vue, Next.js, etc.)
19
- - Create checkout forms and hosted page URLs
20
- - Configure webhooks and validation logic
21
- - Get code recommendations and best practices
22
-
23
- **No API credentials needed!** These tools work out of the box:
24
-
25
- | Tool | Description |
26
- | -------------------------------------------- | ------------------------------------------------ |
27
- | `cheddar_checkout_generate_hosted_url` | Generate hosted checkout page URLs |
28
- | `cheddar_checkout_generate_embedded_form` | Generate embedded checkout form code |
29
- | `cheddar_checkout_generate_integration_code` | Generate complete framework-specific integration |
30
- | `cheddar_checkout_configure_webhook` | Generate webhook handler code |
31
- | `cheddar_checkout_validate_webhook` | Validate webhook signatures |
32
-
33
- **Quick Start (No Auth):**
5
+ This package **does not** use `https://api.*` OAuth2 / Bearer REST.
34
6
 
35
- ```json
36
- {
37
- "mcpServers": {
38
- "cheddar": {
39
- "command": "npx",
40
- "args": ["-y", "@getcheddar/cheddar-mcp@1.0.5"]
41
- }
42
- }
43
- }
44
- ```
45
-
46
- **Example Prompt for Lovable:**
47
-
48
- ```
49
- Create a React checkout page for my SaaS using Cheddar payments.
50
- - Collect customer email and name
51
- - Accept credit card payments securely
52
- - Subscribe customers to a "Pro Plan"
53
- - Handle errors gracefully
54
-
55
- Use cheddar_checkout_generate_integration_code with framework "react".
56
- ```
57
-
58
- ---
59
-
60
- ### Mode B: Full API Access (Auth Required)
61
-
62
- **Use this mode to:**
63
-
64
- - Query actual customer data from your Cheddar account
65
- - Create and update customers, subscriptions, payment methods
66
- - Manage billing and plan changes
67
- - Access real-time subscription status
68
-
69
- **Requires Cheddar API credentials.** These tools need authentication:
70
-
71
- | Tool | Description |
72
- | ------------------------------ | ---------------------------------- |
73
- | `cheddar_customer_get` | Retrieve customer by ID or code |
74
- | `cheddar_customer_create` | Create a new customer |
75
- | `cheddar_customer_update` | Update customer information |
76
- | `cheddar_payment_method_get` | Retrieve payment method by ID |
77
- | `cheddar_payment_token_create` | Tokenize card data (PCI-compliant) |
78
- | `cheddar_subscription_get` | Retrieve subscription details |
79
- | `cheddar_plan_get` | Retrieve plan information |
7
+ **Package:** `@getcheddar/cheddar-mcp`
8
+ **Version:** 2.0.1
80
9
 
81
- **Setup with Auth:**
10
+ ## Requirements
82
11
 
83
- 1. **Sign up for Cheddar:** https://getcheddar.com/signup
84
- 2. **Get your credentials:**
85
- - **Username:** Your Cheddar account email
86
- - **Secret Key:** Top navbar Configuration → Product Settings Secret Key
12
+ - Node.js **18+**
13
+ - The **origin that serves legacy `/xml/…` routes** for your product (see [CHEDDAR_BASE_URL](#cheddar_base_url) below — it is **not** always the same host as hosted **ChargeVault** checkout pages).
14
+ - **Product code** (`productCode` in URLs)
15
+ - An **authorized user email** and **password** *or* the product **API key** (“secret key” from Configuration → Settings) as the Basic password ([auth docs](https://docs.getcheddar.com/#authentication))
87
16
 
88
- 3. **Configure MCP:**
17
+ ## CHEDDAR_BASE_URL
89
18
 
90
- ```json
91
- {
92
- "mcpServers": {
93
- "cheddar": {
94
- "command": "npx",
95
- "args": ["-y", "@getcheddar/cheddar-mcp@1.0.5"],
96
- "env": {
97
- "CHEDDAR_API_URL": "https://api.getcheddar.com",
98
- "CHEDDAR_USERNAME": "your-email@example.com",
99
- "CHEDDAR_SECRET_KEY": "your-secret-key-here"
100
- }
101
- }
102
- }
103
- }
104
- ```
19
+ The MCP calls paths such as **`/xml/plans/get/productCode/{productCode}`** on whatever origin you set.
105
20
 
106
- **Alternative: OAuth2 Access Token**
21
+ - **GetCheddar cloud** products often serve the legacy XML API from **`https://getcheddar.com`**, while **hosted signup / checkout** may live on **`https://{subdomain}.chargevault.com`**. Using only the ChargeVault host can return **404** for `/xml/…` because that host is for **hosted pages**, not the full legacy app.
22
+ - **Self-hosted** Cheddar may use your own domain (the same origin you use in the browser for product admin and legacy XML).
107
23
 
108
- If you have an OAuth2 access token instead:
24
+ **How to verify:** with your credentials, `GET {CHEDDAR_BASE_URL}/xml/plans/get/productCode/{CHEDDAR_PRODUCT_CODE}` should return **200** and XML (or JSON if supported), not an HTML error page. On startup the server runs this check unless `CHEDDAR_SKIP_PREFLIGHT=1`.
109
25
 
110
- ```json
111
- {
112
- "mcpServers": {
113
- "cheddar": {
114
- "command": "npx",
115
- "args": ["-y", "@getcheddar/cheddar-mcp@1.0.5"],
116
- "env": {
117
- "CHEDDAR_API_URL": "https://api.getcheddar.com",
118
- "CHEDDAR_ACCESS_TOKEN": "your-oauth2-access-token"
119
- }
120
- }
121
- }
122
- }
123
- ```
26
+ ## Environment variables
124
27
 
125
- **Example Prompt with Auth:**
28
+ | Variable | Required | Description |
29
+ |----------|----------|-------------|
30
+ | `CHEDDAR_BASE_URL` | **Yes** | Origin where **`/xml/…`** is available, no trailing slash (often `https://getcheddar.com` for cloud; use your real API host if self-hosted). |
31
+ | `CHEDDAR_PRODUCT_CODE` | **Yes** | Your product’s `productCode` segment in legacy URLs. |
32
+ | `CHEDDAR_USERNAME` | **Yes** | Email of an API-enabled user on that product. |
33
+ | `CHEDDAR_PASSWORD` | One of | That user’s login password. |
34
+ | `CHEDDAR_PRODUCT_API_KEY` | One of | Product secret key from admin settings; used as Basic **password** if `CHEDDAR_PASSWORD` is unset. |
35
+ | `CHEDDAR_SKIP_PREFLIGHT` | No | If set to `1`, skip startup `GET /xml/plans/get/...` check. |
126
36
 
127
- ```
128
- Get customer details for customer code "cust_12345" and show me their subscription status and payment methods.
37
+ ## Install & run
129
38
 
130
- Use cheddar_customer_get, then cheddar_subscription_get and cheddar_payment_method_get.
39
+ ```bash
40
+ cd packages/cheddar-mcp
41
+ npm install
42
+ npm run build
131
43
  ```
132
44
 
133
- ---
134
-
135
- ## Configuration Reference
136
-
137
- | Variable | Mode | Description |
138
- | ---------------------- | --------- | -------------------------------------------------------- |
139
- | `CHEDDAR_API_URL` | Auth only | REST API base URL. Default: `https://api.getcheddar.com` |
140
- | `CHEDDAR_USERNAME` | Auth only | Your Cheddar account email address |
141
- | `CHEDDAR_SECRET_KEY` | Auth only | Secret Key from Product Settings |
142
- | `CHEDDAR_ACCESS_TOKEN` | Auth only | OAuth2 Bearer token (alternative to username/secret) |
143
-
144
- **Note:** If no auth credentials are provided, the server runs in **code generation mode only** and will return clear error messages if you try to use data access tools.
145
-
146
- ---
147
-
148
- ## Usage with Claude Desktop
149
-
150
- Add to your Claude Desktop configuration:
151
-
152
- **For code generation (no auth):**
45
+ ```bash
46
+ export CHEDDAR_BASE_URL=https://getcheddar.com
47
+ export CHEDDAR_PRODUCT_CODE=YOUR_PRODUCT_CODE
48
+ export CHEDDAR_USERNAME=api-user@example.com
49
+ export CHEDDAR_PRODUCT_API_KEY=your_secret_key
153
50
 
154
- ```json
155
- {
156
- "mcpServers": {
157
- "cheddar": {
158
- "command": "npx",
159
- "args": ["-y", "@getcheddar/cheddar-mcp@1.0.5"]
160
- }
161
- }
162
- }
51
+ npm run start
52
+ # or: node dist/index.js
163
53
  ```
164
54
 
165
- **For full API access (with auth):**
55
+ Or with `npx` after publish:
166
56
 
167
- ```json
168
- {
169
- "mcpServers": {
170
- "cheddar": {
171
- "command": "npx",
172
- "args": ["-y", "@getcheddar/cheddar-mcp@1.0.5"],
173
- "env": {
174
- "CHEDDAR_API_URL": "https://api.getcheddar.com",
175
- "CHEDDAR_USERNAME": "your-email@example.com",
176
- "CHEDDAR_SECRET_KEY": "your-secret-key"
177
- }
178
- }
179
- }
180
- }
57
+ ```bash
58
+ npx -y @getcheddar/cheddar-mcp
181
59
  ```
182
60
 
183
- ---
184
-
185
- ## Usage with Cursor
186
-
187
- 1. Open Cursor Settings
188
- 2. Navigate to **Features → MCP**
189
- 3. Add a new MCP server:
190
-
191
- **For code generation:**
192
-
193
- - **Name:** `cheddar`
194
- - **Command:** `npx`
195
- - **Arguments:** `-y`, `@getcheddar/cheddar-mcp@1.0.5`
196
-
197
- **For full API access:**
198
-
199
- - **Name:** `cheddar`
200
- - **Command:** `npx`
201
- - **Arguments:** `-y`, `@getcheddar/cheddar-mcp@1.0.5`
202
- - **Environment:** Set `CHEDDAR_USERNAME` and `CHEDDAR_SECRET_KEY`
203
-
204
- ---
205
-
206
- ## Usage with Lovable.dev
207
-
208
- ### Step 1: Get Credentials (for full API access, optional)
61
+ ## Tools
209
62
 
210
- 1. Sign up at https://getcheddar.com/signup
211
- 2. Configure your product
212
- 3. Get your Secret Key: Top navbar → Configuration → Product Settings → Secret Key
63
+ | Tool | Legacy endpoint (conceptually) |
64
+ |------|--------------------------------|
65
+ | `cheddar_customer_get` | `GET /xml/customers/get/productCode/.../code/…` or `/id/…` |
66
+ | `cheddar_customers_search` | `GET /xml/customers/search/productCode/...` (requests `format=json` when supported) |
67
+ | `cheddar_customer_create` | `POST /xml/customers/new/productCode/...` (form body) |
68
+ | `cheddar_customer_update` | `POST /xml/customers/edit/productCode/.../code/...` |
69
+ | `cheddar_plans_get` | `GET /xml/plans/get/productCode/...` (optional `planCode`) |
213
70
 
214
- ### Step 2: Configure MCP in Lovable
71
+ Responses are returned as **JSON text**: XML from the API is parsed to a plain object where possible.
215
72
 
216
- Add to your Lovable project configuration:
73
+ ## Claude Desktop example
217
74
 
218
- **Option 1: Code Generation Only (Recommended for starters)**
75
+ **Recommended:** `npx` (no local build path):
219
76
 
220
77
  ```json
221
78
  {
222
79
  "mcpServers": {
223
80
  "cheddar": {
224
81
  "command": "npx",
225
- "args": ["-y", "@getcheddar/cheddar-mcp@1.0.5"]
226
- }
227
- }
228
- }
229
- ```
230
-
231
- **Option 2: Full API Access**
232
-
233
- ```json
234
- {
235
- "mcpServers": {
236
- "cheddar": {
237
- "command": "npx",
238
- "args": ["-y", "@getcheddar/cheddar-mcp@1.0.5"],
82
+ "args": ["-y", "@getcheddar/cheddar-mcp"],
239
83
  "env": {
240
- "CHEDDAR_API_URL": "https://api.getcheddar.com",
241
- "CHEDDAR_USERNAME": "your-email@example.com",
242
- "CHEDDAR_SECRET_KEY": "your-secret-key"
84
+ "CHEDDAR_BASE_URL": "https://getcheddar.com",
85
+ "CHEDDAR_PRODUCT_CODE": "YOUR_PRODUCT_CODE",
86
+ "CHEDDAR_USERNAME": "api-user@example.com",
87
+ "CHEDDAR_PRODUCT_API_KEY": "your_secret_key"
243
88
  }
244
89
  }
245
90
  }
246
91
  }
247
92
  ```
248
93
 
249
- ### Step 3: Try These Prompts
250
-
251
- **For code generation (no auth needed):**
252
-
253
- ```
254
- Create a complete payment integration for my React app:
255
- 1. A pricing page with 3 tiers (Basic, Pro, Enterprise)
256
- 2. Checkout flow using Cheddar's embedded form
257
- 3. Webhook handler for subscription events
258
- 4. Use Tailwind CSS for styling
259
-
260
- Start with cheddar_checkout_generate_integration_code.
261
- ```
262
-
263
- **For data access (requires auth):**
264
-
265
- ```
266
- Build a customer dashboard showing:
267
- - Customer profile from Cheddar
268
- - Current subscription plan
269
- - Payment methods on file
270
- - Recent invoices
271
-
272
- Use cheddar_customer_get and related tools.
273
- ```
274
-
275
- ---
276
-
277
- ## Testing
278
-
279
- ### Sandbox Environment
280
-
281
- Use the sandbox for testing before going live:
282
-
283
- ```json
284
- {
285
- "env": {
286
- "CHEDDAR_API_URL": "https://sandbox.getcheddar.com",
287
- "CHEDDAR_USERNAME": "your-sandbox-email",
288
- "CHEDDAR_SECRET_KEY": "your-sandbox-secret"
289
- }
290
- }
291
- ```
292
-
293
- ### Test Card Numbers
294
-
295
- - `4111111111111111` - Visa (success)
296
- - `4000000000000002` - Declined
297
-
298
- ---
299
-
300
- ## Complete Tool Reference
301
-
302
- ### Code Generation Tools (No Auth Required)
303
-
304
- | Tool | Description |
305
- | -------------------------------------------- | -------------------------------------------- |
306
- | `cheddar_checkout_generate_hosted_url` | Generate hosted checkout page URLs |
307
- | `cheddar_checkout_generate_embedded_form` | Generate embedded checkout form code |
308
- | `cheddar_checkout_generate_integration_code` | Generate framework-specific integration code |
309
- | `cheddar_checkout_configure_webhook` | Generate webhook handler code |
310
- | `cheddar_checkout_validate_webhook` | Validate webhook signatures |
311
-
312
- ### Data Access Tools (Auth Required)
313
-
314
- | Tool | Description |
315
- | -------------------------------------------- | ---------------------------------------- |
316
- | `cheddar_customer_get` | Retrieve a customer by ID or code |
317
- | `cheddar_customer_create` | Create a new customer |
318
- | `cheddar_customer_update` | Update customer information |
319
- | `cheddar_payment_method_get` | Retrieve a payment method by ID |
320
- | `cheddar_payment_method_get_customer` | Get customer from payment method |
321
- | `cheddar_payment_method_get_gateway_account` | Get gateway account for payment method |
322
- | `cheddar_payment_token_create` | Tokenize card data (PCI-compliant) |
323
- | `cheddar_payment_method_add_to_customer` | Add tokenized payment method to customer |
324
- | `cheddar_subscription_get` | Retrieve subscription by ID |
325
- | `cheddar_subscription_get_customer` | Get customer from subscription |
326
- | `cheddar_subscription_get_plan` | Get plan from subscription |
327
- | `cheddar_subscription_get_payment_method` | Get payment method from subscription |
328
- | `cheddar_subscription_delete_promotion` | Remove promotion from subscription |
329
- | `cheddar_plan_get` | Retrieve plan by ID or code |
330
- | `cheddar_gateway_account_get` | Get gateway account details |
331
-
332
- ---
333
-
334
- ## Docker Usage
335
-
336
- Build and run with Docker:
337
-
338
- ```bash
339
- # Build
340
- docker build -t cheddar-mcp ./packages/cheddar-mcp
341
-
342
- # Run (code generation only)
343
- docker run -i --rm cheddar-mcp
344
-
345
- # Run with auth
346
- docker run -i --rm \
347
- -e CHEDDAR_API_URL=https://api.getcheddar.com \
348
- -e CHEDDAR_USERNAME=your-email \
349
- -e CHEDDAR_SECRET_KEY=your-secret \
350
- cheddar-mcp
351
- ```
352
-
353
- ---
94
+ **Local dev:** point `command` / `args` at `node` and `./dist/index.js` (or `bin/cheddar-mcp.mjs`) under this package after `npm run build`.
354
95
 
355
96
  ## Development
356
97
 
357
98
  ```bash
358
- # Clone the repository
359
- git clone https://github.com/chdr/cheddar-ai-tools.git
360
- cd cheddar-ai-tools/packages/cheddar-mcp
361
-
362
- # Install dependencies
363
- npm install
364
-
365
- # Build
366
99
  npm run build
367
-
368
- # Run in development mode
369
- npm run dev
370
-
371
- # Test
372
100
  npm test
373
101
  ```
374
102
 
375
- ---
376
-
377
103
  ## License
378
104
 
379
105
  MIT © Cheddar (chdr)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI entry for npm `bin` (stable path). npm 10+ may reject `bin` pointing at build output under `dist/`.
4
+ */
5
+ import "../dist/index.js";
package/dist/core.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { LegacyCheddarClient } from "./lib/legacy-client.js";
3
+ /** Keep in sync with package.json version. */
4
+ export declare const MCP_PACKAGE_VERSION = "2.0.1";
5
+ export type CheddarEnv = {
6
+ baseUrl: string;
7
+ productCode: string;
8
+ username: string;
9
+ password: string;
10
+ };
11
+ export declare function loadCheddarEnv(): CheddarEnv;
12
+ export declare function createCheddarMcpServer(version: string): {
13
+ server: Server;
14
+ client: LegacyCheddarClient;
15
+ };
16
+ export declare function runPreflight(client: LegacyCheddarClient): Promise<void>;
17
+ //# sourceMappingURL=core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAMnE,OAAO,EAAkB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAI7E,8CAA8C;AAC9C,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,cAAc,IAAI,UAAU,CAc3C;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,mBAAmB,CAAC;CAC7B,CAiEA;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAK7E"}
package/dist/core.js ADDED
@@ -0,0 +1,79 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
3
+ import { LegacyApiError, LegacyCheddarClient } from "./lib/legacy-client.js";
4
+ import { customerTools, handleCustomerTool } from "./tools/customers.js";
5
+ import { planTools, handlePlanTool } from "./tools/plans.js";
6
+ /** Keep in sync with package.json version. */
7
+ export const MCP_PACKAGE_VERSION = "2.0.1";
8
+ export function loadCheddarEnv() {
9
+ const baseUrl = (process.env.CHEDDAR_BASE_URL || "").replace(/\/+$/, "");
10
+ const productCode = process.env.CHEDDAR_PRODUCT_CODE || "";
11
+ const username = process.env.CHEDDAR_USERNAME || "";
12
+ const password = process.env.CHEDDAR_PASSWORD || process.env.CHEDDAR_PRODUCT_API_KEY || "";
13
+ if (!baseUrl || !productCode || !username || !password) {
14
+ throw new Error("Missing config. Set CHEDDAR_BASE_URL, CHEDDAR_PRODUCT_CODE, CHEDDAR_USERNAME, and CHEDDAR_PASSWORD or CHEDDAR_PRODUCT_API_KEY.");
15
+ }
16
+ return { baseUrl, productCode, username, password };
17
+ }
18
+ export function createCheddarMcpServer(version) {
19
+ const { baseUrl, productCode, username, password } = loadCheddarEnv();
20
+ const client = new LegacyCheddarClient({
21
+ baseUrl,
22
+ productCode,
23
+ username,
24
+ password,
25
+ });
26
+ const ALL_TOOLS = [...customerTools, ...planTools];
27
+ const server = new Server({
28
+ name: "cheddar-mcp",
29
+ version,
30
+ }, {
31
+ capabilities: {
32
+ tools: {},
33
+ },
34
+ });
35
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: ALL_TOOLS }));
36
+ function toolErrorMessage(error) {
37
+ if (error instanceof LegacyApiError) {
38
+ return `Cheddar API error (HTTP ${error.status}). See server logs for details.`;
39
+ }
40
+ if (error instanceof Error) {
41
+ return error.message;
42
+ }
43
+ return String(error);
44
+ }
45
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
46
+ const { name, arguments: args } = request.params;
47
+ try {
48
+ if (name.startsWith("cheddar_customer")) {
49
+ return await handleCustomerTool(client, name, args);
50
+ }
51
+ if (name.startsWith("cheddar_plans_")) {
52
+ return await handlePlanTool(client, name, args);
53
+ }
54
+ throw new Error(`Unknown tool: ${name}`);
55
+ }
56
+ catch (error) {
57
+ if (error instanceof LegacyApiError) {
58
+ console.error("[cheddar-mcp] LegacyApiError body:", typeof error.body === "string"
59
+ ? error.body.slice(0, 4000)
60
+ : JSON.stringify(error.body).slice(0, 4000));
61
+ }
62
+ else {
63
+ console.error("[cheddar-mcp] Tool error:", error);
64
+ }
65
+ return {
66
+ content: [{ type: "text", text: `Error: ${toolErrorMessage(error)}` }],
67
+ isError: true,
68
+ };
69
+ }
70
+ });
71
+ return { server, client };
72
+ }
73
+ export async function runPreflight(client) {
74
+ if (process.env.CHEDDAR_SKIP_PREFLIGHT) {
75
+ return;
76
+ }
77
+ await client.ping();
78
+ }
79
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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iB,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;gBACpC,OAAO,CAAC,KAAK,CACX,oCAAoC,EACpC,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;oBAC5B,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;oBAC3B,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAC9C,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;YACpD,CAAC;YACD,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,gBAAgB,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;gBACtE,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC5B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAA2B;IAC5D,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC;QACvC,OAAO;IACT,CAAC;IACD,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * MCP over Streamable HTTP + ALB-friendly GET /health (plain 200).
3
+ * Bind with MCP_ALLOWED_HOSTS (comma-separated hostnames) when not using 0.0.0.0 DNS-rebinding defaults.
4
+ */
5
+ import "dotenv/config";
6
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,eAAe,CAAC"}
package/dist/http.js ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * MCP over Streamable HTTP + ALB-friendly GET /health (plain 200).
3
+ * Bind with MCP_ALLOWED_HOSTS (comma-separated hostnames) when not using 0.0.0.0 DNS-rebinding defaults.
4
+ */
5
+ import "dotenv/config";
6
+ import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
7
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
8
+ import { LegacyApiError } from "./lib/legacy-client.js";
9
+ import { createCheddarMcpServer, MCP_PACKAGE_VERSION, runPreflight, } from "./core.js";
10
+ const MCP_PATH = (process.env.MCP_HTTP_PATH || "/mcp").replace(/\/+$/, "") || "/mcp";
11
+ function parseAllowedHosts() {
12
+ const raw = process.env.MCP_ALLOWED_HOSTS?.trim();
13
+ if (!raw) {
14
+ return undefined;
15
+ }
16
+ return raw.split(",").map((h) => h.trim()).filter(Boolean);
17
+ }
18
+ async function main() {
19
+ let server;
20
+ let client;
21
+ try {
22
+ ({ server, client } = createCheddarMcpServer(MCP_PACKAGE_VERSION));
23
+ }
24
+ catch (e) {
25
+ console.error(e instanceof Error ? e.message : String(e));
26
+ process.exit(1);
27
+ }
28
+ try {
29
+ await runPreflight(client);
30
+ }
31
+ catch (err) {
32
+ const msg = err instanceof Error ? err.message : String(err);
33
+ console.error(`Cheddar legacy API preflight failed: ${msg}`);
34
+ if (err instanceof LegacyApiError) {
35
+ console.error("[cheddar-mcp] Preflight response body:", typeof err.body === "string"
36
+ ? err.body.slice(0, 4000)
37
+ : JSON.stringify(err.body).slice(0, 4000));
38
+ }
39
+ process.exit(1);
40
+ }
41
+ const allowedHosts = parseAllowedHosts();
42
+ const app = createMcpExpressApp(allowedHosts
43
+ ? { host: "0.0.0.0", allowedHosts }
44
+ : { host: "0.0.0.0" });
45
+ app.get("/health", (_req, res) => {
46
+ res.status(200).type("text/plain").send("ok");
47
+ });
48
+ const transport = new StreamableHTTPServerTransport({
49
+ sessionIdGenerator: undefined,
50
+ });
51
+ await server.connect(transport);
52
+ app.all(MCP_PATH, async (req, res) => {
53
+ await transport.handleRequest(req, res, req.body);
54
+ });
55
+ const port = Number(process.env.PORT || 3000);
56
+ const listenHost = process.env.MCP_HTTP_HOST || "0.0.0.0";
57
+ app.listen(port, listenHost, () => {
58
+ console.error(`Cheddar MCP Streamable HTTP on http://${listenHost}:${port}${MCP_PATH} (health: GET /health)`);
59
+ });
60
+ }
61
+ main().catch((error) => {
62
+ console.error("Fatal error:", error);
63
+ process.exit(1);
64
+ });
65
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,eAAe,CAAC;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAClF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,GACb,MAAM,WAAW,CAAC;AAEnB,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC;AAErF,SAAS,iBAAiB;IACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC;IAClD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC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,2 +1,2 @@
1
- export {};
1
+ import "dotenv/config";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC"}