@modyo/mcp 0.1.0 → 0.1.2

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 (94) hide show
  1. package/README.md +204 -77
  2. package/build/shared/McpServerBase.d.ts.map +1 -1
  3. package/build/shared/McpServerBase.js +3 -25
  4. package/build/shared/McpServerBase.js.map +1 -1
  5. package/build/shared/ToolBase.d.ts +0 -13
  6. package/build/shared/ToolBase.d.ts.map +1 -1
  7. package/build/shared/ToolBase.js +0 -12
  8. package/build/shared/ToolBase.js.map +1 -1
  9. package/build/shared/index.d.ts +0 -1
  10. package/build/shared/index.d.ts.map +1 -1
  11. package/build/shared/index.js +0 -2
  12. package/build/shared/index.js.map +1 -1
  13. package/build/tools/channels/navigation/ManageItem.d.ts +1 -1
  14. package/build/tools/content/types/List.d.ts +1 -1
  15. package/build/tools/core/team/Manage.d.ts +1 -1
  16. package/build/tools/core/teamMembers/Manage.d.ts +1 -1
  17. package/build/tools/customers/forms/FormsManage.d.ts +1 -1
  18. package/build/tools/customers/originations/Manage.d.ts +1 -1
  19. package/build/tools/customers/segments/SegmentsManage.d.ts +1 -1
  20. package/build/tools/customers/settings/DataSetsManage.d.ts +1 -1
  21. package/build/tools/customers/submissions/Manage.d.ts +1 -1
  22. package/package.json +1 -1
  23. package/build/resources/channels/global/PlatformsClass.d.ts +0 -25
  24. package/build/resources/channels/global/PlatformsClass.d.ts.map +0 -1
  25. package/build/resources/channels/global/PlatformsClass.js +0 -34
  26. package/build/resources/channels/global/PlatformsClass.js.map +0 -1
  27. package/build/resources/channels/global/registerGlobalResources.d.ts +0 -2
  28. package/build/resources/channels/global/registerGlobalResources.d.ts.map +0 -1
  29. package/build/resources/channels/global/registerGlobalResources.js +0 -5
  30. package/build/resources/channels/global/registerGlobalResources.js.map +0 -1
  31. package/build/resources/channels/tools/ChannelsDocsToolsResource.d.ts +0 -46
  32. package/build/resources/channels/tools/ChannelsDocsToolsResource.d.ts.map +0 -1
  33. package/build/resources/channels/tools/ChannelsDocsToolsResource.js +0 -160
  34. package/build/resources/channels/tools/ChannelsDocsToolsResource.js.map +0 -1
  35. package/build/resources/content/global/PlatformsClass.d.ts +0 -25
  36. package/build/resources/content/global/PlatformsClass.d.ts.map +0 -1
  37. package/build/resources/content/global/PlatformsClass.js +0 -34
  38. package/build/resources/content/global/PlatformsClass.js.map +0 -1
  39. package/build/resources/content/global/registerGlobalResources.d.ts +0 -2
  40. package/build/resources/content/global/registerGlobalResources.d.ts.map +0 -1
  41. package/build/resources/content/global/registerGlobalResources.js +0 -5
  42. package/build/resources/content/global/registerGlobalResources.js.map +0 -1
  43. package/build/resources/content/tools/ContentDocsToolsResource.d.ts +0 -46
  44. package/build/resources/content/tools/ContentDocsToolsResource.d.ts.map +0 -1
  45. package/build/resources/content/tools/ContentDocsToolsResource.js +0 -160
  46. package/build/resources/content/tools/ContentDocsToolsResource.js.map +0 -1
  47. package/build/resources/content/tools/registerContentToolsResources.d.ts +0 -2
  48. package/build/resources/content/tools/registerContentToolsResources.d.ts.map +0 -1
  49. package/build/resources/content/tools/registerContentToolsResources.js +0 -5
  50. package/build/resources/content/tools/registerContentToolsResources.js.map +0 -1
  51. package/build/resources/core/tools/CoreDocsToolsResource.d.ts +0 -49
  52. package/build/resources/core/tools/CoreDocsToolsResource.d.ts.map +0 -1
  53. package/build/resources/core/tools/CoreDocsToolsResource.js +0 -165
  54. package/build/resources/core/tools/CoreDocsToolsResource.js.map +0 -1
  55. package/build/resources/core/tools/registerCoreToolsResources.d.ts +0 -2
  56. package/build/resources/core/tools/registerCoreToolsResources.d.ts.map +0 -1
  57. package/build/resources/core/tools/registerCoreToolsResources.js +0 -5
  58. package/build/resources/core/tools/registerCoreToolsResources.js.map +0 -1
  59. package/build/resources/customers/global/PlatformsClass.d.ts +0 -25
  60. package/build/resources/customers/global/PlatformsClass.d.ts.map +0 -1
  61. package/build/resources/customers/global/PlatformsClass.js +0 -34
  62. package/build/resources/customers/global/PlatformsClass.js.map +0 -1
  63. package/build/resources/customers/global/registerGlobalResources.d.ts +0 -2
  64. package/build/resources/customers/global/registerGlobalResources.d.ts.map +0 -1
  65. package/build/resources/customers/global/registerGlobalResources.js +0 -5
  66. package/build/resources/customers/global/registerGlobalResources.js.map +0 -1
  67. package/build/resources/customers/tools/CustomersDocsToolsResource.d.ts +0 -46
  68. package/build/resources/customers/tools/CustomersDocsToolsResource.d.ts.map +0 -1
  69. package/build/resources/customers/tools/CustomersDocsToolsResource.js +0 -160
  70. package/build/resources/customers/tools/CustomersDocsToolsResource.js.map +0 -1
  71. package/build/resources/customers/tools/registerCustomersToolsResources.d.ts +0 -2
  72. package/build/resources/customers/tools/registerCustomersToolsResources.d.ts.map +0 -1
  73. package/build/resources/customers/tools/registerCustomersToolsResources.js +0 -5
  74. package/build/resources/customers/tools/registerCustomersToolsResources.js.map +0 -1
  75. package/build/shared/helpers/deprecation.d.ts +0 -76
  76. package/build/shared/helpers/deprecation.d.ts.map +0 -1
  77. package/build/shared/helpers/deprecation.js +0 -97
  78. package/build/shared/helpers/deprecation.js.map +0 -1
  79. package/build/shared/test-utils/index.d.ts +0 -2
  80. package/build/shared/test-utils/index.d.ts.map +0 -1
  81. package/build/shared/test-utils/index.js +0 -2
  82. package/build/shared/test-utils/index.js.map +0 -1
  83. package/build/shared/test-utils/toolTestUtils.d.ts +0 -191
  84. package/build/shared/test-utils/toolTestUtils.d.ts.map +0 -1
  85. package/build/shared/test-utils/toolTestUtils.js +0 -304
  86. package/build/shared/test-utils/toolTestUtils.js.map +0 -1
  87. package/build/tools/channels/widgets/WidgetsTools.d.ts +0 -2
  88. package/build/tools/channels/widgets/WidgetsTools.d.ts.map +0 -1
  89. package/build/tools/channels/widgets/WidgetsTools.js +0 -4
  90. package/build/tools/channels/widgets/WidgetsTools.js.map +0 -1
  91. /package/build/tools/customers/submissions/{submissionsTools.d.ts → SubmissionsTools.d.ts} +0 -0
  92. /package/build/tools/customers/submissions/{submissionsTools.d.ts.map → SubmissionsTools.d.ts.map} +0 -0
  93. /package/build/tools/customers/submissions/{submissionsTools.js → SubmissionsTools.js} +0 -0
  94. /package/build/tools/customers/submissions/{submissionsTools.js.map → SubmissionsTools.js.map} +0 -0
@@ -1,76 +0,0 @@
1
- import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
- /**
3
- * Metadata about a deprecated tool
4
- */
5
- export interface DeprecationMetadata {
6
- /** Version when this tool was deprecated (e.g., "2.0.0") */
7
- since: string;
8
- /** Name of the replacement tool */
9
- replacement: string;
10
- /** Brief example of how to use the replacement */
11
- example: string;
12
- /** Version when this tool will be removed (e.g., "3.0.0") */
13
- removalVersion: string;
14
- /** URL to migration documentation */
15
- documentationUrl: string;
16
- }
17
- /**
18
- * Logs a deprecation warning to console when a deprecated tool is used
19
- *
20
- * @param toolName - Name of the deprecated tool
21
- * @param metadata - Deprecation metadata
22
- *
23
- * @example
24
- * ```typescript
25
- * logDeprecationWarning("entry-create", {
26
- * since: "2.0.0",
27
- * replacement: "entries-manage",
28
- * example: "Use entries-manage with action='manage' and entry creation fields",
29
- * removalVersion: "3.0.0",
30
- * documentationUrl: "modyo://docs/migration/entries#create"
31
- * });
32
- * ```
33
- */
34
- export declare function logDeprecationWarning(toolName: string, metadata: DeprecationMetadata): void;
35
- /**
36
- * Creates a CallToolResult with deprecation metadata included
37
- *
38
- * @param content - The actual tool response data
39
- * @param metadata - Deprecation metadata to include
40
- * @returns CallToolResult with _meta field containing deprecation info
41
- *
42
- * @example
43
- * ```typescript
44
- * const result = await this.repository.create(params);
45
- * return createDeprecationResponse(result, this.deprecationMetadata);
46
- * ```
47
- */
48
- export declare function createDeprecationResponse(content: unknown, metadata: DeprecationMetadata): CallToolResult;
49
- /**
50
- * Class decorator to mark a tool as deprecated
51
- *
52
- * Automatically adds deprecation metadata to the tool's config and ensures
53
- * the tool logs warnings when used.
54
- *
55
- * @param metadata - Deprecation metadata
56
- * @returns Class decorator function
57
- *
58
- * @example
59
- * ```typescript
60
- * @markAsDeprecated({
61
- * since: "2.0.0",
62
- * replacement: "entries-manage",
63
- * example: "Use entries-manage with action='manage'",
64
- * removalVersion: "3.0.0",
65
- * documentationUrl: "modyo://docs/migration/entries#create"
66
- * })
67
- * export class EntryCreateTool extends ToolBase<ParamsSchema> {
68
- * protected config = {
69
- * name: "entry-create",
70
- * description: "Creates a new entry",
71
- * };
72
- * }
73
- * ```
74
- */
75
- export declare function markAsDeprecated(metadata: DeprecationMetadata): <T extends new (...args: any[]) => any>(TargetClass: T) => T;
76
- //# sourceMappingURL=deprecation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deprecation.d.ts","sourceRoot":"","sources":["../../../src/shared/helpers/deprecation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,cAAc,EAAE,MAAM,CAAC;IACvB,qCAAqC;IACrC,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,mBAAmB,GAC5B,IAAI,CAQN;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,mBAAmB,GAC5B,cAAc,CA2BhB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,mBAAmB,IAC3C,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,aAAa,CAAC,KAAG,CAAC,CAS3E"}
@@ -1,97 +0,0 @@
1
- /**
2
- * Logs a deprecation warning to console when a deprecated tool is used
3
- *
4
- * @param toolName - Name of the deprecated tool
5
- * @param metadata - Deprecation metadata
6
- *
7
- * @example
8
- * ```typescript
9
- * logDeprecationWarning("entry-create", {
10
- * since: "2.0.0",
11
- * replacement: "entries-manage",
12
- * example: "Use entries-manage with action='manage' and entry creation fields",
13
- * removalVersion: "3.0.0",
14
- * documentationUrl: "modyo://docs/migration/entries#create"
15
- * });
16
- * ```
17
- */
18
- export function logDeprecationWarning(toolName, metadata) {
19
- console.warn(`[DEPRECATION WARNING] Tool "${toolName}" is deprecated since v${metadata.since}.\n` +
20
- ` → Use "${metadata.replacement}" instead.\n` +
21
- ` → Example: ${metadata.example}\n` +
22
- ` → Will be removed in v${metadata.removalVersion}\n` +
23
- ` → See: ${metadata.documentationUrl}`);
24
- }
25
- /**
26
- * Creates a CallToolResult with deprecation metadata included
27
- *
28
- * @param content - The actual tool response data
29
- * @param metadata - Deprecation metadata to include
30
- * @returns CallToolResult with _meta field containing deprecation info
31
- *
32
- * @example
33
- * ```typescript
34
- * const result = await this.repository.create(params);
35
- * return createDeprecationResponse(result, this.deprecationMetadata);
36
- * ```
37
- */
38
- export function createDeprecationResponse(content, metadata) {
39
- // Convert content to object if it's not already
40
- const contentObj = typeof content === "object" && content !== null ? content : {};
41
- return {
42
- content: [
43
- {
44
- type: "text",
45
- text: JSON.stringify({
46
- ...contentObj,
47
- _meta: {
48
- deprecated: true,
49
- deprecatedSince: metadata.since,
50
- replacement: metadata.replacement,
51
- removalVersion: metadata.removalVersion,
52
- documentationUrl: metadata.documentationUrl,
53
- },
54
- }, null, 2),
55
- },
56
- ],
57
- isError: false,
58
- };
59
- }
60
- /**
61
- * Class decorator to mark a tool as deprecated
62
- *
63
- * Automatically adds deprecation metadata to the tool's config and ensures
64
- * the tool logs warnings when used.
65
- *
66
- * @param metadata - Deprecation metadata
67
- * @returns Class decorator function
68
- *
69
- * @example
70
- * ```typescript
71
- * @markAsDeprecated({
72
- * since: "2.0.0",
73
- * replacement: "entries-manage",
74
- * example: "Use entries-manage with action='manage'",
75
- * removalVersion: "3.0.0",
76
- * documentationUrl: "modyo://docs/migration/entries#create"
77
- * })
78
- * export class EntryCreateTool extends ToolBase<ParamsSchema> {
79
- * protected config = {
80
- * name: "entry-create",
81
- * description: "Creates a new entry",
82
- * };
83
- * }
84
- * ```
85
- */
86
- export function markAsDeprecated(metadata) {
87
- return function (TargetClass) {
88
- return class extends TargetClass {
89
- config = {
90
- ...(super.config || this.config),
91
- isDeprecated: true,
92
- deprecationMetadata: metadata,
93
- };
94
- };
95
- };
96
- }
97
- //# sourceMappingURL=deprecation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deprecation.js","sourceRoot":"","sources":["../../../src/shared/helpers/deprecation.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAgB,EAChB,QAA6B;IAE7B,OAAO,CAAC,IAAI,CACV,+BAA+B,QAAQ,0BAA0B,QAAQ,CAAC,KAAK,KAAK;QAClF,YAAY,QAAQ,CAAC,WAAW,cAAc;QAC9C,gBAAgB,QAAQ,CAAC,OAAO,IAAI;QACpC,2BAA2B,QAAQ,CAAC,cAAc,IAAI;QACtD,YAAY,QAAQ,CAAC,gBAAgB,EAAE,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAgB,EAChB,QAA6B;IAE7B,gDAAgD;IAChD,MAAM,UAAU,GACd,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAEjE,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB;oBACE,GAAG,UAAU;oBACb,KAAK,EAAE;wBACL,UAAU,EAAE,IAAI;wBAChB,eAAe,EAAE,QAAQ,CAAC,KAAK;wBAC/B,WAAW,EAAE,QAAQ,CAAC,WAAW;wBACjC,cAAc,EAAE,QAAQ,CAAC,cAAc;wBACvC,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;qBAC5C;iBACF,EACD,IAAI,EACJ,CAAC,CACF;aACF;SACF;QACD,OAAO,EAAE,KAAK;KACf,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAA6B;IAC5D,OAAO,UAAiD,WAAc;QACpE,OAAO,KAAM,SAAQ,WAAW;YAC9B,MAAM,GAAQ;gBACZ,GAAG,CAAC,KAAK,CAAC,MAAM,IAAK,IAAY,CAAC,MAAM,CAAC;gBACzC,YAAY,EAAE,IAAI;gBAClB,mBAAmB,EAAE,QAAQ;aAC9B,CAAC;SACa,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from "./toolTestUtils.js";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shared/test-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from "./toolTestUtils.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/test-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
@@ -1,191 +0,0 @@
1
- import { type Mock, vi } from "vitest";
2
- import type { Logger } from "../types/Logger.js";
3
- /**
4
- * Test utilities for MCP tool testing
5
- *
6
- * These utilities provide common mocking patterns for testing MCP tools,
7
- * reducing boilerplate and ensuring consistency across tests.
8
- *
9
- * Features:
10
- * - Mock creators for server, organizations, logger
11
- * - Result extractors and parsers
12
- * - Parametrized test case helpers
13
- * - Test fixtures via test.extend pattern
14
- */
15
- export { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi, } from "vitest";
16
- export interface MockServer {
17
- registerTool: Mock;
18
- server: {
19
- elicitInput: Mock;
20
- };
21
- }
22
- /**
23
- * Creates a mock MCP server with registerTool spy
24
- */
25
- export declare function createMockServer(): MockServer;
26
- /**
27
- * Creates a mock logger function
28
- */
29
- export declare function createMockLogger(): Logger;
30
- /**
31
- * Creates a mock repository with specified methods
32
- */
33
- export declare function createMockRepository<T extends Record<string, unknown>>(methods: {
34
- [K in keyof T]: T[K] extends (...args: unknown[]) => unknown ? ReturnType<typeof vi.fn> : never;
35
- }): T;
36
- /**
37
- * Extracts the tool handler function from a mock server's registerTool calls
38
- */
39
- export declare function extractToolHandler(mockServer: MockServer, callIndex?: number): (params: unknown) => Promise<unknown>;
40
- /**
41
- * Extracts tool metadata from registerTool call
42
- */
43
- export declare function extractToolMetadata(mockServer: MockServer, callIndex?: number): {
44
- name: string;
45
- description: unknown;
46
- inputSchema: unknown;
47
- annotations: unknown;
48
- };
49
- /**
50
- * Helper to assert CallToolResult structure
51
- */
52
- export declare function isCallToolResult(result: unknown): boolean;
53
- /**
54
- * Helper to extract text content from CallToolResult
55
- */
56
- export declare function extractResultText(result: unknown): string;
57
- /**
58
- * Helper to parse JSON from CallToolResult text
59
- */
60
- export declare function parseResultJSON<T = unknown>(result: unknown): T;
61
- export interface ToolTestSetup {
62
- server: MockServer;
63
- logger: Logger;
64
- extractHandler: (callIndex?: number) => (params: unknown) => Promise<unknown>;
65
- extractMetadata: (callIndex?: number) => {
66
- name: string;
67
- description: unknown;
68
- inputSchema: unknown;
69
- annotations: unknown;
70
- };
71
- }
72
- /**
73
- * Creates a complete test setup with all common mocks
74
- */
75
- export declare function setupToolTest(): ToolTestSetup;
76
- /**
77
- * Test case type for validation tests
78
- */
79
- export interface ValidationTestCase {
80
- name: string;
81
- input: Record<string, unknown>;
82
- expectedError?: string;
83
- }
84
- /**
85
- * Test case type for query parameter tests
86
- */
87
- export interface QueryParamTestCase {
88
- description: string;
89
- params: Record<string, unknown>;
90
- expectedCall?: Record<string, unknown>;
91
- }
92
- /**
93
- * Test case type for ID iteration tests
94
- */
95
- export interface IdIterationTestCase<T = unknown> {
96
- id: number;
97
- expectedResult?: T;
98
- description?: string;
99
- }
100
- /**
101
- * Standard pagination test cases for reuse across tests
102
- */
103
- export declare const STANDARD_PAGINATION_CASES: QueryParamTestCase[];
104
- /**
105
- * Standard ID iteration test cases
106
- */
107
- export declare const STANDARD_ID_CASES: number[];
108
- /**
109
- * Standard query filter test cases
110
- */
111
- export declare const STANDARD_QUERY_CASES: QueryParamTestCase[];
112
- /**
113
- * Combines pagination and query cases for comprehensive list testing
114
- */
115
- export declare const STANDARD_LIST_CASES: QueryParamTestCase[];
116
- /**
117
- * Standard status filter cases for job/task filtering
118
- */
119
- export declare const STANDARD_STATUS_CASES: ({
120
- status: "pending";
121
- description: string;
122
- } | {
123
- status: "processing";
124
- description: string;
125
- } | {
126
- status: "completed";
127
- description: string;
128
- } | {
129
- status: "failed";
130
- description: string;
131
- })[];
132
- /**
133
- * Standard action test cases for CRUD operations
134
- */
135
- export declare const STANDARD_ACTION_CASES: ({
136
- action: "list";
137
- description: string;
138
- } | {
139
- action: "get";
140
- description: string;
141
- } | {
142
- action: "create";
143
- description: string;
144
- } | {
145
- action: "update";
146
- description: string;
147
- } | {
148
- action: "delete";
149
- description: string;
150
- })[];
151
- /**
152
- * Test fixtures interface for type-safe fixture access
153
- */
154
- export interface ToolTestFixtures {
155
- /** Pre-configured mock MCP server */
156
- server: MockServer;
157
- /** Pre-configured mock logger */
158
- logger: Logger;
159
- /** Complete test setup with extractors */
160
- testSetup: ToolTestSetup;
161
- }
162
- /**
163
- * Extended test with common fixtures for MCP tool testing.
164
- * Use this instead of base `test` when you need server and logger fixtures.
165
- *
166
- * @example
167
- * ```typescript
168
- * import { test, expect, describe } from "./index.js";
169
- *
170
- * describe("MyTool", () => {
171
- * test("should register tool", async ({ server, logger }) => {
172
- * MyTool.registerTool(server, "mcp-test", logger);
173
- * expect(server.registerTool).toHaveBeenCalled();
174
- * });
175
- *
176
- * // Or use the complete testSetup
177
- * test("should handle request", async ({ testSetup }) => {
178
- * MyTool.registerTool(testSetup.server, "mcp-test", testSetup.logger);
179
- * const handler = testSetup.extractHandler();
180
- * const result = await handler({ action: "list" });
181
- * expect(result).toBeDefined();
182
- * });
183
- * });
184
- * ```
185
- */
186
- export declare const test: import("vitest").TestAPI<{
187
- server: MockServer;
188
- logger: Logger;
189
- testSetup: ToolTestSetup;
190
- }>;
191
- //# sourceMappingURL=toolTestUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"toolTestUtils.d.ts","sourceRoot":"","sources":["../../../src/shared/test-utils/toolTestUtils.ts"],"names":[],"mappings":"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"}
@@ -1,304 +0,0 @@
1
- import { test as baseTest, vi } from "vitest";
2
- /**
3
- * Test utilities for MCP tool testing
4
- *
5
- * These utilities provide common mocking patterns for testing MCP tools,
6
- * reducing boilerplate and ensuring consistency across tests.
7
- *
8
- * Features:
9
- * - Mock creators for server, organizations, logger
10
- * - Result extractors and parsers
11
- * - Parametrized test case helpers
12
- * - Test fixtures via test.extend pattern
13
- */
14
- // Re-export vitest utilities for convenience
15
- export { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi, } from "vitest";
16
- // ============================================
17
- // MOCK CREATORS
18
- // ============================================
19
- /**
20
- * Creates a mock MCP server with registerTool spy
21
- */
22
- export function createMockServer() {
23
- return {
24
- registerTool: vi.fn(),
25
- server: {
26
- elicitInput: vi.fn(),
27
- },
28
- };
29
- }
30
- /**
31
- * Creates a mock logger function
32
- */
33
- export function createMockLogger() {
34
- return vi.fn();
35
- }
36
- /**
37
- * Creates a mock repository with specified methods
38
- */
39
- export function createMockRepository(methods) {
40
- return methods;
41
- }
42
- // ============================================
43
- // EXTRACTORS
44
- // ============================================
45
- /**
46
- * Extracts the tool handler function from a mock server's registerTool calls
47
- */
48
- export function extractToolHandler(mockServer, callIndex = 0) {
49
- const calls = mockServer.registerTool.mock.calls;
50
- if (calls.length === 0) {
51
- throw new Error("registerTool was not called on the mock server");
52
- }
53
- if (callIndex >= calls.length) {
54
- throw new Error(`Call index ${callIndex} out of bounds (${calls.length} calls made)`);
55
- }
56
- const handler = calls[callIndex]?.[2];
57
- if (!handler || typeof handler !== "function") {
58
- throw new Error("Handler function not found in registerTool call");
59
- }
60
- return handler;
61
- }
62
- /**
63
- * Extracts tool metadata from registerTool call
64
- */
65
- export function extractToolMetadata(mockServer, callIndex = 0) {
66
- const calls = mockServer.registerTool.mock.calls;
67
- if (calls.length === 0 || callIndex >= calls.length) {
68
- throw new Error("Invalid call index or no calls made");
69
- }
70
- const [name, metadata] = calls[callIndex];
71
- return {
72
- name,
73
- description: metadata.description,
74
- inputSchema: metadata.inputSchema,
75
- annotations: metadata.annotations,
76
- };
77
- }
78
- // ============================================
79
- // RESULT HELPERS
80
- // ============================================
81
- /**
82
- * Helper to assert CallToolResult structure
83
- */
84
- export function isCallToolResult(result) {
85
- if (!result || typeof result !== "object")
86
- return false;
87
- const r = result;
88
- return (Array.isArray(r.content) &&
89
- r.content.every((item) => typeof item === "object" &&
90
- item !== null &&
91
- "type" in item &&
92
- "text" in item));
93
- }
94
- /**
95
- * Helper to extract text content from CallToolResult
96
- */
97
- export function extractResultText(result) {
98
- if (!result || typeof result !== "object") {
99
- throw new Error("Invalid result object");
100
- }
101
- const r = result;
102
- if (!Array.isArray(r.content)) {
103
- throw new Error("Result does not have content array");
104
- }
105
- return r.content.map((item) => item.text ?? "").join("\n");
106
- }
107
- /**
108
- * Helper to parse JSON from CallToolResult text
109
- */
110
- export function parseResultJSON(result) {
111
- const text = extractResultText(result);
112
- try {
113
- return JSON.parse(text);
114
- }
115
- catch (error) {
116
- throw new Error(`Failed to parse result JSON: ${error instanceof Error ? error.message : String(error)}`);
117
- }
118
- }
119
- /**
120
- * Creates a complete test setup with all common mocks
121
- */
122
- export function setupToolTest() {
123
- const server = createMockServer();
124
- const logger = createMockLogger();
125
- return {
126
- server,
127
- logger,
128
- extractHandler: (callIndex = 0) => extractToolHandler(server, callIndex),
129
- extractMetadata: (callIndex = 0) => extractToolMetadata(server, callIndex),
130
- };
131
- }
132
- /**
133
- * Standard pagination test cases for reuse across tests
134
- */
135
- export const STANDARD_PAGINATION_CASES = [
136
- {
137
- description: "page only",
138
- params: {
139
- page: 2,
140
- },
141
- expectedCall: {
142
- page: 2,
143
- },
144
- },
145
- {
146
- description: "per_page only",
147
- params: {
148
- per_page: 50,
149
- },
150
- expectedCall: {
151
- per_page: 50,
152
- },
153
- },
154
- {
155
- description: "page and per_page",
156
- params: {
157
- page: 3,
158
- per_page: 25,
159
- },
160
- expectedCall: {
161
- page: 3,
162
- per_page: 25,
163
- },
164
- },
165
- ];
166
- /**
167
- * Standard ID iteration test cases
168
- */
169
- export const STANDARD_ID_CASES = [
170
- 1,
171
- 42,
172
- 999,
173
- ];
174
- /**
175
- * Standard query filter test cases
176
- */
177
- export const STANDARD_QUERY_CASES = [
178
- {
179
- description: "search query",
180
- params: {
181
- query: "test-search",
182
- },
183
- expectedCall: {
184
- query: "test-search",
185
- },
186
- },
187
- {
188
- description: "sorting ascending",
189
- params: {
190
- sort_by: "name",
191
- order: "asc",
192
- },
193
- expectedCall: {
194
- sort_by: "name",
195
- order: "asc",
196
- },
197
- },
198
- {
199
- description: "sorting descending",
200
- params: {
201
- sort_by: "created_at",
202
- order: "desc",
203
- },
204
- expectedCall: {
205
- sort_by: "created_at",
206
- order: "desc",
207
- },
208
- },
209
- ];
210
- /**
211
- * Combines pagination and query cases for comprehensive list testing
212
- */
213
- export const STANDARD_LIST_CASES = [
214
- ...STANDARD_PAGINATION_CASES,
215
- ...STANDARD_QUERY_CASES,
216
- ];
217
- /**
218
- * Standard status filter cases for job/task filtering
219
- */
220
- export const STANDARD_STATUS_CASES = [
221
- {
222
- status: "pending",
223
- description: "pending items",
224
- },
225
- {
226
- status: "processing",
227
- description: "processing items",
228
- },
229
- {
230
- status: "completed",
231
- description: "completed items",
232
- },
233
- {
234
- status: "failed",
235
- description: "failed items",
236
- },
237
- ];
238
- /**
239
- * Standard action test cases for CRUD operations
240
- */
241
- export const STANDARD_ACTION_CASES = [
242
- {
243
- action: "list",
244
- description: "list action",
245
- },
246
- {
247
- action: "get",
248
- description: "get action",
249
- },
250
- {
251
- action: "create",
252
- description: "create action",
253
- },
254
- {
255
- action: "update",
256
- description: "update action",
257
- },
258
- {
259
- action: "delete",
260
- description: "delete action",
261
- },
262
- ];
263
- /**
264
- * Extended test with common fixtures for MCP tool testing.
265
- * Use this instead of base `test` when you need server and logger fixtures.
266
- *
267
- * @example
268
- * ```typescript
269
- * import { test, expect, describe } from "./index.js";
270
- *
271
- * describe("MyTool", () => {
272
- * test("should register tool", async ({ server, logger }) => {
273
- * MyTool.registerTool(server, "mcp-test", logger);
274
- * expect(server.registerTool).toHaveBeenCalled();
275
- * });
276
- *
277
- * // Or use the complete testSetup
278
- * test("should handle request", async ({ testSetup }) => {
279
- * MyTool.registerTool(testSetup.server, "mcp-test", testSetup.logger);
280
- * const handler = testSetup.extractHandler();
281
- * const result = await handler({ action: "list" });
282
- * expect(result).toBeDefined();
283
- * });
284
- * });
285
- * ```
286
- */
287
- export const test = baseTest.extend({
288
- // biome-ignore lint/correctness/noEmptyPattern: Required by Vitest extend API
289
- server: async ({}, use) => {
290
- const mockServer = createMockServer();
291
- await use(mockServer);
292
- },
293
- // biome-ignore lint/correctness/noEmptyPattern: Required by Vitest extend API
294
- logger: async ({}, use) => {
295
- const mockLogger = createMockLogger();
296
- await use(mockLogger);
297
- },
298
- // biome-ignore lint/correctness/noEmptyPattern: Required by Vitest extend API
299
- testSetup: async ({}, use) => {
300
- const setup = setupToolTest();
301
- await use(setup);
302
- },
303
- });
304
- //# sourceMappingURL=toolTestUtils.js.map