@fruggr/zendesk-mcp-server 1.4.0 → 1.5.0

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.
package/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Zendesk MCP Server
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@fruggr/zendesk-mcp-server)](https://www.npmjs.com/package/@fruggr/zendesk-mcp-server)
3
+ [![Glama score](https://glama.ai/mcp/servers/fruggr/zendesk-mcp-server/badges/score.svg)](https://glama.ai/mcp/servers/fruggr/zendesk-mcp-server)
4
+ [![npm version](https://img.shields.io/npm/v/@fruggr/zendesk-mcp-server?logo=npm&color=cb3837)](https://www.npmjs.com/package/@fruggr/zendesk-mcp-server)
5
+ [![License: MIT](https://img.shields.io/npm/l/@fruggr/zendesk-mcp-server?color=blue)](LICENSE)
6
+ [![Node.js](https://img.shields.io/node/v/@fruggr/zendesk-mcp-server?logo=nodedotjs&logoColor=white&color=339933)](https://nodejs.org)
7
+ [![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen?logo=renovatebot&logoColor=white)](https://renovatebot.com)
8
+ [![semantic-release](https://img.shields.io/badge/semantic--release-e10079?logo=semantic-release&logoColor=white)](https://github.com/semantic-release/semantic-release)
4
9
 
5
10
  A [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server that connects LLMs to the **Zendesk Support & Help Center APIs** — with per-user OAuth 2.1 PKCE authentication and fine-grained tool visibility controls.
6
11
 
@@ -16,6 +21,21 @@ Most Zendesk integrations use a shared admin API key, giving every user full acc
16
21
 
17
22
  > Built and maintained by [Digital4better](https://digital4better.com) for the [Fruggr](https://www.fruggr.io) project.
18
23
 
24
+ ## When to use this server
25
+
26
+ **Reach for it when:**
27
+
28
+ - You want an LLM to read or triage **Zendesk tickets** and **Help Center articles** on behalf of a real user, with that user's own permissions — not a shared admin key.
29
+ - You're editing **large Help Center articles** and want section-scoped reads/rewrites instead of round-tripping the full HTML body through the model.
30
+ - You need to **cap the tool surface** — read-only assistants, a single namespace, or one unified tool to fit a tight context budget.
31
+ - You run a **stdio MCP client** (Claude Desktop, Claude Code, Cursor, VS Code, Cline, …) and want a `npx`-installable server with no extra infrastructure.
32
+
33
+ **Look elsewhere when:**
34
+
35
+ - You need Zendesk products outside Support & Guide (e.g. Talk, Explore analytics, Sell) — those endpoints aren't covered.
36
+ - You want a hosted/remote HTTP server: this one speaks stdio and runs next to the client.
37
+ - You need a single shared service account for all users — that's the opposite of this server's per-user OAuth model (use API-token auth if you must, but one identity then applies to everyone).
38
+
19
39
  ## Tool modes
20
40
 
21
41
  The server registers tools in one of three modes, controlled by `--mode`:
@@ -178,7 +198,11 @@ No API key needed. Each user authenticates via their browser on the first tool c
178
198
  zendesk-mcp-server <your-subdomain>
179
199
  ```
180
200
 
181
- On the first tool call, a browser window opens for the user to authenticate. The token is cached in memory for the session.
201
+ On the first tool call, the server starts the sign-in flow: it opens a browser
202
+ window **and** returns a tool message containing the authorize URL. The call
203
+ does not block waiting for sign-in — authenticate in the browser (or open the
204
+ URL manually if it didn't open), then retry the request. Once authenticated, the
205
+ token is cached in memory and subsequent calls succeed for the session.
182
206
 
183
207
  ### Option B: API token
184
208
 
@@ -299,9 +323,11 @@ If both `ZENDESK_EMAIL` and `ZENDESK_API_TOKEN` are set, the server uses API tok
299
323
 
300
324
  ### The browser doesn't open during OAuth login
301
325
 
302
- The OAuth flow opens your default browser on the first tool call. If it doesn't
303
- open (common in sandboxed or remote desktop environments), the authorization URL
304
- is still printed to the server's stderr open it manually.
326
+ The OAuth flow opens your default browser on the first tool call. The first call
327
+ fails fast with a message that includes the authorize URL, so even if the
328
+ browser can't open (common in sandboxed or remote desktop environments) you can
329
+ open that URL manually — it's also printed to the server's stderr. Sign in, then
330
+ retry the request.
305
331
 
306
332
  To collect diagnostics, restart with `LOG_LEVEL=debug`. The server then emits
307
333
  structured logs through **two channels**, so they're reachable on any MCP client:
@@ -376,6 +402,43 @@ Versions follow [SemVer](https://semver.org/) and are calculated **automatically
376
402
  | `feat!:`, `fix!:`, or a `BREAKING CHANGE:` footer | major |
377
403
  | `docs:`, `chore:`, `refactor:`, `test:`, `ci:`, `style:`, `build:` | no release |
378
404
 
405
+ ## FAQ
406
+
407
+ **Do I need a Zendesk admin API key?**
408
+ No. The default OAuth 2.1 PKCE flow means each user authenticates with their own
409
+ credentials and the server acts with exactly their permissions. API-token auth is
410
+ available for headless/CI use (see [Authentication](#authentication)).
411
+
412
+ **Which Zendesk products are supported?**
413
+ Zendesk Support (tickets, users, organizations) and the Help Center / Guide
414
+ (articles, sections, categories, translations, labels, content tags, segments,
415
+ attachments). Talk, Explore, and Sell are out of scope.
416
+
417
+ **How do I keep the model's context small?**
418
+ Use `--mode single` (one `zendesk` tool) or `--mode namespace` (three proxies),
419
+ and `--read-only` to drop write operations. For big articles, the section-based
420
+ tools (`get_article_outline`, `get_article_section`, `update_article_section`)
421
+ let the model touch one section at a time instead of the whole HTML body.
422
+
423
+ **Can I restrict it to read-only?**
424
+ Yes — pass `--read-only` and every write tool is filtered out before the proxies
425
+ are built, in any mode.
426
+
427
+ **Which Node.js version do I need?**
428
+ Node.js >= 20 to run the published package (`engines.node`). The dev toolchain
429
+ uses a newer Node — see [Development](#development).
430
+
431
+ **The OAuth browser window didn't open. What now?**
432
+ The authorization URL is also printed to stderr — open it manually. Restart with
433
+ `LOG_LEVEL=debug` for the full flow trace. See
434
+ [Troubleshooting](#troubleshooting).
435
+
436
+ **Is it safe to run via `npx`?**
437
+ Releases are published from CI via npm Trusted Publishing (OIDC), so each version
438
+ carries a build provenance attestation you can verify on its
439
+ [npm page](https://www.npmjs.com/package/@fruggr/zendesk-mcp-server). No secrets
440
+ are ever logged by the server.
441
+
379
442
  ## Contributing
380
443
 
381
444
  Pull requests are welcome — including AI-assisted ones, as long as the human author has read and validated every line.
package/dist/index.js CHANGED
@@ -137,21 +137,38 @@ const detectWsl = () => {
137
137
  return false;
138
138
  }
139
139
  };
140
+ /**
141
+ * Escape a string for safe interpolation into HTML text/attribute context.
142
+ * The local callback server echoes attacker-controllable values (the OAuth
143
+ * `error_description` query param, token-exchange error bodies) back into the
144
+ * browser response; without escaping these are a reflected-XSS sink.
145
+ */
146
+ const escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
140
147
  const generateCodeVerifier = () => randomBytes(32).toString("base64url");
141
148
  const generateCodeChallenge = (verifier) => createHash("sha256").update(verifier).digest("base64url");
142
149
  /**
143
- * Performs OAuth 2.1 PKCE flow by opening the user's browser.
144
- * Starts a temporary HTTP server to receive the callback.
145
- * Returns the access token on success.
150
+ * Begin the OAuth 2.1 PKCE flow: start the local callback server, attempt to
151
+ * open the browser, and return as soon as the server is listening with the
152
+ * authorize URL plus a promise that settles when the callback arrives.
153
+ *
154
+ * Splitting "start" from "await the token" lets callers stay non-blocking: they
155
+ * can hand the URL back to the user immediately instead of holding a request
156
+ * open for up to the 5-minute timeout.
146
157
  */
147
- const authenticateViaBrowser = (config, logger = silentLogger) => {
158
+ const startBrowserAuth = (config, logger = silentLogger) => {
148
159
  const { subdomain, oauthClientId } = config;
149
- const { authorizeUrl, tokenUrl } = getOAuthUrls(subdomain);
160
+ const { authorizeUrl: authorizeBase, tokenUrl } = getOAuthUrls(subdomain);
150
161
  const codeVerifier = generateCodeVerifier();
151
162
  const codeChallenge = generateCodeChallenge(codeVerifier);
152
- return new Promise((resolve, reject) => {
153
- let callbackServer;
163
+ return new Promise((resolveStarted, rejectStarted) => {
164
+ let resolveToken;
165
+ let rejectToken;
166
+ const tokenPromise = new Promise((resolve, reject) => {
167
+ resolveToken = resolve;
168
+ rejectToken = reject;
169
+ });
154
170
  let authTimeout;
171
+ let callbackServer;
155
172
  callbackServer = createServer(async (req, res) => {
156
173
  const url = new URL(req.url ?? "/", `http://localhost`);
157
174
  if (url.pathname !== "/callback") {
@@ -168,10 +185,10 @@ const authenticateViaBrowser = (config, logger = silentLogger) => {
168
185
  if (error) {
169
186
  const desc = url.searchParams.get("error_description") ?? error;
170
187
  res.writeHead(400, { "Content-Type": "text/html" });
171
- res.end(`<html><body><h1>Authentication failed</h1><p>${desc}</p></body></html>`);
188
+ res.end(`<html><body><h1>Authentication failed</h1><p>${escapeHtml(desc)}</p></body></html>`);
172
189
  clearTimeout(authTimeout);
173
190
  callbackServer.close();
174
- reject(/* @__PURE__ */ new Error(`OAuth error: ${desc}`));
191
+ rejectToken(/* @__PURE__ */ new Error(`OAuth error: ${desc}`));
175
192
  return;
176
193
  }
177
194
  if (!code) {
@@ -179,7 +196,7 @@ const authenticateViaBrowser = (config, logger = silentLogger) => {
179
196
  res.end("<html><body><h1>Missing authorization code</h1></body></html>");
180
197
  clearTimeout(authTimeout);
181
198
  callbackServer.close();
182
- reject(/* @__PURE__ */ new Error("Missing authorization code in callback"));
199
+ rejectToken(/* @__PURE__ */ new Error("Missing authorization code in callback"));
183
200
  return;
184
201
  }
185
202
  try {
@@ -207,19 +224,30 @@ const authenticateViaBrowser = (config, logger = silentLogger) => {
207
224
  res.end("<html><body><h1>Authentication successful!</h1><p>You can close this tab and return to Claude Code.</p><script>window.close()<\/script></body></html>");
208
225
  clearTimeout(authTimeout);
209
226
  callbackServer.close();
210
- resolve(tokenData);
227
+ resolveToken(tokenData);
211
228
  } catch (err) {
212
229
  res.writeHead(500, { "Content-Type": "text/html" });
213
- res.end(`<html><body><h1>Token exchange failed</h1><p>${err instanceof Error ? err.message : String(err)}</p></body></html>`);
230
+ res.end(`<html><body><h1>Token exchange failed</h1><p>${escapeHtml(err instanceof Error ? err.message : String(err))}</p></body></html>`);
214
231
  clearTimeout(authTimeout);
215
232
  callbackServer.close();
216
- reject(err);
233
+ rejectToken(err);
217
234
  }
218
235
  });
236
+ const onStartError = (err) => {
237
+ clearTimeout(authTimeout);
238
+ rejectStarted(err);
239
+ };
240
+ callbackServer.once("error", onStartError);
219
241
  callbackServer.listen(config.callbackPort ?? DEFAULT_CALLBACK_PORT, () => {
242
+ callbackServer.off("error", onStartError);
243
+ callbackServer.once("error", (err) => {
244
+ clearTimeout(authTimeout);
245
+ callbackServer.close();
246
+ rejectToken(err);
247
+ });
220
248
  const port = callbackServer.address().port;
221
249
  const redirectUri = `http://localhost:${port}/callback`;
222
- const authUrl = `${authorizeUrl}?${new URLSearchParams({
250
+ const authUrl = `${authorizeBase}?${new URLSearchParams({
223
251
  response_type: "code",
224
252
  client_id: oauthClientId,
225
253
  redirect_uri: redirectUri,
@@ -251,54 +279,67 @@ const authenticateViaBrowser = (config, logger = silentLogger) => {
251
279
  hasDisplay: Boolean(process.env["DISPLAY"])
252
280
  });
253
281
  });
282
+ authTimeout = setTimeout(() => {
283
+ logger.error("oauth_timeout", { timeoutMs: AUTH_TIMEOUT_MS });
284
+ callbackServer.close();
285
+ rejectToken(/* @__PURE__ */ new Error("OAuth authentication timed out (5 min). Please try again."));
286
+ }, AUTH_TIMEOUT_MS);
287
+ authTimeout.unref();
288
+ resolveStarted({
289
+ authorizeUrl: authUrl,
290
+ tokenPromise
291
+ });
254
292
  });
255
- authTimeout = setTimeout(() => {
256
- logger.error("oauth_timeout", { timeoutMs: AUTH_TIMEOUT_MS });
257
- callbackServer.close();
258
- reject(/* @__PURE__ */ new Error("OAuth authentication timed out (5 min). Please try again."));
259
- }, AUTH_TIMEOUT_MS);
260
- authTimeout.unref();
261
293
  });
262
294
  };
263
295
  //#endregion
264
296
  //#region src/auth/token-store.ts
297
+ const createAuthRequiredError = (authorizeUrl) => Object.assign(/* @__PURE__ */ new Error("Zendesk authentication required. A browser window should have opened for you to sign in. If it did not, open this URL in your browser, then retry your request:\n" + authorizeUrl), {
298
+ name: "AuthRequiredError",
299
+ authorizeUrl
300
+ });
265
301
  const createTokenStore = (config, logger = silentLogger) => {
266
302
  let token;
267
- let authPromise;
303
+ let authorizeUrl;
304
+ let starting;
268
305
  const setToken = (accessToken, refreshToken) => {
269
306
  token = {
270
307
  accessToken,
271
308
  refreshToken
272
309
  };
273
310
  };
274
- const ensureToken = async () => {
275
- if (token) {
276
- logger.debug("oauth_token_cache_hit");
277
- return token;
278
- }
279
- if (!authPromise) {
280
- logger.info("oauth_auth_start");
281
- authPromise = authenticateViaBrowser({
282
- subdomain: config.subdomain,
283
- oauthClientId: config.oauthClientId
284
- }, logger).then((result) => {
285
- const stored = {
311
+ const beginAuth = () => {
312
+ logger.info("oauth_auth_start");
313
+ return startBrowserAuth({
314
+ subdomain: config.subdomain,
315
+ oauthClientId: config.oauthClientId
316
+ }, logger).then((started) => {
317
+ authorizeUrl = started.authorizeUrl;
318
+ started.tokenPromise.then((result) => {
319
+ token = {
286
320
  accessToken: result.access_token,
287
321
  refreshToken: result.refresh_token
288
322
  };
289
- token = stored;
290
- authPromise = void 0;
291
- return stored;
323
+ logger.info("oauth_token_cached");
292
324
  }).catch((err) => {
293
- authPromise = void 0;
294
325
  logger.warn("oauth_auth_failed", { error: err instanceof Error ? err.message : String(err) });
295
- throw err;
326
+ }).finally(() => {
327
+ starting = void 0;
328
+ authorizeUrl = void 0;
296
329
  });
297
- }
298
- return authPromise;
330
+ return started.authorizeUrl;
331
+ }).catch((err) => {
332
+ starting = void 0;
333
+ throw err;
334
+ });
299
335
  };
300
336
  const getToken = async () => {
301
- return (await ensureToken()).accessToken;
337
+ if (token) {
338
+ logger.debug("oauth_token_cache_hit");
339
+ return token.accessToken;
340
+ }
341
+ if (!starting) starting = beginAuth();
342
+ throw createAuthRequiredError(authorizeUrl ?? await starting);
302
343
  };
303
344
  return {
304
345
  getToken,
@@ -523,7 +564,7 @@ const textOf = (html) => {
523
564
  return cheerio.load(`<div>${html}</div>`, null, false)("div").first().text();
524
565
  };
525
566
  const parseSections = (html) => {
526
- if (!html || !html.trim()) return [];
567
+ if (!html?.trim()) return [];
527
568
  const $ = cheerio.load(html, null, false);
528
569
  const children = $.root().contents().toArray();
529
570
  const introParts = [];
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/auth/api-token.ts","../src/utils/logger.ts","../src/constants.ts","../src/auth/browser-oauth.ts","../src/auth/token-store.ts","../src/config.ts","../src/routing/registry.ts","../src/client/zendesk-api.ts","../src/utils/article-sections.ts","../src/utils/formatting.ts","../src/utils/pagination.ts","../src/tools/help-center.ts","../src/tools/search.ts","../src/tools/tickets.ts","../src/tools/users.ts","../src/tools/index.ts","../src/utils/package-info.ts","../src/server.ts","../src/transports/stdio.ts","../src/index.ts"],"sourcesContent":["/**\n * API token authentication for stdio transport.\n * Uses Basic auth: base64(email/token:api_token)\n */\nexport const buildBasicAuthHeader = (email: string, apiToken: string): string => {\n const credentials = `${email}/token:${apiToken}`;\n return `Basic ${Buffer.from(credentials).toString('base64')}`;\n};\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { LogLevel } from '../config';\n\ntype Fields = Record<string, unknown>;\n\n/**\n * Minimal structured logger with two sinks:\n * - stderr (always, gated by the configured level) — the universal floor that\n * every mainstream MCP client captures to a log file;\n * - MCP `notifications/message` (when a server is attached and advertises the\n * `logging` capability) — surfaced by clients that support it, ignored\n * gracefully by those that don't.\n *\n * Both sinks share a single level gate (`LOG_LEVEL`); MCP clients may further\n * raise the floor via `logging/setLevel`, which the SDK filters on its own.\n */\nexport interface Logger {\n debug(event: string, fields?: Fields): void;\n info(event: string, fields?: Fields): void;\n warn(event: string, fields?: Fields): void;\n error(event: string, fields?: Fields): void;\n /** Attach an McpServer so logs are also emitted as MCP notifications. */\n attachServer(server: Pick<McpServer, 'sendLoggingMessage'>): void;\n}\n\nconst SEVERITY: Record<LogLevel, number> = { debug: 0, info: 1, warn: 2, error: 3 };\n\n// Our 4 levels mapped onto the MCP logging levels (note: `warning`, not `warn`).\nconst MCP_LEVEL: Record<LogLevel, 'debug' | 'info' | 'warning' | 'error'> = {\n debug: 'debug',\n info: 'info',\n warn: 'warning',\n error: 'error',\n};\n\n// Field keys whose values must never reach a sink, matched after normalising\n// (lowercase, separators stripped) so `access_token`, `accessToken` and\n// `ACCESS-TOKEN` all collapse to the same key. Diagnostic fields such as\n// `errorCode`, `status` or `error` (a message) are intentionally NOT listed.\nconst REDACTED_KEYS = new Set([\n 'token',\n 'accesstoken',\n 'refreshtoken',\n 'code',\n 'codeverifier',\n 'authorization',\n 'password',\n 'secret',\n 'apitoken',\n 'bearer',\n]);\n\nconst isSensitive = (key: string): boolean =>\n REDACTED_KEYS.has(key.toLowerCase().replace(/[_-]/g, ''));\n\n// Recursively redact: a sensitive *key* anywhere in the tree (top-level or\n// nested in objects/arrays) has its value replaced, so `{ oauth: { token } }`\n// can't leak. Primitives are returned as-is.\nconst redactValue = (value: unknown): unknown => {\n if (Array.isArray(value)) return value.map(redactValue);\n if (value && typeof value === 'object') {\n const out: Record<string, unknown> = {};\n for (const [key, val] of Object.entries(value as Record<string, unknown>)) {\n out[key] = isSensitive(key) ? '[REDACTED]' : redactValue(val);\n }\n return out;\n }\n return value;\n};\n\nconst renderValue = (value: unknown): string => {\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean' || value === null) {\n return String(value);\n }\n try {\n return JSON.stringify(value);\n } catch {\n return '[unserializable]';\n }\n};\n\nconst formatLine = (level: LogLevel, event: string, fields: Fields): string => {\n const parts = Object.entries(fields).map(([key, value]) => `${key}=${renderValue(value)}`);\n return `[zendesk-mcp] [${level}] ${event}${parts.length ? ` ${parts.join(' ')}` : ''}`;\n};\n\nconst noop = (): void => {};\n\nexport const silentLogger: Logger = {\n debug: noop,\n info: noop,\n warn: noop,\n error: noop,\n attachServer: noop,\n};\n\nexport const createLogger = (level: LogLevel): Logger => {\n const min = SEVERITY[level];\n let server: Pick<McpServer, 'sendLoggingMessage'> | undefined;\n\n const emit = (lvl: LogLevel, event: string, fields?: Fields): void => {\n if (SEVERITY[lvl] < min) return;\n\n const safe = fields ? (redactValue(fields) as Fields) : {};\n console.error(formatLine(lvl, event, safe));\n\n if (server) {\n try {\n void server\n .sendLoggingMessage({\n level: MCP_LEVEL[lvl],\n logger: 'zendesk-mcp-server',\n // `event` last so a caller-supplied `fields.event` can't shadow the\n // canonical event name.\n data: { ...safe, event },\n })\n .catch(noop);\n } catch {\n // Forwarding is best-effort (e.g. transport not connected yet);\n // it must never break the flow that emitted the log.\n }\n }\n };\n\n return {\n debug: (event, fields) => emit('debug', event, fields),\n info: (event, fields) => emit('info', event, fields),\n warn: (event, fields) => emit('warn', event, fields),\n error: (event, fields) => emit('error', event, fields),\n attachServer: (s) => {\n server = s;\n },\n };\n};\n","export const CHARACTER_LIMIT = 25_000;\nexport const DEFAULT_PAGE_SIZE = 100;\nexport const MAX_PAGE_SIZE = 100;\nexport const TOKEN_CACHE_TTL_MS = 5 * 60 * 1000;\n\n// Per-attachment cap for inline image content. Images larger than this are\n// returned as text references instead of base64 image content blocks.\n// Aligned with the Anthropic vision API per-image limit.\nexport const MAX_ATTACHMENT_BYTES = 5 * 1024 * 1024;\n\n// Maximum number of images embedded as base64 in a single tool call.\n// Remaining images are returned as text references.\nexport const MAX_EMBEDDED_IMAGE_COUNT = 10;\n\n// Hard cap on comment pages fetched when collecting ticket attachments.\n// Overridable via ZENDESK_MAX_COMMENT_PAGES for tickets with many comments.\nexport const MAX_COMMENT_PAGES = Number(process.env['ZENDESK_MAX_COMMENT_PAGES'] ?? 10);\n\n// Thresholds used to nudge callers toward section-scoped article tools\n// (get_article_outline / get_article_section / update_article_section)\n// instead of fetching/rewriting the full body.\nexport const LARGE_ARTICLE_BODY_CHARS = 3_000;\nexport const LARGE_ARTICLE_SECTION_COUNT = 4;\n\nexport const getBaseUrl = (subdomain: string): string => `https://${subdomain}.zendesk.com/api/v2`;\n\nexport const getHelpCenterBaseUrl = (subdomain: string): string =>\n `https://${subdomain}.zendesk.com/api/v2/help_center`;\n\nexport const getOAuthUrls = (subdomain: string) => ({\n authorizeUrl: `https://${subdomain}.zendesk.com/oauth/authorizations/new`,\n tokenUrl: `https://${subdomain}.zendesk.com/oauth/tokens`,\n});\n","import { createHash, randomBytes } from 'node:crypto';\nimport { readFileSync } from 'node:fs';\nimport { createServer, type Server } from 'node:http';\nimport { release } from 'node:os';\nimport open from 'open';\nimport { getOAuthUrls } from '../constants';\nimport { type Logger, silentLogger } from '../utils/logger';\n\nconst DEFAULT_CALLBACK_PORT = 3000;\nconst AUTH_TIMEOUT_MS = 5 * 60 * 1000;\n\n/** Best-effort WSL detection: WSL kernels carry \"microsoft\" in /proc/version. */\nconst detectWsl = (): boolean => {\n if (process.platform !== 'linux') return false;\n try {\n return readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft');\n } catch {\n return false;\n }\n};\n\ninterface BrowserOAuthConfig {\n subdomain: string;\n oauthClientId: string;\n callbackPort?: number | undefined;\n}\n\ninterface TokenResult {\n access_token: string;\n refresh_token?: string;\n token_type: string;\n scope: string;\n}\n\nconst generateCodeVerifier = (): string => randomBytes(32).toString('base64url');\n\nconst generateCodeChallenge = (verifier: string): string =>\n createHash('sha256').update(verifier).digest('base64url');\n\n/**\n * Performs OAuth 2.1 PKCE flow by opening the user's browser.\n * Starts a temporary HTTP server to receive the callback.\n * Returns the access token on success.\n */\nexport const authenticateViaBrowser = (\n config: BrowserOAuthConfig,\n logger: Logger = silentLogger,\n): Promise<TokenResult> => {\n const { subdomain, oauthClientId } = config;\n const { authorizeUrl, tokenUrl } = getOAuthUrls(subdomain);\n const codeVerifier = generateCodeVerifier();\n const codeChallenge = generateCodeChallenge(codeVerifier);\n\n return new Promise((resolve, reject) => {\n let callbackServer: Server;\n let authTimeout: ReturnType<typeof setTimeout> | undefined;\n\n callbackServer = createServer(async (req, res) => {\n const url = new URL(req.url ?? '/', `http://localhost`);\n\n if (url.pathname !== '/callback') {\n res.writeHead(404);\n res.end('Not found');\n return;\n }\n\n const code = url.searchParams.get('code');\n const error = url.searchParams.get('error');\n\n logger.debug('oauth_callback_received', {\n hasCode: Boolean(code),\n hasError: Boolean(error),\n });\n\n if (error) {\n const desc = url.searchParams.get('error_description') ?? error;\n res.writeHead(400, { 'Content-Type': 'text/html' });\n res.end(`<html><body><h1>Authentication failed</h1><p>${desc}</p></body></html>`);\n clearTimeout(authTimeout);\n callbackServer.close();\n reject(new Error(`OAuth error: ${desc}`));\n return;\n }\n\n if (!code) {\n res.writeHead(400, { 'Content-Type': 'text/html' });\n res.end('<html><body><h1>Missing authorization code</h1></body></html>');\n clearTimeout(authTimeout);\n callbackServer.close();\n reject(new Error('Missing authorization code in callback'));\n return;\n }\n\n // Exchange code for token\n try {\n const callbackPort = (callbackServer.address() as { port: number }).port;\n const tokenBody = new URLSearchParams({\n grant_type: 'authorization_code',\n code,\n client_id: oauthClientId,\n redirect_uri: `http://localhost:${callbackPort}/callback`,\n code_verifier: codeVerifier,\n });\n\n const tokenResponse = await fetch(tokenUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: tokenBody.toString(),\n });\n\n logger.debug('oauth_token_exchange', { status: tokenResponse.status });\n\n if (!tokenResponse.ok) {\n const errorBody = await tokenResponse.text();\n throw new Error(`Token exchange failed (${tokenResponse.status}): ${errorBody}`);\n }\n\n const tokenData = (await tokenResponse.json()) as TokenResult;\n logger.info('oauth_authenticated');\n\n res.writeHead(200, { 'Content-Type': 'text/html' });\n res.end(\n '<html><body><h1>Authentication successful!</h1>' +\n '<p>You can close this tab and return to Claude Code.</p>' +\n '<script>window.close()</script></body></html>',\n );\n\n clearTimeout(authTimeout);\n callbackServer.close();\n resolve(tokenData);\n } catch (err) {\n res.writeHead(500, { 'Content-Type': 'text/html' });\n res.end(\n `<html><body><h1>Token exchange failed</h1><p>${err instanceof Error ? err.message : String(err)}</p></body></html>`,\n );\n clearTimeout(authTimeout);\n callbackServer.close();\n reject(err);\n }\n });\n\n // Start on fixed port (must match redirect_uri registered in Zendesk OAuth client)\n callbackServer.listen(config.callbackPort ?? DEFAULT_CALLBACK_PORT, () => {\n const port = (callbackServer.address() as { port: number }).port;\n const redirectUri = `http://localhost:${port}/callback`;\n\n const params = new URLSearchParams({\n response_type: 'code',\n client_id: oauthClientId,\n redirect_uri: redirectUri,\n scope: 'read write',\n code_challenge: codeChallenge,\n code_challenge_method: 'S256',\n });\n\n const authUrl = `${authorizeUrl}?${params.toString()}`;\n logger.debug('oauth_callback_listening', { port, redirectUri });\n logger.info('oauth_browser_opening');\n // Full authorize URL is debug-only: it carries the (public) client_id and\n // PKCE challenge — no secret — but stays out of default-level logs.\n logger.debug('oauth_authorize_url', { url: authUrl });\n // Always-on, ungated user-facing fallback: if the browser can't open, the\n // user must see this URL regardless of LOG_LEVEL — do NOT route it through\n // the (level-gated) logger.\n console.error(`Opening browser for Zendesk authentication...`);\n console.error(`If the browser doesn't open, visit: ${authUrl}`);\n\n open(authUrl)\n .then(() => {\n logger.debug('oauth_browser_opened');\n })\n .catch((err: unknown) => {\n // Do NOT swallow: this is the #60 signal. Capture why `open` failed\n // plus environment markers (presence only, never values).\n logger.error('oauth_browser_open_failed', {\n error: err instanceof Error ? err.message : String(err),\n errorCode: (err as NodeJS.ErrnoException | undefined)?.code,\n platform: process.platform,\n release: release(),\n isWsl: detectWsl(),\n hasSystemRoot: Boolean(process.env['SYSTEMROOT']),\n hasWindir: Boolean(process.env['WINDIR']),\n hasComSpec: Boolean(process.env['ComSpec']),\n hasPath: Boolean(process.env['PATH']),\n hasDisplay: Boolean(process.env['DISPLAY']),\n });\n });\n });\n\n // Timeout after 5 minutes. Cleared on every completion path above so a\n // successful auth can't emit a spurious `oauth_timeout` error later.\n authTimeout = setTimeout(() => {\n logger.error('oauth_timeout', { timeoutMs: AUTH_TIMEOUT_MS });\n callbackServer.close();\n reject(new Error('OAuth authentication timed out (5 min). Please try again.'));\n }, AUTH_TIMEOUT_MS);\n authTimeout.unref();\n });\n};\n","import { type Logger, silentLogger } from '../utils/logger';\nimport { authenticateViaBrowser } from './browser-oauth';\n\ninterface StoredToken {\n accessToken: string;\n refreshToken?: string | undefined;\n}\n\nexport const createTokenStore = (\n config: { subdomain: string; oauthClientId: string },\n logger: Logger = silentLogger,\n) => {\n let token: StoredToken | undefined;\n let authPromise: Promise<StoredToken> | undefined;\n\n const setToken = (accessToken: string, refreshToken?: string | undefined) => {\n token = { accessToken, refreshToken };\n };\n\n const ensureToken = async (): Promise<StoredToken> => {\n if (token) {\n logger.debug('oauth_token_cache_hit');\n return token;\n }\n\n if (!authPromise) {\n logger.info('oauth_auth_start');\n authPromise = authenticateViaBrowser(\n {\n subdomain: config.subdomain,\n oauthClientId: config.oauthClientId,\n },\n logger,\n )\n .then((result) => {\n const stored: StoredToken = {\n accessToken: result.access_token,\n refreshToken: result.refresh_token,\n };\n token = stored;\n authPromise = undefined;\n return stored;\n })\n .catch((err) => {\n authPromise = undefined;\n logger.warn('oauth_auth_failed', {\n error: err instanceof Error ? err.message : String(err),\n });\n throw err;\n });\n }\n\n return authPromise;\n };\n\n const getToken = async (): Promise<string> => {\n const stored = await ensureToken();\n return stored.accessToken;\n };\n\n return { getToken, setToken };\n};\n","import * as z from 'zod/v4';\n\nexport const ToolMode = z.enum(['single', 'namespace', 'all']);\nexport type ToolMode = z.infer<typeof ToolMode>;\n\nexport const LogLevel = z.enum(['debug', 'info', 'warn', 'error']);\nexport type LogLevel = z.infer<typeof LogLevel>;\n\nexport const Namespace = z.enum(['tickets', 'help_center', 'users']);\nexport type Namespace = z.infer<typeof Namespace>;\n\nexport const ConfigSchema = z.object({\n subdomain: z.string().min(1, 'ZENDESK_SUBDOMAIN is required'),\n oauthClientId: z.string().min(1),\n zendeskEmail: z.string().optional(),\n zendeskApiToken: z.string().optional(),\n logLevel: LogLevel,\n mode: ToolMode,\n readOnly: z.boolean(),\n namespaces: z.array(Namespace).optional(),\n tools: z.array(z.string()).optional(),\n});\n\nexport type Config = z.infer<typeof ConfigSchema>;\n\ninterface CliResult {\n subdomain?: string;\n mode?: string;\n readOnly?: boolean;\n namespaces?: string[];\n tools?: string[];\n logLevel?: string;\n}\n\nconst parseCliArgs = (args: string[]): CliResult => {\n const result: CliResult = {};\n let positionalIndex = 0;\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg === undefined) continue;\n const next = args[i + 1];\n\n if (arg === '--mode' && next) {\n result.mode = next;\n i++;\n } else if (arg === '--read-only') {\n result.readOnly = true;\n } else if (arg === '--namespace' && next) {\n result.namespaces = result.namespaces ?? [];\n result.namespaces.push(next);\n i++;\n } else if (arg === '--tool' && next) {\n result.tools = result.tools ?? [];\n result.tools.push(next);\n i++;\n } else if (arg === '--log-level' && next) {\n result.logLevel = next;\n i++;\n } else if (!arg.startsWith('-') && positionalIndex === 0) {\n result.subdomain = arg;\n positionalIndex++;\n }\n }\n\n return result;\n};\n\nexport const loadConfig = (argv: string[] = process.argv.slice(2)): Config => {\n const cli = parseCliArgs(argv);\n\n const subdomain = cli.subdomain ?? process.env['ZENDESK_SUBDOMAIN'] ?? '';\n const oauthClientId =\n process.env['ZENDESK_OAUTH_CLIENT_ID'] ?? (subdomain ? `${subdomain}_zendesk` : '');\n\n const mode = cli.tools?.length ? 'all' : (cli.mode ?? 'namespace');\n\n return ConfigSchema.parse({\n subdomain,\n oauthClientId,\n zendeskEmail: process.env['ZENDESK_EMAIL'],\n zendeskApiToken: process.env['ZENDESK_API_TOKEN'],\n logLevel: cli.logLevel ?? process.env['LOG_LEVEL'] ?? 'info',\n mode,\n readOnly: cli.readOnly ?? false,\n namespaces: cli.namespaces,\n tools: cli.tools,\n });\n};\n","import type { Namespace } from '../config';\nimport type { ToolDefinition } from '../tools/definitions';\n\nexport interface FilterOptions {\n readOnly: boolean;\n namespaces?: Namespace[] | undefined;\n tools?: string[] | undefined;\n}\n\nexport const filterTools = (allTools: ToolDefinition[], options: FilterOptions): ToolDefinition[] =>\n allTools.filter((tool) => {\n if (options.readOnly && !tool.readOnly) return false;\n if (options.namespaces?.length && !options.namespaces.includes(tool.namespace)) return false;\n if (options.tools?.length && !options.tools.includes(tool.name)) return false;\n return true;\n });\n\nexport const groupByNamespace = (tools: ToolDefinition[]): Map<string, ToolDefinition[]> => {\n const grouped = new Map<string, ToolDefinition[]>();\n for (const tool of tools) {\n const existing = grouped.get(tool.namespace) ?? [];\n existing.push(tool);\n grouped.set(tool.namespace, existing);\n }\n return grouped;\n};\n","import { getBaseUrl, getHelpCenterBaseUrl } from '../constants.js';\n\nexport class ZendeskApiError extends Error {\n constructor(\n public readonly status: number,\n public readonly statusText: string,\n public readonly body: string,\n ) {\n super(ZendeskApiError.buildMessage(status, statusText, body));\n this.name = 'ZendeskApiError';\n }\n\n private static buildMessage(status: number, statusText: string, body: string): string {\n switch (status) {\n case 401:\n return 'Authentication failed. Your Zendesk token may be expired or invalid. Re-authenticate to get a new token.';\n case 403:\n return 'Permission denied. Your Zendesk account does not have access to this resource.';\n case 404:\n return `Resource not found. Please verify the ID is correct. (${statusText})`;\n case 422:\n return `Validation error: ${body}`;\n case 429:\n return 'Rate limit exceeded. Please wait before making more requests.';\n default:\n return `Zendesk API error ${status}: ${statusText}. ${body}`;\n }\n }\n}\n\nexport interface ZendeskRequestOptions {\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE';\n body?: unknown;\n params?: Record<string, string>;\n}\n\n// token is either a Bearer OAuth token or a \"Basic xxx\" string (stdio API token mode)\nconst buildAuthHeader = (token: string): string =>\n token.startsWith('Basic ') ? token : `Bearer ${token}`;\n\nconst buildUrl = (base: string, path: string, params?: Record<string, string>): string => {\n const url = new URL(`${base}${path}`);\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n url.searchParams.set(key, value);\n }\n }\n return url.toString();\n};\n\nconst executeRequest = async <T>(\n url: string,\n token: string,\n options: ZendeskRequestOptions = {},\n): Promise<T> => {\n const { method = 'GET', body } = options;\n\n const headers: Record<string, string> = {\n Authorization: buildAuthHeader(token),\n Accept: 'application/json',\n };\n\n if (body) {\n headers['Content-Type'] = 'application/json';\n }\n\n const init: RequestInit = { method, headers };\n if (body) {\n init.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, init);\n\n if (!response.ok) {\n const responseBody = await response.text();\n throw new ZendeskApiError(response.status, response.statusText, responseBody);\n }\n\n if (response.status === 204) {\n return {} as T;\n }\n\n return response.json() as Promise<T>;\n};\n\nexport const zendeskGet = <T>(\n subdomain: string,\n token: string,\n path: string,\n params?: Record<string, string>,\n): Promise<T> => {\n const url = buildUrl(getBaseUrl(subdomain), path, params);\n return executeRequest<T>(url, token);\n};\n\nexport const zendeskPost = <T>(\n subdomain: string,\n token: string,\n path: string,\n body: unknown,\n): Promise<T> => {\n const url = buildUrl(getBaseUrl(subdomain), path);\n return executeRequest<T>(url, token, { method: 'POST', body });\n};\n\nexport const zendeskPut = <T>(\n subdomain: string,\n token: string,\n path: string,\n body: unknown,\n): Promise<T> => {\n const url = buildUrl(getBaseUrl(subdomain), path);\n return executeRequest<T>(url, token, { method: 'PUT', body });\n};\n\nexport const helpCenterGet = <T>(\n subdomain: string,\n token: string,\n path: string,\n params?: Record<string, string>,\n): Promise<T> => {\n const url = buildUrl(getHelpCenterBaseUrl(subdomain), path, params);\n return executeRequest<T>(url, token);\n};\n\nexport const helpCenterPost = <T>(\n subdomain: string,\n token: string,\n path: string,\n body: unknown,\n): Promise<T> => {\n const url = buildUrl(getHelpCenterBaseUrl(subdomain), path);\n return executeRequest<T>(url, token, { method: 'POST', body });\n};\n\nexport const helpCenterPut = <T>(\n subdomain: string,\n token: string,\n path: string,\n body: unknown,\n): Promise<T> => {\n const url = buildUrl(getHelpCenterBaseUrl(subdomain), path);\n return executeRequest<T>(url, token, { method: 'PUT', body });\n};\n\nexport const fetchZendeskBinary = async (\n subdomain: string,\n token: string,\n contentUrl: string,\n): Promise<{ data: Buffer; contentType: string }> => {\n const expectedHost = `${subdomain}.zendesk.com`;\n const headers: Record<string, string> = {};\n if (new URL(contentUrl).hostname === expectedHost) {\n headers['Authorization'] = buildAuthHeader(token);\n }\n const response = await fetch(contentUrl, { headers });\n if (!response.ok) {\n const body = await response.text();\n throw new ZendeskApiError(response.status, response.statusText, body);\n }\n const contentType = response.headers.get('content-type') ?? 'application/octet-stream';\n const arrayBuffer = await response.arrayBuffer();\n return { data: Buffer.from(arrayBuffer), contentType };\n};\n\nexport const helpCenterUpload = async <T>(\n subdomain: string,\n token: string,\n path: string,\n formData: FormData,\n): Promise<T> => {\n const url = buildUrl(getHelpCenterBaseUrl(subdomain), path);\n const response = await fetch(url, {\n method: 'POST',\n headers: { Authorization: buildAuthHeader(token) },\n body: formData,\n });\n\n if (!response.ok) {\n const responseBody = await response.text();\n throw new ZendeskApiError(response.status, response.statusText, responseBody);\n }\n\n return response.json() as Promise<T>;\n};\n","import * as cheerio from 'cheerio';\nimport type { Element } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\nimport type { Handle } from 'hast-util-to-mdast';\nimport rehypeParse from 'rehype-parse';\nimport rehypeRaw from 'rehype-raw';\nimport rehypeRemark from 'rehype-remark';\nimport rehypeStringify from 'rehype-stringify';\nimport remarkGfm from 'remark-gfm';\nimport remarkParse from 'remark-parse';\nimport remarkRehype from 'remark-rehype';\nimport remarkStringify from 'remark-stringify';\nimport { unified } from 'unified';\n\nexport interface Section {\n index: number;\n heading: string;\n headingTag: string;\n level: number;\n html: string;\n wordCount: number;\n}\n\nconst HEADING_LEVELS = new Set(['h1', 'h2', 'h3']);\n\nconst countWords = (text: string): number => {\n const trimmed = text.trim();\n if (!trimmed) return 0;\n return trimmed.split(/\\s+/).length;\n};\n\nconst textOf = (html: string): string => {\n if (!html) return '';\n const $ = cheerio.load(`<div>${html}</div>`, null, false);\n return $('div').first().text();\n};\n\nexport const parseSections = (html: string): Section[] => {\n if (!html || !html.trim()) return [];\n\n const $ = cheerio.load(html, null, false);\n const children = $.root().contents().toArray();\n\n const introParts: string[] = [];\n const sections: Array<{\n heading: string;\n headingTag: string;\n level: number;\n contentParts: string[];\n }> = [];\n let current: (typeof sections)[number] | null = null;\n\n for (const node of children) {\n const tagName = node.type === 'tag' ? node.name.toLowerCase() : '';\n\n if (HEADING_LEVELS.has(tagName)) {\n const level = Number.parseInt(tagName.slice(1), 10);\n current = {\n heading: $(node).text().trim(),\n headingTag: tagName,\n level,\n contentParts: [],\n };\n sections.push(current);\n continue;\n }\n\n const outer = $.html(node);\n if (current) {\n current.contentParts.push(outer);\n } else {\n introParts.push(outer);\n }\n }\n\n const result: Section[] = [];\n\n if (introParts.length > 0) {\n const introHtml = introParts.join('');\n result.push({\n index: 0,\n heading: 'intro',\n headingTag: '',\n level: 0,\n html: introHtml,\n wordCount: countWords(textOf(introHtml)),\n });\n }\n\n for (const s of sections) {\n const sectionHtml = s.contentParts.join('');\n result.push({\n index: result.length,\n heading: s.heading,\n headingTag: s.headingTag,\n level: s.level,\n html: sectionHtml,\n wordCount: countWords(textOf(sectionHtml)),\n });\n }\n\n return result;\n};\n\nexport const replaceSectionContent = (\n html: string,\n sectionIndex: number,\n newHtml: string,\n): string => {\n const sections = parseSections(html);\n if (sectionIndex < 0 || sectionIndex >= sections.length) {\n throw new Error(\n `Section index ${sectionIndex} out of range (valid: 0-${Math.max(0, sections.length - 1)})`,\n );\n }\n\n return sections\n .map((section, idx) => {\n const content = idx === sectionIndex ? newHtml : section.html;\n if (section.level === 0) return content;\n return `<${section.headingTag}>${section.heading}</${section.headingTag}>${content}`;\n })\n .join('');\n};\n\n// Keep structural HTML that markdown flattens lossily: <pre> with inline <br>\n// collapses to a single line, and <table> cells with multiple <p> break GFM\n// pipe tables. Leaving them as raw HTML is safer for round-trip.\nconst keepAsHtml: Handle = (_state, node) => ({\n type: 'html',\n value: toHtml(node as Element),\n});\n\nconst htmlToMdProcessor = unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeRemark, { handlers: { table: keepAsHtml, pre: keepAsHtml } })\n .use(remarkGfm)\n .use(remarkStringify, { bullet: '-', emphasis: '_', fences: true });\n\nconst mdToHtmlProcessor = unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkRehype, { allowDangerousHtml: true })\n .use(rehypeRaw)\n .use(rehypeStringify);\n\nexport const htmlToMarkdown = (html: string): string => {\n if (!html) return '';\n return String(htmlToMdProcessor.processSync(html));\n};\n\nexport const markdownToHtml = (markdown: string): string => {\n if (!markdown) return '';\n return String(mdToHtmlProcessor.processSync(markdown));\n};\n","import { CHARACTER_LIMIT } from '../constants.js';\nimport type {\n PaginationMeta,\n ZendeskArticle,\n ZendeskArticleAttachment,\n ZendeskCategory,\n ZendeskComment,\n ZendeskContentTag,\n ZendeskLabel,\n ZendeskOrganization,\n ZendeskPermissionGroup,\n ZendeskSection,\n ZendeskTicket,\n ZendeskTranslation,\n ZendeskUser,\n ZendeskUserSegment,\n} from '../types.js';\n\nexport const truncateIfNeeded = (text: string): string => {\n if (text.length <= CHARACTER_LIMIT) return text;\n return `${text.slice(0, CHARACTER_LIMIT)}\\n\\n--- Response truncated (${text.length} chars, limit ${CHARACTER_LIMIT}). Use pagination or filters to reduce results. ---`;\n};\n\nconst formatPagination = (meta: PaginationMeta): string => {\n const parts = [`Results: ${meta.count}`];\n if (meta.has_more) {\n parts.push(`More available (cursor: ${meta.after_cursor})`);\n }\n return parts.join(' | ');\n};\n\nexport const formatTicket = (ticket: ZendeskTicket): string =>\n [\n `## Ticket #${ticket.id}: ${ticket.subject}`,\n `- **Status**: ${ticket.status} | **Priority**: ${ticket.priority ?? 'none'} | **Type**: ${ticket.type ?? 'none'}`,\n `- **Requester**: ${ticket.requester_id} | **Assignee**: ${ticket.assignee_id ?? 'unassigned'}`,\n `- **Tags**: ${ticket.tags.length > 0 ? ticket.tags.join(', ') : 'none'}`,\n `- **Created**: ${ticket.created_at} | **Updated**: ${ticket.updated_at}`,\n ticket.description ? `\\n${ticket.description}` : '',\n ]\n .filter(Boolean)\n .join('\\n');\n\nexport const formatComment = (comment: ZendeskComment): string => {\n const lines = [\n `### ${comment.public ? 'Public comment' : 'Internal note'} by ${comment.author_id}`,\n `*${comment.created_at}*`,\n ];\n if (comment.attachments?.length) {\n const summary = comment.attachments.map((a) => `#${a.id} (${a.content_type})`).join(', ');\n lines.push(`Attachments: ${summary}`);\n }\n lines.push('', comment.body);\n return lines.join('\\n');\n};\n\nexport const formatUser = (user: ZendeskUser): string =>\n [\n `## ${user.name} (${user.id})`,\n `- **Email**: ${user.email}`,\n `- **Role**: ${user.role}`,\n user.role_type != null ? `- **Role type**: ${user.role_type}` : '',\n `- **Active**: ${user.active}`,\n user.organization_id ? `- **Organization**: ${user.organization_id}` : '',\n ]\n .filter(Boolean)\n .join('\\n');\n\nexport const formatOrganization = (org: ZendeskOrganization): string =>\n [\n `## ${org.name} (${org.id})`,\n org.details ? `- **Details**: ${org.details}` : '',\n org.domain_names.length > 0 ? `- **Domains**: ${org.domain_names.join(', ')}` : '',\n org.tags.length > 0 ? `- **Tags**: ${org.tags.join(', ')}` : '',\n ]\n .filter(Boolean)\n .join('\\n');\n\nexport const formatArticleSummary = (article: ZendeskArticle): string =>\n [\n `## ${article.title} (${article.id})`,\n `- **Locale**: ${article.locale} | **Source locale**: ${article.source_locale}`,\n `- **Section**: ${article.section_id} | **Draft**: ${article.draft}`,\n typeof article.position === 'number' ? `- **Position**: ${article.position}` : '',\n article.label_names.length > 0 ? `- **Labels**: ${article.label_names.join(', ')}` : '',\n `- **Created**: ${article.created_at} | **Updated**: ${article.updated_at}`,\n ]\n .filter(Boolean)\n .join('\\n');\n\nexport const formatArticle = (article: ZendeskArticle): string =>\n [formatArticleSummary(article), '', article.body].join('\\n');\n\nexport const formatTranslationSummary = (translation: ZendeskTranslation): string =>\n [\n `## Translation: ${translation.locale} (${translation.id})`,\n `- **Title**: ${translation.title}`,\n `- **Draft**: ${translation.draft}`,\n `- **Updated**: ${translation.updated_at}`,\n ].join('\\n');\n\nexport const formatTranslation = (translation: ZendeskTranslation): string =>\n [formatTranslationSummary(translation), '', translation.body].join('\\n');\n\nexport const formatCategory = (category: ZendeskCategory): string =>\n `- **${category.name}** (${category.id}) — ${category.description || 'No description'}`;\n\nexport const formatSection = (section: ZendeskSection): string =>\n `- **${section.name}** (${section.id}) — Category: ${section.category_id} — ${section.description || 'No description'}`;\n\nexport const formatPermissionGroup = (group: ZendeskPermissionGroup): string =>\n `- **${group.name}** (${group.id})${group.built_in ? ' — Built-in' : ''}`;\n\nexport const formatContentTag = (tag: ZendeskContentTag): string => `- **${tag.name}** (${tag.id})`;\n\nexport const formatLabel = (label: ZendeskLabel): string => `- **${label.name}** (${label.id})`;\n\nexport const formatUserSegment = (segment: ZendeskUserSegment): string =>\n `- **${segment.name}** (${segment.id}) — ${segment.user_type}${segment.built_in ? ' — Built-in' : ''}`;\n\nexport const formatAttachment = (attachment: ZendeskArticleAttachment): string =>\n `- **${attachment.file_name}** (${attachment.id}) — ${attachment.content_type} — ${attachment.size} bytes`;\n\nexport const formatList = <T>(\n items: T[],\n formatter: (item: T) => string,\n meta?: PaginationMeta,\n): string => {\n const header = meta ? formatPagination(meta) : '';\n const body = items.map(formatter).join('\\n\\n');\n const text = [header, body].filter(Boolean).join('\\n\\n');\n return truncateIfNeeded(text);\n};\n","import type { PaginationMeta, ZendeskListResponse } from '../types';\n\n// Cursor-based pagination (for list endpoints: /tickets, /organizations, etc.)\nexport const buildCursorParams = (pageSize: number, cursor?: string): Record<string, string> => {\n const params: Record<string, string> = {\n 'page[size]': String(pageSize),\n };\n if (cursor) {\n params['page[after]'] = cursor;\n }\n return params;\n};\n\n// Offset-based pagination (for search endpoints: /search, /help_center/articles/search)\nexport const buildOffsetParams = (perPage: number, page?: number): Record<string, string> => {\n const params: Record<string, string> = {\n per_page: String(perPage),\n };\n if (page && page > 1) {\n params['page'] = String(page);\n }\n return params;\n};\n\nexport const extractPaginationMeta = <T>(response: ZendeskListResponse<T>): PaginationMeta => ({\n has_more: response.meta?.has_more ?? response.next_page != null,\n after_cursor: response.meta?.after_cursor ?? null,\n count: response.count ?? 0,\n});\n\n// For search responses — offset-based, count is always present\nexport const extractSearchPaginationMeta = <T>(\n response: ZendeskListResponse<T>,\n perPage: number,\n page: number,\n): PaginationMeta => {\n const count = response.count ?? 0;\n const has_more = count > page * perPage;\n return {\n has_more,\n after_cursor: has_more ? String(page + 1) : null,\n count,\n };\n};\n","import * as z from 'zod/v4';\nimport {\n helpCenterGet,\n helpCenterPost,\n helpCenterPut,\n helpCenterUpload,\n zendeskGet,\n zendeskPost,\n} from '../client/zendesk-api';\nimport {\n DEFAULT_PAGE_SIZE,\n LARGE_ARTICLE_BODY_CHARS,\n LARGE_ARTICLE_SECTION_COUNT,\n MAX_PAGE_SIZE,\n} from '../constants';\nimport type {\n ZendeskArticle,\n ZendeskArticleAttachment,\n ZendeskCategory,\n ZendeskContentTag,\n ZendeskLabel,\n ZendeskListResponse,\n ZendeskPermissionGroup,\n ZendeskSection,\n ZendeskTranslation,\n ZendeskUserSegment,\n} from '../types';\nimport {\n htmlToMarkdown,\n markdownToHtml,\n parseSections,\n replaceSectionContent,\n} from '../utils/article-sections';\nimport {\n formatArticle,\n formatArticleSummary,\n formatAttachment,\n formatCategory,\n formatContentTag,\n formatLabel,\n formatList,\n formatPermissionGroup,\n formatSection,\n formatTranslation,\n formatTranslationSummary,\n formatUserSegment,\n truncateIfNeeded,\n} from '../utils/formatting';\nimport {\n buildCursorParams,\n buildOffsetParams,\n extractPaginationMeta,\n extractSearchPaginationMeta,\n} from '../utils/pagination';\nimport type { ToolContext, ToolDefinition } from './definitions';\n\nconst largeArticleHint = (body: string, sectionCount: number): string | null => {\n if (body.length < LARGE_ARTICLE_BODY_CHARS && sectionCount < LARGE_ARTICLE_SECTION_COUNT) {\n return null;\n }\n return [\n `> ⚠ Large article (${body.length} chars, ${sectionCount} sections).`,\n '> For targeted edits, prefer get_article_outline + get_article_section +',\n '> update_article_section to avoid re-sending the full body on each write.',\n '',\n ].join('\\n');\n};\n\nexport const createHelpCenterTools = (ctx: ToolContext): ToolDefinition[] => {\n const { subdomain, getToken } = ctx;\n\n return [\n {\n name: 'search_articles',\n namespace: 'help_center',\n readOnly: true,\n title: 'Search Help Center Articles',\n description:\n 'Full-text search across Help Center articles (metadata only, no body). Use get_article for full content. Supports locale filtering. Returns total count.',\n inputSchema: z.object({\n query: z.string().min(1).describe('Search query'),\n locale: z.string().optional().describe('Filter by locale (e.g., \"en-us\", \"fr\")'),\n per_page: z\n .number()\n .int()\n .min(1)\n .max(MAX_PAGE_SIZE)\n .default(DEFAULT_PAGE_SIZE)\n .describe('Results per page'),\n page: z.number().int().min(1).default(1).describe('Page number'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { query, locale, per_page, page } = params as {\n query: string;\n locale?: string;\n per_page: number;\n page: number;\n };\n const token = await getToken();\n const p: Record<string, string> = { query, ...buildOffsetParams(per_page, page) };\n if (locale) p['locale'] = locale;\n const response = await helpCenterGet<ZendeskListResponse<ZendeskArticle>>(\n subdomain,\n token,\n '/articles/search',\n p,\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.results ?? [],\n formatArticleSummary,\n extractSearchPaginationMeta(response, per_page, page),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'get_article',\n namespace: 'help_center',\n readOnly: true,\n title: 'Get Help Center Article',\n description:\n 'Retrieve an article by ID with full body content. For large articles, prefer get_article_outline + get_article_section to save tokens. Optionally specify locale for a translated version. Returns body (HTML), metadata, source_locale, and list of available translations.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n locale: z.string().optional().describe('Locale for translated version'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale } = params as { article_id: number; locale?: string };\n const token = await getToken();\n const path = locale ? `/${locale}/articles/${article_id}` : `/articles/${article_id}`;\n const { article } = await helpCenterGet<{ article: ZendeskArticle }>(\n subdomain,\n token,\n path,\n );\n const { translations } = await helpCenterGet<{ translations: ZendeskTranslation[] }>(\n subdomain,\n token,\n `/articles/${article_id}/translations`,\n );\n const hint = largeArticleHint(article.body, parseSections(article.body).length);\n const text =\n (hint ?? '') +\n formatArticle(article) +\n `\\n\\n**Available translations**: ${translations.map((t) => t.locale).join(', ')}`;\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'list_categories',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Help Center Categories',\n description: 'List all Help Center categories. Optionally filter by locale.',\n inputSchema: z.object({\n locale: z.string().optional(),\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional(),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { locale, page_size, cursor } = params as {\n locale?: string;\n page_size: number;\n cursor?: string;\n };\n const token = await getToken();\n const path = locale ? `/${locale}/categories` : '/categories';\n const response = await helpCenterGet<ZendeskListResponse<ZendeskCategory>>(\n subdomain,\n token,\n path,\n buildCursorParams(page_size, cursor),\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.categories ?? [],\n formatCategory,\n extractPaginationMeta(response),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'list_sections',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Help Center Sections',\n description: 'List sections, optionally filtered by category ID and locale.',\n inputSchema: z.object({\n category_id: z.number().int().optional(),\n locale: z.string().optional(),\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional(),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { category_id, locale, page_size, cursor } = params as {\n category_id?: number;\n locale?: string;\n page_size: number;\n cursor?: string;\n };\n const token = await getToken();\n const path =\n category_id && locale\n ? `/${locale}/categories/${category_id}/sections`\n : category_id\n ? `/categories/${category_id}/sections`\n : locale\n ? `/${locale}/sections`\n : '/sections';\n const response = await helpCenterGet<ZendeskListResponse<ZendeskSection>>(\n subdomain,\n token,\n path,\n buildCursorParams(page_size, cursor),\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.sections ?? [],\n formatSection,\n extractPaginationMeta(response),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'list_articles',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Help Center Articles',\n description:\n 'List articles (metadata only, no body). Use get_article for full content. Optionally filter by section ID and locale. Supports sort_by (\"title\", \"created_at\", \"updated_at\") and include_translations: true to show available translation locales per article. Note: include_translations must be re-sent on each paginated request.',\n inputSchema: z.object({\n section_id: z.number().int().optional(),\n locale: z.string().optional(),\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional(),\n sort_by: z\n .enum(['created_at', 'updated_at', 'position', 'title'])\n .default('position')\n .describe('Sort field'),\n sort_order: z.enum(['asc', 'desc']).default('asc').describe('Sort direction'),\n include_translations: z\n .boolean()\n .default(false)\n .describe(\n 'Include available translation locales per article (causes 1 extra API call per article)',\n ),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { section_id, locale, page_size, cursor, sort_by, sort_order, include_translations } =\n params as {\n section_id?: number;\n locale?: string;\n page_size: number;\n cursor?: string;\n sort_by: string;\n sort_order: string;\n include_translations: boolean;\n };\n const token = await getToken();\n const path =\n section_id && locale\n ? `/${locale}/sections/${section_id}/articles`\n : section_id\n ? `/sections/${section_id}/articles`\n : locale\n ? `/${locale}/articles`\n : '/articles';\n const response = await helpCenterGet<ZendeskListResponse<ZendeskArticle>>(\n subdomain,\n token,\n path,\n { ...buildCursorParams(page_size, cursor), sort_by, sort_order },\n );\n const articles = response.articles ?? [];\n if (!include_translations) {\n return {\n content: [\n {\n type: 'text',\n text: formatList(articles, formatArticleSummary, extractPaginationMeta(response)),\n },\n ],\n };\n }\n const formatted = await Promise.all(\n articles.map(async (article) => {\n const { translations } = await helpCenterGet<{ translations: ZendeskTranslation[] }>(\n subdomain,\n token,\n `/articles/${article.id}/translations`,\n );\n const locales = translations.map((t) => t.locale).join(', ');\n return `${formatArticleSummary(article)}\\n- **Translations**: ${locales}`;\n }),\n );\n const meta = extractPaginationMeta(response);\n const header = meta.count\n ? `Results: ${meta.count}${meta.has_more ? ` | More available (cursor: ${meta.after_cursor})` : ''}`\n : '';\n const text = [header, ...formatted].filter(Boolean).join('\\n\\n');\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'list_article_translations',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Article Translations',\n description:\n 'List all available translations for an article (metadata only, no body: locale, title, draft, updated_at). Use get_article with locale for full translated content.',\n inputSchema: z.object({ article_id: z.number().int().describe('Article ID') }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id } = params as { article_id: number };\n const token = await getToken();\n const { translations } = await helpCenterGet<{ translations: ZendeskTranslation[] }>(\n subdomain,\n token,\n `/articles/${article_id}/translations`,\n );\n return {\n content: [{ type: 'text', text: formatList(translations, formatTranslationSummary) }],\n };\n },\n },\n {\n name: 'create_article_translation',\n namespace: 'help_center',\n readOnly: false,\n title: 'Create Article Translation',\n description: 'Create a translation for an existing article in a specific locale.',\n inputSchema: z.object({\n article_id: z.number().int(),\n locale: z.string().describe('Target locale (e.g., \"fr\", \"de\")'),\n title: z.string().min(1),\n body: z.string().min(1).describe('Translated body (HTML)'),\n draft: z.boolean().default(false),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale, title, body, draft } = params as {\n article_id: number;\n locale: string;\n title: string;\n body: string;\n draft: boolean;\n };\n const token = await getToken();\n const { translation } = await helpCenterPost<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations`,\n { translation: { locale, title, body, draft } },\n );\n return {\n content: [\n {\n type: 'text',\n text: `Translation created for article #${article_id} in \"${locale}\".\\n\\n${formatTranslation(translation)}`,\n },\n ],\n };\n },\n },\n {\n name: 'update_article_translation',\n namespace: 'help_center',\n readOnly: false,\n title: 'Update Article Translation',\n description:\n \"Update article content (title, body) in a specific locale. For targeted edits on one or a few sections, prefer update_article_section — this tool replaces the FULL body and re-sends the entire article on each write. Use the article's source_locale (from get_article) for the default language, or another locale for translations.\",\n inputSchema: z.object({\n article_id: z.number().int(),\n locale: z.string(),\n title: z.string().optional(),\n body: z.string().optional(),\n draft: z.boolean().optional(),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale, ...updates } = params as {\n article_id: number;\n locale: string;\n } & Record<string, unknown>;\n const token = await getToken();\n const { translation } = await helpCenterPut<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${locale}`,\n { translation: updates },\n );\n return {\n content: [\n {\n type: 'text',\n text: `Translation updated for article #${article_id} in \"${locale}\".\\n\\n${formatTranslation(translation)}`,\n },\n ],\n };\n },\n },\n {\n name: 'list_permission_groups',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Permission Groups',\n description:\n 'List all Guide permission groups. Use this to find the permission_group_id required when creating articles.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const response = await zendeskGet<{\n permission_groups: ZendeskPermissionGroup[];\n count: number;\n }>(subdomain, token, '/guide/permission_groups');\n return {\n content: [\n {\n type: 'text',\n text: formatList(response.permission_groups ?? [], formatPermissionGroup),\n },\n ],\n };\n },\n },\n {\n name: 'create_article',\n namespace: 'help_center',\n readOnly: false,\n title: 'Create Help Center Article',\n description:\n \"Create a new article in a section. The locale becomes the article's source_locale. Requires a permission_group_id (use list_permission_groups to find available IDs). To add content in other locales afterwards, use create_article_translation.\",\n inputSchema: z.object({\n section_id: z.number().int(),\n title: z.string().min(1),\n body: z.string().min(1).describe('Article body (HTML)'),\n permission_group_id: z\n .number()\n .int()\n .describe('Permission group ID (use list_permission_groups to find it)'),\n user_segment_id: z\n .number()\n .int()\n .optional()\n .describe(\n 'User segment ID for visibility (use list_user_segments to find it). Defaults to everyone.',\n ),\n author_id: z\n .number()\n .int()\n .optional()\n .describe('Author user ID. Defaults to the authenticated user.'),\n content_tag_ids: z\n .array(z.string())\n .optional()\n .describe('Content tag IDs (use list_content_tags to find them)'),\n locale: z.string().optional(),\n draft: z.boolean().default(true),\n promoted: z.boolean().default(false),\n label_names: z\n .array(z.string())\n .optional()\n .describe('Label names for search ranking (use list_labels to see existing labels)'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { section_id, ...articleData } = params as { section_id: number } & Record<\n string,\n unknown\n >;\n const token = await getToken();\n const { article } = await helpCenterPost<{ article: ZendeskArticle }>(\n subdomain,\n token,\n `/sections/${section_id}/articles`,\n { article: articleData },\n );\n return {\n content: [\n { type: 'text', text: `Article #${article.id} created.\\n\\n${formatArticle(article)}` },\n ],\n };\n },\n },\n {\n name: 'update_article',\n namespace: 'help_center',\n readOnly: false,\n title: 'Update Help Center Article',\n description:\n 'Update article metadata only (draft, promoted, labels, tags, visibility, section, sort position, etc.). Does NOT update content (title, body) — use update_article_translation for that.',\n inputSchema: z.object({\n article_id: z.number().int(),\n draft: z.boolean().optional(),\n promoted: z.boolean().optional(),\n label_names: z.array(z.string()).optional().describe('Label names for search ranking'),\n content_tag_ids: z.array(z.string()).optional().describe('Content tag IDs'),\n user_segment_id: z.number().int().optional().describe('User segment ID for visibility'),\n author_id: z.number().int().optional().describe('Author user ID'),\n permission_group_id: z.number().int().optional().describe('Permission group ID'),\n section_id: z.number().int().optional(),\n position: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe(\n 'Sort position within the section (manual ordering only; 0 = first/top). New articles default to position 0. To move an article to the END of its section, set this to one more than the highest current position: read the highest position P from list_articles with sort_by=\"position\", sort_order=\"desc\", then set position = P + 1.',\n ),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, ...updates } = params as { article_id: number } & Record<\n string,\n unknown\n >;\n const token = await getToken();\n const { article } = await helpCenterPut<{ article: ZendeskArticle }>(\n subdomain,\n token,\n `/articles/${article_id}`,\n { article: updates },\n );\n return {\n content: [\n { type: 'text', text: `Article #${article.id} updated.\\n\\n${formatArticle(article)}` },\n ],\n };\n },\n },\n {\n name: 'list_content_tags',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Content Tags',\n description:\n 'List all Guide content tags. Content tags are visible to end users and help them find related articles.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const response = await zendeskGet<{ records: ZendeskContentTag[]; count: number }>(\n subdomain,\n token,\n '/guide/content_tags',\n );\n return {\n content: [{ type: 'text', text: formatList(response.records ?? [], formatContentTag) }],\n };\n },\n },\n {\n name: 'create_content_tag',\n namespace: 'help_center',\n readOnly: false,\n title: 'Create Content Tag',\n description: 'Create a new content tag for Guide articles.',\n inputSchema: z.object({\n name: z.string().min(1).describe('Content tag name'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { name } = params as { name: string };\n const token = await getToken();\n const { record } = await zendeskPost<{ record: ZendeskContentTag }>(\n subdomain,\n token,\n '/guide/content_tags',\n { record: { name } },\n );\n return {\n content: [{ type: 'text', text: `Content tag created.\\n\\n${formatContentTag(record)}` }],\n };\n },\n },\n {\n name: 'list_labels',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Article Labels',\n description:\n 'List all article labels. Labels improve Help Center search ranking and are not visible to end users.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const response = await helpCenterGet<{ labels: ZendeskLabel[]; count: number }>(\n subdomain,\n token,\n '/articles/labels',\n );\n return {\n content: [{ type: 'text', text: formatList(response.labels ?? [], formatLabel) }],\n };\n },\n },\n {\n name: 'list_user_segments',\n namespace: 'help_center',\n readOnly: true,\n title: 'List User Segments',\n description:\n 'List all user segments. User segments control article visibility (who can view). Use the ID when creating or updating articles.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const response = await helpCenterGet<{\n user_segments: ZendeskUserSegment[];\n count: number;\n }>(subdomain, token, '/user_segments');\n return {\n content: [\n { type: 'text', text: formatList(response.user_segments ?? [], formatUserSegment) },\n ],\n };\n },\n },\n {\n name: 'list_article_attachments',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Article Attachments',\n description: 'List all attachments for an article.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id } = params as { article_id: number };\n const token = await getToken();\n const response = await helpCenterGet<{\n article_attachments: ZendeskArticleAttachment[];\n count: number;\n }>(subdomain, token, `/articles/${article_id}/attachments`);\n return {\n content: [\n {\n type: 'text',\n text: formatList(response.article_attachments ?? [], formatAttachment),\n },\n ],\n };\n },\n },\n {\n name: 'get_article_outline',\n namespace: 'help_center',\n readOnly: true,\n title: 'Get Article Outline',\n description:\n 'Return a compact outline of an article (list of sections delimited by h1/h2/h3, with word counts) for the given locale (defaults to source_locale). Includes available translations with their outdated status. Use get_article_section to fetch a specific section.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n locale: z\n .string()\n .optional()\n .describe('Locale of the body to outline (defaults to article source_locale)'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale } = params as { article_id: number; locale?: string };\n const token = await getToken();\n const { article } = await helpCenterGet<{ article: ZendeskArticle }>(\n subdomain,\n token,\n `/articles/${article_id}`,\n );\n const effectiveLocale = locale ?? article.source_locale;\n const { translation } = await helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${effectiveLocale}`,\n );\n const { translations } = await helpCenterGet<{\n translations: Array<ZendeskTranslation & { outdated?: boolean }>;\n }>(subdomain, token, `/articles/${article_id}/translations`);\n const sections = parseSections(translation.body);\n\n const outlineLines = sections.length\n ? sections\n .map(\n (s) =>\n `- [${s.index}] ${s.headingTag ? `${s.headingTag}: ` : ''}${s.heading} (${s.wordCount} words)`,\n )\n .join('\\n')\n : '_(no sections detected)_';\n const translationsList = translations\n .map((t) => `- ${t.locale}${t.outdated ? ' (outdated)' : ''}`)\n .join('\\n');\n\n const text = [\n `# Outline — Article #${article_id} (${effectiveLocale})`,\n `**Title**: ${translation.title}`,\n '',\n '## Sections',\n outlineLines,\n '',\n '## Available translations',\n translationsList,\n ].join('\\n');\n return { content: [{ type: 'text', text }] };\n },\n },\n {\n name: 'get_article_section',\n namespace: 'help_center',\n readOnly: true,\n title: 'Get Article Section',\n description:\n 'Retrieve the content of a single section of an article in a given locale. Use get_article_outline first to discover section indexes. Default format=\"html\" for round-trip safety. Pass format=\"markdown\" only for human review — the Markdown representation is lossy on some structures (<pre> with <br>, tables with multi-<p> cells are kept as raw HTML to limit the damage, but do not round-trip markdown content back through update_article_section).',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n locale: z.string().describe('Locale of the body (e.g., \"en-us\", \"fr\")'),\n section_index: z\n .number()\n .int()\n .min(0)\n .describe('0-based index of the section (see get_article_outline)'),\n format: z\n .enum(['html', 'markdown'])\n .default('html')\n .describe(\n 'Output format. \"html\" (default) is round-trip safe. \"markdown\" is lossy on some HTML structures — use only for human review, not before update_article_section.',\n ),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale, section_index, format } = params as {\n article_id: number;\n locale: string;\n section_index: number;\n format: 'html' | 'markdown';\n };\n const token = await getToken();\n const { translation } = await helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${locale}`,\n );\n const sections = parseSections(translation.body);\n const section = sections[section_index];\n if (!section) {\n throw new Error(\n `Section index ${section_index} not found. Article has ${sections.length} section(s) (0-${Math.max(0, sections.length - 1)}).`,\n );\n }\n const content = format === 'markdown' ? htmlToMarkdown(section.html) : section.html;\n const headerLine = section.headingTag\n ? `## [${section.index}] ${section.headingTag}: ${section.heading}`\n : `## [${section.index}] ${section.heading}`;\n const text = [\n headerLine,\n `_Locale: ${locale} | Words: ${section.wordCount} | Format: ${format}_`,\n '',\n content,\n ].join('\\n');\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'update_article_section',\n namespace: 'help_center',\n readOnly: false,\n title: 'Update Article Section',\n description:\n 'Replace the content of a single section of an article in a given locale, keeping the rest of the body intact. The server fetches the current body, replaces the targeted section, and PUTs the full reconstructed body via the Translations API. Default format=\"html\" for fidelity. Use format=\"markdown\" only when you control the input and know it does not rely on structures that round-trip poorly (code blocks with line breaks, tables with multi-paragraph cells). The section heading is preserved and is NOT part of the replaced content.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n locale: z.string().describe('Locale of the translation to update'),\n section_index: z\n .number()\n .int()\n .min(0)\n .describe('0-based index of the section to replace (see get_article_outline)'),\n content: z\n .string()\n .describe(\n 'New content for the section (heading excluded). HTML by default, Markdown if format=\"markdown\".',\n ),\n format: z\n .enum(['html', 'markdown'])\n .default('html')\n .describe(\n 'Input format. \"html\" (default) is the safe path. \"markdown\" is converted to HTML server-side but may introduce artifacts on complex content.',\n ),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale, section_index, content, format } = params as {\n article_id: number;\n locale: string;\n section_index: number;\n content: string;\n format: 'html' | 'markdown';\n };\n const token = await getToken();\n const { translation } = await helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${locale}`,\n );\n const newSectionHtml = format === 'markdown' ? markdownToHtml(content) : content;\n const newBody = replaceSectionContent(translation.body, section_index, newSectionHtml);\n const { translation: updated } = await helpCenterPut<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${locale}`,\n { translation: { body: newBody } },\n );\n const updatedSections = parseSections(updated.body);\n const updatedSection = updatedSections[section_index];\n const newWordCount = updatedSection?.wordCount ?? 0;\n const headingLabel = updatedSection?.heading ?? '(intro)';\n const text = [\n `Section [${section_index}] \"${headingLabel}\" updated for article #${article_id} (${locale}).`,\n `New word count: ${newWordCount}.`,\n ].join('\\n');\n return { content: [{ type: 'text', text }] };\n },\n },\n {\n name: 'compare_translations',\n namespace: 'help_center',\n readOnly: true,\n title: 'Compare Article Translations',\n description:\n 'Compare section structure between two locales of the same article, matched by index. Returns a compact table (one row per section) with status: \"ok\" (both present, source/target word count ratio within 25%), \"different\" (word count ratio diverges by more than 25% — size signal only, NOT a semantic divergence: two locales may legitimately differ in verbosity) or \"missing\" (section absent in target). Useful to spot structurally stale or missing sections; do not interpret \"different\" as an edit regression on its own.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n source_locale: z.string().describe('Source (reference) locale'),\n target_locale: z.string().describe('Target locale to compare against source'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, source_locale, target_locale } = params as {\n article_id: number;\n source_locale: string;\n target_locale: string;\n };\n const token = await getToken();\n const [sourceRes, targetRes] = await Promise.all([\n helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${source_locale}`,\n ),\n helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${target_locale}`,\n ),\n ]);\n const sourceSections = parseSections(sourceRes.translation.body);\n const targetSections = parseSections(targetRes.translation.body);\n const maxLen = Math.max(sourceSections.length, targetSections.length);\n\n const rows: string[] = [];\n rows.push(`| Idx | Heading | Status | Source words | Target words |`);\n rows.push(`| --- | --- | --- | --- | --- |`);\n for (let i = 0; i < maxLen; i += 1) {\n const src = sourceSections[i];\n const tgt = targetSections[i];\n const heading = src?.heading ?? tgt?.heading ?? '';\n const sourceWords = src?.wordCount ?? 0;\n const targetWords = tgt?.wordCount ?? 0;\n let status: 'ok' | 'missing' | 'different';\n if (!tgt) status = 'missing';\n else if (!src) status = 'different';\n else {\n const denom = Math.max(sourceWords, 1);\n const diffRatio = Math.abs(sourceWords - targetWords) / denom;\n status = diffRatio > 0.25 ? 'different' : 'ok';\n }\n rows.push(`| ${i} | ${heading} | ${status} | ${sourceWords} | ${targetWords} |`);\n }\n\n const text = [\n `# Translation diff — Article #${article_id} (${source_locale} → ${target_locale})`,\n '',\n ...rows,\n ].join('\\n');\n return { content: [{ type: 'text', text }] };\n },\n },\n {\n name: 'create_article_attachment',\n namespace: 'help_center',\n readOnly: false,\n title: 'Create Article Attachment',\n description:\n 'Upload an attachment to an article. Provide file content as base64-encoded string.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n file_name: z.string().min(1).describe('File name (e.g., \"screenshot.png\")'),\n file_base64: z.string().min(1).describe('File content encoded as base64'),\n content_type: z\n .string()\n .default('application/octet-stream')\n .describe('MIME type (e.g., \"image/png\", \"application/pdf\")'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, file_name, file_base64, content_type } = params as {\n article_id: number;\n file_name: string;\n file_base64: string;\n content_type: string;\n };\n const token = await getToken();\n const buffer = Buffer.from(file_base64, 'base64');\n const blob = new Blob([buffer], { type: content_type });\n const formData = new FormData();\n formData.append('file', blob, file_name);\n const { article_attachment } = await helpCenterUpload<{\n article_attachment: ZendeskArticleAttachment;\n }>(subdomain, token, `/articles/${article_id}/attachments`, formData);\n return {\n content: [\n {\n type: 'text',\n text: `Attachment created for article #${article_id}.\\n\\n${formatAttachment(article_attachment)}`,\n },\n ],\n };\n },\n },\n ];\n};\n","import * as z from 'zod/v4';\nimport { zendeskGet } from '../client/zendesk-api';\nimport { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE } from '../constants';\nimport type { ZendeskListResponse } from '../types';\nimport { truncateIfNeeded } from '../utils/formatting';\nimport { buildOffsetParams, extractSearchPaginationMeta } from '../utils/pagination';\nimport type { ToolContext, ToolDefinition } from './definitions';\n\nconst formatSearchResult = (result: Record<string, unknown>): string => {\n const lines: string[] = [`## [${result['result_type']}] #${result['id']}`];\n if (result['subject']) lines.push(`**Subject**: ${result['subject']}`);\n if (result['name']) lines.push(`**Name**: ${result['name']}`);\n if (result['title']) lines.push(`**Title**: ${result['title']}`);\n if (result['email']) lines.push(`**Email**: ${result['email']}`);\n if (result['status']) lines.push(`**Status**: ${result['status']}`);\n if (result['description']) {\n const desc = String(result['description']);\n lines.push(desc.length > 200 ? `${desc.slice(0, 200)}...` : desc);\n }\n return lines.join('\\n');\n};\n\nexport const createSearchTools = (ctx: ToolContext): ToolDefinition[] => {\n const { subdomain, getToken } = ctx;\n\n return [\n {\n name: 'search',\n namespace: 'tickets',\n readOnly: true,\n title: 'Zendesk Unified Search',\n description:\n 'Search across tickets, users, and organizations. Supports filters like \"type:ticket status:open\", \"type:user role:agent\". Returns total count and paginated results (100 per page). Organization results include name and ID only — use get_organization for full details (tags, domains, details).',\n inputSchema: z.object({\n query: z.string().min(1).describe('Zendesk search query'),\n per_page: z\n .number()\n .int()\n .min(1)\n .max(MAX_PAGE_SIZE)\n .default(DEFAULT_PAGE_SIZE)\n .describe('Results per page (max 100)'),\n page: z.number().int().min(1).default(1).describe('Page number (1-based)'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { query, per_page, page } = params as {\n query: string;\n per_page: number;\n page: number;\n };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<Record<string, unknown>>>(\n subdomain,\n token,\n '/search',\n {\n query,\n ...buildOffsetParams(per_page, page),\n },\n );\n const results = response.results ?? [];\n const meta = extractSearchPaginationMeta(response, per_page, page);\n const header = `Total: ${meta.count} | Page ${page} (${results.length} results)${meta.has_more ? ` | Next page: ${meta.after_cursor}` : ''}`;\n const body = results.map(formatSearchResult).join('\\n\\n');\n return {\n content: [\n { type: 'text', text: truncateIfNeeded([header, body].filter(Boolean).join('\\n\\n')) },\n ],\n };\n },\n },\n ];\n};\n","import * as z from 'zod/v4';\nimport {\n fetchZendeskBinary,\n ZendeskApiError,\n zendeskGet,\n zendeskPost,\n zendeskPut,\n} from '../client/zendesk-api';\nimport {\n DEFAULT_PAGE_SIZE,\n MAX_ATTACHMENT_BYTES,\n MAX_COMMENT_PAGES,\n MAX_EMBEDDED_IMAGE_COUNT,\n MAX_PAGE_SIZE,\n} from '../constants';\nimport type {\n ZendeskComment,\n ZendeskListResponse,\n ZendeskTicket,\n ZendeskTicketAttachment,\n} from '../types';\nimport { formatComment, formatList, formatTicket, truncateIfNeeded } from '../utils/formatting';\nimport {\n buildCursorParams,\n buildOffsetParams,\n extractPaginationMeta,\n extractSearchPaginationMeta,\n} from '../utils/pagination';\nimport type { ToolContext, ToolDefinition, ToolImageContent, ToolTextContent } from './definitions';\n\nconst formatReference = (attachment: ZendeskTicketAttachment): string =>\n `**${attachment.file_name}** (id ${attachment.id}, ${attachment.content_type}, ${attachment.size} bytes) — ${attachment.content_url}`;\n\nconst buildEmbeddedImageBlocks = async (\n subdomain: string,\n token: string,\n attachment: ZendeskTicketAttachment,\n reference: string,\n): Promise<Array<ToolTextContent | ToolImageContent>> => {\n const { data, contentType } = await fetchZendeskBinary(subdomain, token, attachment.content_url);\n return [\n { type: 'image', data: data.toString('base64'), mimeType: contentType },\n { type: 'text', text: reference },\n ];\n};\n\n// Zendesk has no endpoint to list a ticket's attachments directly.\n// Attachments are always attached to comments, so the only way to collect\n// them all is to walk through every comment page and extract their attachments.\nconst fetchAllTicketComments = async (\n subdomain: string,\n token: string,\n ticketId: number,\n): Promise<ZendeskComment[]> => {\n const all: ZendeskComment[] = [];\n let cursor: string | undefined;\n let pages = 0;\n while (pages < MAX_COMMENT_PAGES) {\n const response = await zendeskGet<{\n comments: ZendeskComment[];\n meta?: { has_more: boolean; after_cursor: string };\n }>(subdomain, token, `/tickets/${ticketId}/comments`, buildCursorParams(MAX_PAGE_SIZE, cursor));\n all.push(...response.comments);\n pages += 1;\n if (!response.meta?.has_more || !response.meta?.after_cursor) break;\n cursor = response.meta.after_cursor;\n }\n return all;\n};\n\nconst collectAttachmentBlocks = async (\n subdomain: string,\n token: string,\n attachments: ZendeskTicketAttachment[],\n): Promise<Array<ToolTextContent | ToolImageContent>> => {\n const blocks: Array<ToolTextContent | ToolImageContent> = [];\n let embeddedCount = 0;\n\n for (const attachment of attachments) {\n const reference = formatReference(attachment);\n const isImage = attachment.content_type.startsWith('image/');\n\n if (!isImage) {\n blocks.push({ type: 'text', text: reference });\n continue;\n }\n\n let skipReason: string | null = null;\n if (attachment.size > MAX_ATTACHMENT_BYTES) {\n skipReason = 'skipped: exceeds 5 MB per-image limit';\n } else if (embeddedCount >= MAX_EMBEDDED_IMAGE_COUNT) {\n skipReason = `skipped: max ${MAX_EMBEDDED_IMAGE_COUNT} embedded images reached`;\n }\n\n if (skipReason) {\n blocks.push({ type: 'text', text: `${reference} — ${skipReason}` });\n continue;\n }\n\n try {\n blocks.push(...(await buildEmbeddedImageBlocks(subdomain, token, attachment, reference)));\n embeddedCount += 1;\n } catch (error) {\n const reason =\n error instanceof ZendeskApiError\n ? `download failed: ${error.status} ${error.statusText}`\n : 'download failed';\n blocks.push({ type: 'text', text: `${reference} — ${reason}` });\n }\n }\n\n return blocks;\n};\n\nexport const createTicketTools = (ctx: ToolContext): ToolDefinition[] => {\n const { subdomain, getToken } = ctx;\n\n return [\n {\n name: 'get_ticket',\n namespace: 'tickets',\n readOnly: true,\n title: 'Get Zendesk Ticket',\n description:\n 'Retrieve a Zendesk ticket by ID, including its comments if requested. Returns ticket details (subject, status, priority, assignee, tags, description) and optionally all comments/internal notes.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n include_comments: z.boolean().default(false).describe('Include ticket comments'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, include_comments } = params as {\n ticket_id: number;\n include_comments: boolean;\n };\n const token = await getToken();\n const { ticket } = await zendeskGet<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n `/tickets/${ticket_id}`,\n );\n let text = formatTicket(ticket);\n if (include_comments) {\n const { comments } = await zendeskGet<{ comments: ZendeskComment[] }>(\n subdomain,\n token,\n `/tickets/${ticket_id}/comments`,\n );\n text += `\\n\\n---\\n# Comments\\n\\n${comments.map(formatComment).join('\\n\\n')}`;\n }\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'get_ticket_attachments',\n namespace: 'tickets',\n readOnly: true,\n title: 'Get Zendesk Ticket Attachments',\n description:\n 'Retrieve ticket attachments. Images are embedded inline; other files are listed as text references.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n attachment_ids: z\n .array(z.number().int())\n .optional()\n .describe(\n 'Attachment IDs to fetch directly (e.g. extracted from a previous get_ticket(include_comments=true) call). When provided, skips the comments fetch entirely. When omitted, all attachments of the ticket are returned.',\n ),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, attachment_ids } = params as {\n ticket_id: number;\n attachment_ids?: number[];\n };\n const token = await getToken();\n\n let attachments: ZendeskTicketAttachment[];\n if (attachment_ids && attachment_ids.length > 0) {\n attachments = [];\n for (const id of attachment_ids) {\n try {\n const { attachment } = await zendeskGet<{ attachment: ZendeskTicketAttachment }>(\n subdomain,\n token,\n `/attachments/${id}`,\n );\n attachments.push(attachment);\n } catch (error) {\n if (!(error instanceof ZendeskApiError) || error.status !== 404) throw error;\n }\n }\n } else {\n const comments = await fetchAllTicketComments(subdomain, token, ticket_id);\n attachments = comments.flatMap((c) => c.attachments ?? []);\n }\n\n if (attachments.length === 0) {\n return {\n content: [{ type: 'text', text: `No attachments found on ticket #${ticket_id}.` }],\n };\n }\n const blocks = await collectAttachmentBlocks(subdomain, token, attachments);\n return {\n content: [\n {\n type: 'text',\n text: `# Attachments for ticket #${ticket_id} (${attachments.length} total)`,\n },\n ...blocks,\n ],\n };\n },\n },\n {\n name: 'search_tickets',\n namespace: 'tickets',\n readOnly: true,\n title: 'Search Zendesk Tickets',\n description:\n 'Search tickets using Zendesk query syntax (e.g., \"status:open assignee:me\", \"priority:urgent type:incident\"). Returns total count.',\n inputSchema: z.object({\n query: z.string().min(1).describe('Zendesk search query string'),\n per_page: z\n .number()\n .int()\n .min(1)\n .max(MAX_PAGE_SIZE)\n .default(DEFAULT_PAGE_SIZE)\n .describe('Results per page'),\n page: z.number().int().min(1).default(1).describe('Page number'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { query, per_page, page } = params as {\n query: string;\n per_page: number;\n page: number;\n };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskTicket>>(\n subdomain,\n token,\n '/search',\n {\n query: `type:ticket ${query}`,\n ...buildOffsetParams(per_page, page),\n },\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.results ?? [],\n formatTicket,\n extractSearchPaginationMeta(response, per_page, page),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'create_ticket',\n namespace: 'tickets',\n readOnly: false,\n title: 'Create Zendesk Ticket',\n description:\n 'Create a new Zendesk support ticket with subject, description, and optional priority/type/assignee/tags.',\n inputSchema: z.object({\n subject: z.string().min(1).describe('Ticket subject'),\n description: z.string().min(1).describe('Ticket description'),\n priority: z.enum(['urgent', 'high', 'normal', 'low']).optional(),\n type: z.enum(['problem', 'incident', 'question', 'task']).optional(),\n assignee_id: z.number().int().optional(),\n group_id: z.number().int().optional(),\n tags: z.array(z.string()).optional(),\n custom_fields: z.array(z.object({ id: z.number().int(), value: z.unknown() })).optional(),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { subject, description, ...rest } = params as Record<string, unknown>;\n const token = await getToken();\n const { ticket } = await zendeskPost<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n '/tickets',\n {\n ticket: { subject, comment: { body: description }, ...rest },\n },\n );\n return {\n content: [\n { type: 'text', text: `Ticket #${ticket.id} created.\\n\\n${formatTicket(ticket)}` },\n ],\n };\n },\n },\n {\n name: 'update_ticket',\n namespace: 'tickets',\n readOnly: false,\n title: 'Update Zendesk Ticket',\n description:\n 'Update an existing ticket (status, priority, type, assignee, group, subject, tags, custom fields).',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n status: z.enum(['new', 'open', 'pending', 'hold', 'solved', 'closed']).optional(),\n priority: z.enum(['urgent', 'high', 'normal', 'low']).optional(),\n type: z.enum(['problem', 'incident', 'question', 'task']).optional(),\n assignee_id: z.number().int().optional(),\n group_id: z.number().int().optional(),\n subject: z.string().optional(),\n tags: z.array(z.string()).optional(),\n custom_fields: z.array(z.object({ id: z.number().int(), value: z.unknown() })).optional(),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, ...updates } = params as { ticket_id: number } & Record<string, unknown>;\n const token = await getToken();\n const { ticket } = await zendeskPut<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n `/tickets/${ticket_id}`,\n { ticket: updates },\n );\n return {\n content: [\n { type: 'text', text: `Ticket #${ticket.id} updated.\\n\\n${formatTicket(ticket)}` },\n ],\n };\n },\n },\n {\n name: 'add_private_note',\n namespace: 'tickets',\n readOnly: false,\n title: 'Add Private Note',\n description: 'Add an internal note (not visible to requester) to a ticket.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n body: z.string().min(1).describe('Note content'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, body } = params as { ticket_id: number; body: string };\n const token = await getToken();\n await zendeskPut(subdomain, token, `/tickets/${ticket_id}`, {\n ticket: { comment: { body, public: false } },\n });\n return { content: [{ type: 'text', text: `Private note added to ticket #${ticket_id}.` }] };\n },\n },\n {\n name: 'add_public_comment',\n namespace: 'tickets',\n readOnly: false,\n title: 'Add Public Comment',\n description: 'Add a public comment (visible to requester) to a ticket.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n body: z.string().min(1).describe('Comment content'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, body } = params as { ticket_id: number; body: string };\n const token = await getToken();\n await zendeskPut(subdomain, token, `/tickets/${ticket_id}`, {\n ticket: { comment: { body, public: true } },\n });\n return {\n content: [{ type: 'text', text: `Public comment added to ticket #${ticket_id}.` }],\n };\n },\n },\n {\n name: 'list_tickets',\n namespace: 'tickets',\n readOnly: true,\n title: 'List Zendesk Tickets',\n description: 'List tickets with cursor-based pagination, sorted by most recently updated.',\n inputSchema: z.object({\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional().describe('Pagination cursor'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { page_size, cursor } = params as { page_size: number; cursor?: string };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskTicket>>(\n subdomain,\n token,\n '/tickets',\n buildCursorParams(page_size, cursor),\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.tickets ?? [],\n formatTicket,\n extractPaginationMeta(response),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'get_linked_incidents',\n namespace: 'tickets',\n readOnly: true,\n title: 'Get Linked Incidents',\n description: 'Get all incident tickets linked to a problem ticket.',\n inputSchema: z.object({\n problem_id: z.number().int().describe('Problem ticket ID'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { problem_id } = params as { problem_id: number };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskTicket>>(\n subdomain,\n token,\n `/tickets/${problem_id}/incidents`,\n );\n const incidents = response.tickets ?? [];\n const text =\n incidents.length > 0\n ? `# Incidents linked to problem #${problem_id}\\n\\n${incidents.map(formatTicket).join('\\n\\n')}`\n : `No incidents linked to problem #${problem_id}.`;\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'manage_tags',\n namespace: 'tickets',\n readOnly: false,\n title: 'Manage Ticket Tags',\n description: 'Add or remove tags on a ticket.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n add: z.array(z.string()).optional().describe('Tags to add'),\n remove: z.array(z.string()).optional().describe('Tags to remove'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, add, remove } = params as {\n ticket_id: number;\n add?: string[];\n remove?: string[];\n };\n const token = await getToken();\n const { ticket } = await zendeskGet<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n `/tickets/${ticket_id}`,\n );\n const tags = new Set(ticket.tags);\n add?.forEach((t) => {\n tags.add(t);\n });\n remove?.forEach((t) => {\n tags.delete(t);\n });\n const { ticket: updated } = await zendeskPut<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n `/tickets/${ticket_id}`,\n { ticket: { tags: [...tags] } },\n );\n return {\n content: [\n {\n type: 'text',\n text: `Tags updated on ticket #${ticket_id}. Current: ${updated.tags.join(', ') || 'none'}`,\n },\n ],\n };\n },\n },\n ];\n};\n","import * as z from 'zod/v4';\nimport { zendeskGet } from '../client/zendesk-api';\nimport { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE } from '../constants';\nimport type { ZendeskListResponse, ZendeskOrganization, ZendeskUser } from '../types';\nimport { formatList, formatOrganization, formatUser } from '../utils/formatting';\nimport {\n buildCursorParams,\n buildOffsetParams,\n extractPaginationMeta,\n extractSearchPaginationMeta,\n} from '../utils/pagination';\nimport type { ToolContext, ToolDefinition } from './definitions';\n\nexport const createUserTools = (ctx: ToolContext): ToolDefinition[] => {\n const { subdomain, getToken } = ctx;\n\n return [\n {\n name: 'get_current_user',\n namespace: 'users',\n readOnly: true,\n title: 'Get Current Zendesk User',\n description:\n 'Get the currently authenticated Zendesk user. Useful to verify identity and permissions.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const { user } = await zendeskGet<{ user: ZendeskUser }>(subdomain, token, '/users/me');\n return { content: [{ type: 'text', text: formatUser(user) }] };\n },\n },\n {\n name: 'search_users',\n namespace: 'users',\n readOnly: true,\n title: 'Search Zendesk Users',\n description:\n 'Search for users by name, email, or other criteria using Zendesk search query syntax. Returns total count.',\n inputSchema: z.object({\n query: z.string().min(1).describe('Search query'),\n per_page: z\n .number()\n .int()\n .min(1)\n .max(MAX_PAGE_SIZE)\n .default(DEFAULT_PAGE_SIZE)\n .describe('Results per page'),\n page: z.number().int().min(1).default(1).describe('Page number'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { query, per_page, page } = params as {\n query: string;\n per_page: number;\n page: number;\n };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskUser>>(\n subdomain,\n token,\n '/search',\n {\n query: `type:user ${query}`,\n ...buildOffsetParams(per_page, page),\n },\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.results ?? [],\n formatUser,\n extractSearchPaginationMeta(response, per_page, page),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'get_user',\n namespace: 'users',\n readOnly: true,\n title: 'Get Zendesk User',\n description: 'Retrieve a user by ID.',\n inputSchema: z.object({ user_id: z.number().int().describe('User ID') }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { user_id } = params as { user_id: number };\n const token = await getToken();\n const { user } = await zendeskGet<{ user: ZendeskUser }>(\n subdomain,\n token,\n `/users/${user_id}`,\n );\n return { content: [{ type: 'text', text: formatUser(user) }] };\n },\n },\n {\n name: 'get_organization',\n namespace: 'users',\n readOnly: true,\n title: 'Get Zendesk Organization',\n description: 'Retrieve an organization by ID.',\n inputSchema: z.object({ organization_id: z.number().int().describe('Organization ID') }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { organization_id } = params as { organization_id: number };\n const token = await getToken();\n const { organization } = await zendeskGet<{ organization: ZendeskOrganization }>(\n subdomain,\n token,\n `/organizations/${organization_id}`,\n );\n return { content: [{ type: 'text', text: formatOrganization(organization) }] };\n },\n },\n {\n name: 'list_organizations',\n namespace: 'users',\n readOnly: true,\n title: 'List Zendesk Organizations',\n description: 'List all organizations with pagination.',\n inputSchema: z.object({\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional(),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { page_size, cursor } = params as { page_size: number; cursor?: string };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskOrganization>>(\n subdomain,\n token,\n '/organizations',\n buildCursorParams(page_size, cursor),\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.organizations ?? [],\n formatOrganization,\n extractPaginationMeta(response),\n ),\n },\n ],\n };\n },\n },\n ];\n};\n","import type { ToolContext, ToolDefinition } from './definitions';\nimport { createHelpCenterTools } from './help-center';\nimport { createSearchTools } from './search';\nimport { createTicketTools } from './tickets';\nimport { createUserTools } from './users';\n\nexport type { ToolContext, ToolDefinition } from './definitions';\n\nexport const createAllTools = (ctx: ToolContext): ToolDefinition[] => [\n ...createTicketTools(ctx),\n ...createSearchTools(ctx),\n ...createHelpCenterTools(ctx),\n ...createUserTools(ctx),\n];\n","import { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nexport interface PackageInfo {\n name: string;\n version: string;\n}\n\n// Used only if package.json can't be located/parsed (should not happen in a\n// published install). Keeps the server bootable rather than throwing.\nconst FALLBACK: PackageInfo = {\n name: '@fruggr/zendesk-mcp-server',\n version: '0.0.0',\n};\n\n/**\n * Read `name`/`version` from the package's own package.json at runtime instead\n * of hardcoding them. Walks up from this module to the nearest package.json,\n * which resolves correctly both when bundled (`dist/index.js` → repo root) and\n * from source/tests (`src/` has no package.json, so the root is found). Reading\n * at runtime (not inlining at build) matters because semantic-release bumps the\n * version into package.json before publishing, after the build step.\n */\n// package.json can't change during the process lifetime, and createMcpServer\n// (hence this) may run several times (notably across tests) — cache the result.\nlet cached: PackageInfo | undefined;\n\nexport const readPackageInfo = (): PackageInfo => {\n if (cached) return cached;\n // Only readFileSync/JSON.parse can throw here (caught per-iteration below);\n // fileURLToPath/dirname/join don't, so no outer guard is needed.\n let dir = dirname(fileURLToPath(import.meta.url));\n for (let depth = 0; depth < 8; depth++) {\n try {\n // JSON.parse yields `unknown`; validate at runtime rather than asserting.\n const raw: unknown = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));\n if (raw && typeof raw === 'object') {\n const pkg = raw as Partial<PackageInfo>;\n if (typeof pkg.name === 'string' && typeof pkg.version === 'string') {\n cached = { name: pkg.name, version: pkg.version };\n return cached;\n }\n }\n } catch {\n // No readable/valid package.json here — keep walking up.\n }\n const parent = dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n cached = FALLBACK;\n return cached;\n};\n","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport * as z from 'zod/v4';\nimport type { Config } from './config';\nimport { filterTools, groupByNamespace } from './routing/registry';\nimport { createAllTools, type ToolDefinition } from './tools/index';\nimport { type Logger, silentLogger } from './utils/logger';\nimport { readPackageInfo } from './utils/package-info';\n\nconst NAMESPACE_LABELS: Record<string, { toolName: string; title: string }> = {\n tickets: { toolName: 'zendesk_tickets', title: 'Zendesk Tickets' },\n help_center: { toolName: 'zendesk_help_center', title: 'Zendesk Help Center' },\n users: { toolName: 'zendesk_users', title: 'Zendesk Users' },\n};\n\n// Keep proxy descriptions compact: a proxy tool concatenates one line per\n// sub-operation, so only the first sentence of each tool description is\n// included. Clients still receive the full schema via the wrapped tool.\nexport const summarizeDescription = (description: string): string => {\n const idx = description.indexOf('. ');\n if (idx === -1) return description;\n return description.slice(0, idx + 1);\n};\n\nexport const buildOperationList = (\n tools: ReadonlyArray<Pick<ToolDefinition, 'name' | 'description' | 'readOnly'>>,\n): string =>\n tools\n .map(\n (t) =>\n `- **${t.name}**: ${summarizeDescription(t.description)}${t.readOnly ? '' : ' (write)'}`,\n )\n .join('\\n');\n\nconst registerProxyTool = (\n server: McpServer,\n toolName: string,\n title: string,\n tools: ToolDefinition[],\n handlerMap: Map<string, ToolDefinition>,\n): void => {\n const operationNames = tools.map((t) => t.name);\n const operationList = buildOperationList(tools);\n\n server.registerTool(\n toolName,\n {\n title,\n description: `${title}. Specify the operation and its parameters.\\n\\nAvailable operations:\\n${operationList}`,\n inputSchema: z.object({\n operation: z.string().describe(`One of: ${operationNames.join(', ')}`),\n params: z.record(z.string(), z.unknown()).default({}).describe('Operation parameters'),\n }),\n },\n async ({ operation, params }) => {\n const def = handlerMap.get(operation);\n if (!def) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `Unknown operation \"${operation}\". Available: ${operationNames.join(', ')}`,\n },\n ],\n };\n }\n // Validate params through the tool's own schema\n const validated = def.inputSchema.parse(params);\n return def.handler(validated);\n },\n );\n};\n\nexport const createMcpServer = (\n config: Config,\n getToken: () => string | Promise<string>,\n logger: Logger = silentLogger,\n): McpServer => {\n // Read name/version from package.json at runtime rather than hardcoding them\n // (the old literals were stale and even carried the wrong package name).\n const pkg = readPackageInfo();\n const server = new McpServer(\n {\n name: pkg.name,\n version: pkg.version,\n },\n // Advertise the logging capability so structured diagnostics (notably the\n // OAuth browser flow) reach clients that support it. Clients that don't\n // simply ignore the notifications.\n { capabilities: { logging: {} } },\n );\n\n // Route the logger's MCP sink through this server. Auth runs lazily on the\n // first tool call (after connect), so notifications can flow by then.\n logger.attachServer(server);\n\n const allTools = createAllTools({ subdomain: config.subdomain, getToken });\n\n // Apply filters (--read-only, --namespace, --tool)\n const filteredTools = filterTools(allTools, {\n readOnly: config.readOnly,\n namespaces: config.namespaces,\n tools: config.tools,\n });\n\n // Build handler map for proxy dispatch\n const handlerMap = new Map<string, ToolDefinition>();\n for (const tool of filteredTools) {\n handlerMap.set(tool.name, tool);\n }\n\n switch (config.mode) {\n case 'all': {\n // Register each tool individually\n for (const tool of filteredTools) {\n server.registerTool(\n tool.name,\n {\n title: tool.title,\n description: tool.description,\n inputSchema: tool.inputSchema,\n annotations: tool.annotations,\n },\n async (params) => tool.handler(params as Record<string, unknown>),\n );\n }\n break;\n }\n case 'namespace': {\n const grouped = groupByNamespace(filteredTools);\n for (const [namespace, tools] of grouped) {\n const label = NAMESPACE_LABELS[namespace];\n if (label) {\n registerProxyTool(server, label.toolName, label.title, tools, handlerMap);\n }\n }\n break;\n }\n case 'single': {\n registerProxyTool(server, 'zendesk', 'Zendesk', filteredTools, handlerMap);\n break;\n }\n }\n\n logger.info('tools_registered', { count: filteredTools.length, mode: config.mode });\n return server;\n};\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport { type Logger, silentLogger } from '../utils/logger';\n\nexport const startStdioTransport = async (\n server: McpServer,\n logger: Logger = silentLogger,\n): Promise<void> => {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n logger.info('stdio_transport_ready');\n};\n","import { buildBasicAuthHeader } from './auth/api-token';\nimport { createTokenStore } from './auth/token-store';\nimport { loadConfig } from './config';\nimport { createMcpServer } from './server';\nimport { startStdioTransport } from './transports/stdio';\nimport { createLogger } from './utils/logger';\n\nconst main = async (): Promise<void> => {\n const config = loadConfig();\n const logger = createLogger(config.logLevel);\n\n if (config.zendeskEmail && config.zendeskApiToken) {\n // API token mode — static Basic auth\n const staticToken = buildBasicAuthHeader(config.zendeskEmail, config.zendeskApiToken);\n const getToken = () => staticToken;\n const server = createMcpServer(config, getToken, logger);\n await startStdioTransport(server, logger);\n } else {\n // OAuth mode — browser-based auth on first tool call\n const tokenStore = createTokenStore(\n {\n subdomain: config.subdomain,\n oauthClientId: config.oauthClientId,\n },\n logger,\n );\n const server = createMcpServer(config, tokenStore.getToken, logger);\n await startStdioTransport(server, logger);\n }\n};\n\nmain().catch((error) => {\n console.error('Fatal error:', error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAa,wBAAwB,OAAe,aAA6B;CAC/E,MAAM,cAAc,GAAG,MAAM,SAAS;CACtC,OAAO,SAAS,O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K;IAClB,aAAa,KAAK;GACpB,GACA,OAAO,WAAW,KAAK,QAAQ,MAAiC,CAClE;GAEF;EAEF,KAAK,aAAa;GAChB,MAAM,UAAU,iBAAiB,aAAa;GAC9C,KAAK,MAAM,CAAC,WAAW,UAAU,SAAS;IACxC,MAAM,QAAQ,iBAAiB;IAC/B,IAAI,OACF,kBAAkB,QAAQ,MAAM,UAAU,MAAM,OAAO,OAAO,UAAU;GAE5E;GACA;EACF;EACA,KAAK;GACH,kBAAkB,QAAQ,WAAW,WAAW,eAAe,UAAU;GACzE;CAEJ;CAEA,OAAO,KAAK,oBAAoB;EAAE,OAAO,cAAc;EAAQ,MAAM,OAAO;CAAK,CAAC;CAClF,OAAO;AACT;;;AC7IA,MAAa,sBAAsB,OACjC,QACA,SAAiB,iBACC;CAClB,MAAM,YAAY,IAAI,qBAAqB;CAC3C,MAAM,OAAO,QAAQ,SAAS;CAC9B,OAAO,KAAK,uBAAuB;AACrC;;;ACJA,MAAM,OAAO,YAA2B;CACtC,MAAM,SAAS,WAAW;CAC1B,MAAM,SAAS,aAAa,OAAO,QAAQ;CAE3C,IAAI,OAAO,gBAAgB,OAAO,iBAAiB;EAEjD,MAAM,cAAc,qBAAqB,OAAO,cAAc,OAAO,eAAe;EACpF,MAAM,iBAAiB;EAEvB,MAAM,oBADS,gBAAgB,QAAQ,UAAU,MAClB,GAAG,MAAM;CAC1C,OAUE,MAAM,oBADS,gBAAgB,QAPZ,iBACjB;EACE,WAAW,OAAO;EAClB,eAAe,OAAO;CACxB,GACA,MAE8C,EAAE,UAAU,MAC7B,GAAG,MAAM;AAE5C;AAEA,KAAK,EAAE,OAAO,UAAU;CACtB,QAAQ,MAAM,gBAAgB,KAAK;CACnC,QAAQ,KAAK,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/auth/api-token.ts","../src/utils/logger.ts","../src/constants.ts","../src/auth/browser-oauth.ts","../src/auth/token-store.ts","../src/config.ts","../src/routing/registry.ts","../src/client/zendesk-api.ts","../src/utils/article-sections.ts","../src/utils/formatting.ts","../src/utils/pagination.ts","../src/tools/help-center.ts","../src/tools/search.ts","../src/tools/tickets.ts","../src/tools/users.ts","../src/tools/index.ts","../src/utils/package-info.ts","../src/server.ts","../src/transports/stdio.ts","../src/index.ts"],"sourcesContent":["/**\n * API token authentication for stdio transport.\n * Uses Basic auth: base64(email/token:api_token)\n */\nexport const buildBasicAuthHeader = (email: string, apiToken: string): string => {\n const credentials = `${email}/token:${apiToken}`;\n return `Basic ${Buffer.from(credentials).toString('base64')}`;\n};\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { LogLevel } from '../config';\n\ntype Fields = Record<string, unknown>;\n\n/**\n * Minimal structured logger with two sinks:\n * - stderr (always, gated by the configured level) — the universal floor that\n * every mainstream MCP client captures to a log file;\n * - MCP `notifications/message` (when a server is attached and advertises the\n * `logging` capability) — surfaced by clients that support it, ignored\n * gracefully by those that don't.\n *\n * Both sinks share a single level gate (`LOG_LEVEL`); MCP clients may further\n * raise the floor via `logging/setLevel`, which the SDK filters on its own.\n */\nexport interface Logger {\n debug(event: string, fields?: Fields): void;\n info(event: string, fields?: Fields): void;\n warn(event: string, fields?: Fields): void;\n error(event: string, fields?: Fields): void;\n /** Attach an McpServer so logs are also emitted as MCP notifications. */\n attachServer(server: Pick<McpServer, 'sendLoggingMessage'>): void;\n}\n\nconst SEVERITY: Record<LogLevel, number> = { debug: 0, info: 1, warn: 2, error: 3 };\n\n// Our 4 levels mapped onto the MCP logging levels (note: `warning`, not `warn`).\nconst MCP_LEVEL: Record<LogLevel, 'debug' | 'info' | 'warning' | 'error'> = {\n debug: 'debug',\n info: 'info',\n warn: 'warning',\n error: 'error',\n};\n\n// Field keys whose values must never reach a sink, matched after normalising\n// (lowercase, separators stripped) so `access_token`, `accessToken` and\n// `ACCESS-TOKEN` all collapse to the same key. Diagnostic fields such as\n// `errorCode`, `status` or `error` (a message) are intentionally NOT listed.\nconst REDACTED_KEYS = new Set([\n 'token',\n 'accesstoken',\n 'refreshtoken',\n 'code',\n 'codeverifier',\n 'authorization',\n 'password',\n 'secret',\n 'apitoken',\n 'bearer',\n]);\n\nconst isSensitive = (key: string): boolean =>\n REDACTED_KEYS.has(key.toLowerCase().replace(/[_-]/g, ''));\n\n// Recursively redact: a sensitive *key* anywhere in the tree (top-level or\n// nested in objects/arrays) has its value replaced, so `{ oauth: { token } }`\n// can't leak. Primitives are returned as-is.\nconst redactValue = (value: unknown): unknown => {\n if (Array.isArray(value)) return value.map(redactValue);\n if (value && typeof value === 'object') {\n const out: Record<string, unknown> = {};\n for (const [key, val] of Object.entries(value as Record<string, unknown>)) {\n out[key] = isSensitive(key) ? '[REDACTED]' : redactValue(val);\n }\n return out;\n }\n return value;\n};\n\nconst renderValue = (value: unknown): string => {\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean' || value === null) {\n return String(value);\n }\n try {\n return JSON.stringify(value);\n } catch {\n return '[unserializable]';\n }\n};\n\nconst formatLine = (level: LogLevel, event: string, fields: Fields): string => {\n const parts = Object.entries(fields).map(([key, value]) => `${key}=${renderValue(value)}`);\n return `[zendesk-mcp] [${level}] ${event}${parts.length ? ` ${parts.join(' ')}` : ''}`;\n};\n\nconst noop = (): void => {};\n\nexport const silentLogger: Logger = {\n debug: noop,\n info: noop,\n warn: noop,\n error: noop,\n attachServer: noop,\n};\n\nexport const createLogger = (level: LogLevel): Logger => {\n const min = SEVERITY[level];\n let server: Pick<McpServer, 'sendLoggingMessage'> | undefined;\n\n const emit = (lvl: LogLevel, event: string, fields?: Fields): void => {\n if (SEVERITY[lvl] < min) return;\n\n const safe = fields ? (redactValue(fields) as Fields) : {};\n console.error(formatLine(lvl, event, safe));\n\n if (server) {\n try {\n void server\n .sendLoggingMessage({\n level: MCP_LEVEL[lvl],\n logger: 'zendesk-mcp-server',\n // `event` last so a caller-supplied `fields.event` can't shadow the\n // canonical event name.\n data: { ...safe, event },\n })\n .catch(noop);\n } catch {\n // Forwarding is best-effort (e.g. transport not connected yet);\n // it must never break the flow that emitted the log.\n }\n }\n };\n\n return {\n debug: (event, fields) => emit('debug', event, fields),\n info: (event, fields) => emit('info', event, fields),\n warn: (event, fields) => emit('warn', event, fields),\n error: (event, fields) => emit('error', event, fields),\n attachServer: (s) => {\n server = s;\n },\n };\n};\n","export const CHARACTER_LIMIT = 25_000;\nexport const DEFAULT_PAGE_SIZE = 100;\nexport const MAX_PAGE_SIZE = 100;\nexport const TOKEN_CACHE_TTL_MS = 5 * 60 * 1000;\n\n// Per-attachment cap for inline image content. Images larger than this are\n// returned as text references instead of base64 image content blocks.\n// Aligned with the Anthropic vision API per-image limit.\nexport const MAX_ATTACHMENT_BYTES = 5 * 1024 * 1024;\n\n// Maximum number of images embedded as base64 in a single tool call.\n// Remaining images are returned as text references.\nexport const MAX_EMBEDDED_IMAGE_COUNT = 10;\n\n// Hard cap on comment pages fetched when collecting ticket attachments.\n// Overridable via ZENDESK_MAX_COMMENT_PAGES for tickets with many comments.\nexport const MAX_COMMENT_PAGES = Number(process.env['ZENDESK_MAX_COMMENT_PAGES'] ?? 10);\n\n// Thresholds used to nudge callers toward section-scoped article tools\n// (get_article_outline / get_article_section / update_article_section)\n// instead of fetching/rewriting the full body.\nexport const LARGE_ARTICLE_BODY_CHARS = 3_000;\nexport const LARGE_ARTICLE_SECTION_COUNT = 4;\n\nexport const getBaseUrl = (subdomain: string): string => `https://${subdomain}.zendesk.com/api/v2`;\n\nexport const getHelpCenterBaseUrl = (subdomain: string): string =>\n `https://${subdomain}.zendesk.com/api/v2/help_center`;\n\nexport const getOAuthUrls = (subdomain: string) => ({\n authorizeUrl: `https://${subdomain}.zendesk.com/oauth/authorizations/new`,\n tokenUrl: `https://${subdomain}.zendesk.com/oauth/tokens`,\n});\n","import { createHash, randomBytes } from 'node:crypto';\nimport { readFileSync } from 'node:fs';\nimport { createServer, type Server } from 'node:http';\nimport { release } from 'node:os';\nimport open from 'open';\nimport { getOAuthUrls } from '../constants';\nimport { type Logger, silentLogger } from '../utils/logger';\n\nconst DEFAULT_CALLBACK_PORT = 3000;\nconst AUTH_TIMEOUT_MS = 5 * 60 * 1000;\n\n/** Best-effort WSL detection: WSL kernels carry \"microsoft\" in /proc/version. */\nconst detectWsl = (): boolean => {\n if (process.platform !== 'linux') return false;\n try {\n return readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft');\n } catch {\n return false;\n }\n};\n\ninterface BrowserOAuthConfig {\n subdomain: string;\n oauthClientId: string;\n callbackPort?: number | undefined;\n}\n\ninterface TokenResult {\n access_token: string;\n refresh_token?: string;\n token_type: string;\n scope: string;\n}\n\n/**\n * Escape a string for safe interpolation into HTML text/attribute context.\n * The local callback server echoes attacker-controllable values (the OAuth\n * `error_description` query param, token-exchange error bodies) back into the\n * browser response; without escaping these are a reflected-XSS sink.\n */\nconst escapeHtml = (value: string): string =>\n value\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&#39;');\n\n/**\n * A started OAuth flow: the local callback server is already listening and the\n * browser-open attempt has been made. `authorizeUrl` is available immediately\n * (so callers can surface it to the user without blocking), while `tokenPromise`\n * resolves later, when the user completes the browser flow — or rejects on\n * error/timeout.\n */\nexport interface StartedBrowserAuth {\n authorizeUrl: string;\n tokenPromise: Promise<TokenResult>;\n}\n\nconst generateCodeVerifier = (): string => randomBytes(32).toString('base64url');\n\nconst generateCodeChallenge = (verifier: string): string =>\n createHash('sha256').update(verifier).digest('base64url');\n\n/**\n * Begin the OAuth 2.1 PKCE flow: start the local callback server, attempt to\n * open the browser, and return as soon as the server is listening with the\n * authorize URL plus a promise that settles when the callback arrives.\n *\n * Splitting \"start\" from \"await the token\" lets callers stay non-blocking: they\n * can hand the URL back to the user immediately instead of holding a request\n * open for up to the 5-minute timeout.\n */\nexport const startBrowserAuth = (\n config: BrowserOAuthConfig,\n logger: Logger = silentLogger,\n): Promise<StartedBrowserAuth> => {\n const { subdomain, oauthClientId } = config;\n const { authorizeUrl: authorizeBase, tokenUrl } = getOAuthUrls(subdomain);\n const codeVerifier = generateCodeVerifier();\n const codeChallenge = generateCodeChallenge(codeVerifier);\n\n return new Promise<StartedBrowserAuth>((resolveStarted, rejectStarted) => {\n let resolveToken!: (token: TokenResult) => void;\n let rejectToken!: (err: unknown) => void;\n const tokenPromise = new Promise<TokenResult>((resolve, reject) => {\n resolveToken = resolve;\n rejectToken = reject;\n });\n\n let authTimeout: ReturnType<typeof setTimeout> | undefined;\n let callbackServer: Server;\n\n callbackServer = createServer(async (req, res) => {\n const url = new URL(req.url ?? '/', `http://localhost`);\n\n if (url.pathname !== '/callback') {\n res.writeHead(404);\n res.end('Not found');\n return;\n }\n\n const code = url.searchParams.get('code');\n const error = url.searchParams.get('error');\n\n logger.debug('oauth_callback_received', {\n hasCode: Boolean(code),\n hasError: Boolean(error),\n });\n\n if (error) {\n const desc = url.searchParams.get('error_description') ?? error;\n res.writeHead(400, { 'Content-Type': 'text/html' });\n res.end(\n `<html><body><h1>Authentication failed</h1><p>${escapeHtml(desc)}</p></body></html>`,\n );\n clearTimeout(authTimeout);\n callbackServer.close();\n rejectToken(new Error(`OAuth error: ${desc}`));\n return;\n }\n\n if (!code) {\n res.writeHead(400, { 'Content-Type': 'text/html' });\n res.end('<html><body><h1>Missing authorization code</h1></body></html>');\n clearTimeout(authTimeout);\n callbackServer.close();\n rejectToken(new Error('Missing authorization code in callback'));\n return;\n }\n\n // Exchange code for token\n try {\n const callbackPort = (callbackServer.address() as { port: number }).port;\n const tokenBody = new URLSearchParams({\n grant_type: 'authorization_code',\n code,\n client_id: oauthClientId,\n redirect_uri: `http://localhost:${callbackPort}/callback`,\n code_verifier: codeVerifier,\n });\n\n const tokenResponse = await fetch(tokenUrl, {\n method: 'POST',\n headers: { 'Content-Type': 'application/x-www-form-urlencoded' },\n body: tokenBody.toString(),\n });\n\n logger.debug('oauth_token_exchange', { status: tokenResponse.status });\n\n if (!tokenResponse.ok) {\n const errorBody = await tokenResponse.text();\n throw new Error(`Token exchange failed (${tokenResponse.status}): ${errorBody}`);\n }\n\n const tokenData = (await tokenResponse.json()) as TokenResult;\n logger.info('oauth_authenticated');\n\n res.writeHead(200, { 'Content-Type': 'text/html' });\n res.end(\n '<html><body><h1>Authentication successful!</h1>' +\n '<p>You can close this tab and return to Claude Code.</p>' +\n '<script>window.close()</script></body></html>',\n );\n\n clearTimeout(authTimeout);\n callbackServer.close();\n resolveToken(tokenData);\n } catch (err) {\n res.writeHead(500, { 'Content-Type': 'text/html' });\n res.end(\n `<html><body><h1>Token exchange failed</h1><p>${escapeHtml(err instanceof Error ? err.message : String(err))}</p></body></html>`,\n );\n clearTimeout(authTimeout);\n callbackServer.close();\n rejectToken(err);\n }\n });\n\n // Listen failure (e.g. port already in use) before we ever get a URL: the\n // whole start fails so the caller can surface/retry.\n const onStartError = (err: Error) => {\n clearTimeout(authTimeout);\n rejectStarted(err);\n };\n callbackServer.once('error', onStartError);\n\n // Start on fixed port (must match redirect_uri registered in Zendesk OAuth client)\n callbackServer.listen(config.callbackPort ?? DEFAULT_CALLBACK_PORT, () => {\n // Now that we're listening, a later server error must settle the *token*\n // flow (the started promise is already resolved) and tear the server down,\n // so the token store doesn't wedge waiting on a promise that never settles.\n callbackServer.off('error', onStartError);\n callbackServer.once('error', (err) => {\n clearTimeout(authTimeout);\n callbackServer.close();\n rejectToken(err);\n });\n\n const port = (callbackServer.address() as { port: number }).port;\n const redirectUri = `http://localhost:${port}/callback`;\n\n const params = new URLSearchParams({\n response_type: 'code',\n client_id: oauthClientId,\n redirect_uri: redirectUri,\n scope: 'read write',\n code_challenge: codeChallenge,\n code_challenge_method: 'S256',\n });\n\n const authUrl = `${authorizeBase}?${params.toString()}`;\n logger.debug('oauth_callback_listening', { port, redirectUri });\n logger.info('oauth_browser_opening');\n // Full authorize URL is debug-only: it carries the (public) client_id and\n // PKCE challenge — no secret — but stays out of default-level logs.\n logger.debug('oauth_authorize_url', { url: authUrl });\n // Always-on, ungated user-facing fallback: if the browser can't open, the\n // user must see this URL regardless of LOG_LEVEL — do NOT route it through\n // the (level-gated) logger.\n console.error(`Opening browser for Zendesk authentication...`);\n console.error(`If the browser doesn't open, visit: ${authUrl}`);\n\n open(authUrl)\n .then(() => {\n logger.debug('oauth_browser_opened');\n })\n .catch((err: unknown) => {\n // Do NOT swallow: this is the #60 signal. Capture why `open` failed\n // plus environment markers (presence only, never values).\n logger.error('oauth_browser_open_failed', {\n error: err instanceof Error ? err.message : String(err),\n errorCode: (err as NodeJS.ErrnoException | undefined)?.code,\n platform: process.platform,\n release: release(),\n isWsl: detectWsl(),\n hasSystemRoot: Boolean(process.env['SYSTEMROOT']),\n hasWindir: Boolean(process.env['WINDIR']),\n hasComSpec: Boolean(process.env['ComSpec']),\n hasPath: Boolean(process.env['PATH']),\n hasDisplay: Boolean(process.env['DISPLAY']),\n });\n });\n\n // Timeout after 5 minutes. Cleared on every completion path above so a\n // successful auth can't emit a spurious `oauth_timeout` error later.\n authTimeout = setTimeout(() => {\n logger.error('oauth_timeout', { timeoutMs: AUTH_TIMEOUT_MS });\n callbackServer.close();\n rejectToken(new Error('OAuth authentication timed out (5 min). Please try again.'));\n }, AUTH_TIMEOUT_MS);\n authTimeout.unref();\n\n resolveStarted({ authorizeUrl: authUrl, tokenPromise });\n });\n });\n};\n\n/**\n * Convenience wrapper that performs the full PKCE flow and resolves with the\n * token once the browser flow completes (blocking until then). Retained for\n * callers/tests that want the original \"await the token\" semantics.\n */\nexport const authenticateViaBrowser = async (\n config: BrowserOAuthConfig,\n logger: Logger = silentLogger,\n): Promise<TokenResult> => {\n const { tokenPromise } = await startBrowserAuth(config, logger);\n return tokenPromise;\n};\n","import { type Logger, silentLogger } from '../utils/logger';\nimport { startBrowserAuth } from './browser-oauth';\n\ninterface StoredToken {\n accessToken: string;\n refreshToken?: string | undefined;\n}\n\n/**\n * Signals that interactive sign-in is required. The message is user-facing: MCP\n * surfaces it as the tool-call error text, so it carries the authorize URL and\n * tells the user to authenticate and retry. Kept as an Error factory (not a\n * class) to match the repo's functional style.\n */\nexport type AuthRequiredError = Error & { readonly authorizeUrl: string };\n\nexport const createAuthRequiredError = (authorizeUrl: string): AuthRequiredError =>\n Object.assign(\n new Error(\n 'Zendesk authentication required. A browser window should have opened for you to sign in. ' +\n 'If it did not, open this URL in your browser, then retry your request:\\n' +\n authorizeUrl,\n ),\n { name: 'AuthRequiredError', authorizeUrl } as const,\n );\n\nexport const isAuthRequiredError = (err: unknown): err is AuthRequiredError =>\n err instanceof Error &&\n err.name === 'AuthRequiredError' &&\n typeof (err as AuthRequiredError).authorizeUrl === 'string';\n\nexport const createTokenStore = (\n config: { subdomain: string; oauthClientId: string },\n logger: Logger = silentLogger,\n) => {\n let token: StoredToken | undefined;\n // The authorize URL of the in-flight flow (set once the callback server is\n // listening); `undefined` means no flow is currently pending.\n let authorizeUrl: string | undefined;\n // Resolves to the authorize URL while a flow is being started; guards against\n // launching multiple browser flows for concurrent first calls.\n let starting: Promise<string> | undefined;\n\n const setToken = (accessToken: string, refreshToken?: string | undefined) => {\n token = { accessToken, refreshToken };\n };\n\n const beginAuth = (): Promise<string> => {\n logger.info('oauth_auth_start');\n return startBrowserAuth(\n { subdomain: config.subdomain, oauthClientId: config.oauthClientId },\n logger,\n )\n .then((started) => {\n authorizeUrl = started.authorizeUrl;\n started.tokenPromise\n .then((result) => {\n token = { accessToken: result.access_token, refreshToken: result.refresh_token };\n logger.info('oauth_token_cached');\n })\n .catch((err) => {\n logger.warn('oauth_auth_failed', {\n error: err instanceof Error ? err.message : String(err),\n });\n })\n .finally(() => {\n // Let the next call start a fresh flow: on success the cached token\n // short-circuits anyway; on failure/timeout we want a clean retry.\n starting = undefined;\n authorizeUrl = undefined;\n });\n return started.authorizeUrl;\n })\n .catch((err) => {\n // The callback server couldn't even start listening (e.g. port in use).\n // Reset so a later call can retry, and surface the underlying error.\n starting = undefined;\n throw err;\n });\n };\n\n const getToken = async (): Promise<string> => {\n if (token) {\n logger.debug('oauth_token_cache_hit');\n return token.accessToken;\n }\n\n if (!starting) {\n starting = beginAuth();\n }\n\n // Fail fast: don't hold the tool call open for the whole browser flow.\n // Surface the authorize URL so the user can sign in, then retry — the\n // callback server keeps running in the background and caches the token,\n // so the next call succeeds.\n const url = authorizeUrl ?? (await starting);\n throw createAuthRequiredError(url);\n };\n\n return { getToken, setToken };\n};\n","import * as z from 'zod/v4';\n\nexport const ToolMode = z.enum(['single', 'namespace', 'all']);\nexport type ToolMode = z.infer<typeof ToolMode>;\n\nexport const LogLevel = z.enum(['debug', 'info', 'warn', 'error']);\nexport type LogLevel = z.infer<typeof LogLevel>;\n\nexport const Namespace = z.enum(['tickets', 'help_center', 'users']);\nexport type Namespace = z.infer<typeof Namespace>;\n\nexport const ConfigSchema = z.object({\n subdomain: z.string().min(1, 'ZENDESK_SUBDOMAIN is required'),\n oauthClientId: z.string().min(1),\n zendeskEmail: z.string().optional(),\n zendeskApiToken: z.string().optional(),\n logLevel: LogLevel,\n mode: ToolMode,\n readOnly: z.boolean(),\n namespaces: z.array(Namespace).optional(),\n tools: z.array(z.string()).optional(),\n});\n\nexport type Config = z.infer<typeof ConfigSchema>;\n\ninterface CliResult {\n subdomain?: string;\n mode?: string;\n readOnly?: boolean;\n namespaces?: string[];\n tools?: string[];\n logLevel?: string;\n}\n\nconst parseCliArgs = (args: string[]): CliResult => {\n const result: CliResult = {};\n let positionalIndex = 0;\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (arg === undefined) continue;\n const next = args[i + 1];\n\n if (arg === '--mode' && next) {\n result.mode = next;\n i++;\n } else if (arg === '--read-only') {\n result.readOnly = true;\n } else if (arg === '--namespace' && next) {\n result.namespaces = result.namespaces ?? [];\n result.namespaces.push(next);\n i++;\n } else if (arg === '--tool' && next) {\n result.tools = result.tools ?? [];\n result.tools.push(next);\n i++;\n } else if (arg === '--log-level' && next) {\n result.logLevel = next;\n i++;\n } else if (!arg.startsWith('-') && positionalIndex === 0) {\n result.subdomain = arg;\n positionalIndex++;\n }\n }\n\n return result;\n};\n\nexport const loadConfig = (argv: string[] = process.argv.slice(2)): Config => {\n const cli = parseCliArgs(argv);\n\n const subdomain = cli.subdomain ?? process.env['ZENDESK_SUBDOMAIN'] ?? '';\n const oauthClientId =\n process.env['ZENDESK_OAUTH_CLIENT_ID'] ?? (subdomain ? `${subdomain}_zendesk` : '');\n\n const mode = cli.tools?.length ? 'all' : (cli.mode ?? 'namespace');\n\n return ConfigSchema.parse({\n subdomain,\n oauthClientId,\n zendeskEmail: process.env['ZENDESK_EMAIL'],\n zendeskApiToken: process.env['ZENDESK_API_TOKEN'],\n logLevel: cli.logLevel ?? process.env['LOG_LEVEL'] ?? 'info',\n mode,\n readOnly: cli.readOnly ?? false,\n namespaces: cli.namespaces,\n tools: cli.tools,\n });\n};\n","import type { Namespace } from '../config';\nimport type { ToolDefinition } from '../tools/definitions';\n\nexport interface FilterOptions {\n readOnly: boolean;\n namespaces?: Namespace[] | undefined;\n tools?: string[] | undefined;\n}\n\nexport const filterTools = (allTools: ToolDefinition[], options: FilterOptions): ToolDefinition[] =>\n allTools.filter((tool) => {\n if (options.readOnly && !tool.readOnly) return false;\n if (options.namespaces?.length && !options.namespaces.includes(tool.namespace)) return false;\n if (options.tools?.length && !options.tools.includes(tool.name)) return false;\n return true;\n });\n\nexport const groupByNamespace = (tools: ToolDefinition[]): Map<string, ToolDefinition[]> => {\n const grouped = new Map<string, ToolDefinition[]>();\n for (const tool of tools) {\n const existing = grouped.get(tool.namespace) ?? [];\n existing.push(tool);\n grouped.set(tool.namespace, existing);\n }\n return grouped;\n};\n","import { getBaseUrl, getHelpCenterBaseUrl } from '../constants.js';\n\nexport class ZendeskApiError extends Error {\n constructor(\n public readonly status: number,\n public readonly statusText: string,\n public readonly body: string,\n ) {\n super(ZendeskApiError.buildMessage(status, statusText, body));\n this.name = 'ZendeskApiError';\n }\n\n private static buildMessage(status: number, statusText: string, body: string): string {\n switch (status) {\n case 401:\n return 'Authentication failed. Your Zendesk token may be expired or invalid. Re-authenticate to get a new token.';\n case 403:\n return 'Permission denied. Your Zendesk account does not have access to this resource.';\n case 404:\n return `Resource not found. Please verify the ID is correct. (${statusText})`;\n case 422:\n return `Validation error: ${body}`;\n case 429:\n return 'Rate limit exceeded. Please wait before making more requests.';\n default:\n return `Zendesk API error ${status}: ${statusText}. ${body}`;\n }\n }\n}\n\nexport interface ZendeskRequestOptions {\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE';\n body?: unknown;\n params?: Record<string, string>;\n}\n\n// token is either a Bearer OAuth token or a \"Basic xxx\" string (stdio API token mode)\nconst buildAuthHeader = (token: string): string =>\n token.startsWith('Basic ') ? token : `Bearer ${token}`;\n\nconst buildUrl = (base: string, path: string, params?: Record<string, string>): string => {\n const url = new URL(`${base}${path}`);\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n url.searchParams.set(key, value);\n }\n }\n return url.toString();\n};\n\nconst executeRequest = async <T>(\n url: string,\n token: string,\n options: ZendeskRequestOptions = {},\n): Promise<T> => {\n const { method = 'GET', body } = options;\n\n const headers: Record<string, string> = {\n Authorization: buildAuthHeader(token),\n Accept: 'application/json',\n };\n\n if (body) {\n headers['Content-Type'] = 'application/json';\n }\n\n const init: RequestInit = { method, headers };\n if (body) {\n init.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, init);\n\n if (!response.ok) {\n const responseBody = await response.text();\n throw new ZendeskApiError(response.status, response.statusText, responseBody);\n }\n\n if (response.status === 204) {\n return {} as T;\n }\n\n return response.json() as Promise<T>;\n};\n\nexport const zendeskGet = <T>(\n subdomain: string,\n token: string,\n path: string,\n params?: Record<string, string>,\n): Promise<T> => {\n const url = buildUrl(getBaseUrl(subdomain), path, params);\n return executeRequest<T>(url, token);\n};\n\nexport const zendeskPost = <T>(\n subdomain: string,\n token: string,\n path: string,\n body: unknown,\n): Promise<T> => {\n const url = buildUrl(getBaseUrl(subdomain), path);\n return executeRequest<T>(url, token, { method: 'POST', body });\n};\n\nexport const zendeskPut = <T>(\n subdomain: string,\n token: string,\n path: string,\n body: unknown,\n): Promise<T> => {\n const url = buildUrl(getBaseUrl(subdomain), path);\n return executeRequest<T>(url, token, { method: 'PUT', body });\n};\n\nexport const helpCenterGet = <T>(\n subdomain: string,\n token: string,\n path: string,\n params?: Record<string, string>,\n): Promise<T> => {\n const url = buildUrl(getHelpCenterBaseUrl(subdomain), path, params);\n return executeRequest<T>(url, token);\n};\n\nexport const helpCenterPost = <T>(\n subdomain: string,\n token: string,\n path: string,\n body: unknown,\n): Promise<T> => {\n const url = buildUrl(getHelpCenterBaseUrl(subdomain), path);\n return executeRequest<T>(url, token, { method: 'POST', body });\n};\n\nexport const helpCenterPut = <T>(\n subdomain: string,\n token: string,\n path: string,\n body: unknown,\n): Promise<T> => {\n const url = buildUrl(getHelpCenterBaseUrl(subdomain), path);\n return executeRequest<T>(url, token, { method: 'PUT', body });\n};\n\nexport const fetchZendeskBinary = async (\n subdomain: string,\n token: string,\n contentUrl: string,\n): Promise<{ data: Buffer; contentType: string }> => {\n const expectedHost = `${subdomain}.zendesk.com`;\n const headers: Record<string, string> = {};\n if (new URL(contentUrl).hostname === expectedHost) {\n headers['Authorization'] = buildAuthHeader(token);\n }\n const response = await fetch(contentUrl, { headers });\n if (!response.ok) {\n const body = await response.text();\n throw new ZendeskApiError(response.status, response.statusText, body);\n }\n const contentType = response.headers.get('content-type') ?? 'application/octet-stream';\n const arrayBuffer = await response.arrayBuffer();\n return { data: Buffer.from(arrayBuffer), contentType };\n};\n\nexport const helpCenterUpload = async <T>(\n subdomain: string,\n token: string,\n path: string,\n formData: FormData,\n): Promise<T> => {\n const url = buildUrl(getHelpCenterBaseUrl(subdomain), path);\n const response = await fetch(url, {\n method: 'POST',\n headers: { Authorization: buildAuthHeader(token) },\n body: formData,\n });\n\n if (!response.ok) {\n const responseBody = await response.text();\n throw new ZendeskApiError(response.status, response.statusText, responseBody);\n }\n\n return response.json() as Promise<T>;\n};\n","import * as cheerio from 'cheerio';\nimport type { Element } from 'hast';\nimport { toHtml } from 'hast-util-to-html';\nimport type { Handle } from 'hast-util-to-mdast';\nimport rehypeParse from 'rehype-parse';\nimport rehypeRaw from 'rehype-raw';\nimport rehypeRemark from 'rehype-remark';\nimport rehypeStringify from 'rehype-stringify';\nimport remarkGfm from 'remark-gfm';\nimport remarkParse from 'remark-parse';\nimport remarkRehype from 'remark-rehype';\nimport remarkStringify from 'remark-stringify';\nimport { unified } from 'unified';\n\nexport interface Section {\n index: number;\n heading: string;\n headingTag: string;\n level: number;\n html: string;\n wordCount: number;\n}\n\nconst HEADING_LEVELS = new Set(['h1', 'h2', 'h3']);\n\nconst countWords = (text: string): number => {\n const trimmed = text.trim();\n if (!trimmed) return 0;\n return trimmed.split(/\\s+/).length;\n};\n\nconst textOf = (html: string): string => {\n if (!html) return '';\n const $ = cheerio.load(`<div>${html}</div>`, null, false);\n return $('div').first().text();\n};\n\nexport const parseSections = (html: string): Section[] => {\n if (!html?.trim()) return [];\n\n const $ = cheerio.load(html, null, false);\n const children = $.root().contents().toArray();\n\n const introParts: string[] = [];\n const sections: Array<{\n heading: string;\n headingTag: string;\n level: number;\n contentParts: string[];\n }> = [];\n let current: (typeof sections)[number] | null = null;\n\n for (const node of children) {\n const tagName = node.type === 'tag' ? node.name.toLowerCase() : '';\n\n if (HEADING_LEVELS.has(tagName)) {\n const level = Number.parseInt(tagName.slice(1), 10);\n current = {\n heading: $(node).text().trim(),\n headingTag: tagName,\n level,\n contentParts: [],\n };\n sections.push(current);\n continue;\n }\n\n const outer = $.html(node);\n if (current) {\n current.contentParts.push(outer);\n } else {\n introParts.push(outer);\n }\n }\n\n const result: Section[] = [];\n\n if (introParts.length > 0) {\n const introHtml = introParts.join('');\n result.push({\n index: 0,\n heading: 'intro',\n headingTag: '',\n level: 0,\n html: introHtml,\n wordCount: countWords(textOf(introHtml)),\n });\n }\n\n for (const s of sections) {\n const sectionHtml = s.contentParts.join('');\n result.push({\n index: result.length,\n heading: s.heading,\n headingTag: s.headingTag,\n level: s.level,\n html: sectionHtml,\n wordCount: countWords(textOf(sectionHtml)),\n });\n }\n\n return result;\n};\n\nexport const replaceSectionContent = (\n html: string,\n sectionIndex: number,\n newHtml: string,\n): string => {\n const sections = parseSections(html);\n if (sectionIndex < 0 || sectionIndex >= sections.length) {\n throw new Error(\n `Section index ${sectionIndex} out of range (valid: 0-${Math.max(0, sections.length - 1)})`,\n );\n }\n\n return sections\n .map((section, idx) => {\n const content = idx === sectionIndex ? newHtml : section.html;\n if (section.level === 0) return content;\n return `<${section.headingTag}>${section.heading}</${section.headingTag}>${content}`;\n })\n .join('');\n};\n\n// Keep structural HTML that markdown flattens lossily: <pre> with inline <br>\n// collapses to a single line, and <table> cells with multiple <p> break GFM\n// pipe tables. Leaving them as raw HTML is safer for round-trip.\nconst keepAsHtml: Handle = (_state, node) => ({\n type: 'html',\n value: toHtml(node as Element),\n});\n\nconst htmlToMdProcessor = unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeRemark, { handlers: { table: keepAsHtml, pre: keepAsHtml } })\n .use(remarkGfm)\n .use(remarkStringify, { bullet: '-', emphasis: '_', fences: true });\n\nconst mdToHtmlProcessor = unified()\n .use(remarkParse)\n .use(remarkGfm)\n .use(remarkRehype, { allowDangerousHtml: true })\n .use(rehypeRaw)\n .use(rehypeStringify);\n\nexport const htmlToMarkdown = (html: string): string => {\n if (!html) return '';\n return String(htmlToMdProcessor.processSync(html));\n};\n\nexport const markdownToHtml = (markdown: string): string => {\n if (!markdown) return '';\n return String(mdToHtmlProcessor.processSync(markdown));\n};\n","import { CHARACTER_LIMIT } from '../constants.js';\nimport type {\n PaginationMeta,\n ZendeskArticle,\n ZendeskArticleAttachment,\n ZendeskCategory,\n ZendeskComment,\n ZendeskContentTag,\n ZendeskLabel,\n ZendeskOrganization,\n ZendeskPermissionGroup,\n ZendeskSection,\n ZendeskTicket,\n ZendeskTranslation,\n ZendeskUser,\n ZendeskUserSegment,\n} from '../types.js';\n\nexport const truncateIfNeeded = (text: string): string => {\n if (text.length <= CHARACTER_LIMIT) return text;\n return `${text.slice(0, CHARACTER_LIMIT)}\\n\\n--- Response truncated (${text.length} chars, limit ${CHARACTER_LIMIT}). Use pagination or filters to reduce results. ---`;\n};\n\nconst formatPagination = (meta: PaginationMeta): string => {\n const parts = [`Results: ${meta.count}`];\n if (meta.has_more) {\n parts.push(`More available (cursor: ${meta.after_cursor})`);\n }\n return parts.join(' | ');\n};\n\nexport const formatTicket = (ticket: ZendeskTicket): string =>\n [\n `## Ticket #${ticket.id}: ${ticket.subject}`,\n `- **Status**: ${ticket.status} | **Priority**: ${ticket.priority ?? 'none'} | **Type**: ${ticket.type ?? 'none'}`,\n `- **Requester**: ${ticket.requester_id} | **Assignee**: ${ticket.assignee_id ?? 'unassigned'}`,\n `- **Tags**: ${ticket.tags.length > 0 ? ticket.tags.join(', ') : 'none'}`,\n `- **Created**: ${ticket.created_at} | **Updated**: ${ticket.updated_at}`,\n ticket.description ? `\\n${ticket.description}` : '',\n ]\n .filter(Boolean)\n .join('\\n');\n\nexport const formatComment = (comment: ZendeskComment): string => {\n const lines = [\n `### ${comment.public ? 'Public comment' : 'Internal note'} by ${comment.author_id}`,\n `*${comment.created_at}*`,\n ];\n if (comment.attachments?.length) {\n const summary = comment.attachments.map((a) => `#${a.id} (${a.content_type})`).join(', ');\n lines.push(`Attachments: ${summary}`);\n }\n lines.push('', comment.body);\n return lines.join('\\n');\n};\n\nexport const formatUser = (user: ZendeskUser): string =>\n [\n `## ${user.name} (${user.id})`,\n `- **Email**: ${user.email}`,\n `- **Role**: ${user.role}`,\n user.role_type != null ? `- **Role type**: ${user.role_type}` : '',\n `- **Active**: ${user.active}`,\n user.organization_id ? `- **Organization**: ${user.organization_id}` : '',\n ]\n .filter(Boolean)\n .join('\\n');\n\nexport const formatOrganization = (org: ZendeskOrganization): string =>\n [\n `## ${org.name} (${org.id})`,\n org.details ? `- **Details**: ${org.details}` : '',\n org.domain_names.length > 0 ? `- **Domains**: ${org.domain_names.join(', ')}` : '',\n org.tags.length > 0 ? `- **Tags**: ${org.tags.join(', ')}` : '',\n ]\n .filter(Boolean)\n .join('\\n');\n\nexport const formatArticleSummary = (article: ZendeskArticle): string =>\n [\n `## ${article.title} (${article.id})`,\n `- **Locale**: ${article.locale} | **Source locale**: ${article.source_locale}`,\n `- **Section**: ${article.section_id} | **Draft**: ${article.draft}`,\n typeof article.position === 'number' ? `- **Position**: ${article.position}` : '',\n article.label_names.length > 0 ? `- **Labels**: ${article.label_names.join(', ')}` : '',\n `- **Created**: ${article.created_at} | **Updated**: ${article.updated_at}`,\n ]\n .filter(Boolean)\n .join('\\n');\n\nexport const formatArticle = (article: ZendeskArticle): string =>\n [formatArticleSummary(article), '', article.body].join('\\n');\n\nexport const formatTranslationSummary = (translation: ZendeskTranslation): string =>\n [\n `## Translation: ${translation.locale} (${translation.id})`,\n `- **Title**: ${translation.title}`,\n `- **Draft**: ${translation.draft}`,\n `- **Updated**: ${translation.updated_at}`,\n ].join('\\n');\n\nexport const formatTranslation = (translation: ZendeskTranslation): string =>\n [formatTranslationSummary(translation), '', translation.body].join('\\n');\n\nexport const formatCategory = (category: ZendeskCategory): string =>\n `- **${category.name}** (${category.id}) — ${category.description || 'No description'}`;\n\nexport const formatSection = (section: ZendeskSection): string =>\n `- **${section.name}** (${section.id}) — Category: ${section.category_id} — ${section.description || 'No description'}`;\n\nexport const formatPermissionGroup = (group: ZendeskPermissionGroup): string =>\n `- **${group.name}** (${group.id})${group.built_in ? ' — Built-in' : ''}`;\n\nexport const formatContentTag = (tag: ZendeskContentTag): string => `- **${tag.name}** (${tag.id})`;\n\nexport const formatLabel = (label: ZendeskLabel): string => `- **${label.name}** (${label.id})`;\n\nexport const formatUserSegment = (segment: ZendeskUserSegment): string =>\n `- **${segment.name}** (${segment.id}) — ${segment.user_type}${segment.built_in ? ' — Built-in' : ''}`;\n\nexport const formatAttachment = (attachment: ZendeskArticleAttachment): string =>\n `- **${attachment.file_name}** (${attachment.id}) — ${attachment.content_type} — ${attachment.size} bytes`;\n\nexport const formatList = <T>(\n items: T[],\n formatter: (item: T) => string,\n meta?: PaginationMeta,\n): string => {\n const header = meta ? formatPagination(meta) : '';\n const body = items.map(formatter).join('\\n\\n');\n const text = [header, body].filter(Boolean).join('\\n\\n');\n return truncateIfNeeded(text);\n};\n","import type { PaginationMeta, ZendeskListResponse } from '../types';\n\n// Cursor-based pagination (for list endpoints: /tickets, /organizations, etc.)\nexport const buildCursorParams = (pageSize: number, cursor?: string): Record<string, string> => {\n const params: Record<string, string> = {\n 'page[size]': String(pageSize),\n };\n if (cursor) {\n params['page[after]'] = cursor;\n }\n return params;\n};\n\n// Offset-based pagination (for search endpoints: /search, /help_center/articles/search)\nexport const buildOffsetParams = (perPage: number, page?: number): Record<string, string> => {\n const params: Record<string, string> = {\n per_page: String(perPage),\n };\n if (page && page > 1) {\n params['page'] = String(page);\n }\n return params;\n};\n\nexport const extractPaginationMeta = <T>(response: ZendeskListResponse<T>): PaginationMeta => ({\n has_more: response.meta?.has_more ?? response.next_page != null,\n after_cursor: response.meta?.after_cursor ?? null,\n count: response.count ?? 0,\n});\n\n// For search responses — offset-based, count is always present\nexport const extractSearchPaginationMeta = <T>(\n response: ZendeskListResponse<T>,\n perPage: number,\n page: number,\n): PaginationMeta => {\n const count = response.count ?? 0;\n const has_more = count > page * perPage;\n return {\n has_more,\n after_cursor: has_more ? String(page + 1) : null,\n count,\n };\n};\n","import * as z from 'zod/v4';\nimport {\n helpCenterGet,\n helpCenterPost,\n helpCenterPut,\n helpCenterUpload,\n zendeskGet,\n zendeskPost,\n} from '../client/zendesk-api';\nimport {\n DEFAULT_PAGE_SIZE,\n LARGE_ARTICLE_BODY_CHARS,\n LARGE_ARTICLE_SECTION_COUNT,\n MAX_PAGE_SIZE,\n} from '../constants';\nimport type {\n ZendeskArticle,\n ZendeskArticleAttachment,\n ZendeskCategory,\n ZendeskContentTag,\n ZendeskLabel,\n ZendeskListResponse,\n ZendeskPermissionGroup,\n ZendeskSection,\n ZendeskTranslation,\n ZendeskUserSegment,\n} from '../types';\nimport {\n htmlToMarkdown,\n markdownToHtml,\n parseSections,\n replaceSectionContent,\n} from '../utils/article-sections';\nimport {\n formatArticle,\n formatArticleSummary,\n formatAttachment,\n formatCategory,\n formatContentTag,\n formatLabel,\n formatList,\n formatPermissionGroup,\n formatSection,\n formatTranslation,\n formatTranslationSummary,\n formatUserSegment,\n truncateIfNeeded,\n} from '../utils/formatting';\nimport {\n buildCursorParams,\n buildOffsetParams,\n extractPaginationMeta,\n extractSearchPaginationMeta,\n} from '../utils/pagination';\nimport type { ToolContext, ToolDefinition } from './definitions';\n\nconst largeArticleHint = (body: string, sectionCount: number): string | null => {\n if (body.length < LARGE_ARTICLE_BODY_CHARS && sectionCount < LARGE_ARTICLE_SECTION_COUNT) {\n return null;\n }\n return [\n `> ⚠ Large article (${body.length} chars, ${sectionCount} sections).`,\n '> For targeted edits, prefer get_article_outline + get_article_section +',\n '> update_article_section to avoid re-sending the full body on each write.',\n '',\n ].join('\\n');\n};\n\nexport const createHelpCenterTools = (ctx: ToolContext): ToolDefinition[] => {\n const { subdomain, getToken } = ctx;\n\n return [\n {\n name: 'search_articles',\n namespace: 'help_center',\n readOnly: true,\n title: 'Search Help Center Articles',\n description:\n 'Full-text search across Help Center articles (metadata only, no body). Use get_article for full content. Supports locale filtering. Returns total count.',\n inputSchema: z.object({\n query: z.string().min(1).describe('Search query'),\n locale: z.string().optional().describe('Filter by locale (e.g., \"en-us\", \"fr\")'),\n per_page: z\n .number()\n .int()\n .min(1)\n .max(MAX_PAGE_SIZE)\n .default(DEFAULT_PAGE_SIZE)\n .describe('Results per page'),\n page: z.number().int().min(1).default(1).describe('Page number'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { query, locale, per_page, page } = params as {\n query: string;\n locale?: string;\n per_page: number;\n page: number;\n };\n const token = await getToken();\n const p: Record<string, string> = { query, ...buildOffsetParams(per_page, page) };\n if (locale) p['locale'] = locale;\n const response = await helpCenterGet<ZendeskListResponse<ZendeskArticle>>(\n subdomain,\n token,\n '/articles/search',\n p,\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.results ?? [],\n formatArticleSummary,\n extractSearchPaginationMeta(response, per_page, page),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'get_article',\n namespace: 'help_center',\n readOnly: true,\n title: 'Get Help Center Article',\n description:\n 'Retrieve an article by ID with full body content. For large articles, prefer get_article_outline + get_article_section to save tokens. Optionally specify locale for a translated version. Returns body (HTML), metadata, source_locale, and list of available translations.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n locale: z.string().optional().describe('Locale for translated version'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale } = params as { article_id: number; locale?: string };\n const token = await getToken();\n const path = locale ? `/${locale}/articles/${article_id}` : `/articles/${article_id}`;\n const { article } = await helpCenterGet<{ article: ZendeskArticle }>(\n subdomain,\n token,\n path,\n );\n const { translations } = await helpCenterGet<{ translations: ZendeskTranslation[] }>(\n subdomain,\n token,\n `/articles/${article_id}/translations`,\n );\n const hint = largeArticleHint(article.body, parseSections(article.body).length);\n const text =\n (hint ?? '') +\n formatArticle(article) +\n `\\n\\n**Available translations**: ${translations.map((t) => t.locale).join(', ')}`;\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'list_categories',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Help Center Categories',\n description: 'List all Help Center categories. Optionally filter by locale.',\n inputSchema: z.object({\n locale: z.string().optional(),\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional(),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { locale, page_size, cursor } = params as {\n locale?: string;\n page_size: number;\n cursor?: string;\n };\n const token = await getToken();\n const path = locale ? `/${locale}/categories` : '/categories';\n const response = await helpCenterGet<ZendeskListResponse<ZendeskCategory>>(\n subdomain,\n token,\n path,\n buildCursorParams(page_size, cursor),\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.categories ?? [],\n formatCategory,\n extractPaginationMeta(response),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'list_sections',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Help Center Sections',\n description: 'List sections, optionally filtered by category ID and locale.',\n inputSchema: z.object({\n category_id: z.number().int().optional(),\n locale: z.string().optional(),\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional(),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { category_id, locale, page_size, cursor } = params as {\n category_id?: number;\n locale?: string;\n page_size: number;\n cursor?: string;\n };\n const token = await getToken();\n const path =\n category_id && locale\n ? `/${locale}/categories/${category_id}/sections`\n : category_id\n ? `/categories/${category_id}/sections`\n : locale\n ? `/${locale}/sections`\n : '/sections';\n const response = await helpCenterGet<ZendeskListResponse<ZendeskSection>>(\n subdomain,\n token,\n path,\n buildCursorParams(page_size, cursor),\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.sections ?? [],\n formatSection,\n extractPaginationMeta(response),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'list_articles',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Help Center Articles',\n description:\n 'List articles (metadata only, no body). Use get_article for full content. Optionally filter by section ID and locale. Supports sort_by (\"title\", \"created_at\", \"updated_at\") and include_translations: true to show available translation locales per article. Note: include_translations must be re-sent on each paginated request.',\n inputSchema: z.object({\n section_id: z.number().int().optional(),\n locale: z.string().optional(),\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional(),\n sort_by: z\n .enum(['created_at', 'updated_at', 'position', 'title'])\n .default('position')\n .describe('Sort field'),\n sort_order: z.enum(['asc', 'desc']).default('asc').describe('Sort direction'),\n include_translations: z\n .boolean()\n .default(false)\n .describe(\n 'Include available translation locales per article (causes 1 extra API call per article)',\n ),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { section_id, locale, page_size, cursor, sort_by, sort_order, include_translations } =\n params as {\n section_id?: number;\n locale?: string;\n page_size: number;\n cursor?: string;\n sort_by: string;\n sort_order: string;\n include_translations: boolean;\n };\n const token = await getToken();\n const path =\n section_id && locale\n ? `/${locale}/sections/${section_id}/articles`\n : section_id\n ? `/sections/${section_id}/articles`\n : locale\n ? `/${locale}/articles`\n : '/articles';\n const response = await helpCenterGet<ZendeskListResponse<ZendeskArticle>>(\n subdomain,\n token,\n path,\n { ...buildCursorParams(page_size, cursor), sort_by, sort_order },\n );\n const articles = response.articles ?? [];\n if (!include_translations) {\n return {\n content: [\n {\n type: 'text',\n text: formatList(articles, formatArticleSummary, extractPaginationMeta(response)),\n },\n ],\n };\n }\n const formatted = await Promise.all(\n articles.map(async (article) => {\n const { translations } = await helpCenterGet<{ translations: ZendeskTranslation[] }>(\n subdomain,\n token,\n `/articles/${article.id}/translations`,\n );\n const locales = translations.map((t) => t.locale).join(', ');\n return `${formatArticleSummary(article)}\\n- **Translations**: ${locales}`;\n }),\n );\n const meta = extractPaginationMeta(response);\n const header = meta.count\n ? `Results: ${meta.count}${meta.has_more ? ` | More available (cursor: ${meta.after_cursor})` : ''}`\n : '';\n const text = [header, ...formatted].filter(Boolean).join('\\n\\n');\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'list_article_translations',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Article Translations',\n description:\n 'List all available translations for an article (metadata only, no body: locale, title, draft, updated_at). Use get_article with locale for full translated content.',\n inputSchema: z.object({ article_id: z.number().int().describe('Article ID') }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id } = params as { article_id: number };\n const token = await getToken();\n const { translations } = await helpCenterGet<{ translations: ZendeskTranslation[] }>(\n subdomain,\n token,\n `/articles/${article_id}/translations`,\n );\n return {\n content: [{ type: 'text', text: formatList(translations, formatTranslationSummary) }],\n };\n },\n },\n {\n name: 'create_article_translation',\n namespace: 'help_center',\n readOnly: false,\n title: 'Create Article Translation',\n description: 'Create a translation for an existing article in a specific locale.',\n inputSchema: z.object({\n article_id: z.number().int(),\n locale: z.string().describe('Target locale (e.g., \"fr\", \"de\")'),\n title: z.string().min(1),\n body: z.string().min(1).describe('Translated body (HTML)'),\n draft: z.boolean().default(false),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale, title, body, draft } = params as {\n article_id: number;\n locale: string;\n title: string;\n body: string;\n draft: boolean;\n };\n const token = await getToken();\n const { translation } = await helpCenterPost<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations`,\n { translation: { locale, title, body, draft } },\n );\n return {\n content: [\n {\n type: 'text',\n text: `Translation created for article #${article_id} in \"${locale}\".\\n\\n${formatTranslation(translation)}`,\n },\n ],\n };\n },\n },\n {\n name: 'update_article_translation',\n namespace: 'help_center',\n readOnly: false,\n title: 'Update Article Translation',\n description:\n \"Update article content (title, body) in a specific locale. For targeted edits on one or a few sections, prefer update_article_section — this tool replaces the FULL body and re-sends the entire article on each write. Use the article's source_locale (from get_article) for the default language, or another locale for translations.\",\n inputSchema: z.object({\n article_id: z.number().int(),\n locale: z.string(),\n title: z.string().optional(),\n body: z.string().optional(),\n draft: z.boolean().optional(),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale, ...updates } = params as {\n article_id: number;\n locale: string;\n } & Record<string, unknown>;\n const token = await getToken();\n const { translation } = await helpCenterPut<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${locale}`,\n { translation: updates },\n );\n return {\n content: [\n {\n type: 'text',\n text: `Translation updated for article #${article_id} in \"${locale}\".\\n\\n${formatTranslation(translation)}`,\n },\n ],\n };\n },\n },\n {\n name: 'list_permission_groups',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Permission Groups',\n description:\n 'List all Guide permission groups. Use this to find the permission_group_id required when creating articles.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const response = await zendeskGet<{\n permission_groups: ZendeskPermissionGroup[];\n count: number;\n }>(subdomain, token, '/guide/permission_groups');\n return {\n content: [\n {\n type: 'text',\n text: formatList(response.permission_groups ?? [], formatPermissionGroup),\n },\n ],\n };\n },\n },\n {\n name: 'create_article',\n namespace: 'help_center',\n readOnly: false,\n title: 'Create Help Center Article',\n description:\n \"Create a new article in a section. The locale becomes the article's source_locale. Requires a permission_group_id (use list_permission_groups to find available IDs). To add content in other locales afterwards, use create_article_translation.\",\n inputSchema: z.object({\n section_id: z.number().int(),\n title: z.string().min(1),\n body: z.string().min(1).describe('Article body (HTML)'),\n permission_group_id: z\n .number()\n .int()\n .describe('Permission group ID (use list_permission_groups to find it)'),\n user_segment_id: z\n .number()\n .int()\n .optional()\n .describe(\n 'User segment ID for visibility (use list_user_segments to find it). Defaults to everyone.',\n ),\n author_id: z\n .number()\n .int()\n .optional()\n .describe('Author user ID. Defaults to the authenticated user.'),\n content_tag_ids: z\n .array(z.string())\n .optional()\n .describe('Content tag IDs (use list_content_tags to find them)'),\n locale: z.string().optional(),\n draft: z.boolean().default(true),\n promoted: z.boolean().default(false),\n label_names: z\n .array(z.string())\n .optional()\n .describe('Label names for search ranking (use list_labels to see existing labels)'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { section_id, ...articleData } = params as { section_id: number } & Record<\n string,\n unknown\n >;\n const token = await getToken();\n const { article } = await helpCenterPost<{ article: ZendeskArticle }>(\n subdomain,\n token,\n `/sections/${section_id}/articles`,\n { article: articleData },\n );\n return {\n content: [\n { type: 'text', text: `Article #${article.id} created.\\n\\n${formatArticle(article)}` },\n ],\n };\n },\n },\n {\n name: 'update_article',\n namespace: 'help_center',\n readOnly: false,\n title: 'Update Help Center Article',\n description:\n 'Update article metadata only (draft, promoted, labels, tags, visibility, section, sort position, etc.). Does NOT update content (title, body) — use update_article_translation for that.',\n inputSchema: z.object({\n article_id: z.number().int(),\n draft: z.boolean().optional(),\n promoted: z.boolean().optional(),\n label_names: z.array(z.string()).optional().describe('Label names for search ranking'),\n content_tag_ids: z.array(z.string()).optional().describe('Content tag IDs'),\n user_segment_id: z.number().int().optional().describe('User segment ID for visibility'),\n author_id: z.number().int().optional().describe('Author user ID'),\n permission_group_id: z.number().int().optional().describe('Permission group ID'),\n section_id: z.number().int().optional(),\n position: z\n .number()\n .int()\n .min(0)\n .optional()\n .describe(\n 'Sort position within the section (manual ordering only; 0 = first/top). New articles default to position 0. To move an article to the END of its section, set this to one more than the highest current position: read the highest position P from list_articles with sort_by=\"position\", sort_order=\"desc\", then set position = P + 1.',\n ),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, ...updates } = params as { article_id: number } & Record<\n string,\n unknown\n >;\n const token = await getToken();\n const { article } = await helpCenterPut<{ article: ZendeskArticle }>(\n subdomain,\n token,\n `/articles/${article_id}`,\n { article: updates },\n );\n return {\n content: [\n { type: 'text', text: `Article #${article.id} updated.\\n\\n${formatArticle(article)}` },\n ],\n };\n },\n },\n {\n name: 'list_content_tags',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Content Tags',\n description:\n 'List all Guide content tags. Content tags are visible to end users and help them find related articles.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const response = await zendeskGet<{ records: ZendeskContentTag[]; count: number }>(\n subdomain,\n token,\n '/guide/content_tags',\n );\n return {\n content: [{ type: 'text', text: formatList(response.records ?? [], formatContentTag) }],\n };\n },\n },\n {\n name: 'create_content_tag',\n namespace: 'help_center',\n readOnly: false,\n title: 'Create Content Tag',\n description: 'Create a new content tag for Guide articles.',\n inputSchema: z.object({\n name: z.string().min(1).describe('Content tag name'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { name } = params as { name: string };\n const token = await getToken();\n const { record } = await zendeskPost<{ record: ZendeskContentTag }>(\n subdomain,\n token,\n '/guide/content_tags',\n { record: { name } },\n );\n return {\n content: [{ type: 'text', text: `Content tag created.\\n\\n${formatContentTag(record)}` }],\n };\n },\n },\n {\n name: 'list_labels',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Article Labels',\n description:\n 'List all article labels. Labels improve Help Center search ranking and are not visible to end users.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const response = await helpCenterGet<{ labels: ZendeskLabel[]; count: number }>(\n subdomain,\n token,\n '/articles/labels',\n );\n return {\n content: [{ type: 'text', text: formatList(response.labels ?? [], formatLabel) }],\n };\n },\n },\n {\n name: 'list_user_segments',\n namespace: 'help_center',\n readOnly: true,\n title: 'List User Segments',\n description:\n 'List all user segments. User segments control article visibility (who can view). Use the ID when creating or updating articles.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const response = await helpCenterGet<{\n user_segments: ZendeskUserSegment[];\n count: number;\n }>(subdomain, token, '/user_segments');\n return {\n content: [\n { type: 'text', text: formatList(response.user_segments ?? [], formatUserSegment) },\n ],\n };\n },\n },\n {\n name: 'list_article_attachments',\n namespace: 'help_center',\n readOnly: true,\n title: 'List Article Attachments',\n description: 'List all attachments for an article.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id } = params as { article_id: number };\n const token = await getToken();\n const response = await helpCenterGet<{\n article_attachments: ZendeskArticleAttachment[];\n count: number;\n }>(subdomain, token, `/articles/${article_id}/attachments`);\n return {\n content: [\n {\n type: 'text',\n text: formatList(response.article_attachments ?? [], formatAttachment),\n },\n ],\n };\n },\n },\n {\n name: 'get_article_outline',\n namespace: 'help_center',\n readOnly: true,\n title: 'Get Article Outline',\n description:\n 'Return a compact outline of an article (list of sections delimited by h1/h2/h3, with word counts) for the given locale (defaults to source_locale). Includes available translations with their outdated status. Use get_article_section to fetch a specific section.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n locale: z\n .string()\n .optional()\n .describe('Locale of the body to outline (defaults to article source_locale)'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale } = params as { article_id: number; locale?: string };\n const token = await getToken();\n const { article } = await helpCenterGet<{ article: ZendeskArticle }>(\n subdomain,\n token,\n `/articles/${article_id}`,\n );\n const effectiveLocale = locale ?? article.source_locale;\n const { translation } = await helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${effectiveLocale}`,\n );\n const { translations } = await helpCenterGet<{\n translations: Array<ZendeskTranslation & { outdated?: boolean }>;\n }>(subdomain, token, `/articles/${article_id}/translations`);\n const sections = parseSections(translation.body);\n\n const outlineLines = sections.length\n ? sections\n .map(\n (s) =>\n `- [${s.index}] ${s.headingTag ? `${s.headingTag}: ` : ''}${s.heading} (${s.wordCount} words)`,\n )\n .join('\\n')\n : '_(no sections detected)_';\n const translationsList = translations\n .map((t) => `- ${t.locale}${t.outdated ? ' (outdated)' : ''}`)\n .join('\\n');\n\n const text = [\n `# Outline — Article #${article_id} (${effectiveLocale})`,\n `**Title**: ${translation.title}`,\n '',\n '## Sections',\n outlineLines,\n '',\n '## Available translations',\n translationsList,\n ].join('\\n');\n return { content: [{ type: 'text', text }] };\n },\n },\n {\n name: 'get_article_section',\n namespace: 'help_center',\n readOnly: true,\n title: 'Get Article Section',\n description:\n 'Retrieve the content of a single section of an article in a given locale. Use get_article_outline first to discover section indexes. Default format=\"html\" for round-trip safety. Pass format=\"markdown\" only for human review — the Markdown representation is lossy on some structures (<pre> with <br>, tables with multi-<p> cells are kept as raw HTML to limit the damage, but do not round-trip markdown content back through update_article_section).',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n locale: z.string().describe('Locale of the body (e.g., \"en-us\", \"fr\")'),\n section_index: z\n .number()\n .int()\n .min(0)\n .describe('0-based index of the section (see get_article_outline)'),\n format: z\n .enum(['html', 'markdown'])\n .default('html')\n .describe(\n 'Output format. \"html\" (default) is round-trip safe. \"markdown\" is lossy on some HTML structures — use only for human review, not before update_article_section.',\n ),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale, section_index, format } = params as {\n article_id: number;\n locale: string;\n section_index: number;\n format: 'html' | 'markdown';\n };\n const token = await getToken();\n const { translation } = await helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${locale}`,\n );\n const sections = parseSections(translation.body);\n const section = sections[section_index];\n if (!section) {\n throw new Error(\n `Section index ${section_index} not found. Article has ${sections.length} section(s) (0-${Math.max(0, sections.length - 1)}).`,\n );\n }\n const content = format === 'markdown' ? htmlToMarkdown(section.html) : section.html;\n const headerLine = section.headingTag\n ? `## [${section.index}] ${section.headingTag}: ${section.heading}`\n : `## [${section.index}] ${section.heading}`;\n const text = [\n headerLine,\n `_Locale: ${locale} | Words: ${section.wordCount} | Format: ${format}_`,\n '',\n content,\n ].join('\\n');\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'update_article_section',\n namespace: 'help_center',\n readOnly: false,\n title: 'Update Article Section',\n description:\n 'Replace the content of a single section of an article in a given locale, keeping the rest of the body intact. The server fetches the current body, replaces the targeted section, and PUTs the full reconstructed body via the Translations API. Default format=\"html\" for fidelity. Use format=\"markdown\" only when you control the input and know it does not rely on structures that round-trip poorly (code blocks with line breaks, tables with multi-paragraph cells). The section heading is preserved and is NOT part of the replaced content.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n locale: z.string().describe('Locale of the translation to update'),\n section_index: z\n .number()\n .int()\n .min(0)\n .describe('0-based index of the section to replace (see get_article_outline)'),\n content: z\n .string()\n .describe(\n 'New content for the section (heading excluded). HTML by default, Markdown if format=\"markdown\".',\n ),\n format: z\n .enum(['html', 'markdown'])\n .default('html')\n .describe(\n 'Input format. \"html\" (default) is the safe path. \"markdown\" is converted to HTML server-side but may introduce artifacts on complex content.',\n ),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, locale, section_index, content, format } = params as {\n article_id: number;\n locale: string;\n section_index: number;\n content: string;\n format: 'html' | 'markdown';\n };\n const token = await getToken();\n const { translation } = await helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${locale}`,\n );\n const newSectionHtml = format === 'markdown' ? markdownToHtml(content) : content;\n const newBody = replaceSectionContent(translation.body, section_index, newSectionHtml);\n const { translation: updated } = await helpCenterPut<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${locale}`,\n { translation: { body: newBody } },\n );\n const updatedSections = parseSections(updated.body);\n const updatedSection = updatedSections[section_index];\n const newWordCount = updatedSection?.wordCount ?? 0;\n const headingLabel = updatedSection?.heading ?? '(intro)';\n const text = [\n `Section [${section_index}] \"${headingLabel}\" updated for article #${article_id} (${locale}).`,\n `New word count: ${newWordCount}.`,\n ].join('\\n');\n return { content: [{ type: 'text', text }] };\n },\n },\n {\n name: 'compare_translations',\n namespace: 'help_center',\n readOnly: true,\n title: 'Compare Article Translations',\n description:\n 'Compare section structure between two locales of the same article, matched by index. Returns a compact table (one row per section) with status: \"ok\" (both present, source/target word count ratio within 25%), \"different\" (word count ratio diverges by more than 25% — size signal only, NOT a semantic divergence: two locales may legitimately differ in verbosity) or \"missing\" (section absent in target). Useful to spot structurally stale or missing sections; do not interpret \"different\" as an edit regression on its own.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n source_locale: z.string().describe('Source (reference) locale'),\n target_locale: z.string().describe('Target locale to compare against source'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, source_locale, target_locale } = params as {\n article_id: number;\n source_locale: string;\n target_locale: string;\n };\n const token = await getToken();\n const [sourceRes, targetRes] = await Promise.all([\n helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${source_locale}`,\n ),\n helpCenterGet<{ translation: ZendeskTranslation }>(\n subdomain,\n token,\n `/articles/${article_id}/translations/${target_locale}`,\n ),\n ]);\n const sourceSections = parseSections(sourceRes.translation.body);\n const targetSections = parseSections(targetRes.translation.body);\n const maxLen = Math.max(sourceSections.length, targetSections.length);\n\n const rows: string[] = [];\n rows.push(`| Idx | Heading | Status | Source words | Target words |`);\n rows.push(`| --- | --- | --- | --- | --- |`);\n for (let i = 0; i < maxLen; i += 1) {\n const src = sourceSections[i];\n const tgt = targetSections[i];\n const heading = src?.heading ?? tgt?.heading ?? '';\n const sourceWords = src?.wordCount ?? 0;\n const targetWords = tgt?.wordCount ?? 0;\n let status: 'ok' | 'missing' | 'different';\n if (!tgt) status = 'missing';\n else if (!src) status = 'different';\n else {\n const denom = Math.max(sourceWords, 1);\n const diffRatio = Math.abs(sourceWords - targetWords) / denom;\n status = diffRatio > 0.25 ? 'different' : 'ok';\n }\n rows.push(`| ${i} | ${heading} | ${status} | ${sourceWords} | ${targetWords} |`);\n }\n\n const text = [\n `# Translation diff — Article #${article_id} (${source_locale} → ${target_locale})`,\n '',\n ...rows,\n ].join('\\n');\n return { content: [{ type: 'text', text }] };\n },\n },\n {\n name: 'create_article_attachment',\n namespace: 'help_center',\n readOnly: false,\n title: 'Create Article Attachment',\n description:\n 'Upload an attachment to an article. Provide file content as base64-encoded string.',\n inputSchema: z.object({\n article_id: z.number().int().describe('Article ID'),\n file_name: z.string().min(1).describe('File name (e.g., \"screenshot.png\")'),\n file_base64: z.string().min(1).describe('File content encoded as base64'),\n content_type: z\n .string()\n .default('application/octet-stream')\n .describe('MIME type (e.g., \"image/png\", \"application/pdf\")'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { article_id, file_name, file_base64, content_type } = params as {\n article_id: number;\n file_name: string;\n file_base64: string;\n content_type: string;\n };\n const token = await getToken();\n const buffer = Buffer.from(file_base64, 'base64');\n const blob = new Blob([buffer], { type: content_type });\n const formData = new FormData();\n formData.append('file', blob, file_name);\n const { article_attachment } = await helpCenterUpload<{\n article_attachment: ZendeskArticleAttachment;\n }>(subdomain, token, `/articles/${article_id}/attachments`, formData);\n return {\n content: [\n {\n type: 'text',\n text: `Attachment created for article #${article_id}.\\n\\n${formatAttachment(article_attachment)}`,\n },\n ],\n };\n },\n },\n ];\n};\n","import * as z from 'zod/v4';\nimport { zendeskGet } from '../client/zendesk-api';\nimport { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE } from '../constants';\nimport type { ZendeskListResponse } from '../types';\nimport { truncateIfNeeded } from '../utils/formatting';\nimport { buildOffsetParams, extractSearchPaginationMeta } from '../utils/pagination';\nimport type { ToolContext, ToolDefinition } from './definitions';\n\nconst formatSearchResult = (result: Record<string, unknown>): string => {\n const lines: string[] = [`## [${result['result_type']}] #${result['id']}`];\n if (result['subject']) lines.push(`**Subject**: ${result['subject']}`);\n if (result['name']) lines.push(`**Name**: ${result['name']}`);\n if (result['title']) lines.push(`**Title**: ${result['title']}`);\n if (result['email']) lines.push(`**Email**: ${result['email']}`);\n if (result['status']) lines.push(`**Status**: ${result['status']}`);\n if (result['description']) {\n const desc = String(result['description']);\n lines.push(desc.length > 200 ? `${desc.slice(0, 200)}...` : desc);\n }\n return lines.join('\\n');\n};\n\nexport const createSearchTools = (ctx: ToolContext): ToolDefinition[] => {\n const { subdomain, getToken } = ctx;\n\n return [\n {\n name: 'search',\n namespace: 'tickets',\n readOnly: true,\n title: 'Zendesk Unified Search',\n description:\n 'Search across tickets, users, and organizations. Supports filters like \"type:ticket status:open\", \"type:user role:agent\". Returns total count and paginated results (100 per page). Organization results include name and ID only — use get_organization for full details (tags, domains, details).',\n inputSchema: z.object({\n query: z.string().min(1).describe('Zendesk search query'),\n per_page: z\n .number()\n .int()\n .min(1)\n .max(MAX_PAGE_SIZE)\n .default(DEFAULT_PAGE_SIZE)\n .describe('Results per page (max 100)'),\n page: z.number().int().min(1).default(1).describe('Page number (1-based)'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { query, per_page, page } = params as {\n query: string;\n per_page: number;\n page: number;\n };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<Record<string, unknown>>>(\n subdomain,\n token,\n '/search',\n {\n query,\n ...buildOffsetParams(per_page, page),\n },\n );\n const results = response.results ?? [];\n const meta = extractSearchPaginationMeta(response, per_page, page);\n const header = `Total: ${meta.count} | Page ${page} (${results.length} results)${meta.has_more ? ` | Next page: ${meta.after_cursor}` : ''}`;\n const body = results.map(formatSearchResult).join('\\n\\n');\n return {\n content: [\n { type: 'text', text: truncateIfNeeded([header, body].filter(Boolean).join('\\n\\n')) },\n ],\n };\n },\n },\n ];\n};\n","import * as z from 'zod/v4';\nimport {\n fetchZendeskBinary,\n ZendeskApiError,\n zendeskGet,\n zendeskPost,\n zendeskPut,\n} from '../client/zendesk-api';\nimport {\n DEFAULT_PAGE_SIZE,\n MAX_ATTACHMENT_BYTES,\n MAX_COMMENT_PAGES,\n MAX_EMBEDDED_IMAGE_COUNT,\n MAX_PAGE_SIZE,\n} from '../constants';\nimport type {\n ZendeskComment,\n ZendeskListResponse,\n ZendeskTicket,\n ZendeskTicketAttachment,\n} from '../types';\nimport { formatComment, formatList, formatTicket, truncateIfNeeded } from '../utils/formatting';\nimport {\n buildCursorParams,\n buildOffsetParams,\n extractPaginationMeta,\n extractSearchPaginationMeta,\n} from '../utils/pagination';\nimport type { ToolContext, ToolDefinition, ToolImageContent, ToolTextContent } from './definitions';\n\nconst formatReference = (attachment: ZendeskTicketAttachment): string =>\n `**${attachment.file_name}** (id ${attachment.id}, ${attachment.content_type}, ${attachment.size} bytes) — ${attachment.content_url}`;\n\nconst buildEmbeddedImageBlocks = async (\n subdomain: string,\n token: string,\n attachment: ZendeskTicketAttachment,\n reference: string,\n): Promise<Array<ToolTextContent | ToolImageContent>> => {\n const { data, contentType } = await fetchZendeskBinary(subdomain, token, attachment.content_url);\n return [\n { type: 'image', data: data.toString('base64'), mimeType: contentType },\n { type: 'text', text: reference },\n ];\n};\n\n// Zendesk has no endpoint to list a ticket's attachments directly.\n// Attachments are always attached to comments, so the only way to collect\n// them all is to walk through every comment page and extract their attachments.\nconst fetchAllTicketComments = async (\n subdomain: string,\n token: string,\n ticketId: number,\n): Promise<ZendeskComment[]> => {\n const all: ZendeskComment[] = [];\n let cursor: string | undefined;\n let pages = 0;\n while (pages < MAX_COMMENT_PAGES) {\n const response = await zendeskGet<{\n comments: ZendeskComment[];\n meta?: { has_more: boolean; after_cursor: string };\n }>(subdomain, token, `/tickets/${ticketId}/comments`, buildCursorParams(MAX_PAGE_SIZE, cursor));\n all.push(...response.comments);\n pages += 1;\n if (!response.meta?.has_more || !response.meta?.after_cursor) break;\n cursor = response.meta.after_cursor;\n }\n return all;\n};\n\nconst collectAttachmentBlocks = async (\n subdomain: string,\n token: string,\n attachments: ZendeskTicketAttachment[],\n): Promise<Array<ToolTextContent | ToolImageContent>> => {\n const blocks: Array<ToolTextContent | ToolImageContent> = [];\n let embeddedCount = 0;\n\n for (const attachment of attachments) {\n const reference = formatReference(attachment);\n const isImage = attachment.content_type.startsWith('image/');\n\n if (!isImage) {\n blocks.push({ type: 'text', text: reference });\n continue;\n }\n\n let skipReason: string | null = null;\n if (attachment.size > MAX_ATTACHMENT_BYTES) {\n skipReason = 'skipped: exceeds 5 MB per-image limit';\n } else if (embeddedCount >= MAX_EMBEDDED_IMAGE_COUNT) {\n skipReason = `skipped: max ${MAX_EMBEDDED_IMAGE_COUNT} embedded images reached`;\n }\n\n if (skipReason) {\n blocks.push({ type: 'text', text: `${reference} — ${skipReason}` });\n continue;\n }\n\n try {\n blocks.push(...(await buildEmbeddedImageBlocks(subdomain, token, attachment, reference)));\n embeddedCount += 1;\n } catch (error) {\n const reason =\n error instanceof ZendeskApiError\n ? `download failed: ${error.status} ${error.statusText}`\n : 'download failed';\n blocks.push({ type: 'text', text: `${reference} — ${reason}` });\n }\n }\n\n return blocks;\n};\n\nexport const createTicketTools = (ctx: ToolContext): ToolDefinition[] => {\n const { subdomain, getToken } = ctx;\n\n return [\n {\n name: 'get_ticket',\n namespace: 'tickets',\n readOnly: true,\n title: 'Get Zendesk Ticket',\n description:\n 'Retrieve a Zendesk ticket by ID, including its comments if requested. Returns ticket details (subject, status, priority, assignee, tags, description) and optionally all comments/internal notes.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n include_comments: z.boolean().default(false).describe('Include ticket comments'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, include_comments } = params as {\n ticket_id: number;\n include_comments: boolean;\n };\n const token = await getToken();\n const { ticket } = await zendeskGet<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n `/tickets/${ticket_id}`,\n );\n let text = formatTicket(ticket);\n if (include_comments) {\n const { comments } = await zendeskGet<{ comments: ZendeskComment[] }>(\n subdomain,\n token,\n `/tickets/${ticket_id}/comments`,\n );\n text += `\\n\\n---\\n# Comments\\n\\n${comments.map(formatComment).join('\\n\\n')}`;\n }\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'get_ticket_attachments',\n namespace: 'tickets',\n readOnly: true,\n title: 'Get Zendesk Ticket Attachments',\n description:\n 'Retrieve ticket attachments. Images are embedded inline; other files are listed as text references.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n attachment_ids: z\n .array(z.number().int())\n .optional()\n .describe(\n 'Attachment IDs to fetch directly (e.g. extracted from a previous get_ticket(include_comments=true) call). When provided, skips the comments fetch entirely. When omitted, all attachments of the ticket are returned.',\n ),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, attachment_ids } = params as {\n ticket_id: number;\n attachment_ids?: number[];\n };\n const token = await getToken();\n\n let attachments: ZendeskTicketAttachment[];\n if (attachment_ids && attachment_ids.length > 0) {\n attachments = [];\n for (const id of attachment_ids) {\n try {\n const { attachment } = await zendeskGet<{ attachment: ZendeskTicketAttachment }>(\n subdomain,\n token,\n `/attachments/${id}`,\n );\n attachments.push(attachment);\n } catch (error) {\n if (!(error instanceof ZendeskApiError) || error.status !== 404) throw error;\n }\n }\n } else {\n const comments = await fetchAllTicketComments(subdomain, token, ticket_id);\n attachments = comments.flatMap((c) => c.attachments ?? []);\n }\n\n if (attachments.length === 0) {\n return {\n content: [{ type: 'text', text: `No attachments found on ticket #${ticket_id}.` }],\n };\n }\n const blocks = await collectAttachmentBlocks(subdomain, token, attachments);\n return {\n content: [\n {\n type: 'text',\n text: `# Attachments for ticket #${ticket_id} (${attachments.length} total)`,\n },\n ...blocks,\n ],\n };\n },\n },\n {\n name: 'search_tickets',\n namespace: 'tickets',\n readOnly: true,\n title: 'Search Zendesk Tickets',\n description:\n 'Search tickets using Zendesk query syntax (e.g., \"status:open assignee:me\", \"priority:urgent type:incident\"). Returns total count.',\n inputSchema: z.object({\n query: z.string().min(1).describe('Zendesk search query string'),\n per_page: z\n .number()\n .int()\n .min(1)\n .max(MAX_PAGE_SIZE)\n .default(DEFAULT_PAGE_SIZE)\n .describe('Results per page'),\n page: z.number().int().min(1).default(1).describe('Page number'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { query, per_page, page } = params as {\n query: string;\n per_page: number;\n page: number;\n };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskTicket>>(\n subdomain,\n token,\n '/search',\n {\n query: `type:ticket ${query}`,\n ...buildOffsetParams(per_page, page),\n },\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.results ?? [],\n formatTicket,\n extractSearchPaginationMeta(response, per_page, page),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'create_ticket',\n namespace: 'tickets',\n readOnly: false,\n title: 'Create Zendesk Ticket',\n description:\n 'Create a new Zendesk support ticket with subject, description, and optional priority/type/assignee/tags.',\n inputSchema: z.object({\n subject: z.string().min(1).describe('Ticket subject'),\n description: z.string().min(1).describe('Ticket description'),\n priority: z.enum(['urgent', 'high', 'normal', 'low']).optional(),\n type: z.enum(['problem', 'incident', 'question', 'task']).optional(),\n assignee_id: z.number().int().optional(),\n group_id: z.number().int().optional(),\n tags: z.array(z.string()).optional(),\n custom_fields: z.array(z.object({ id: z.number().int(), value: z.unknown() })).optional(),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { subject, description, ...rest } = params as Record<string, unknown>;\n const token = await getToken();\n const { ticket } = await zendeskPost<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n '/tickets',\n {\n ticket: { subject, comment: { body: description }, ...rest },\n },\n );\n return {\n content: [\n { type: 'text', text: `Ticket #${ticket.id} created.\\n\\n${formatTicket(ticket)}` },\n ],\n };\n },\n },\n {\n name: 'update_ticket',\n namespace: 'tickets',\n readOnly: false,\n title: 'Update Zendesk Ticket',\n description:\n 'Update an existing ticket (status, priority, type, assignee, group, subject, tags, custom fields).',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n status: z.enum(['new', 'open', 'pending', 'hold', 'solved', 'closed']).optional(),\n priority: z.enum(['urgent', 'high', 'normal', 'low']).optional(),\n type: z.enum(['problem', 'incident', 'question', 'task']).optional(),\n assignee_id: z.number().int().optional(),\n group_id: z.number().int().optional(),\n subject: z.string().optional(),\n tags: z.array(z.string()).optional(),\n custom_fields: z.array(z.object({ id: z.number().int(), value: z.unknown() })).optional(),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, ...updates } = params as { ticket_id: number } & Record<string, unknown>;\n const token = await getToken();\n const { ticket } = await zendeskPut<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n `/tickets/${ticket_id}`,\n { ticket: updates },\n );\n return {\n content: [\n { type: 'text', text: `Ticket #${ticket.id} updated.\\n\\n${formatTicket(ticket)}` },\n ],\n };\n },\n },\n {\n name: 'add_private_note',\n namespace: 'tickets',\n readOnly: false,\n title: 'Add Private Note',\n description: 'Add an internal note (not visible to requester) to a ticket.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n body: z.string().min(1).describe('Note content'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, body } = params as { ticket_id: number; body: string };\n const token = await getToken();\n await zendeskPut(subdomain, token, `/tickets/${ticket_id}`, {\n ticket: { comment: { body, public: false } },\n });\n return { content: [{ type: 'text', text: `Private note added to ticket #${ticket_id}.` }] };\n },\n },\n {\n name: 'add_public_comment',\n namespace: 'tickets',\n readOnly: false,\n title: 'Add Public Comment',\n description: 'Add a public comment (visible to requester) to a ticket.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n body: z.string().min(1).describe('Comment content'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, body } = params as { ticket_id: number; body: string };\n const token = await getToken();\n await zendeskPut(subdomain, token, `/tickets/${ticket_id}`, {\n ticket: { comment: { body, public: true } },\n });\n return {\n content: [{ type: 'text', text: `Public comment added to ticket #${ticket_id}.` }],\n };\n },\n },\n {\n name: 'list_tickets',\n namespace: 'tickets',\n readOnly: true,\n title: 'List Zendesk Tickets',\n description: 'List tickets with cursor-based pagination, sorted by most recently updated.',\n inputSchema: z.object({\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional().describe('Pagination cursor'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { page_size, cursor } = params as { page_size: number; cursor?: string };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskTicket>>(\n subdomain,\n token,\n '/tickets',\n buildCursorParams(page_size, cursor),\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.tickets ?? [],\n formatTicket,\n extractPaginationMeta(response),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'get_linked_incidents',\n namespace: 'tickets',\n readOnly: true,\n title: 'Get Linked Incidents',\n description: 'Get all incident tickets linked to a problem ticket.',\n inputSchema: z.object({\n problem_id: z.number().int().describe('Problem ticket ID'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { problem_id } = params as { problem_id: number };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskTicket>>(\n subdomain,\n token,\n `/tickets/${problem_id}/incidents`,\n );\n const incidents = response.tickets ?? [];\n const text =\n incidents.length > 0\n ? `# Incidents linked to problem #${problem_id}\\n\\n${incidents.map(formatTicket).join('\\n\\n')}`\n : `No incidents linked to problem #${problem_id}.`;\n return { content: [{ type: 'text', text: truncateIfNeeded(text) }] };\n },\n },\n {\n name: 'manage_tags',\n namespace: 'tickets',\n readOnly: false,\n title: 'Manage Ticket Tags',\n description: 'Add or remove tags on a ticket.',\n inputSchema: z.object({\n ticket_id: z.number().int().describe('Ticket ID'),\n add: z.array(z.string()).optional().describe('Tags to add'),\n remove: z.array(z.string()).optional().describe('Tags to remove'),\n }),\n annotations: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { ticket_id, add, remove } = params as {\n ticket_id: number;\n add?: string[];\n remove?: string[];\n };\n const token = await getToken();\n const { ticket } = await zendeskGet<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n `/tickets/${ticket_id}`,\n );\n const tags = new Set(ticket.tags);\n add?.forEach((t) => {\n tags.add(t);\n });\n remove?.forEach((t) => {\n tags.delete(t);\n });\n const { ticket: updated } = await zendeskPut<{ ticket: ZendeskTicket }>(\n subdomain,\n token,\n `/tickets/${ticket_id}`,\n { ticket: { tags: [...tags] } },\n );\n return {\n content: [\n {\n type: 'text',\n text: `Tags updated on ticket #${ticket_id}. Current: ${updated.tags.join(', ') || 'none'}`,\n },\n ],\n };\n },\n },\n ];\n};\n","import * as z from 'zod/v4';\nimport { zendeskGet } from '../client/zendesk-api';\nimport { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE } from '../constants';\nimport type { ZendeskListResponse, ZendeskOrganization, ZendeskUser } from '../types';\nimport { formatList, formatOrganization, formatUser } from '../utils/formatting';\nimport {\n buildCursorParams,\n buildOffsetParams,\n extractPaginationMeta,\n extractSearchPaginationMeta,\n} from '../utils/pagination';\nimport type { ToolContext, ToolDefinition } from './definitions';\n\nexport const createUserTools = (ctx: ToolContext): ToolDefinition[] => {\n const { subdomain, getToken } = ctx;\n\n return [\n {\n name: 'get_current_user',\n namespace: 'users',\n readOnly: true,\n title: 'Get Current Zendesk User',\n description:\n 'Get the currently authenticated Zendesk user. Useful to verify identity and permissions.',\n inputSchema: z.object({}),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async () => {\n const token = await getToken();\n const { user } = await zendeskGet<{ user: ZendeskUser }>(subdomain, token, '/users/me');\n return { content: [{ type: 'text', text: formatUser(user) }] };\n },\n },\n {\n name: 'search_users',\n namespace: 'users',\n readOnly: true,\n title: 'Search Zendesk Users',\n description:\n 'Search for users by name, email, or other criteria using Zendesk search query syntax. Returns total count.',\n inputSchema: z.object({\n query: z.string().min(1).describe('Search query'),\n per_page: z\n .number()\n .int()\n .min(1)\n .max(MAX_PAGE_SIZE)\n .default(DEFAULT_PAGE_SIZE)\n .describe('Results per page'),\n page: z.number().int().min(1).default(1).describe('Page number'),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { query, per_page, page } = params as {\n query: string;\n per_page: number;\n page: number;\n };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskUser>>(\n subdomain,\n token,\n '/search',\n {\n query: `type:user ${query}`,\n ...buildOffsetParams(per_page, page),\n },\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.results ?? [],\n formatUser,\n extractSearchPaginationMeta(response, per_page, page),\n ),\n },\n ],\n };\n },\n },\n {\n name: 'get_user',\n namespace: 'users',\n readOnly: true,\n title: 'Get Zendesk User',\n description: 'Retrieve a user by ID.',\n inputSchema: z.object({ user_id: z.number().int().describe('User ID') }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { user_id } = params as { user_id: number };\n const token = await getToken();\n const { user } = await zendeskGet<{ user: ZendeskUser }>(\n subdomain,\n token,\n `/users/${user_id}`,\n );\n return { content: [{ type: 'text', text: formatUser(user) }] };\n },\n },\n {\n name: 'get_organization',\n namespace: 'users',\n readOnly: true,\n title: 'Get Zendesk Organization',\n description: 'Retrieve an organization by ID.',\n inputSchema: z.object({ organization_id: z.number().int().describe('Organization ID') }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { organization_id } = params as { organization_id: number };\n const token = await getToken();\n const { organization } = await zendeskGet<{ organization: ZendeskOrganization }>(\n subdomain,\n token,\n `/organizations/${organization_id}`,\n );\n return { content: [{ type: 'text', text: formatOrganization(organization) }] };\n },\n },\n {\n name: 'list_organizations',\n namespace: 'users',\n readOnly: true,\n title: 'List Zendesk Organizations',\n description: 'List all organizations with pagination.',\n inputSchema: z.object({\n page_size: z.number().int().min(1).max(MAX_PAGE_SIZE).default(DEFAULT_PAGE_SIZE),\n cursor: z.string().optional(),\n }),\n annotations: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: true,\n },\n handler: async (params) => {\n const { page_size, cursor } = params as { page_size: number; cursor?: string };\n const token = await getToken();\n const response = await zendeskGet<ZendeskListResponse<ZendeskOrganization>>(\n subdomain,\n token,\n '/organizations',\n buildCursorParams(page_size, cursor),\n );\n return {\n content: [\n {\n type: 'text',\n text: formatList(\n response.organizations ?? [],\n formatOrganization,\n extractPaginationMeta(response),\n ),\n },\n ],\n };\n },\n },\n ];\n};\n","import type { ToolContext, ToolDefinition } from './definitions';\nimport { createHelpCenterTools } from './help-center';\nimport { createSearchTools } from './search';\nimport { createTicketTools } from './tickets';\nimport { createUserTools } from './users';\n\nexport type { ToolContext, ToolDefinition } from './definitions';\n\nexport const createAllTools = (ctx: ToolContext): ToolDefinition[] => [\n ...createTicketTools(ctx),\n ...createSearchTools(ctx),\n ...createHelpCenterTools(ctx),\n ...createUserTools(ctx),\n];\n","import { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nexport interface PackageInfo {\n name: string;\n version: string;\n}\n\n// Used only if package.json can't be located/parsed (should not happen in a\n// published install). Keeps the server bootable rather than throwing.\nconst FALLBACK: PackageInfo = {\n name: '@fruggr/zendesk-mcp-server',\n version: '0.0.0',\n};\n\n/**\n * Read `name`/`version` from the package's own package.json at runtime instead\n * of hardcoding them. Walks up from this module to the nearest package.json,\n * which resolves correctly both when bundled (`dist/index.js` → repo root) and\n * from source/tests (`src/` has no package.json, so the root is found). Reading\n * at runtime (not inlining at build) matters because semantic-release bumps the\n * version into package.json before publishing, after the build step.\n */\n// package.json can't change during the process lifetime, and createMcpServer\n// (hence this) may run several times (notably across tests) — cache the result.\nlet cached: PackageInfo | undefined;\n\nexport const readPackageInfo = (): PackageInfo => {\n if (cached) return cached;\n // Only readFileSync/JSON.parse can throw here (caught per-iteration below);\n // fileURLToPath/dirname/join don't, so no outer guard is needed.\n let dir = dirname(fileURLToPath(import.meta.url));\n for (let depth = 0; depth < 8; depth++) {\n try {\n // JSON.parse yields `unknown`; validate at runtime rather than asserting.\n const raw: unknown = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));\n if (raw && typeof raw === 'object') {\n const pkg = raw as Partial<PackageInfo>;\n if (typeof pkg.name === 'string' && typeof pkg.version === 'string') {\n cached = { name: pkg.name, version: pkg.version };\n return cached;\n }\n }\n } catch {\n // No readable/valid package.json here — keep walking up.\n }\n const parent = dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n cached = FALLBACK;\n return cached;\n};\n","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport * as z from 'zod/v4';\nimport type { Config } from './config';\nimport { filterTools, groupByNamespace } from './routing/registry';\nimport { createAllTools, type ToolDefinition } from './tools/index';\nimport { type Logger, silentLogger } from './utils/logger';\nimport { readPackageInfo } from './utils/package-info';\n\nconst NAMESPACE_LABELS: Record<string, { toolName: string; title: string }> = {\n tickets: { toolName: 'zendesk_tickets', title: 'Zendesk Tickets' },\n help_center: { toolName: 'zendesk_help_center', title: 'Zendesk Help Center' },\n users: { toolName: 'zendesk_users', title: 'Zendesk Users' },\n};\n\n// Keep proxy descriptions compact: a proxy tool concatenates one line per\n// sub-operation, so only the first sentence of each tool description is\n// included. Clients still receive the full schema via the wrapped tool.\nexport const summarizeDescription = (description: string): string => {\n const idx = description.indexOf('. ');\n if (idx === -1) return description;\n return description.slice(0, idx + 1);\n};\n\nexport const buildOperationList = (\n tools: ReadonlyArray<Pick<ToolDefinition, 'name' | 'description' | 'readOnly'>>,\n): string =>\n tools\n .map(\n (t) =>\n `- **${t.name}**: ${summarizeDescription(t.description)}${t.readOnly ? '' : ' (write)'}`,\n )\n .join('\\n');\n\nconst registerProxyTool = (\n server: McpServer,\n toolName: string,\n title: string,\n tools: ToolDefinition[],\n handlerMap: Map<string, ToolDefinition>,\n): void => {\n const operationNames = tools.map((t) => t.name);\n const operationList = buildOperationList(tools);\n\n server.registerTool(\n toolName,\n {\n title,\n description: `${title}. Specify the operation and its parameters.\\n\\nAvailable operations:\\n${operationList}`,\n inputSchema: z.object({\n operation: z.string().describe(`One of: ${operationNames.join(', ')}`),\n params: z.record(z.string(), z.unknown()).default({}).describe('Operation parameters'),\n }),\n },\n async ({ operation, params }) => {\n const def = handlerMap.get(operation);\n if (!def) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `Unknown operation \"${operation}\". Available: ${operationNames.join(', ')}`,\n },\n ],\n };\n }\n // Validate params through the tool's own schema\n const validated = def.inputSchema.parse(params);\n return def.handler(validated);\n },\n );\n};\n\nexport const createMcpServer = (\n config: Config,\n getToken: () => string | Promise<string>,\n logger: Logger = silentLogger,\n): McpServer => {\n // Read name/version from package.json at runtime rather than hardcoding them\n // (the old literals were stale and even carried the wrong package name).\n const pkg = readPackageInfo();\n const server = new McpServer(\n {\n name: pkg.name,\n version: pkg.version,\n },\n // Advertise the logging capability so structured diagnostics (notably the\n // OAuth browser flow) reach clients that support it. Clients that don't\n // simply ignore the notifications.\n { capabilities: { logging: {} } },\n );\n\n // Route the logger's MCP sink through this server. Auth runs lazily on the\n // first tool call (after connect), so notifications can flow by then.\n logger.attachServer(server);\n\n const allTools = createAllTools({ subdomain: config.subdomain, getToken });\n\n // Apply filters (--read-only, --namespace, --tool)\n const filteredTools = filterTools(allTools, {\n readOnly: config.readOnly,\n namespaces: config.namespaces,\n tools: config.tools,\n });\n\n // Build handler map for proxy dispatch\n const handlerMap = new Map<string, ToolDefinition>();\n for (const tool of filteredTools) {\n handlerMap.set(tool.name, tool);\n }\n\n switch (config.mode) {\n case 'all': {\n // Register each tool individually\n for (const tool of filteredTools) {\n server.registerTool(\n tool.name,\n {\n title: tool.title,\n description: tool.description,\n inputSchema: tool.inputSchema,\n annotations: tool.annotations,\n },\n async (params) => tool.handler(params as Record<string, unknown>),\n );\n }\n break;\n }\n case 'namespace': {\n const grouped = groupByNamespace(filteredTools);\n for (const [namespace, tools] of grouped) {\n const label = NAMESPACE_LABELS[namespace];\n if (label) {\n registerProxyTool(server, label.toolName, label.title, tools, handlerMap);\n }\n }\n break;\n }\n case 'single': {\n registerProxyTool(server, 'zendesk', 'Zendesk', filteredTools, handlerMap);\n break;\n }\n }\n\n logger.info('tools_registered', { count: filteredTools.length, mode: config.mode });\n return server;\n};\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport { type Logger, silentLogger } from '../utils/logger';\n\nexport const startStdioTransport = async (\n server: McpServer,\n logger: Logger = silentLogger,\n): Promise<void> => {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n logger.info('stdio_transport_ready');\n};\n","import { buildBasicAuthHeader } from './auth/api-token';\nimport { createTokenStore } from './auth/token-store';\nimport { loadConfig } from './config';\nimport { createMcpServer } from './server';\nimport { startStdioTransport } from './transports/stdio';\nimport { createLogger } from './utils/logger';\n\nconst main = async (): Promise<void> => {\n const config = loadConfig();\n const logger = createLogger(config.logLevel);\n\n if (config.zendeskEmail && config.zendeskApiToken) {\n // API token mode — static Basic auth\n const staticToken = buildBasicAuthHeader(config.zendeskEmail, config.zendeskApiToken);\n const getToken = () => staticToken;\n const server = createMcpServer(config, getToken, logger);\n await startStdioTransport(server, logger);\n } else {\n // OAuth mode — browser-based auth on first tool call\n const tokenStore = createTokenStore(\n {\n subdomain: config.subdomain,\n oauthClientId: config.oauthClientId,\n },\n logger,\n );\n const server = createMcpServer(config, tokenStore.getToken, logger);\n await startStdioTransport(server, logger);\n }\n};\n\nmain().catch((error) => {\n console.error('Fatal error:', error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAa,wBAAwB,OAAe,aAA6B;CAC/E,MAAM,cAAc,GAAG,MAAM,SAAS;CACtC,OAAO,SAAS,OAAO,KAAK,WAAW,EAAE,SAAS,QAAQ;AAC5D;;;ACkBA,MAAM,WAAqC;CAAE,OAAO;CAAG,MAAM;CAAG,MAAM;CAAG,OAAO;AAAE;AAGlF,MAAM,YAAsE;CAC1E,OAAO;CACP,MAAM;CACN,MAAM;CACN,OAAO;AACT;AAMA,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,eAAe,QACnB,cAAc,IAAI,IAAI,YAAY,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,qBAAqB,OAAO,cAAc,OAAO,eAAe;EACpF,MAAM,iBAAiB;EAEvB,MAAM,oBADS,gBAAgB,QAAQ,UAAU,MAClB,GAAG,MAAM;CAC1C,OAUE,MAAM,oBADS,gBAAgB,QAPZ,iBACjB;EACE,WAAW,OAAO;EAClB,eAAe,OAAO;CACxB,GACA,MAE8C,EAAE,UAAU,MAC7B,GAAG,MAAM;AAE5C;AAEA,KAAK,EAAE,OAAO,UAAU;CACtB,QAAQ,MAAM,gBAAgB,KAAK;CACnC,QAAQ,KAAK,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fruggr/zendesk-mcp-server",
3
- "version": "1.4.0",
4
- "description": "MCP server for Zendesk Support & Help Center APIs with OAuth 2.1 PKCE",
3
+ "version": "1.5.0",
4
+ "description": "Model Context Protocol (MCP) server for the Zendesk Support & Help Center APIs per-user OAuth 2.1 PKCE authentication, read-only mode, and token-efficient section-based article editing.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -18,8 +18,8 @@
18
18
  "dev": "tsx watch src/index.ts",
19
19
  "prepare": "npm run build",
20
20
  "prepublishOnly": "npm run build",
21
- "check": "biome check src/",
22
- "check:fix": "biome check --write src/",
21
+ "check": "biome check --error-on-warnings src/ tests/ scripts/",
22
+ "check:fix": "biome check --write src/ tests/ scripts/",
23
23
  "test": "vitest run",
24
24
  "test:watch": "vitest watch",
25
25
  "test:coverage": "vitest run --coverage",
@@ -28,11 +28,25 @@
28
28
  },
29
29
  "keywords": [
30
30
  "mcp",
31
+ "model-context-protocol",
32
+ "modelcontextprotocol",
33
+ "mcp-server",
31
34
  "zendesk",
35
+ "zendesk-api",
36
+ "zendesk-support",
32
37
  "help-center",
33
- "modelcontextprotocol",
38
+ "knowledge-base",
39
+ "customer-support",
40
+ "customer-service",
41
+ "help-desk",
42
+ "support-tickets",
43
+ "oauth2",
44
+ "pkce",
45
+ "llm",
34
46
  "ai",
35
- "claude"
47
+ "claude",
48
+ "anthropic",
49
+ "cli"
36
50
  ],
37
51
  "author": "Digital4Better <hello@digital4better.com>",
38
52
  "license": "MIT",
@@ -50,7 +64,7 @@
50
64
  "engines": {
51
65
  "node": ">=20"
52
66
  },
53
- "packageManager": "pnpm@11.4.0+sha512.f0febc7e37552ab485494a914241b338e0b3580b93d54ce31f00933015880863129038a1b4ae4e414a0ee63ac35bf21197e990172c4a68256450b5636310968f",
67
+ "packageManager": "pnpm@11.5.0+sha512.dbfcc4f81cf48597afd4bc391ffdf12c11f1a9fb83a395bfa6b0a2d9cc2fd8ffebafdb1ccbd529632153f793904c2615b7f09fe1a345473fd1c35845172a8eb1",
54
68
  "dependencies": {
55
69
  "@modelcontextprotocol/sdk": "1.29.0",
56
70
  "cheerio": "1.2.0",
@@ -69,7 +83,7 @@
69
83
  "zod": "4.4.3"
70
84
  },
71
85
  "devDependencies": {
72
- "@biomejs/biome": "^2.4.7",
86
+ "@biomejs/biome": "2.4.16",
73
87
  "@semantic-release/changelog": "^6.0.3",
74
88
  "@semantic-release/git": "^10.0.1",
75
89
  "@semantic-release/github": "^12.0.6",