@channlize/mcp 0.1.1 → 0.4.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/dist/index.d.mts CHANGED
@@ -1,17 +1,35 @@
1
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
- export { AuthenticationError, ChannlizeConfig, ChannlizeError, ChatMessage, ChatSession, ContactFormData, CreateChatSessionResponse, CreateContactResponse, FileAttachment, RateLimitError, SendMessageResponse, ValidationError } from '@channlize/core';
1
+ import * as node_http from 'node:http';
2
+ import { McpServer } from '@modelcontextprotocol/server';
3
+ export { AuthenticationError, ChannlizeConfig, ChannlizeError, ChatMessage, ChatSession, ContactFormData, CreateChatSessionResponse, CreateContactResponse, FileAttachment, KeyKind, NotifyResponse, RateLimitError, SendMessageResponse, ValidationError, keyKind } from '@channlize/core';
3
4
 
4
5
  /**
5
6
  * MCP-specific types and configuration for Channlize
6
7
  */
7
8
  interface ChannlizeMCPConfig {
8
- /** Channlize API key (widget key) */
9
- apiKey: string;
10
- /** Channlize project ID */
9
+ /**
10
+ * Server API key (`ch_live_…`) for the project, conversation, contact,
11
+ * Events and log tools. A `read`-scoped key exposes the read tools; add
12
+ * the `write` scope to send events and logs and to open conversations.
13
+ */
14
+ serverApiKey?: string;
15
+ /**
16
+ * Public widget key (`wk_…`), only for the visitor-side tools (contact
17
+ * form, chat session). Optional.
18
+ */
19
+ widgetKey?: string;
20
+ /**
21
+ * Either kind of key, detected by its prefix (`wk_` → widget key,
22
+ * otherwise server key). Fills `serverApiKey` / `widgetKey` when unset.
23
+ */
24
+ apiKey?: string;
25
+ /**
26
+ * Project ID for Events, logs and project-scoped reads. Defaults to the
27
+ * first project of the key's organization.
28
+ */
11
29
  projectId?: string;
12
- /** Base URL for Channlize API */
30
+ /** Base URL for the Channlize API (default https://api.channlize.com) */
13
31
  baseUrl?: string;
14
- /** Request timeout in milliseconds */
32
+ /** Request timeout in milliseconds (default 10000) */
15
33
  timeout?: number;
16
34
  }
17
35
  interface MCPServerOptions {
@@ -22,98 +40,85 @@ interface MCPServerOptions {
22
40
  /** Channlize configuration */
23
41
  config?: ChannlizeMCPConfig;
24
42
  }
25
- interface ToolContext {
26
- config: ChannlizeMCPConfig;
27
- }
28
- interface ResourceContext {
29
- config?: ChannlizeMCPConfig;
30
- }
31
43
 
32
- /**
33
- * MCP Resources for Channlize
34
- * Provides read-only context about schemas, API docs, and guides
35
- */
36
- interface Resource {
37
- uri: string;
38
- name: string;
39
- description: string;
40
- mimeType: string;
41
- getText(): string;
44
+ interface HttpServerOptions {
45
+ /** Interface to bind (default 127.0.0.1). */
46
+ host?: string;
47
+ /** Port (default 3333). */
48
+ port?: number;
49
+ /** Endpoint path (default /mcp). */
50
+ path?: string;
42
51
  }
43
- declare function getResource(uri: string): Resource | undefined;
44
- declare function listResources(): Resource[];
45
52
 
53
+ /** A configuration problem the user must fix; the CLI prints it and exits 1. */
54
+ declare class ConfigError extends Error {
55
+ constructor(message: string);
56
+ }
57
+ interface ResolvedConfig {
58
+ serverApiKey?: string;
59
+ widgetKey?: string;
60
+ projectId?: string;
61
+ baseUrl: string;
62
+ timeout: number;
63
+ }
46
64
  /**
47
- * MCP Tools for Channlize
48
- * Wraps ChannlizeClient methods for AI agent interaction
65
+ * Normalizes the config: `apiKey` (either kind, detected by prefix) fills
66
+ * whichever of `serverApiKey` / `widgetKey` is missing, and a key passed in
67
+ * the wrong slot fails with a message that says which one to use.
49
68
  */
50
-
51
- interface ToolDefinition {
52
- name: string;
53
- description: string;
54
- inputSchema: {
55
- type: 'object';
56
- properties: Record<string, any>;
57
- required?: string[];
58
- };
59
- handler: (args: any, context: ToolContext) => Promise<any>;
60
- }
61
- declare function getTool(name: string): ToolDefinition | undefined;
62
- declare function listTools(): ToolDefinition[];
69
+ declare function resolveConfig(config: ChannlizeMCPConfig): ResolvedConfig;
70
+ /** Reads `ChannlizeMCPConfig` from the environment (CLI flags override it). */
71
+ declare function configFromEnv(env?: NodeJS.ProcessEnv): ChannlizeMCPConfig;
63
72
 
64
73
  /**
65
- * MCP Prompts for Channlize
66
- * Templates for common integration patterns and use cases
74
+ * A failed Channlize call, worded for the model: what went wrong and how
75
+ * to fix it (wrong key, missing scope, unknown id). Tool handlers throw it
76
+ * and the MCP server returns it as a tool error (`isError: true`).
67
77
  */
68
- interface PromptDefinition {
69
- name: string;
70
- description: string;
71
- arguments?: Array<{
72
- name: string;
73
- description: string;
74
- required?: boolean;
75
- }>;
76
- getPrompt: (args?: Record<string, string>) => string;
78
+ declare class ToolError extends Error {
79
+ statusCode?: number | undefined;
80
+ code?: string | undefined;
81
+ constructor(message: string, statusCode?: number | undefined, code?: string | undefined);
77
82
  }
78
- declare function getPrompt(name: string): PromptDefinition | undefined;
79
- declare function listPrompts(): PromptDefinition[];
83
+
84
+ declare const VERSION: string;
80
85
 
81
86
  /**
82
- * @channlize/mcp
83
- * Model Context Protocol (MCP) server for Channlize
84
- * Enables AI agents to interact with Channlize platform
87
+ * Builds a configured `McpServer` (tools, resources and prompts) without
88
+ * connecting it. Tools are registered for the keys you pass: server-key
89
+ * tools for `serverApiKey`, visitor tools for `widgetKey`.
85
90
  */
86
-
91
+ declare function buildServer(config: ChannlizeMCPConfig, info?: {
92
+ name?: string;
93
+ version?: string;
94
+ }): McpServer;
87
95
  /**
88
- * Channlize MCP Server
89
- * Provides resources, tools, and prompts for AI agents
96
+ * Channlize MCP server. Validates the configuration on construction (a
97
+ * missing key or a widget key passed as the server key throws
98
+ * `ConfigError`).
90
99
  */
91
100
  declare class ChannlizeMCPServer {
92
101
  private server;
93
- private config?;
102
+ private readonly config;
103
+ private readonly info;
94
104
  constructor(options?: MCPServerOptions);
95
- private setupHandlers;
96
- /**
97
- * Set or update the Channlize configuration
98
- */
99
- setConfig(config: ChannlizeMCPConfig): void;
100
- /**
101
- * Get the underlying MCP server instance
102
- */
103
- getServer(): Server;
104
- /**
105
- * Start the server with stdio transport
106
- */
105
+ /** The underlying `McpServer`. */
106
+ getServer(): McpServer;
107
+ /** Serve over stdio (what desktop and IDE clients launch). */
107
108
  runStdio(): Promise<void>;
108
109
  /**
109
- * Close the server
110
+ * Serve Streamable HTTP at `http://<host>:<port>/mcp` (default
111
+ * 127.0.0.1:3333). Each request gets a fresh server; nothing is shared.
110
112
  */
113
+ runHttp(options?: HttpServerOptions): Promise<{
114
+ url: string;
115
+ server: node_http.Server;
116
+ close: () => Promise<void>;
117
+ }>;
111
118
  close(): Promise<void>;
112
119
  }
113
- /**
114
- * Create and return a new Channlize MCP Server instance
115
- */
120
+ /** Create a new Channlize MCP server. */
116
121
  declare function createMCPServer(options?: MCPServerOptions): ChannlizeMCPServer;
117
122
 
118
- export { ChannlizeMCPServer, createMCPServer, ChannlizeMCPServer as default, getPrompt, getResource, getTool, listPrompts, listResources, listTools };
119
- export type { ChannlizeMCPConfig, MCPServerOptions, ResourceContext, ToolContext };
123
+ export { ChannlizeMCPServer, ConfigError, ToolError, VERSION, buildServer, configFromEnv, createMCPServer, ChannlizeMCPServer as default, resolveConfig };
124
+ export type { ChannlizeMCPConfig, HttpServerOptions, MCPServerOptions, ResolvedConfig };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,35 @@
1
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
- export { AuthenticationError, ChannlizeConfig, ChannlizeError, ChatMessage, ChatSession, ContactFormData, CreateChatSessionResponse, CreateContactResponse, FileAttachment, RateLimitError, SendMessageResponse, ValidationError } from '@channlize/core';
1
+ import * as node_http from 'node:http';
2
+ import { McpServer } from '@modelcontextprotocol/server';
3
+ export { AuthenticationError, ChannlizeConfig, ChannlizeError, ChatMessage, ChatSession, ContactFormData, CreateChatSessionResponse, CreateContactResponse, FileAttachment, KeyKind, NotifyResponse, RateLimitError, SendMessageResponse, ValidationError, keyKind } from '@channlize/core';
3
4
 
4
5
  /**
5
6
  * MCP-specific types and configuration for Channlize
6
7
  */
7
8
  interface ChannlizeMCPConfig {
8
- /** Channlize API key (widget key) */
9
- apiKey: string;
10
- /** Channlize project ID */
9
+ /**
10
+ * Server API key (`ch_live_…`) for the project, conversation, contact,
11
+ * Events and log tools. A `read`-scoped key exposes the read tools; add
12
+ * the `write` scope to send events and logs and to open conversations.
13
+ */
14
+ serverApiKey?: string;
15
+ /**
16
+ * Public widget key (`wk_…`), only for the visitor-side tools (contact
17
+ * form, chat session). Optional.
18
+ */
19
+ widgetKey?: string;
20
+ /**
21
+ * Either kind of key, detected by its prefix (`wk_` → widget key,
22
+ * otherwise server key). Fills `serverApiKey` / `widgetKey` when unset.
23
+ */
24
+ apiKey?: string;
25
+ /**
26
+ * Project ID for Events, logs and project-scoped reads. Defaults to the
27
+ * first project of the key's organization.
28
+ */
11
29
  projectId?: string;
12
- /** Base URL for Channlize API */
30
+ /** Base URL for the Channlize API (default https://api.channlize.com) */
13
31
  baseUrl?: string;
14
- /** Request timeout in milliseconds */
32
+ /** Request timeout in milliseconds (default 10000) */
15
33
  timeout?: number;
16
34
  }
17
35
  interface MCPServerOptions {
@@ -22,98 +40,85 @@ interface MCPServerOptions {
22
40
  /** Channlize configuration */
23
41
  config?: ChannlizeMCPConfig;
24
42
  }
25
- interface ToolContext {
26
- config: ChannlizeMCPConfig;
27
- }
28
- interface ResourceContext {
29
- config?: ChannlizeMCPConfig;
30
- }
31
43
 
32
- /**
33
- * MCP Resources for Channlize
34
- * Provides read-only context about schemas, API docs, and guides
35
- */
36
- interface Resource {
37
- uri: string;
38
- name: string;
39
- description: string;
40
- mimeType: string;
41
- getText(): string;
44
+ interface HttpServerOptions {
45
+ /** Interface to bind (default 127.0.0.1). */
46
+ host?: string;
47
+ /** Port (default 3333). */
48
+ port?: number;
49
+ /** Endpoint path (default /mcp). */
50
+ path?: string;
42
51
  }
43
- declare function getResource(uri: string): Resource | undefined;
44
- declare function listResources(): Resource[];
45
52
 
53
+ /** A configuration problem the user must fix; the CLI prints it and exits 1. */
54
+ declare class ConfigError extends Error {
55
+ constructor(message: string);
56
+ }
57
+ interface ResolvedConfig {
58
+ serverApiKey?: string;
59
+ widgetKey?: string;
60
+ projectId?: string;
61
+ baseUrl: string;
62
+ timeout: number;
63
+ }
46
64
  /**
47
- * MCP Tools for Channlize
48
- * Wraps ChannlizeClient methods for AI agent interaction
65
+ * Normalizes the config: `apiKey` (either kind, detected by prefix) fills
66
+ * whichever of `serverApiKey` / `widgetKey` is missing, and a key passed in
67
+ * the wrong slot fails with a message that says which one to use.
49
68
  */
50
-
51
- interface ToolDefinition {
52
- name: string;
53
- description: string;
54
- inputSchema: {
55
- type: 'object';
56
- properties: Record<string, any>;
57
- required?: string[];
58
- };
59
- handler: (args: any, context: ToolContext) => Promise<any>;
60
- }
61
- declare function getTool(name: string): ToolDefinition | undefined;
62
- declare function listTools(): ToolDefinition[];
69
+ declare function resolveConfig(config: ChannlizeMCPConfig): ResolvedConfig;
70
+ /** Reads `ChannlizeMCPConfig` from the environment (CLI flags override it). */
71
+ declare function configFromEnv(env?: NodeJS.ProcessEnv): ChannlizeMCPConfig;
63
72
 
64
73
  /**
65
- * MCP Prompts for Channlize
66
- * Templates for common integration patterns and use cases
74
+ * A failed Channlize call, worded for the model: what went wrong and how
75
+ * to fix it (wrong key, missing scope, unknown id). Tool handlers throw it
76
+ * and the MCP server returns it as a tool error (`isError: true`).
67
77
  */
68
- interface PromptDefinition {
69
- name: string;
70
- description: string;
71
- arguments?: Array<{
72
- name: string;
73
- description: string;
74
- required?: boolean;
75
- }>;
76
- getPrompt: (args?: Record<string, string>) => string;
78
+ declare class ToolError extends Error {
79
+ statusCode?: number | undefined;
80
+ code?: string | undefined;
81
+ constructor(message: string, statusCode?: number | undefined, code?: string | undefined);
77
82
  }
78
- declare function getPrompt(name: string): PromptDefinition | undefined;
79
- declare function listPrompts(): PromptDefinition[];
83
+
84
+ declare const VERSION: string;
80
85
 
81
86
  /**
82
- * @channlize/mcp
83
- * Model Context Protocol (MCP) server for Channlize
84
- * Enables AI agents to interact with Channlize platform
87
+ * Builds a configured `McpServer` (tools, resources and prompts) without
88
+ * connecting it. Tools are registered for the keys you pass: server-key
89
+ * tools for `serverApiKey`, visitor tools for `widgetKey`.
85
90
  */
86
-
91
+ declare function buildServer(config: ChannlizeMCPConfig, info?: {
92
+ name?: string;
93
+ version?: string;
94
+ }): McpServer;
87
95
  /**
88
- * Channlize MCP Server
89
- * Provides resources, tools, and prompts for AI agents
96
+ * Channlize MCP server. Validates the configuration on construction (a
97
+ * missing key or a widget key passed as the server key throws
98
+ * `ConfigError`).
90
99
  */
91
100
  declare class ChannlizeMCPServer {
92
101
  private server;
93
- private config?;
102
+ private readonly config;
103
+ private readonly info;
94
104
  constructor(options?: MCPServerOptions);
95
- private setupHandlers;
96
- /**
97
- * Set or update the Channlize configuration
98
- */
99
- setConfig(config: ChannlizeMCPConfig): void;
100
- /**
101
- * Get the underlying MCP server instance
102
- */
103
- getServer(): Server;
104
- /**
105
- * Start the server with stdio transport
106
- */
105
+ /** The underlying `McpServer`. */
106
+ getServer(): McpServer;
107
+ /** Serve over stdio (what desktop and IDE clients launch). */
107
108
  runStdio(): Promise<void>;
108
109
  /**
109
- * Close the server
110
+ * Serve Streamable HTTP at `http://<host>:<port>/mcp` (default
111
+ * 127.0.0.1:3333). Each request gets a fresh server; nothing is shared.
110
112
  */
113
+ runHttp(options?: HttpServerOptions): Promise<{
114
+ url: string;
115
+ server: node_http.Server;
116
+ close: () => Promise<void>;
117
+ }>;
111
118
  close(): Promise<void>;
112
119
  }
113
- /**
114
- * Create and return a new Channlize MCP Server instance
115
- */
120
+ /** Create a new Channlize MCP server. */
116
121
  declare function createMCPServer(options?: MCPServerOptions): ChannlizeMCPServer;
117
122
 
118
- export { ChannlizeMCPServer, createMCPServer, ChannlizeMCPServer as default, getPrompt, getResource, getTool, listPrompts, listResources, listTools };
119
- export type { ChannlizeMCPConfig, MCPServerOptions, ResourceContext, ToolContext };
123
+ export { ChannlizeMCPServer, ConfigError, ToolError, VERSION, buildServer, configFromEnv, createMCPServer, ChannlizeMCPServer as default, resolveConfig };
124
+ export type { ChannlizeMCPConfig, HttpServerOptions, MCPServerOptions, ResolvedConfig };