cowork-os 0.3.21 → 0.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +293 -6
  2. package/connectors/README.md +20 -0
  3. package/connectors/asana-mcp/README.md +24 -0
  4. package/connectors/asana-mcp/dist/index.js +427 -0
  5. package/connectors/asana-mcp/package.json +15 -0
  6. package/connectors/asana-mcp/src/index.ts +553 -0
  7. package/connectors/asana-mcp/tsconfig.json +13 -0
  8. package/connectors/hubspot-mcp/README.md +35 -0
  9. package/connectors/hubspot-mcp/dist/index.js +454 -0
  10. package/connectors/hubspot-mcp/package.json +15 -0
  11. package/connectors/hubspot-mcp/src/index.ts +562 -0
  12. package/connectors/hubspot-mcp/tsconfig.json +13 -0
  13. package/connectors/jira-mcp/README.md +49 -0
  14. package/connectors/jira-mcp/dist/index.js +588 -0
  15. package/connectors/jira-mcp/package.json +15 -0
  16. package/connectors/jira-mcp/src/index.ts +711 -0
  17. package/connectors/jira-mcp/tsconfig.json +13 -0
  18. package/connectors/linear-mcp/README.md +22 -0
  19. package/connectors/linear-mcp/dist/index.js +402 -0
  20. package/connectors/linear-mcp/package.json +15 -0
  21. package/connectors/linear-mcp/src/index.ts +522 -0
  22. package/connectors/linear-mcp/tsconfig.json +13 -0
  23. package/connectors/okta-mcp/README.md +24 -0
  24. package/connectors/okta-mcp/dist/index.js +411 -0
  25. package/connectors/okta-mcp/package.json +15 -0
  26. package/connectors/okta-mcp/src/index.ts +520 -0
  27. package/connectors/okta-mcp/tsconfig.json +13 -0
  28. package/connectors/salesforce-mcp/README.md +47 -0
  29. package/connectors/salesforce-mcp/dist/index.js +584 -0
  30. package/connectors/salesforce-mcp/package.json +15 -0
  31. package/connectors/salesforce-mcp/src/index.ts +722 -0
  32. package/connectors/salesforce-mcp/tsconfig.json +13 -0
  33. package/connectors/servicenow-mcp/README.md +26 -0
  34. package/connectors/servicenow-mcp/dist/index.js +400 -0
  35. package/connectors/servicenow-mcp/package.json +15 -0
  36. package/connectors/servicenow-mcp/src/index.ts +500 -0
  37. package/connectors/servicenow-mcp/tsconfig.json +13 -0
  38. package/connectors/templates/mcp-connector/README.md +31 -0
  39. package/connectors/templates/mcp-connector/package.json +15 -0
  40. package/connectors/templates/mcp-connector/src/index.ts +330 -0
  41. package/connectors/templates/mcp-connector/tsconfig.json +13 -0
  42. package/connectors/zendesk-mcp/README.md +40 -0
  43. package/connectors/zendesk-mcp/dist/index.js +431 -0
  44. package/connectors/zendesk-mcp/package.json +15 -0
  45. package/connectors/zendesk-mcp/src/index.ts +543 -0
  46. package/connectors/zendesk-mcp/tsconfig.json +13 -0
  47. package/dist/electron/electron/agent/daemon.js +25 -0
  48. package/dist/electron/electron/agent/executor.js +181 -26
  49. package/dist/electron/electron/agent/llm/anthropic-compatible-provider.js +177 -0
  50. package/dist/electron/electron/agent/llm/github-copilot-provider.js +97 -0
  51. package/dist/electron/electron/agent/llm/groq-provider.js +33 -0
  52. package/dist/electron/electron/agent/llm/index.js +11 -1
  53. package/dist/electron/electron/agent/llm/kimi-provider.js +33 -0
  54. package/dist/electron/electron/agent/llm/openai-compatible-provider.js +116 -0
  55. package/dist/electron/electron/agent/llm/openai-compatible.js +111 -0
  56. package/dist/electron/electron/agent/llm/openai-oauth.js +2 -1
  57. package/dist/electron/electron/agent/llm/openrouter-provider.js +1 -1
  58. package/dist/electron/electron/agent/llm/provider-factory.js +318 -4
  59. package/dist/electron/electron/agent/llm/types.js +66 -1
  60. package/dist/electron/electron/agent/llm/xai-provider.js +33 -0
  61. package/dist/electron/electron/agent/tools/box-tools.js +231 -0
  62. package/dist/electron/electron/agent/tools/builtin-settings.js +28 -0
  63. package/dist/electron/electron/agent/tools/dropbox-tools.js +237 -0
  64. package/dist/electron/electron/agent/tools/google-drive-tools.js +227 -0
  65. package/dist/electron/electron/agent/tools/notion-tools.js +312 -0
  66. package/dist/electron/electron/agent/tools/onedrive-tools.js +217 -0
  67. package/dist/electron/electron/agent/tools/registry.js +541 -0
  68. package/dist/electron/electron/agent/tools/sharepoint-tools.js +243 -0
  69. package/dist/electron/electron/agent/tools/shell-tools.js +12 -3
  70. package/dist/electron/electron/agent/tools/x-tools.js +1 -1
  71. package/dist/electron/electron/gateway/index.js +1 -0
  72. package/dist/electron/electron/gateway/router.js +123 -143
  73. package/dist/electron/electron/ipc/canvas-handlers.js +5 -0
  74. package/dist/electron/electron/ipc/handlers.js +627 -158
  75. package/dist/electron/electron/main.js +63 -0
  76. package/dist/electron/electron/mcp/oauth/connector-oauth.js +333 -0
  77. package/dist/electron/electron/mcp/registry/MCPRegistryManager.js +503 -154
  78. package/dist/electron/electron/memory/MemoryService.js +1 -1
  79. package/dist/electron/electron/preload.js +74 -1
  80. package/dist/electron/electron/settings/box-manager.js +54 -0
  81. package/dist/electron/electron/settings/dropbox-manager.js +54 -0
  82. package/dist/electron/electron/settings/google-drive-manager.js +54 -0
  83. package/dist/electron/electron/settings/notion-manager.js +56 -0
  84. package/dist/electron/electron/settings/onedrive-manager.js +54 -0
  85. package/dist/electron/electron/settings/sharepoint-manager.js +54 -0
  86. package/dist/electron/electron/utils/box-api.js +153 -0
  87. package/dist/electron/electron/utils/dropbox-api.js +144 -0
  88. package/dist/electron/electron/utils/env-migration.js +19 -0
  89. package/dist/electron/electron/utils/google-drive-api.js +152 -0
  90. package/dist/electron/electron/utils/notion-api.js +103 -0
  91. package/dist/electron/electron/utils/onedrive-api.js +113 -0
  92. package/dist/electron/electron/utils/sharepoint-api.js +109 -0
  93. package/dist/electron/electron/utils/validation.js +82 -3
  94. package/dist/electron/electron/utils/x-cli.js +1 -1
  95. package/dist/electron/shared/channelMessages.js +284 -3
  96. package/dist/electron/shared/llm-provider-catalog.js +198 -0
  97. package/dist/electron/shared/types.js +88 -1
  98. package/package.json +12 -2
  99. package/src/electron/agent/executor.ts +205 -28
  100. package/src/electron/agent/llm/anthropic-compatible-provider.ts +214 -0
  101. package/src/electron/agent/llm/github-copilot-provider.ts +117 -0
  102. package/src/electron/agent/llm/groq-provider.ts +39 -0
  103. package/src/electron/agent/llm/index.ts +5 -0
  104. package/src/electron/agent/llm/kimi-provider.ts +39 -0
  105. package/src/electron/agent/llm/openai-compatible-provider.ts +153 -0
  106. package/src/electron/agent/llm/openai-compatible.ts +133 -0
  107. package/src/electron/agent/llm/openai-oauth.ts +2 -1
  108. package/src/electron/agent/llm/openrouter-provider.ts +2 -1
  109. package/src/electron/agent/llm/provider-factory.ts +414 -6
  110. package/src/electron/agent/llm/types.ts +90 -1
  111. package/src/electron/agent/llm/xai-provider.ts +39 -0
  112. package/src/electron/agent/tools/box-tools.ts +239 -0
  113. package/src/electron/agent/tools/builtin-settings.ts +34 -0
  114. package/src/electron/agent/tools/dropbox-tools.ts +237 -0
  115. package/src/electron/agent/tools/google-drive-tools.ts +228 -0
  116. package/src/electron/agent/tools/notion-tools.ts +330 -0
  117. package/src/electron/agent/tools/onedrive-tools.ts +217 -0
  118. package/src/electron/agent/tools/registry.ts +565 -0
  119. package/src/electron/agent/tools/sharepoint-tools.ts +247 -0
  120. package/src/electron/agent/tools/shell-tools.ts +11 -3
  121. package/src/electron/agent/tools/x-tools.ts +1 -1
  122. package/src/electron/database/SecureSettingsRepository.ts +7 -1
  123. package/src/electron/gateway/index.ts +1 -0
  124. package/src/electron/gateway/router.ts +134 -149
  125. package/src/electron/ipc/canvas-handlers.ts +10 -0
  126. package/src/electron/ipc/handlers.ts +673 -153
  127. package/src/electron/main.ts +35 -0
  128. package/src/electron/mcp/oauth/connector-oauth.ts +448 -0
  129. package/src/electron/mcp/registry/MCPRegistryManager.ts +343 -12
  130. package/src/electron/memory/MemoryService.ts +5 -1
  131. package/src/electron/preload.ts +167 -4
  132. package/src/electron/settings/box-manager.ts +58 -0
  133. package/src/electron/settings/dropbox-manager.ts +58 -0
  134. package/src/electron/settings/google-drive-manager.ts +58 -0
  135. package/src/electron/settings/notion-manager.ts +60 -0
  136. package/src/electron/settings/onedrive-manager.ts +58 -0
  137. package/src/electron/settings/sharepoint-manager.ts +58 -0
  138. package/src/electron/utils/box-api.ts +184 -0
  139. package/src/electron/utils/dropbox-api.ts +171 -0
  140. package/src/electron/utils/env-migration.ts +22 -0
  141. package/src/electron/utils/google-drive-api.ts +183 -0
  142. package/src/electron/utils/notion-api.ts +126 -0
  143. package/src/electron/utils/onedrive-api.ts +137 -0
  144. package/src/electron/utils/sharepoint-api.ts +132 -0
  145. package/src/electron/utils/validation.ts +102 -1
  146. package/src/electron/utils/x-cli.ts +1 -1
  147. package/src/renderer/App.tsx +20 -2
  148. package/src/renderer/components/BoxSettings.tsx +203 -0
  149. package/src/renderer/components/BrowserView.tsx +101 -0
  150. package/src/renderer/components/BuiltinToolsSettings.tsx +105 -0
  151. package/src/renderer/components/CanvasPreview.tsx +68 -1
  152. package/src/renderer/components/ConnectorEnvModal.tsx +116 -0
  153. package/src/renderer/components/ConnectorSetupModal.tsx +566 -0
  154. package/src/renderer/components/ConnectorsSettings.tsx +397 -0
  155. package/src/renderer/components/DropboxSettings.tsx +202 -0
  156. package/src/renderer/components/GoogleDriveSettings.tsx +201 -0
  157. package/src/renderer/components/MCPSettings.tsx +56 -0
  158. package/src/renderer/components/MainContent.tsx +270 -34
  159. package/src/renderer/components/NotionSettings.tsx +231 -0
  160. package/src/renderer/components/Onboarding/Onboarding.tsx +13 -1
  161. package/src/renderer/components/OnboardingModal.tsx +70 -1
  162. package/src/renderer/components/OneDriveSettings.tsx +212 -0
  163. package/src/renderer/components/Settings.tsx +611 -8
  164. package/src/renderer/components/SharePointSettings.tsx +224 -0
  165. package/src/renderer/components/Sidebar.tsx +25 -9
  166. package/src/renderer/hooks/useOnboardingFlow.ts +21 -0
  167. package/src/renderer/styles/index.css +438 -25
  168. package/src/shared/channelMessages.ts +367 -4
  169. package/src/shared/llm-provider-catalog.ts +217 -0
  170. package/src/shared/types.ts +226 -1
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "rootDir": "src",
6
+ "outDir": "dist",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "lib": ["ES2020", "DOM"]
11
+ },
12
+ "include": ["src"]
13
+ }
@@ -0,0 +1,26 @@
1
+ # ServiceNow MCP Connector (MVP)
2
+
3
+ This connector exposes ServiceNow Table API endpoints to CoWork OS through MCP tools.
4
+
5
+ ## Requirements
6
+
7
+ Provide credentials via environment variables:
8
+
9
+ - `SERVICENOW_INSTANCE_URL` (e.g., `https://dev12345.service-now.com`) OR `SERVICENOW_INSTANCE` (subdomain only)
10
+ - `SERVICENOW_USERNAME` + `SERVICENOW_PASSWORD` (basic auth) OR `SERVICENOW_ACCESS_TOKEN` (bearer)
11
+
12
+ ## Build & Run
13
+
14
+ ```bash
15
+ npm install
16
+ npm run build
17
+ npm start
18
+ ```
19
+
20
+ ## Tools
21
+
22
+ - `servicenow.health`
23
+ - `servicenow.list_records`
24
+ - `servicenow.get_record`
25
+ - `servicenow.create_record`
26
+ - `servicenow.update_record`
@@ -0,0 +1,400 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const readline = __importStar(require("readline"));
37
+ const PROTOCOL_VERSION = '2024-11-05';
38
+ const MCP_METHODS = {
39
+ INITIALIZE: 'initialize',
40
+ INITIALIZED: 'notifications/initialized',
41
+ SHUTDOWN: 'shutdown',
42
+ TOOLS_LIST: 'tools/list',
43
+ TOOLS_CALL: 'tools/call',
44
+ };
45
+ const MCP_ERROR_CODES = {
46
+ PARSE_ERROR: -32700,
47
+ INVALID_REQUEST: -32600,
48
+ METHOD_NOT_FOUND: -32601,
49
+ INVALID_PARAMS: -32602,
50
+ INTERNAL_ERROR: -32603,
51
+ SERVER_NOT_INITIALIZED: -32002,
52
+ };
53
+ class ServiceNowClient {
54
+ constructor(config) {
55
+ this.config = config;
56
+ }
57
+ async health() {
58
+ return this.requestJson('GET', 'table/sys_user?sysparm_limit=1');
59
+ }
60
+ async listRecords(table, query, limit, offset, fields) {
61
+ const params = new URLSearchParams();
62
+ if (query)
63
+ params.set('sysparm_query', query);
64
+ if (limit !== undefined)
65
+ params.set('sysparm_limit', String(limit));
66
+ if (offset !== undefined)
67
+ params.set('sysparm_offset', String(offset));
68
+ if (fields && fields.length > 0)
69
+ params.set('sysparm_fields', fields.join(','));
70
+ const queryString = params.toString();
71
+ return this.requestJson('GET', `table/${encodeURIComponent(table)}${queryString ? `?${queryString}` : ''}`);
72
+ }
73
+ async getRecord(table, sysId, fields) {
74
+ const params = new URLSearchParams();
75
+ if (fields && fields.length > 0)
76
+ params.set('sysparm_fields', fields.join(','));
77
+ const queryString = params.toString();
78
+ return this.requestJson('GET', `table/${encodeURIComponent(table)}/${encodeURIComponent(sysId)}${queryString ? `?${queryString}` : ''}`);
79
+ }
80
+ async createRecord(table, fields) {
81
+ return this.requestJson('POST', `table/${encodeURIComponent(table)}`, fields);
82
+ }
83
+ async updateRecord(table, sysId, fields) {
84
+ return this.requestJson('PATCH', `table/${encodeURIComponent(table)}/${encodeURIComponent(sysId)}`, fields);
85
+ }
86
+ getBaseUrl() {
87
+ if (this.config.instanceUrl) {
88
+ return this.config.instanceUrl.replace(/\/$/, '');
89
+ }
90
+ if (this.config.instance) {
91
+ return `https://${this.config.instance}.service-now.com`;
92
+ }
93
+ throw new Error('SERVICENOW_INSTANCE_URL or SERVICENOW_INSTANCE is required');
94
+ }
95
+ getAuthHeader() {
96
+ if (this.config.accessToken) {
97
+ return `Bearer ${this.config.accessToken}`;
98
+ }
99
+ if (this.config.username && this.config.password) {
100
+ const basic = Buffer.from(`${this.config.username}:${this.config.password}`).toString('base64');
101
+ return `Basic ${basic}`;
102
+ }
103
+ throw new Error('Missing ServiceNow credentials');
104
+ }
105
+ async requestJson(method, path, body) {
106
+ const start = Date.now();
107
+ const url = `${this.getBaseUrl()}/api/now/${path.replace(/^\//, '')}`;
108
+ const res = await fetch(url, {
109
+ method,
110
+ headers: {
111
+ Authorization: this.getAuthHeader(),
112
+ 'Content-Type': 'application/json',
113
+ 'User-Agent': 'CoWork-ServiceNow-Connector/0.1.0',
114
+ },
115
+ body: body ? JSON.stringify(body) : undefined,
116
+ });
117
+ const durationMs = Date.now() - start;
118
+ const vendorRequestId = res.headers.get('x-request-id') || undefined;
119
+ if (!res.ok) {
120
+ const message = await res.text();
121
+ throw new Error(message || `ServiceNow API error (${res.status})`);
122
+ }
123
+ let data = null;
124
+ if (res.status !== 204) {
125
+ data = await res.json();
126
+ }
127
+ return {
128
+ data,
129
+ meta: {
130
+ durationMs,
131
+ vendorRequestId,
132
+ baseUrl: this.getBaseUrl(),
133
+ },
134
+ };
135
+ }
136
+ }
137
+ class StdioMCPServer {
138
+ constructor(toolProvider, serverInfo) {
139
+ this.toolProvider = toolProvider;
140
+ this.serverInfo = serverInfo;
141
+ this.initialized = false;
142
+ this.rl = null;
143
+ }
144
+ start() {
145
+ this.rl = readline.createInterface({
146
+ input: process.stdin,
147
+ output: process.stdout,
148
+ terminal: false,
149
+ });
150
+ this.rl.on('line', (line) => this.handleLine(line));
151
+ this.rl.on('close', () => this.stop());
152
+ process.on('SIGINT', () => this.stop());
153
+ process.on('SIGTERM', () => this.stop());
154
+ }
155
+ stop() {
156
+ if (this.rl) {
157
+ this.rl.close();
158
+ this.rl = null;
159
+ }
160
+ process.exit(0);
161
+ }
162
+ handleLine(line) {
163
+ const trimmed = line.trim();
164
+ if (!trimmed)
165
+ return;
166
+ try {
167
+ const message = JSON.parse(trimmed);
168
+ this.handleMessage(message);
169
+ }
170
+ catch {
171
+ this.sendError(0, MCP_ERROR_CODES.PARSE_ERROR, 'Parse error');
172
+ }
173
+ }
174
+ async handleMessage(message) {
175
+ if ('id' in message && message.id !== null) {
176
+ await this.handleRequest(message);
177
+ return;
178
+ }
179
+ if ('method' in message) {
180
+ await this.handleNotification(message);
181
+ }
182
+ }
183
+ async handleRequest(request) {
184
+ const { id, method, params } = request;
185
+ try {
186
+ let result;
187
+ switch (method) {
188
+ case MCP_METHODS.INITIALIZE:
189
+ result = this.handleInitialize(params);
190
+ break;
191
+ case MCP_METHODS.TOOLS_LIST:
192
+ this.requireInitialized();
193
+ result = this.handleToolsList();
194
+ break;
195
+ case MCP_METHODS.TOOLS_CALL:
196
+ this.requireInitialized();
197
+ result = await this.handleToolsCall(params);
198
+ break;
199
+ case MCP_METHODS.SHUTDOWN:
200
+ result = this.handleShutdown();
201
+ break;
202
+ default:
203
+ throw this.createError(MCP_ERROR_CODES.METHOD_NOT_FOUND, `Method not found: ${method}`);
204
+ }
205
+ this.sendResult(id, result);
206
+ }
207
+ catch (error) {
208
+ if (error.code !== undefined) {
209
+ this.sendError(id, error.code, error.message, error.data);
210
+ }
211
+ else {
212
+ this.sendError(id, MCP_ERROR_CODES.INTERNAL_ERROR, error?.message || 'Internal error');
213
+ }
214
+ }
215
+ }
216
+ async handleNotification(notification) {
217
+ const { method } = notification;
218
+ if (method === MCP_METHODS.INITIALIZED) {
219
+ this.initialized = true;
220
+ }
221
+ }
222
+ handleInitialize(_params) {
223
+ if (this.initialized) {
224
+ throw this.createError(MCP_ERROR_CODES.INVALID_REQUEST, 'Already initialized');
225
+ }
226
+ return {
227
+ protocolVersion: PROTOCOL_VERSION,
228
+ capabilities: this.serverInfo.capabilities,
229
+ serverInfo: this.serverInfo,
230
+ };
231
+ }
232
+ handleToolsList() {
233
+ return { tools: this.toolProvider.getTools() };
234
+ }
235
+ async handleToolsCall(params) {
236
+ const { name, arguments: args } = params || {};
237
+ if (!name) {
238
+ throw this.createError(MCP_ERROR_CODES.INVALID_PARAMS, 'Tool name is required');
239
+ }
240
+ try {
241
+ const result = await this.toolProvider.executeTool(name, args || {});
242
+ if (typeof result === 'string') {
243
+ return { content: [{ type: 'text', text: result }] };
244
+ }
245
+ if (result && typeof result === 'object') {
246
+ if (result.content && Array.isArray(result.content)) {
247
+ return result;
248
+ }
249
+ return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
250
+ }
251
+ return { content: [{ type: 'text', text: String(result) }] };
252
+ }
253
+ catch (error) {
254
+ return {
255
+ content: [{ type: 'text', text: `Error: ${error?.message || 'Tool failed'}` }],
256
+ isError: true,
257
+ };
258
+ }
259
+ }
260
+ handleShutdown() {
261
+ setImmediate(() => this.stop());
262
+ return {};
263
+ }
264
+ sendResult(id, result) {
265
+ const response = { jsonrpc: '2.0', id, result };
266
+ this.sendMessage(response);
267
+ }
268
+ sendError(id, code, message, data) {
269
+ const response = {
270
+ jsonrpc: '2.0',
271
+ id,
272
+ error: { code, message, data },
273
+ };
274
+ this.sendMessage(response);
275
+ }
276
+ sendMessage(message) {
277
+ process.stdout.write(JSON.stringify(message) + '\n');
278
+ }
279
+ requireInitialized() {
280
+ if (!this.initialized) {
281
+ throw this.createError(MCP_ERROR_CODES.SERVER_NOT_INITIALIZED, 'Server not initialized');
282
+ }
283
+ }
284
+ createError(code, message, data) {
285
+ return { code, message, data };
286
+ }
287
+ }
288
+ // ==================== Tool Definitions ====================
289
+ const CONNECTOR_PREFIX = 'servicenow';
290
+ const config = {
291
+ instanceUrl: process.env.SERVICENOW_INSTANCE_URL,
292
+ instance: process.env.SERVICENOW_INSTANCE,
293
+ username: process.env.SERVICENOW_USERNAME,
294
+ password: process.env.SERVICENOW_PASSWORD,
295
+ accessToken: process.env.SERVICENOW_ACCESS_TOKEN,
296
+ };
297
+ const client = new ServiceNowClient(config);
298
+ const tools = [
299
+ {
300
+ name: `${CONNECTOR_PREFIX}.health`,
301
+ description: 'Check connector health and authentication status',
302
+ inputSchema: { type: 'object', properties: {}, additionalProperties: false },
303
+ },
304
+ {
305
+ name: `${CONNECTOR_PREFIX}.list_records`,
306
+ description: 'List records from a ServiceNow table',
307
+ inputSchema: {
308
+ type: 'object',
309
+ properties: {
310
+ table: { type: 'string', description: 'Table name (e.g., incident)' },
311
+ query: { type: 'string', description: 'sysparm_query string' },
312
+ limit: { type: 'number', description: 'Max records to return' },
313
+ offset: { type: 'number', description: 'Offset for pagination' },
314
+ fields: { type: 'array', description: 'Fields to return', items: { type: 'string' } },
315
+ },
316
+ required: ['table'],
317
+ additionalProperties: false,
318
+ },
319
+ },
320
+ {
321
+ name: `${CONNECTOR_PREFIX}.get_record`,
322
+ description: 'Fetch a record by sys_id',
323
+ inputSchema: {
324
+ type: 'object',
325
+ properties: {
326
+ table: { type: 'string', description: 'Table name (e.g., incident)' },
327
+ sysId: { type: 'string', description: 'sys_id of the record' },
328
+ fields: { type: 'array', description: 'Fields to return', items: { type: 'string' } },
329
+ },
330
+ required: ['table', 'sysId'],
331
+ additionalProperties: false,
332
+ },
333
+ },
334
+ {
335
+ name: `${CONNECTOR_PREFIX}.create_record`,
336
+ description: 'Create a record in a table',
337
+ inputSchema: {
338
+ type: 'object',
339
+ properties: {
340
+ table: { type: 'string', description: 'Table name (e.g., incident)' },
341
+ fields: { type: 'object', description: 'Field map for creation' },
342
+ },
343
+ required: ['table', 'fields'],
344
+ additionalProperties: false,
345
+ },
346
+ },
347
+ {
348
+ name: `${CONNECTOR_PREFIX}.update_record`,
349
+ description: 'Update a record in a table',
350
+ inputSchema: {
351
+ type: 'object',
352
+ properties: {
353
+ table: { type: 'string', description: 'Table name (e.g., incident)' },
354
+ sysId: { type: 'string', description: 'sys_id of the record' },
355
+ fields: { type: 'object', description: 'Field map for update' },
356
+ },
357
+ required: ['table', 'sysId', 'fields'],
358
+ additionalProperties: false,
359
+ },
360
+ },
361
+ ];
362
+ const handlers = {
363
+ [`${CONNECTOR_PREFIX}.health`]: async () => buildEnvelope(await client.health()),
364
+ [`${CONNECTOR_PREFIX}.list_records`]: async (args) => buildEnvelope(await client.listRecords(args.table, args.query, args.limit, args.offset, args.fields)),
365
+ [`${CONNECTOR_PREFIX}.get_record`]: async (args) => buildEnvelope(await client.getRecord(args.table, args.sysId, args.fields)),
366
+ [`${CONNECTOR_PREFIX}.create_record`]: async (args) => buildEnvelope(await client.createRecord(args.table, args.fields || {})),
367
+ [`${CONNECTOR_PREFIX}.update_record`]: async (args) => buildEnvelope(await client.updateRecord(args.table, args.sysId, args.fields || {})),
368
+ };
369
+ const toolProvider = {
370
+ getTools: () => tools,
371
+ executeTool: async (name, args) => {
372
+ const handler = handlers[name];
373
+ if (!handler) {
374
+ throw new Error(`Unknown tool: ${name}`);
375
+ }
376
+ return handler(args);
377
+ },
378
+ };
379
+ const serverInfo = {
380
+ name: 'ServiceNow Connector',
381
+ version: '0.1.0',
382
+ protocolVersion: PROTOCOL_VERSION,
383
+ capabilities: {
384
+ tools: { listChanged: false },
385
+ },
386
+ };
387
+ const server = new StdioMCPServer(toolProvider, serverInfo);
388
+ server.start();
389
+ function buildEnvelope(result) {
390
+ return {
391
+ ok: true,
392
+ data: result.data,
393
+ meta: {
394
+ durationMs: result.meta.durationMs,
395
+ vendorRequestId: result.meta.vendorRequestId,
396
+ baseUrl: result.meta.baseUrl,
397
+ },
398
+ warnings: [],
399
+ };
400
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "cowork-servicenow-mcp",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "commonjs",
6
+ "main": "dist/index.js",
7
+ "scripts": {
8
+ "build": "tsc -p tsconfig.json",
9
+ "start": "node dist/index.js"
10
+ },
11
+ "devDependencies": {
12
+ "@types/node": "^20.11.30",
13
+ "typescript": "^5.7.3"
14
+ }
15
+ }