@t4dhg/mcp-factorial 3.2.0 → 5.0.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/README.md +21 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +175 -286
- package/dist/api.js.map +1 -1
- package/dist/endpoints.d.ts +51 -0
- package/dist/endpoints.d.ts.map +1 -0
- package/dist/endpoints.js +63 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +22 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.js +106 -257
- package/dist/index.js.map +1 -1
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +2 -1
- package/dist/pagination.js.map +1 -1
- package/dist/tool-utils.d.ts +59 -0
- package/dist/tool-utils.d.ts.map +1 -0
- package/dist/tool-utils.js +71 -0
- package/dist/tool-utils.js.map +1 -0
- package/dist/utils.d.ts +33 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +48 -0
- package/dist/utils.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool utilities for MCP FactorialHR
|
|
3
|
+
*
|
|
4
|
+
* Provides helper functions for consistent tool handler implementation.
|
|
5
|
+
*/
|
|
6
|
+
import { getOperationPolicy, getWarningMessage } from './write-safety.js';
|
|
7
|
+
/**
|
|
8
|
+
* Format an error into a consistent tool error response
|
|
9
|
+
*/
|
|
10
|
+
export function formatToolError(error) {
|
|
11
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
12
|
+
return {
|
|
13
|
+
content: [{ type: 'text', text: `Error: ${message}` }],
|
|
14
|
+
isError: true,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a successful text response
|
|
19
|
+
*/
|
|
20
|
+
export function textResponse(text) {
|
|
21
|
+
return {
|
|
22
|
+
content: [{ type: 'text', text }],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Wrap a tool handler with consistent error handling
|
|
27
|
+
*
|
|
28
|
+
* @param handler - The async handler function
|
|
29
|
+
* @returns A wrapped handler that catches errors and formats them consistently
|
|
30
|
+
*/
|
|
31
|
+
export function wrapToolHandler(handler) {
|
|
32
|
+
return async (args) => {
|
|
33
|
+
try {
|
|
34
|
+
return await handler(args);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return formatToolError(error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Wrap a high-risk tool handler with confirmation requirement
|
|
43
|
+
*
|
|
44
|
+
* @param operationName - The operation name (e.g., 'delete_team') for policy lookup
|
|
45
|
+
* @param handler - The async handler function
|
|
46
|
+
* @returns A wrapped handler that requires confirmation for high-risk operations
|
|
47
|
+
*/
|
|
48
|
+
export function wrapHighRiskToolHandler(operationName, handler) {
|
|
49
|
+
return wrapToolHandler(async (args) => {
|
|
50
|
+
const policy = getOperationPolicy(operationName);
|
|
51
|
+
if (policy.requiresConfirmation && !args.confirm) {
|
|
52
|
+
const warning = getWarningMessage(operationName);
|
|
53
|
+
return textResponse(`${warning}\n\nTo proceed, call this tool again with \`confirm: true\`.`);
|
|
54
|
+
}
|
|
55
|
+
return handler(args);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Format JSON data for display in a tool response
|
|
60
|
+
*/
|
|
61
|
+
export function formatJson(data, prefix) {
|
|
62
|
+
const json = JSON.stringify(data, null, 2);
|
|
63
|
+
return prefix ? `${prefix}\n\n${json}` : json;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Format a list result with pagination info
|
|
67
|
+
*/
|
|
68
|
+
export function formatListResult(items, entityName, paginationInfo) {
|
|
69
|
+
return `Found ${items.length} ${entityName}${items.length !== 1 ? 's' : ''} (${paginationInfo}):\n\n${JSON.stringify(items, null,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CAAC,OAAO,EAAE,CAAC;YACjD,MAAM,OAAO,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;YACjD,OAAO,YAAY,CAAC,GAAG,OAAO,8DAA8D,CAAC,CAAC;QAChG,CAAC;QAED,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAa,EAAE,MAAe;IACvD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC3C,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAgB,EAChB,UAAkB,EAClB,cAAsB;IAEtB,OAAO,SAAS,KAAK,CAAC,MAAM,IAAI,UAAU,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,cAAc,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;AACzI,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for MCP FactorialHR
|
|
3
|
+
*
|
|
4
|
+
* Provides common validation and helper functions used across the codebase.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Validate that a value is a positive integer ID
|
|
8
|
+
*
|
|
9
|
+
* @param id - The value to validate
|
|
10
|
+
* @param resourceType - The type of resource for error messages (e.g., "employee", "team")
|
|
11
|
+
* @returns The validated ID as a number
|
|
12
|
+
* @throws Error if the ID is invalid
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateId(id: unknown, resourceType: string): number;
|
|
15
|
+
/**
|
|
16
|
+
* Validate that a value is a positive number
|
|
17
|
+
*
|
|
18
|
+
* @param value - The value to validate
|
|
19
|
+
* @param fieldName - The field name for error messages
|
|
20
|
+
* @returns The validated number
|
|
21
|
+
* @throws Error if the value is invalid
|
|
22
|
+
*/
|
|
23
|
+
export declare function validatePositiveNumber(value: unknown, fieldName: string): number;
|
|
24
|
+
/**
|
|
25
|
+
* Validate that a value is a non-empty string
|
|
26
|
+
*
|
|
27
|
+
* @param value - The value to validate
|
|
28
|
+
* @param fieldName - The field name for error messages
|
|
29
|
+
* @returns The validated string
|
|
30
|
+
* @throws Error if the value is invalid
|
|
31
|
+
*/
|
|
32
|
+
export declare function validateNonEmptyString(value: unknown, fieldName: string): string;
|
|
33
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAKpE;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAKhF;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAKhF"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for MCP FactorialHR
|
|
3
|
+
*
|
|
4
|
+
* Provides common validation and helper functions used across the codebase.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Validate that a value is a positive integer ID
|
|
8
|
+
*
|
|
9
|
+
* @param id - The value to validate
|
|
10
|
+
* @param resourceType - The type of resource for error messages (e.g., "employee", "team")
|
|
11
|
+
* @returns The validated ID as a number
|
|
12
|
+
* @throws Error if the ID is invalid
|
|
13
|
+
*/
|
|
14
|
+
export function validateId(id, resourceType) {
|
|
15
|
+
if (typeof id !== 'number' || !id || id <= 0 || !Number.isInteger(id)) {
|
|
16
|
+
throw new Error(`Invalid ${resourceType} ID. Please provide a positive integer.`);
|
|
17
|
+
}
|
|
18
|
+
return id;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validate that a value is a positive number
|
|
22
|
+
*
|
|
23
|
+
* @param value - The value to validate
|
|
24
|
+
* @param fieldName - The field name for error messages
|
|
25
|
+
* @returns The validated number
|
|
26
|
+
* @throws Error if the value is invalid
|
|
27
|
+
*/
|
|
28
|
+
export function validatePositiveNumber(value, fieldName) {
|
|
29
|
+
if (typeof value !== 'number' || value <= 0) {
|
|
30
|
+
throw new Error(`Invalid ${fieldName}. Please provide a positive number.`);
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validate that a value is a non-empty string
|
|
36
|
+
*
|
|
37
|
+
* @param value - The value to validate
|
|
38
|
+
* @param fieldName - The field name for error messages
|
|
39
|
+
* @returns The validated string
|
|
40
|
+
* @throws Error if the value is invalid
|
|
41
|
+
*/
|
|
42
|
+
export function validateNonEmptyString(value, fieldName) {
|
|
43
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
44
|
+
throw new Error(`Invalid ${fieldName}. Please provide a non-empty string.`);
|
|
45
|
+
}
|
|
46
|
+
return value.trim();
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,EAAW,EAAE,YAAoB;IAC1D,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,WAAW,YAAY,yCAAyC,CAAC,CAAC;IACpF,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc,EAAE,SAAiB;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,WAAW,SAAS,qCAAqC,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc,EAAE,SAAiB;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,WAAW,SAAS,sCAAsC,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t4dhg/mcp-factorial",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "The definitive MCP server for FactorialHR - Full CRUD operations for employees, teams, time off, projects, training, recruiting (ATS), and payroll. 80+ tools with safety guardrails.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|