@channlize/mcp 0.4.0 → 0.6.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.
@@ -0,0 +1,194 @@
1
+ import * as z from 'zod/v4';
2
+ import { ChannlizeClient } from '@channlize/core';
3
+
4
+ /**
5
+ * MCP-specific types and configuration for Channlize
6
+ */
7
+ interface ChannlizeMCPConfig {
8
+ /**
9
+ * Server API key (`ch_live_…`) for the project, conversation, contact,
10
+ * Events and log tools. A `read`-scoped key exposes the read tools; add
11
+ * the `write` scope to send events and logs and to open conversations.
12
+ */
13
+ serverApiKey?: string;
14
+ /**
15
+ * Public widget key (`wk_…`), only for the visitor-side tools (contact
16
+ * form, chat session). Optional.
17
+ */
18
+ widgetKey?: string;
19
+ /**
20
+ * Either kind of key, detected by its prefix (`wk_` → widget key,
21
+ * otherwise server key). Fills `serverApiKey` / `widgetKey` when unset.
22
+ */
23
+ apiKey?: string;
24
+ /**
25
+ * Project ID for Events, logs and project-scoped reads. Defaults to the
26
+ * first project of the key's organization.
27
+ */
28
+ projectId?: string;
29
+ /**
30
+ * Channlize for Agents: the agent the agent tools act as when a call
31
+ * doesn't pass `agentId`. Needed with a multi-agent key (unless it lists
32
+ * one agent); an agent key always acts as its own agent.
33
+ */
34
+ agentId?: string;
35
+ /** Base URL for the Channlize API (default https://api.channlize.com) */
36
+ baseUrl?: string;
37
+ /** Request timeout in milliseconds (default 10000) */
38
+ timeout?: number;
39
+ }
40
+ interface MCPServerOptions {
41
+ /** Server name */
42
+ name?: string;
43
+ /** Server version */
44
+ version?: string;
45
+ /** Channlize configuration */
46
+ config?: ChannlizeMCPConfig;
47
+ }
48
+
49
+ /** A configuration problem the user must fix; the CLI prints it and exits 1. */
50
+ declare class ConfigError extends Error {
51
+ constructor(message: string);
52
+ }
53
+ interface ResolvedConfig {
54
+ serverApiKey?: string;
55
+ widgetKey?: string;
56
+ projectId?: string;
57
+ /** Default agent for the agent tools (multi-agent keys). */
58
+ agentId?: string;
59
+ baseUrl: string;
60
+ timeout: number;
61
+ }
62
+ /**
63
+ * Normalizes the config: `apiKey` (either kind, detected by prefix) fills
64
+ * whichever of `serverApiKey` / `widgetKey` is missing, and a key passed in
65
+ * the wrong slot fails with a message that says which one to use.
66
+ */
67
+ declare function resolveConfig(config: ChannlizeMCPConfig): ResolvedConfig;
68
+ /** Reads `ChannlizeMCPConfig` from the environment (CLI flags override it). */
69
+ declare function configFromEnv(env?: NodeJS.ProcessEnv): ChannlizeMCPConfig;
70
+
71
+ type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'DELETE';
72
+ /**
73
+ * A failed Channlize call, worded for the model: what went wrong and how
74
+ * to fix it (wrong key, missing scope, unknown id). Tool handlers throw it
75
+ * and the MCP server returns it as a tool error (`isError: true`).
76
+ */
77
+ declare class ToolError extends Error {
78
+ statusCode?: number | undefined;
79
+ code?: string | undefined;
80
+ /** ISO time the call may succeed again (agent policies, takeovers). */
81
+ retryAt?: string | undefined;
82
+ constructor(message: string, statusCode?: number | undefined, code?: string | undefined,
83
+ /** ISO time the call may succeed again (agent policies, takeovers). */
84
+ retryAt?: string | undefined);
85
+ }
86
+ type Query$1 = Record<string, string | number | boolean | undefined>;
87
+ /** Maps a `@channlize/core` error to a `ToolError` with the same hints. */
88
+ declare function toToolError(err: unknown): ToolError;
89
+ /**
90
+ * Thin client for the API-key endpoints `@channlize/core` doesn't wrap
91
+ * (projects, the inbox, routing rules, contacts, Events and log reads,
92
+ * agents). Widget-key
93
+ * calls and `notify` go through `@channlize/core`.
94
+ */
95
+ declare class ChannlizeApi {
96
+ readonly config: ResolvedConfig;
97
+ private projectIdPromise?;
98
+ private widgetClient?;
99
+ constructor(config: ResolvedConfig);
100
+ get hasServerKey(): boolean;
101
+ get hasWidgetKey(): boolean;
102
+ /** The default agent for the agent tools (`CHANNLIZE_AGENT_ID`). */
103
+ get agentId(): string | undefined;
104
+ private requireServerKey;
105
+ request<T>(method: HttpMethod, path: string, options?: {
106
+ query?: Query$1;
107
+ body?: unknown;
108
+ headers?: Record<string, string>;
109
+ /** Overrides the configured timeout, in ms (long-polls). */
110
+ timeout?: number;
111
+ }): Promise<T>;
112
+ /**
113
+ * `CHANNLIZE_PROJECT_ID`, or the first project of the key's organization
114
+ * (`GET /projects/me`), looked up once.
115
+ */
116
+ projectId(): Promise<string>;
117
+ /** `@channlize/core` client bound to the widget key (visitor tools). */
118
+ widget(): ChannlizeClient;
119
+ /** `@channlize/core` client for `notify` (server key + project). */
120
+ notifier(): Promise<ChannlizeClient>;
121
+ }
122
+
123
+ /**
124
+ * The Channlize inbox toolset: names, zod input/output schemas and handlers
125
+ * for working the inbox through the API-key endpoints under `/v1`.
126
+ *
127
+ * This module has no dependency on the MCP server or its transports, so any
128
+ * agent can import it (`@channlize/mcp/inbox`): the stdio/HTTP server
129
+ * registers these tools (`registerInboxTools` in `tools.ts`), and the
130
+ * dashboard copilot or an internal bot can run the same handlers with its own
131
+ * client (anything with a `request(method, path, { query, body })`).
132
+ *
133
+ * Writes act as a named agent: the API key's name. Replies show in Slack as
134
+ * "Replied by <key name> (agent)", and changes as "… by <key name> (agent)".
135
+ *
136
+ * Scopes (pick them when creating the key): `inbox:read`, `inbox:write`,
137
+ * `routing:write`, `analytics:read`. A `read` key can use the read tools.
138
+ */
139
+
140
+ type Json = Record<string, unknown>;
141
+ type Query = Record<string, string | number | boolean | undefined>;
142
+ /** What a handler needs: `ChannlizeApi` from this package, or your own. */
143
+ interface InboxRequester {
144
+ request<T>(method: HttpMethod, path: string, options?: {
145
+ query?: Query;
146
+ body?: unknown;
147
+ }): Promise<T>;
148
+ }
149
+ /** The API key scope a tool needs. `routing:read` is granted by `routing:write`, `inbox:read` or `read`. */
150
+ type InboxScope = 'inbox:read' | 'inbox:write' | 'routing:read' | 'routing:write' | 'analytics:read';
151
+ interface ToolAnnotations {
152
+ readOnlyHint: boolean;
153
+ destructiveHint: boolean;
154
+ idempotentHint: boolean;
155
+ openWorldHint: boolean;
156
+ }
157
+ interface InboxTool<I extends z.ZodObject = z.ZodObject, O extends z.ZodObject = z.ZodObject> {
158
+ name: string;
159
+ title: string;
160
+ description: string;
161
+ scope: InboxScope;
162
+ /** The HTTP endpoint it calls, for docs and logs. */
163
+ endpoint: string;
164
+ inputSchema: I;
165
+ outputSchema: O;
166
+ annotations: ToolAnnotations;
167
+ handler: (api: InboxRequester, args: z.output<I>) => Promise<z.output<O>>;
168
+ }
169
+ declare const CONVERSATION_STATUSES: readonly ["open", "pending", "resolved", "closed"];
170
+ declare const CONVERSATION_PRIORITIES: readonly ["low", "normal", "high", "urgent"];
171
+ declare const CONVERSATION_SORTS: readonly ["recent", "oldest", "newest", "priority"];
172
+ declare const ROUTING_FIELDS: readonly ["source", "project", "widget", "connection", "page_url", "page_domain", "customer_email", "customer_email_domain", "message", "subject", "tags", "priority", "language"];
173
+ declare const ROUTING_OPERATORS: readonly ["equals", "not_equals", "contains", "not_contains", "starts_with", "ends_with", "matches"];
174
+ declare const INBOX_TOOLS: readonly InboxTool[];
175
+ declare const INBOX_TOOL_NAMES: string[];
176
+ declare function getInboxTool(name: string): InboxTool | undefined;
177
+ /**
178
+ * Validate `args` against the tool's input schema and run it. Throws
179
+ * `ToolError` for an unknown tool or invalid arguments, and for API
180
+ * failures (`toToolError` in `api.ts` words them for the model).
181
+ */
182
+ declare function runInboxTool(api: InboxRequester, name: string, args: unknown): Promise<Json>;
183
+ /**
184
+ * The tools as JSON Schema function definitions, for LLM APIs that take
185
+ * `{ name, description, parameters }` (OpenAI / OpenRouter style).
186
+ */
187
+ declare function inboxToolsAsJsonSchema(filter?: (tool: InboxTool) => boolean): Array<{
188
+ name: string;
189
+ description: string;
190
+ parameters: Json;
191
+ }>;
192
+
193
+ export { ChannlizeApi as C, INBOX_TOOLS as I, ROUTING_FIELDS as R, CONVERSATION_PRIORITIES as b, CONVERSATION_SORTS as c, CONVERSATION_STATUSES as d, ConfigError as e, INBOX_TOOL_NAMES as f, ROUTING_OPERATORS as j, ToolError as l, configFromEnv as m, getInboxTool as n, inboxToolsAsJsonSchema as o, runInboxTool as p, resolveConfig as r, toToolError as t };
194
+ export type { HttpMethod as H, MCPServerOptions as M, ToolAnnotations as T, ChannlizeMCPConfig as a, InboxRequester as g, InboxScope as h, InboxTool as i, ResolvedConfig as k };
@@ -0,0 +1,3 @@
1
+ import 'zod/v4';
2
+ export { b as CONVERSATION_PRIORITIES, c as CONVERSATION_SORTS, d as CONVERSATION_STATUSES, H as HttpMethod, I as INBOX_TOOLS, f as INBOX_TOOL_NAMES, g as InboxRequester, h as InboxScope, i as InboxTool, R as ROUTING_FIELDS, j as ROUTING_OPERATORS, T as ToolAnnotations, n as getInboxTool, o as inboxToolsAsJsonSchema, p as runInboxTool } from './inbox-BfpFVoK7.mjs';
3
+ import '@channlize/core';
@@ -0,0 +1,3 @@
1
+ import 'zod/v4';
2
+ export { b as CONVERSATION_PRIORITIES, c as CONVERSATION_SORTS, d as CONVERSATION_STATUSES, H as HttpMethod, I as INBOX_TOOLS, f as INBOX_TOOL_NAMES, g as InboxRequester, h as InboxScope, i as InboxTool, R as ROUTING_FIELDS, j as ROUTING_OPERATORS, T as ToolAnnotations, n as getInboxTool, o as inboxToolsAsJsonSchema, p as runInboxTool } from './inbox-BfpFVoK7.js';
3
+ import '@channlize/core';