@teamnetwork-nz/teamlink-mcp-server 0.2.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.
Files changed (2) hide show
  1. package/build/index.js +112 -0
  2. package/package.json +31 -0
package/build/index.js ADDED
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+ import 'dotenv/config';
3
+ import axios from 'axios';
4
+ import { z } from 'zod';
5
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
7
+ /**
8
+ * TEAMlink MCP server. Exposes read/write tools that proxy the TEAMlink REST API
9
+ * (teamlink-api). The API enforces auth (CSCApiKey) and all business rules — this
10
+ * server is a thin, typed adapter.
11
+ *
12
+ * Config:
13
+ * - TEAMLINK_API_BASE (default http://localhost:3100)
14
+ * - TEAMLINK_API_KEY the staff-allocated CSCApiKey used for all calls
15
+ */
16
+ const API_BASE = (process.env.TEAMLINK_API_BASE ?? 'http://localhost:3100').replace(/\/$/, '');
17
+ const API_KEY = process.env.TEAMLINK_API_KEY ?? '';
18
+ const http = axios.create({
19
+ baseURL: API_BASE,
20
+ timeout: 20_000,
21
+ headers: API_KEY ? { 'X-API-Key': API_KEY } : {},
22
+ });
23
+ function ok(data) {
24
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
25
+ }
26
+ function fail(err) {
27
+ if (!API_KEY) {
28
+ return {
29
+ content: [{ type: 'text', text: 'TEAMLINK_API_KEY is not set. Configure a staff CSCApiKey for the MCP server.' }],
30
+ isError: true,
31
+ };
32
+ }
33
+ const ax = err;
34
+ const body = ax.response?.data ?? { message: ax.message ?? String(err) };
35
+ const status = ax.response?.status;
36
+ return {
37
+ content: [{ type: 'text', text: `API error${status ? ` (${status})` : ''}: ${JSON.stringify(body)}` }],
38
+ isError: true,
39
+ };
40
+ }
41
+ async function get(path, params) {
42
+ try {
43
+ const r = await http.get(path, { params });
44
+ return ok(r.data);
45
+ }
46
+ catch (e) {
47
+ return fail(e);
48
+ }
49
+ }
50
+ async function post(path, body) {
51
+ try {
52
+ const r = await http.post(path, body);
53
+ return ok(r.data);
54
+ }
55
+ catch (e) {
56
+ return fail(e);
57
+ }
58
+ }
59
+ async function put(path, body) {
60
+ try {
61
+ const r = await http.put(path, body);
62
+ return ok(r.data);
63
+ }
64
+ catch (e) {
65
+ return fail(e);
66
+ }
67
+ }
68
+ const server = new McpServer({ name: 'teamlink-mcp', version: '0.2.0' });
69
+ // --- Identity ---
70
+ server.tool('teamlink_whoami', 'Return the authenticated TEAMlink user context for the configured API key.', {}, async () => get('/me'));
71
+ // --- CRM: accounts ---
72
+ server.tool('crm_search_accounts', 'Search customer accounts by name, alpha id, phone or website (priority search).', { q: z.string().describe('search text (name / alpha id)'), phone: z.string().optional(), exactWebsite: z.string().optional() }, async ({ q, phone, exactWebsite }) => get('/accounts/search', { q, phone, exactWebsite }));
73
+ server.tool('crm_list_accounts', 'List/filter accounts.', {
74
+ search: z.string().optional(), isCustomer: z.boolean().optional(), isProspect: z.boolean().optional(),
75
+ isSupplier: z.boolean().optional(), branchId: z.string().optional(), page: z.number().optional(), pageSize: z.number().optional(),
76
+ }, async (args) => get('/accounts', args));
77
+ server.tool('crm_get_account', 'Get one account by id.', { accountId: z.number() }, async ({ accountId }) => get(`/accounts/${accountId}`));
78
+ server.tool('crm_list_account_contacts', 'List active contacts linked to an account.', { accountId: z.number() }, async ({ accountId }) => get(`/accounts/${accountId}/contacts`));
79
+ server.tool('crm_create_account', 'Create an account. Returns duplicate-candidate warnings unless createAnyway=true.', {
80
+ name: z.string(), alphaId: z.string().optional(), website: z.string().optional(), phone: z.string().optional(),
81
+ isCustomer: z.boolean().optional(), isProspect: z.boolean().optional(), createAnyway: z.boolean().optional(),
82
+ }, async (args) => post('/accounts', args));
83
+ // --- CRM: contacts ---
84
+ server.tool('crm_search_contacts', 'Search contacts by name/email/phone.', { q: z.string().optional(), accountId: z.number().optional(), email: z.string().optional(), page: z.number().optional(), pageSize: z.number().optional() }, async (args) => get('/contacts/search', args));
85
+ server.tool('crm_get_contact', 'Get one contact by id.', { contactId: z.number() }, async ({ contactId }) => get(`/contacts/${contactId}`));
86
+ server.tool('crm_create_contact', 'Create a contact under an account (also creates the active account link).', {
87
+ accountId: z.number(), firstName: z.string(), lastName: z.string(), email: z.string(),
88
+ mobile: z.string().optional(), businessPhone: z.string().optional(), role: z.string().optional(),
89
+ }, async ({ accountId, ...body }) => post(`/accounts/${accountId}/contacts`, body));
90
+ server.tool('crm_update_contact', 'Update a contact. Password only applied if supplied.', { contactId: z.number(), firstName: z.string(), lastName: z.string(), email: z.string(), mobile: z.string().optional(), role: z.string().optional(), active: z.boolean().optional() }, async ({ contactId, ...body }) => put(`/contacts/${contactId}`, body));
91
+ // --- Lookups ---
92
+ server.tool('lookup_selectors', 'Get options for a CSSelectors list (Industry, Source, SalesStatus, OrderType, IncomeCat, City, Country, ...).', { selectorClass: z.string() }, async ({ selectorClass }) => get(`/lookups/selectors/${encodeURIComponent(selectorClass)}`));
93
+ server.tool('lookup_branches', 'List branches.', {}, async () => get('/lookups/branches'));
94
+ // --- Tasks / time (read) ---
95
+ server.tool('task_get', 'Get a task by id.', { taskId: z.number() }, async ({ taskId }) => get(`/tasks/${taskId}`));
96
+ server.tool('task_list_time_entries', 'List time/incidental entries + totals for a task.', { taskId: z.number(), type: z.enum(['time', 'incidentals', 'all']).optional() }, async ({ taskId, type }) => get(`/tasks/${taskId}/time-entries`, { type }));
97
+ // --- Orders / PM (read) ---
98
+ server.tool('order_get', 'Get an order header + totals.', { orderId: z.number() }, async ({ orderId }) => get(`/orders/${orderId}`));
99
+ server.tool('order_list_items', 'List order line items.', { orderId: z.number() }, async ({ orderId }) => get(`/orders/${orderId}/items`));
100
+ server.tool('product_search', 'Search the (read-only) product catalog.', { q: z.string(), vendorId: z.number().optional() }, async ({ q, vendorId }) => get('/orders/products/search', { q, vendorId }));
101
+ async function main() {
102
+ if (!API_KEY) {
103
+ console.error('[teamlink-mcp] WARNING: TEAMLINK_API_KEY is not set; all tool calls will fail until it is configured.');
104
+ }
105
+ const transport = new StdioServerTransport();
106
+ await server.connect(transport);
107
+ console.error(`[teamlink-mcp] connected (stdio), proxying ${API_BASE}`);
108
+ }
109
+ main().catch((e) => {
110
+ console.error('[teamlink-mcp] fatal', e);
111
+ process.exit(1);
112
+ });
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@teamnetwork-nz/teamlink-mcp-server",
3
+ "version": "0.2.0",
4
+ "private": false,
5
+ "description": "stdio MCP server exposing tools that proxy the TEAMlink REST API",
6
+ "main": "build/index.js",
7
+ "type": "module",
8
+ "bin": {
9
+ "teamlink-mcp-server": "build/index.js"
10
+ },
11
+ "files": [
12
+ "build"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "start": "node build/index.js"
17
+ },
18
+ "dependencies": {
19
+ "@modelcontextprotocol/sdk": "^1.25.1",
20
+ "axios": "^1.4.0",
21
+ "dotenv": "^16.0.3",
22
+ "zod": "^4.2.1"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^20.4.2",
26
+ "typescript": "^5.9.3"
27
+ },
28
+ "engines": {
29
+ "node": ">=14"
30
+ }
31
+ }