@teamnetwork-nz/teamlink-mcp-server 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/env.js ADDED
@@ -0,0 +1,7 @@
1
+ export function parsePositiveInt(name, raw, fallback, maximum) {
2
+ const value = raw === undefined || raw === '' ? fallback : Number(raw);
3
+ if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
4
+ throw new Error(`${name} must be a positive integer no greater than ${maximum}`);
5
+ }
6
+ return value;
7
+ }
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import 'dotenv/config';
2
+ import dotenv from 'dotenv';
3
3
  import { readFileSync } from 'node:fs';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { dirname, join } from 'node:path';
@@ -8,6 +8,8 @@ import { z } from 'zod';
8
8
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
9
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
10
10
  import { createHttpServer } from './http-server.js';
11
+ import { parsePositiveInt } from './env.js';
12
+ dotenv.config({ quiet: true });
11
13
  const __dirname = dirname(fileURLToPath(import.meta.url));
12
14
  function pkgVersion() {
13
15
  try {
@@ -26,14 +28,24 @@ function pkgVersion() {
26
28
  * - TEAMLINK_API_BASE (default http://localhost:3100)
27
29
  * - TEAMLINK_API_KEY the staff-allocated CSCApiKey used for all calls
28
30
  */
29
- const API_BASE = (process.env.TEAMLINK_API_BASE ?? 'http://localhost:3100').replace(/\/$/, '');
30
- const API_KEY = process.env.TEAMLINK_API_KEY ?? '';
31
+ export const TeamlinkConfigSchema = z.object({
32
+ apiBase: z.string().url(),
33
+ apiKey: z.string().min(1, 'TEAMLINK_API_KEY is required'),
34
+ readWrite: z.boolean(),
35
+ }).strict();
31
36
  /**
32
37
  * Write-tool gate. Defaults to false (non-destructive/read-only) so this server
33
38
  * is safe to point at production unless explicitly opted in. Accepts common
34
- * truthy strings; anything else (including unset) is treated as false.
39
+ * only the case-insensitive value "true" enables writes.
35
40
  */
36
- const READWRITE = /^(1|true|yes|on)$/i.test(process.env.TEAMLINK_READWRITE ?? '');
41
+ const teamlinkConfig = TeamlinkConfigSchema.parse({
42
+ apiBase: (process.env.TEAMLINK_API_BASE ?? 'http://localhost:3100').replace(/\/$/, ''),
43
+ apiKey: process.env.TEAMLINK_API_KEY ?? '',
44
+ readWrite: (process.env.TEAMLINK_READWRITE ?? '').toLowerCase() === 'true',
45
+ });
46
+ const API_BASE = teamlinkConfig.apiBase;
47
+ const API_KEY = teamlinkConfig.apiKey;
48
+ const READWRITE = teamlinkConfig.readWrite;
37
49
  const http = axios.create({
38
50
  baseURL: API_BASE,
39
51
  timeout: 20_000,
@@ -83,6 +95,8 @@ async function get(path, params) {
83
95
  }
84
96
  }
85
97
  async function post(path, body) {
98
+ if (!READWRITE)
99
+ return usageError('Write operations are disabled. Set TEAMLINK_READWRITE=true to enable them.');
86
100
  try {
87
101
  const r = await http.post(path, body);
88
102
  return ok(r.data);
@@ -92,6 +106,8 @@ async function post(path, body) {
92
106
  }
93
107
  }
94
108
  async function put(path, body) {
109
+ if (!READWRITE)
110
+ return usageError('Write operations are disabled. Set TEAMLINK_READWRITE=true to enable them.');
95
111
  try {
96
112
  const r = await http.put(path, body);
97
113
  return ok(r.data);
@@ -313,27 +329,29 @@ strictTool('product_search', 'Search the read-only product catalog. `q` splits o
313
329
  page: z.number().optional(), pageSize: z.number().optional(),
314
330
  }, async (args) => get('/orders/products/search', args));
315
331
  function createConfiguredServer() {
316
- const server = new McpServer({ name: 'teamlink-mcp', version: pkgVersion() });
332
+ const server = new McpServer({ name: '@teamnetwork-nz/teamlink-mcp-server', version: pkgVersion() }, {
333
+ instructions: 'TEAMlink business operations MCP server supporting stdio and HTTP. Read-only by default; mutation tools are available only when TEAMLINK_READWRITE=true. Use the most specific search filters available and treat customer, order, invoice, and credential data as sensitive.',
334
+ });
317
335
  for (const register of registrations)
318
336
  register(server);
319
337
  return server;
320
338
  }
321
339
  async function main() {
322
340
  if (!API_KEY) {
323
- console.error('[teamlink-mcp] WARNING: TEAMLINK_API_KEY is not set; all tool calls will fail until it is configured.');
341
+ process.stderr.write('[teamlink-mcp] WARNING: TEAMLINK_API_KEY is not set; all tool calls will fail until it is configured.\n');
324
342
  }
325
- console.error(`[teamlink-mcp] mode: ${READWRITE ? 'READ-WRITE (write tools enabled)' : 'read-only (set TEAMLINK_READWRITE=true to enable write tools)'}`);
343
+ process.stderr.write(`[teamlink-mcp] mode: ${READWRITE ? 'READ-WRITE (write tools enabled)' : 'read-only (set TEAMLINK_READWRITE=true to enable write tools)'}\n`);
326
344
  if ((process.env.TEAMLINK_TRANSPORT ?? 'stdio') === 'http') {
327
345
  const host = process.env.TEAMLINK_HTTP_HOST ?? '127.0.0.1';
328
- const port = Number.parseInt(process.env.TEAMLINK_HTTP_PORT ?? '3000', 10);
329
- createHttpServer(createConfiguredServer, { host, port, serverName: '@teamnetwork-nz/teamlink-mcp-server', bearerToken: process.env.TEAMLINK_HTTP_BEARER_TOKEN, allowedHosts: process.env.TEAMLINK_HTTP_ALLOWED_HOSTS?.split(',').map(v => v.trim()).filter(Boolean), allowedOrigins: process.env.TEAMLINK_HTTP_ALLOWED_ORIGINS?.split(',').map(v => v.trim()).filter(Boolean) }).listen(port, host, () => console.error(`[teamlink-mcp] connected (http ${host}:${port}/mcp), proxying ${API_BASE}`));
346
+ const port = parsePositiveInt('TEAMLINK_HTTP_PORT', process.env.TEAMLINK_HTTP_PORT, 3000, 65535);
347
+ createHttpServer(createConfiguredServer, { host, port, serverName: '@teamnetwork-nz/teamlink-mcp-server', bearerToken: process.env.TEAMLINK_HTTP_BEARER_TOKEN, allowedHosts: process.env.TEAMLINK_HTTP_ALLOWED_HOSTS?.split(',').map(v => v.trim()).filter(Boolean), allowedOrigins: process.env.TEAMLINK_HTTP_ALLOWED_ORIGINS?.split(',').map(v => v.trim()).filter(Boolean), maxBodyBytes: parsePositiveInt('TEAMLINK_HTTP_MAX_BODY_BYTES', process.env.TEAMLINK_HTTP_MAX_BODY_BYTES, 1_048_576, 16_777_216) }).listen(port, host, () => process.stderr.write(`[teamlink-mcp] connected (http ${host}:${port}/mcp), proxying ${API_BASE}\n`));
330
348
  }
331
349
  else {
332
350
  await createConfiguredServer().connect(new StdioServerTransport());
333
- console.error(`[teamlink-mcp] connected (stdio), proxying ${API_BASE}`);
351
+ process.stderr.write(`[teamlink-mcp] connected (stdio), proxying ${API_BASE}\n`);
334
352
  }
335
353
  }
336
354
  main().catch((e) => {
337
- console.error('[teamlink-mcp] fatal', e);
355
+ process.stderr.write(`[teamlink-mcp] fatal: ${e instanceof Error ? e.stack ?? e.message : String(e)}\n`);
338
356
  process.exit(1);
339
357
  });
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,yBAAuB;AACvB,sDAA8B;AAC9B,gDAAwB;AACxB,kDAA0B;AAC1B,+BAAoC;AAEpC,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AACtB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC;AACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,uBAAuB,CAAC;AAE1E,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;AAChB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AAExB,cAAc;AACd,MAAM,UAAU,GAA4C,EAAE,CAAC;AAE/D,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IAClC,GAAG,CAAC,GAAG,CAAC;QACN,cAAc,EAAE,mBAAmB;QACnC,eAAe,EAAE,UAAU;QAC3B,UAAU,EAAE,YAAY;KACzB,CAAC,CAAC;IACH,GAAG,CAAC,YAAY,E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,SAAS,EAAE,CAAC,CAAC;QAC3F,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,IAAI,IAAI,EAAE,CAAC,CAAC;IAC3F,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;AAEpF,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE;IAC5B,OAAO,CAAC,GAAG,CAAC,gCAAgC,IAAI,oBAAoB,QAAQ,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,32 +1,34 @@
1
1
  {
2
2
  "name": "@teamnetwork-nz/teamlink-mcp-server",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "private": false,
5
- "description": "stdio MCP server exposing tools that proxy the TEAMlink REST API",
6
- "main": "build/index.js",
5
+ "description": "MCP server exposing TEAMlink REST API tools over stdio and Streamable HTTP",
6
+ "main": "dist/index.js",
7
7
  "type": "module",
8
8
  "bin": {
9
- "teamlink-mcp-server": "build/index.js"
9
+ "teamlink-mcp-server": "dist/index.js"
10
10
  },
11
11
  "files": [
12
- "build"
12
+ "dist"
13
13
  ],
14
14
  "scripts": {
15
15
  "build": "tsc",
16
16
  "test": "npm run build && node --test tests/*.test.mjs",
17
- "start": "node build/index.js"
17
+ "start": "node dist/index.js",
18
+ "dev": "tsc --watch",
19
+ "typecheck": "tsc --noEmit"
18
20
  },
19
21
  "dependencies": {
20
- "@modelcontextprotocol/sdk": "^1.25.1",
22
+ "@modelcontextprotocol/sdk": "^1.29.0",
21
23
  "axios": "^1.4.0",
22
24
  "dotenv": "^16.0.3",
23
- "zod": "^4.2.1"
25
+ "zod": "^3.25.0"
24
26
  },
25
27
  "devDependencies": {
26
28
  "@types/node": "^20.4.2",
27
29
  "typescript": "^5.9.3"
28
30
  },
29
31
  "engines": {
30
- "node": ">=14"
32
+ "node": ">=20"
31
33
  }
32
34
  }
File without changes