@teamso/teamso-mcp 0.0.0-stage → 1.2.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.
Files changed (112) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/LICENSE +21 -0
  3. package/README.md +506 -2
  4. package/dist/client.d.ts +215 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +797 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +32 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/prompts/index.d.ts +12 -0
  13. package/dist/prompts/index.d.ts.map +1 -0
  14. package/dist/prompts/index.js +58 -0
  15. package/dist/prompts/index.js.map +1 -0
  16. package/dist/server.d.ts +28 -0
  17. package/dist/server.d.ts.map +1 -0
  18. package/dist/server.js +58 -0
  19. package/dist/server.js.map +1 -0
  20. package/dist/tools/account.d.ts +4 -0
  21. package/dist/tools/account.d.ts.map +1 -0
  22. package/dist/tools/account.js +34 -0
  23. package/dist/tools/account.js.map +1 -0
  24. package/dist/tools/api.d.ts +13 -0
  25. package/dist/tools/api.d.ts.map +1 -0
  26. package/dist/tools/api.js +982 -0
  27. package/dist/tools/api.js.map +1 -0
  28. package/dist/tools/approvals.d.ts +5 -0
  29. package/dist/tools/approvals.d.ts.map +1 -0
  30. package/dist/tools/approvals.js +120 -0
  31. package/dist/tools/approvals.js.map +1 -0
  32. package/dist/tools/communication.d.ts +4 -0
  33. package/dist/tools/communication.d.ts.map +1 -0
  34. package/dist/tools/communication.js +39 -0
  35. package/dist/tools/communication.js.map +1 -0
  36. package/dist/tools/employees.d.ts +5 -0
  37. package/dist/tools/employees.d.ts.map +1 -0
  38. package/dist/tools/employees.js +113 -0
  39. package/dist/tools/employees.js.map +1 -0
  40. package/dist/tools/help.d.ts +6 -0
  41. package/dist/tools/help.d.ts.map +1 -0
  42. package/dist/tools/help.js +171 -0
  43. package/dist/tools/help.js.map +1 -0
  44. package/dist/tools/index.d.ts +86 -0
  45. package/dist/tools/index.d.ts.map +1 -0
  46. package/dist/tools/index.js +118 -0
  47. package/dist/tools/index.js.map +1 -0
  48. package/dist/tools/leave-support.d.ts +60 -0
  49. package/dist/tools/leave-support.d.ts.map +1 -0
  50. package/dist/tools/leave-support.js +185 -0
  51. package/dist/tools/leave-support.js.map +1 -0
  52. package/dist/tools/leave.d.ts +14 -0
  53. package/dist/tools/leave.d.ts.map +1 -0
  54. package/dist/tools/leave.js +388 -0
  55. package/dist/tools/leave.js.map +1 -0
  56. package/dist/tools/payroll.d.ts +5 -0
  57. package/dist/tools/payroll.d.ts.map +1 -0
  58. package/dist/tools/payroll.js +101 -0
  59. package/dist/tools/payroll.js.map +1 -0
  60. package/dist/tools/performance.d.ts +13 -0
  61. package/dist/tools/performance.d.ts.map +1 -0
  62. package/dist/tools/performance.js +592 -0
  63. package/dist/tools/performance.js.map +1 -0
  64. package/dist/tools/schemas.d.ts +2079 -0
  65. package/dist/tools/schemas.d.ts.map +1 -0
  66. package/dist/tools/schemas.js +460 -0
  67. package/dist/tools/schemas.js.map +1 -0
  68. package/dist/tools/shared.d.ts +20 -0
  69. package/dist/tools/shared.d.ts.map +1 -0
  70. package/dist/tools/shared.js +64 -0
  71. package/dist/tools/shared.js.map +1 -0
  72. package/dist/types.d.ts +545 -0
  73. package/dist/types.d.ts.map +1 -0
  74. package/dist/types.js +7 -0
  75. package/dist/types.js.map +1 -0
  76. package/dist/utils/api-endpoints.d.ts +130 -0
  77. package/dist/utils/api-endpoints.d.ts.map +1 -0
  78. package/dist/utils/api-endpoints.js +459 -0
  79. package/dist/utils/api-endpoints.js.map +1 -0
  80. package/dist/utils/dates.d.ts +27 -0
  81. package/dist/utils/dates.d.ts.map +1 -0
  82. package/dist/utils/dates.js +102 -0
  83. package/dist/utils/dates.js.map +1 -0
  84. package/dist/utils/format.d.ts +8 -0
  85. package/dist/utils/format.d.ts.map +1 -0
  86. package/dist/utils/format.js +26 -0
  87. package/dist/utils/format.js.map +1 -0
  88. package/dist/utils/help-search.d.ts +25 -0
  89. package/dist/utils/help-search.d.ts.map +1 -0
  90. package/dist/utils/help-search.js +93 -0
  91. package/dist/utils/help-search.js.map +1 -0
  92. package/dist/utils/json-schema-dialect.d.ts +12 -0
  93. package/dist/utils/json-schema-dialect.d.ts.map +1 -0
  94. package/dist/utils/json-schema-dialect.js +146 -0
  95. package/dist/utils/json-schema-dialect.js.map +1 -0
  96. package/dist/utils/results.d.ts +27 -0
  97. package/dist/utils/results.d.ts.map +1 -0
  98. package/dist/utils/results.js +88 -0
  99. package/dist/utils/results.js.map +1 -0
  100. package/dist/utils/structured.d.ts +89 -0
  101. package/dist/utils/structured.d.ts.map +1 -0
  102. package/dist/utils/structured.js +307 -0
  103. package/dist/utils/structured.js.map +1 -0
  104. package/dist/utils/text.d.ts +12 -0
  105. package/dist/utils/text.d.ts.map +1 -0
  106. package/dist/utils/text.js +46 -0
  107. package/dist/utils/text.js.map +1 -0
  108. package/dist/version.d.ts +3 -0
  109. package/dist/version.d.ts.map +1 -0
  110. package/dist/version.js +6 -0
  111. package/dist/version.js.map +1 -0
  112. package/package.json +86 -4
@@ -0,0 +1,86 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { TeamsoClient } from '../client.js';
3
+ import { registerGetMe } from './account.js';
4
+ import { registerCallApiRead, registerCallApiWrite, registerDescribeApiEndpoint, registerFindApiEndpoints, registerListApiModules, registerRequestSmsCode } from './api.js';
5
+ import { registerApproveOrRejectLeave, registerListPendingApprovals } from './approvals.js';
6
+ import { registerListAnnouncements } from './communication.js';
7
+ import { registerGetEmployeeProfile, registerSearchEmployees } from './employees.js';
8
+ import { registerGetHelpArticle, registerListHelpModules, registerSearchHelpArticles } from './help.js';
9
+ import { registerCalculateLeaveDays, registerCancelLeaveRequest, registerCreateLeaveRequest, registerGetMyLeaveBalance, registerListLeaveTypes, registerListMyLeaves, registerRequestLeaveOtp } from './leave.js';
10
+ import { registerGetPayslipPdf, registerListMyPayslips } from './payroll.js';
11
+ import { registerApproveGoal, registerApproveGoalEvaluation, registerCreateUserGoal, registerListMyGoals, registerListPerformancePeriods, registerListTeamGoals, registerReviseAndApproveGoal, registerSendGoalsToApproval, registerUpdateGoalActualValue, registerUpdateManagerActualValue } from './performance.js';
12
+ /**
13
+ * Every tool this package serves, in registration order. The names are a
14
+ * contract: the hosted server routes any other tool name to the backend MCP,
15
+ * and the documentation pages list exactly these.
16
+ */
17
+ declare const REGISTRARS: {
18
+ readonly search_help_articles: typeof registerSearchHelpArticles;
19
+ readonly get_help_article: typeof registerGetHelpArticle;
20
+ readonly list_help_modules: typeof registerListHelpModules;
21
+ readonly get_me: typeof registerGetMe;
22
+ readonly list_leave_types: typeof registerListLeaveTypes;
23
+ readonly get_my_leave_balance: typeof registerGetMyLeaveBalance;
24
+ readonly calculate_leave_days: typeof registerCalculateLeaveDays;
25
+ readonly request_leave_otp: typeof registerRequestLeaveOtp;
26
+ readonly create_leave_request: typeof registerCreateLeaveRequest;
27
+ readonly list_my_leaves: typeof registerListMyLeaves;
28
+ readonly cancel_leave_request: typeof registerCancelLeaveRequest;
29
+ readonly list_pending_approvals: typeof registerListPendingApprovals;
30
+ readonly approve_or_reject_leave: typeof registerApproveOrRejectLeave;
31
+ readonly search_employees: typeof registerSearchEmployees;
32
+ readonly get_employee_profile: typeof registerGetEmployeeProfile;
33
+ readonly list_performance_periods: typeof registerListPerformancePeriods;
34
+ readonly list_my_goals: typeof registerListMyGoals;
35
+ readonly list_team_goals: typeof registerListTeamGoals;
36
+ readonly create_user_goal: typeof registerCreateUserGoal;
37
+ readonly send_goals_to_approval: typeof registerSendGoalsToApproval;
38
+ readonly approve_goal: typeof registerApproveGoal;
39
+ readonly revise_and_approve_goal: typeof registerReviseAndApproveGoal;
40
+ readonly update_goal_actual_value: typeof registerUpdateGoalActualValue;
41
+ readonly update_manager_actual_value: typeof registerUpdateManagerActualValue;
42
+ readonly approve_goal_evaluation: typeof registerApproveGoalEvaluation;
43
+ readonly list_announcements: typeof registerListAnnouncements;
44
+ readonly list_my_payslips: typeof registerListMyPayslips;
45
+ readonly get_payslip_pdf: typeof registerGetPayslipPdf;
46
+ readonly find_api_endpoints: typeof registerFindApiEndpoints;
47
+ readonly list_api_modules: typeof registerListApiModules;
48
+ readonly describe_api_endpoint: typeof registerDescribeApiEndpoint;
49
+ readonly call_api_read: typeof registerCallApiRead;
50
+ readonly call_api_write: typeof registerCallApiWrite;
51
+ readonly request_sms_code: typeof registerRequestSmsCode;
52
+ };
53
+ export type ToolName = keyof typeof REGISTRARS;
54
+ export declare const TOOL_NAMES: readonly ToolName[];
55
+ /**
56
+ * Tool groups for `TEAMSO_TOOLSETS` / the `toolsets` option. Every tool is in
57
+ * exactly one group; `api` holds the generic tools that reach every module.
58
+ */
59
+ export declare const TOOLSETS: Readonly<{
60
+ readonly core: readonly "get_me"[];
61
+ readonly help: readonly ("search_help_articles" | "get_help_article" | "list_help_modules")[];
62
+ readonly leave: readonly ("list_leave_types" | "get_my_leave_balance" | "calculate_leave_days" | "request_leave_otp" | "create_leave_request" | "list_my_leaves" | "cancel_leave_request")[];
63
+ readonly approvals: readonly ("list_pending_approvals" | "approve_or_reject_leave")[];
64
+ readonly employees: readonly ("search_employees" | "get_employee_profile")[];
65
+ readonly performance: readonly ("list_performance_periods" | "list_my_goals" | "send_goals_to_approval" | "list_team_goals" | "approve_goal" | "create_user_goal" | "revise_and_approve_goal" | "update_goal_actual_value" | "update_manager_actual_value" | "approve_goal_evaluation")[];
66
+ readonly communication: readonly "list_announcements"[];
67
+ readonly payroll: readonly ("list_my_payslips" | "get_payslip_pdf")[];
68
+ readonly api: readonly ("call_api_read" | "call_api_write" | "find_api_endpoints" | "describe_api_endpoint" | "list_api_modules" | "request_sms_code")[];
69
+ }>;
70
+ export type ToolsetName = keyof typeof TOOLSETS;
71
+ export declare const TOOLSET_NAMES: readonly ToolsetName[];
72
+ export interface RegisterToolsOptions {
73
+ /**
74
+ * Tool groups to serve (see TOOLSETS): an array or a comma-separated list such as
75
+ * `"core,leave,api"`. `all`, an empty list or undefined serve every tool.
76
+ */
77
+ toolsets?: string | readonly string[];
78
+ }
79
+ /**
80
+ * Tool names for a toolset selection, in TOOL_NAMES order. Throws on unknown
81
+ * toolset names so a typo in `TEAMSO_TOOLSETS` is not silently ignored.
82
+ */
83
+ export declare function resolveToolsets(toolsets?: string | readonly string[]): ToolName[];
84
+ export declare function registerTools(server: McpServer, client: TeamsoClient, options?: RegisterToolsOptions): void;
85
+ export { registerSearchHelpArticles, registerGetHelpArticle, registerListHelpModules, registerGetMe, registerListLeaveTypes, registerGetMyLeaveBalance, registerCalculateLeaveDays, registerRequestLeaveOtp, registerCreateLeaveRequest, registerListMyLeaves, registerCancelLeaveRequest, registerListPendingApprovals, registerApproveOrRejectLeave, registerSearchEmployees, registerGetEmployeeProfile, registerListPerformancePeriods, registerListMyGoals, registerListTeamGoals, registerCreateUserGoal, registerSendGoalsToApproval, registerApproveGoal, registerReviseAndApproveGoal, registerUpdateGoalActualValue, registerUpdateManagerActualValue, registerApproveGoalEvaluation, registerListAnnouncements, registerListMyPayslips, registerGetPayslipPdf, registerFindApiEndpoints, registerListApiModules, registerDescribeApiEndpoint, registerCallApiRead, registerCallApiWrite, registerRequestSmsCode, };
86
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,UAAU,CAAC;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S,MAAM,EAAE,GAAG,QAAQ,EAAE,CAYjF;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,oBAAyB,GAAG,IAAI,CAI/G;AAED,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,0BAA0B,EAC1B,4BAA4B,EAC5B,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,4BAA4B,EAC5B,6BAA6B,EAC7B,gCAAgC,EAChC,6BAA6B,EAC7B,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,GACvB,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { registerGetMe } from './account.js';
2
+ import { registerCallApiRead, registerCallApiWrite, registerDescribeApiEndpoint, registerFindApiEndpoints, registerListApiModules, registerRequestSmsCode, } from './api.js';
3
+ import { registerApproveOrRejectLeave, registerListPendingApprovals } from './approvals.js';
4
+ import { registerListAnnouncements } from './communication.js';
5
+ import { registerGetEmployeeProfile, registerSearchEmployees } from './employees.js';
6
+ import { registerGetHelpArticle, registerListHelpModules, registerSearchHelpArticles, } from './help.js';
7
+ import { registerCalculateLeaveDays, registerCancelLeaveRequest, registerCreateLeaveRequest, registerGetMyLeaveBalance, registerListLeaveTypes, registerListMyLeaves, registerRequestLeaveOtp, } from './leave.js';
8
+ import { registerGetPayslipPdf, registerListMyPayslips } from './payroll.js';
9
+ import { registerApproveGoal, registerApproveGoalEvaluation, registerCreateUserGoal, registerListMyGoals, registerListPerformancePeriods, registerListTeamGoals, registerReviseAndApproveGoal, registerSendGoalsToApproval, registerUpdateGoalActualValue, registerUpdateManagerActualValue, } from './performance.js';
10
+ /**
11
+ * Every tool this package serves, in registration order. The names are a
12
+ * contract: the hosted server routes any other tool name to the backend MCP,
13
+ * and the documentation pages list exactly these.
14
+ */
15
+ const REGISTRARS = {
16
+ search_help_articles: registerSearchHelpArticles,
17
+ get_help_article: registerGetHelpArticle,
18
+ list_help_modules: registerListHelpModules,
19
+ get_me: registerGetMe,
20
+ list_leave_types: registerListLeaveTypes,
21
+ get_my_leave_balance: registerGetMyLeaveBalance,
22
+ calculate_leave_days: registerCalculateLeaveDays,
23
+ request_leave_otp: registerRequestLeaveOtp,
24
+ create_leave_request: registerCreateLeaveRequest,
25
+ list_my_leaves: registerListMyLeaves,
26
+ cancel_leave_request: registerCancelLeaveRequest,
27
+ list_pending_approvals: registerListPendingApprovals,
28
+ approve_or_reject_leave: registerApproveOrRejectLeave,
29
+ search_employees: registerSearchEmployees,
30
+ get_employee_profile: registerGetEmployeeProfile,
31
+ list_performance_periods: registerListPerformancePeriods,
32
+ list_my_goals: registerListMyGoals,
33
+ list_team_goals: registerListTeamGoals,
34
+ create_user_goal: registerCreateUserGoal,
35
+ send_goals_to_approval: registerSendGoalsToApproval,
36
+ approve_goal: registerApproveGoal,
37
+ revise_and_approve_goal: registerReviseAndApproveGoal,
38
+ update_goal_actual_value: registerUpdateGoalActualValue,
39
+ update_manager_actual_value: registerUpdateManagerActualValue,
40
+ approve_goal_evaluation: registerApproveGoalEvaluation,
41
+ list_announcements: registerListAnnouncements,
42
+ list_my_payslips: registerListMyPayslips,
43
+ get_payslip_pdf: registerGetPayslipPdf,
44
+ find_api_endpoints: registerFindApiEndpoints,
45
+ list_api_modules: registerListApiModules,
46
+ describe_api_endpoint: registerDescribeApiEndpoint,
47
+ call_api_read: registerCallApiRead,
48
+ call_api_write: registerCallApiWrite,
49
+ request_sms_code: registerRequestSmsCode,
50
+ };
51
+ export const TOOL_NAMES = Object.freeze(Object.keys(REGISTRARS));
52
+ /**
53
+ * Tool groups for `TEAMSO_TOOLSETS` / the `toolsets` option. Every tool is in
54
+ * exactly one group; `api` holds the generic tools that reach every module.
55
+ */
56
+ export const TOOLSETS = Object.freeze({
57
+ core: Object.freeze(['get_me']),
58
+ help: Object.freeze(['search_help_articles', 'get_help_article', 'list_help_modules']),
59
+ leave: Object.freeze([
60
+ 'list_leave_types',
61
+ 'get_my_leave_balance',
62
+ 'calculate_leave_days',
63
+ 'request_leave_otp',
64
+ 'create_leave_request',
65
+ 'list_my_leaves',
66
+ 'cancel_leave_request',
67
+ ]),
68
+ approvals: Object.freeze(['list_pending_approvals', 'approve_or_reject_leave']),
69
+ employees: Object.freeze(['search_employees', 'get_employee_profile']),
70
+ performance: Object.freeze([
71
+ 'list_performance_periods',
72
+ 'list_my_goals',
73
+ 'list_team_goals',
74
+ 'create_user_goal',
75
+ 'send_goals_to_approval',
76
+ 'approve_goal',
77
+ 'revise_and_approve_goal',
78
+ 'update_goal_actual_value',
79
+ 'update_manager_actual_value',
80
+ 'approve_goal_evaluation',
81
+ ]),
82
+ communication: Object.freeze(['list_announcements']),
83
+ payroll: Object.freeze(['list_my_payslips', 'get_payslip_pdf']),
84
+ api: Object.freeze([
85
+ 'find_api_endpoints',
86
+ 'list_api_modules',
87
+ 'describe_api_endpoint',
88
+ 'call_api_read',
89
+ 'call_api_write',
90
+ 'request_sms_code',
91
+ ]),
92
+ });
93
+ export const TOOLSET_NAMES = Object.freeze(Object.keys(TOOLSETS));
94
+ /**
95
+ * Tool names for a toolset selection, in TOOL_NAMES order. Throws on unknown
96
+ * toolset names so a typo in `TEAMSO_TOOLSETS` is not silently ignored.
97
+ */
98
+ export function resolveToolsets(toolsets) {
99
+ const requested = (typeof toolsets === 'string' ? toolsets.split(',') : [...(toolsets ?? [])])
100
+ .map(name => name.trim().toLowerCase())
101
+ .filter(Boolean);
102
+ if (requested.length === 0 || requested.includes('all'))
103
+ return [...TOOL_NAMES];
104
+ const unknown = requested.filter(name => !TOOLSET_NAMES.includes(name));
105
+ if (unknown.length) {
106
+ throw new Error(`Unknown Teamso toolset(s): ${unknown.join(', ')}. `
107
+ + `Valid toolsets: ${TOOLSET_NAMES.join(', ')} (or all).`);
108
+ }
109
+ const selected = new Set(requested.flatMap(name => TOOLSETS[name]));
110
+ return TOOL_NAMES.filter(name => selected.has(name));
111
+ }
112
+ export function registerTools(server, client, options = {}) {
113
+ for (const name of resolveToolsets(options.toolsets)) {
114
+ REGISTRARS[name](server, client);
115
+ }
116
+ }
117
+ export { registerSearchHelpArticles, registerGetHelpArticle, registerListHelpModules, registerGetMe, registerListLeaveTypes, registerGetMyLeaveBalance, registerCalculateLeaveDays, registerRequestLeaveOtp, registerCreateLeaveRequest, registerListMyLeaves, registerCancelLeaveRequest, registerListPendingApprovals, registerApproveOrRejectLeave, registerSearchEmployees, registerGetEmployeeProfile, registerListPerformancePeriods, registerListMyGoals, registerListTeamGoals, registerCreateUserGoal, registerSendGoalsToApproval, registerApproveGoal, registerReviseAndApproveGoal, registerUpdateGoalActualValue, registerUpdateManagerActualValue, registerApproveGoalEvaluation, registerListAnnouncements, registerListMyPayslips, registerGetPayslipPdf, registerFindApiEndpoints, registerListApiModules, registerDescribeApiEndpoint, registerCallApiRead, registerCallApiWrite, registerRequestSmsCode, };
118
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,2BAA2B,EAC3B,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AA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,IAAI,GAAG,CAAS,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAmB,CAAC,CAAC,CAAC,CAAC;IAC3F,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAiB,EAAE,MAAoB,EAAE,UAAgC,EAAE;IACvG,KAAK,MAAM,IAAI,IAAI,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrD,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;AACH,CAAC;AAED,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,0BAA0B,EAC1B,4BAA4B,EAC5B,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,4BAA4B,EAC5B,6BAA6B,EAC7B,gCAAgC,EAChC,6BAA6B,EAC7B,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,GACvB,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { type TeamsoClient } from '../client.js';
2
+ import type { TeamsoLeave, TeamsoLeaveListParams, TeamsoLeavePolicyAssignment, TeamsoLeaveTypeBalance, TeamsoUser, TeamsoWorkingDays } from '../types.js';
3
+ import { type LeaveTypeProjection } from '../utils/structured.js';
4
+ export declare function explainLeaveReason(reason: string): string;
5
+ export interface LeavePolicyContext {
6
+ assignment: TeamsoLeavePolicyAssignment;
7
+ balances: TeamsoLeaveTypeBalance[];
8
+ }
9
+ /** The caller's active leave policy and the leave types (with balances) it allows. */
10
+ export declare function loadLeavePolicy(client: TeamsoClient, signal?: AbortSignal): Promise<LeavePolicyContext>;
11
+ export declare function findLeaveType(context: LeavePolicyContext, leaveTypeId: string): TeamsoLeaveTypeBalance;
12
+ /** Shift start/end of the caller's working-day calendar, falling back to 09:00-18:00. */
13
+ export declare function shiftWindow(workingDays: TeamsoWorkingDays | undefined): {
14
+ start: string;
15
+ end: string;
16
+ };
17
+ export interface PreparedLeaveRequest {
18
+ me: TeamsoUser;
19
+ context: LeavePolicyContext;
20
+ balance: TeamsoLeaveTypeBalance;
21
+ leaveType: LeaveTypeProjection;
22
+ /** `yyyy-MM-dd HH:mm`. */
23
+ startDate: string;
24
+ /** `yyyy-MM-dd HH:mm`. */
25
+ endDate: string;
26
+ workingDays: number;
27
+ returnToWorkDate?: string;
28
+ /** Reasons Teamso would refuse the request; empty when it can be created. */
29
+ problems: string[];
30
+ }
31
+ /**
32
+ * Everything the web app checks before creating a leave request: resolves the
33
+ * leave type in the caller's policy, applies the shift times, lets Teamso
34
+ * count the working days, then runs Teamso's own pre-check.
35
+ */
36
+ export declare function prepareLeaveRequest(client: TeamsoClient, input: {
37
+ leaveTypeId: string;
38
+ start: string;
39
+ end: string;
40
+ }, signal?: AbortSignal): Promise<PreparedLeaveRequest>;
41
+ export interface LeaveScanOptions {
42
+ /** Stop after this many matching leaves. */
43
+ limit: number;
44
+ pageSize?: number;
45
+ maxPages?: number;
46
+ }
47
+ export interface LeaveScanResult {
48
+ leaves: TeamsoLeave[];
49
+ /** True when more matching leaves may exist beyond what was collected. */
50
+ truncated: boolean;
51
+ }
52
+ /**
53
+ * Pages through the leave list (which also contains subordinates' and
54
+ * approval-queue leaves) and keeps the ones `predicate` accepts.
55
+ */
56
+ export declare function scanLeaves(client: TeamsoClient, params: TeamsoLeaveListParams, predicate: (leave: TeamsoLeave) => boolean, options: LeaveScanOptions, signal?: AbortSignal): Promise<LeaveScanResult>;
57
+ export declare function leaveTypeIdOf(leave: TeamsoLeave): string | undefined;
58
+ /** Owner of a leave: the list endpoints fill `user` and leave the flat `userId` null. */
59
+ export declare function leaveOwnerId(leave: TeamsoLeave): string | undefined;
60
+ //# sourceMappingURL=leave-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leave-support.d.ts","sourceRoot":"","sources":["../../src/tools/leave-support.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,UAAU,EACV,iBAAiB,EAClB,MAAM,aAAa,CAAC;AASrB,OAAO,EAAe,KAAK,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAmB/E,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,2BAA2B,CAAC;IACxC,QAAQ,EAAE,sBAAsB,EAAE,CAAC;CACpC;AAED,sFAAsF;AACtF,wBAAsB,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAS7G;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,GAAG,sBAAsB,CAUtG;AAED,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,WAAW,EAAE,iBAAiB,GAAG,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAOtG;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,UAAU,CAAC;IACf,OAAO,EAAE,kBAAkB,CAAC;IAC5B,OAAO,EAAE,sBAAsB,CAAC;IACh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AY_END, DEFAULT_WORKDAY_START, formatWallClock, parseWallClock, toClockTime, } from '../utils/dates.js';
3
+ import { ToolInputError } from '../utils/results.js';
4
+ import { toLeaveType } from '../utils/structured.js';
5
+ /** Machine reasons the leave endpoints return, explained for the assistant. */
6
+ const LEAVE_REASONS = {
7
+ least_day_count: 'The request is shorter than the minimum number of days per request for this leave type.',
8
+ most_day_count: 'The request is longer than the maximum number of days per request for this leave type.',
9
+ limited_for_each_request: 'The request exceeds the per-request day limit of this leave type.',
10
+ leave_available_for_dates: 'You already have leave on some of these dates.',
11
+ balance_cannot_go_negative: 'Your remaining balance for this leave type is not enough.',
12
+ limited_overdrawn: 'The request exceeds the overdraft allowed for this leave type.',
13
+ waiting_period: 'You are still in the waiting period for this leave type.',
14
+ BIRTHDAY_NOT_DEFINED: 'Your birthday is not recorded in Teamso, so birthday leave cannot be used.',
15
+ BIRTHDAY_LEAVE_DATE_OUT_OF_RANGE: 'Birthday leave must fall within the allowed range around your birthday.',
16
+ BIRTHDAY_LEAVE_MAX_ONE_DAY: 'Birthday leave can be at most one day.',
17
+ BIRTHDAY_LEAVE_BALANCE_ZERO: 'You have no birthday leave left.',
18
+ LEAVE_TYPE_GENDER_NOT_ELIGIBLE: 'This leave type is not available for you.',
19
+ DESCRIPTION_REQUIRED: 'This leave type requires a description.',
20
+ };
21
+ export function explainLeaveReason(reason) {
22
+ const text = LEAVE_REASONS[reason];
23
+ return text ? `${text} (\`${reason}\`)` : reason;
24
+ }
25
+ /** The caller's active leave policy and the leave types (with balances) it allows. */
26
+ export async function loadLeavePolicy(client, signal) {
27
+ const policies = await client.listLeavePolicies(signal);
28
+ const assignment = policies.find(policy => policy.activated) ?? policies[0];
29
+ if (!assignment) {
30
+ throw new ToolInputError('No leave policy is assigned to you in Teamso, so you cannot request leave yet. '
31
+ + 'Ask your HR administrator to assign one.');
32
+ }
33
+ const balances = await client.getLeavePolicyBalances(assignment.leavePolicyUserId, signal);
34
+ return { assignment, balances };
35
+ }
36
+ export function findLeaveType(context, leaveTypeId) {
37
+ const balance = context.balances.find(item => item.leaveTypeRequestModel?.id === leaveTypeId);
38
+ if (!balance) {
39
+ const available = context.balances
40
+ .map(item => `\`${item.leaveTypeRequestModel.id}\` (${item.leaveTypeRequestModel.name ?? 'unnamed'})`)
41
+ .join(', ');
42
+ throw new ToolInputError(`Leave type \`${leaveTypeId}\` is not in your leave policy. `
43
+ + `Available types: ${available || 'none'}. Call \`list_leave_types\` to choose one.`);
44
+ }
45
+ return balance;
46
+ }
47
+ /** Shift start/end of the caller's working-day calendar, falling back to 09:00-18:00. */
48
+ export function shiftWindow(workingDays) {
49
+ const details = workingDays?.workingDaysDetailRequestModels ?? [];
50
+ const day = details.find(detail => detail.visible !== false && detail.shiftStart && detail.shiftEnd);
51
+ return {
52
+ start: toClockTime(day?.shiftStart) ?? DEFAULT_WORKDAY_START,
53
+ end: toClockTime(day?.shiftEnd) ?? DEFAULT_WORKDAY_END,
54
+ };
55
+ }
56
+ /**
57
+ * Everything the web app checks before creating a leave request: resolves the
58
+ * leave type in the caller's policy, applies the shift times, lets Teamso
59
+ * count the working days, then runs Teamso's own pre-check.
60
+ */
61
+ export async function prepareLeaveRequest(client, input, signal) {
62
+ const start = parseWallClock(input.start, 'start');
63
+ const end = parseWallClock(input.end, 'end');
64
+ const [me, context, workingDays, holidays] = await Promise.all([
65
+ client.getMe(signal),
66
+ loadLeavePolicy(client, signal),
67
+ client.getMyWorkingDays(signal),
68
+ client.getMyPublicHolidays(signal),
69
+ ]);
70
+ const balance = findLeaveType(context, input.leaveTypeId);
71
+ const leaveType = toLeaveType(balance);
72
+ // Calendar-day types ignore times; the web app sends 00:00 for both ends.
73
+ const shift = shiftWindow(workingDays);
74
+ const startDate = formatWallClock(start.date, leaveType.countsCalendarDays ? '00:00' : start.time ?? shift.start);
75
+ const endDate = formatWallClock(end.date, leaveType.countsCalendarDays ? '00:00' : end.time ?? shift.end);
76
+ if (endDate < startDate) {
77
+ throw new ToolInputError(`The leave ends (${endDate}) before it starts (${startDate}).`);
78
+ }
79
+ let calculation;
80
+ try {
81
+ calculation = await client.calculateLeaveDays({
82
+ workingDaysId: workingDays.id,
83
+ publicHolidayId: holidays.id,
84
+ leaveTypeId: leaveType.id,
85
+ startDate,
86
+ endDate,
87
+ }, signal);
88
+ }
89
+ catch (error) {
90
+ throw explainDayLimitError(error, leaveType);
91
+ }
92
+ const workingDayCount = Number(calculation?.totalWorkingDays ?? 0);
93
+ const problems = [];
94
+ if (!(workingDayCount > 0)) {
95
+ problems.push('The selected dates contain no working days.');
96
+ }
97
+ if (leaveType.documentRequired) {
98
+ problems.push('This leave type requires a supporting document, which can only be uploaded in the '
99
+ + 'Teamso web or mobile app. Create this request there.');
100
+ }
101
+ if (workingDayCount > 0) {
102
+ try {
103
+ const check = await client.checkLeaveRequest({
104
+ leaveTypeId: leaveType.id,
105
+ addedDay: workingDayCount,
106
+ startDate,
107
+ endDate,
108
+ leavePolicyUserId: context.assignment.leavePolicyUserId,
109
+ userId: me.id,
110
+ }, signal);
111
+ for (const reason of check.allUserError ?? [])
112
+ problems.push(explainLeaveReason(String(reason)));
113
+ for (const entry of check.singleUserError ?? []) {
114
+ for (const reason of entry.title ?? [])
115
+ problems.push(explainLeaveReason(reason));
116
+ }
117
+ }
118
+ catch (error) {
119
+ if (error instanceof TeamsoApiError && error.status === 401)
120
+ throw error;
121
+ problems.push(`Teamso's pre-check could not run: ${error instanceof Error ? error.message : String(error)}`);
122
+ }
123
+ }
124
+ return {
125
+ me,
126
+ context,
127
+ balance,
128
+ leaveType,
129
+ startDate,
130
+ endDate,
131
+ workingDays: workingDayCount,
132
+ returnToWorkDate: calculation?.returnToWorkDate ?? undefined,
133
+ problems: [...new Set(problems)],
134
+ };
135
+ }
136
+ function explainDayLimitError(error, leaveType) {
137
+ if (!(error instanceof TeamsoApiError) || error.messageCode !== 'GET_ERROR')
138
+ return error;
139
+ const reason = typeof error.result === 'string' ? error.result : undefined;
140
+ switch (reason) {
141
+ case 'least_day_count':
142
+ return new ToolInputError(`"${leaveType.name}" needs at least ${leaveType.minDaysPerRequest ?? 'more'} `
143
+ + 'working days per request. Choose a longer range.');
144
+ case 'most_day_count':
145
+ return new ToolInputError(`"${leaveType.name}" allows at most ${leaveType.maxDaysPerRequest ?? 'fewer'} `
146
+ + 'working days per request. Choose a shorter range or split the request.');
147
+ case 'limited_for_each_request':
148
+ return new ToolInputError(`"${leaveType.name}" allows at most ${leaveType.dayLimit ?? 'fewer'} `
149
+ + 'days per request. Choose a shorter range.');
150
+ default:
151
+ return new ToolInputError(`Teamso could not count the working days for these dates${reason ? ` (${reason})` : ''}.`);
152
+ }
153
+ }
154
+ /**
155
+ * Pages through the leave list (which also contains subordinates' and
156
+ * approval-queue leaves) and keeps the ones `predicate` accepts.
157
+ */
158
+ export async function scanLeaves(client, params, predicate, options, signal) {
159
+ const pageSize = options.pageSize ?? 100;
160
+ const maxPages = options.maxPages ?? 10;
161
+ const leaves = [];
162
+ for (let page = 0; page < maxPages; page++) {
163
+ const result = await client.listLeaves({ ...params, page, size: pageSize }, signal);
164
+ const items = result?.items ?? [];
165
+ for (const leave of items) {
166
+ if (!predicate(leave))
167
+ continue;
168
+ if (leaves.length === options.limit)
169
+ return { leaves, truncated: true };
170
+ leaves.push(leave);
171
+ }
172
+ const hasNext = result?.pagination?.hasNext ?? items.length === pageSize;
173
+ if (!hasNext)
174
+ return { leaves, truncated: false };
175
+ }
176
+ return { leaves, truncated: true };
177
+ }
178
+ export function leaveTypeIdOf(leave) {
179
+ return leave.leaveTypeRequestModel?.id ?? leave.leaveTypeId;
180
+ }
181
+ /** Owner of a leave: the list endpoints fill `user` and leave the flat `userId` null. */
182
+ export function leaveOwnerId(leave) {
183
+ return leave.user?.id ?? leave.userId ?? undefined;
184
+ }
185
+ //# sourceMappingURL=leave-support.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leave-support.js","sourceRoot":"","sources":["../../src/tools/leave-support.ts"],"names":[],"mappings":"AAAA,OAAO,EA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EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;YACxE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,EAAE,UAAU,EAAE,OAAO,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC;QACzE,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACpD,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAkB;IAC9C,OAAO,KAAK,CAAC,qBAAqB,EAAE,EAAE,IAAI,KAAK,CAAC,WAAW,CAAC;AAC9D,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,YAAY,CAAC,KAAkB;IAC7C,OAAO,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,KAAK,CAAC,MAAM,IAAI,SAAS,CAAC;AACrD,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { TeamsoClient } from '../client.js';
3
+ export declare function registerListLeaveTypes(server: McpServer, client: TeamsoClient): void;
4
+ export declare function registerGetMyLeaveBalance(server: McpServer, client: TeamsoClient): void;
5
+ export declare function registerCalculateLeaveDays(server: McpServer, client: TeamsoClient): void;
6
+ export declare function registerRequestLeaveOtp(server: McpServer, client: TeamsoClient): void;
7
+ export declare function registerCreateLeaveRequest(server: McpServer, client: TeamsoClient): void;
8
+ export declare function registerListMyLeaves(server: McpServer, client: TeamsoClient): void;
9
+ export declare function registerCancelLeaveRequest(server: McpServer, client: TeamsoClient): void;
10
+ /** What happened to a new leave, from its status: approval chains can approve it on the spot. */
11
+ export declare function createdLeaveMessage(leave: {
12
+ status?: string;
13
+ } | null | undefined): string;
14
+ //# sourceMappingURL=leave.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leave.d.ts","sourceRoot":"","sources":["../../src/tools/leave.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAgFjD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAgCpF;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CA6BvF;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAyDxF;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAsCrF;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CA2ExF;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CA8ClF;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAqDxF;AA4DD,iGAAiG;AACjG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAgBzF"}