@cyanheads/mcp-ts-core 0.11.2 → 0.11.4

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 (163) hide show
  1. package/AGENTS.md +14 -10
  2. package/CLAUDE.md +14 -10
  3. package/README.md +3 -3
  4. package/changelog/0.11.x/0.11.3.md +49 -0
  5. package/changelog/0.11.x/0.11.4.md +67 -0
  6. package/dist/config/index.d.ts +0 -10
  7. package/dist/config/index.d.ts.map +1 -1
  8. package/dist/config/index.js +1 -25
  9. package/dist/config/index.js.map +1 -1
  10. package/dist/config/logLevelAlias.d.ts +15 -0
  11. package/dist/config/logLevelAlias.d.ts.map +1 -0
  12. package/dist/config/logLevelAlias.js +30 -0
  13. package/dist/config/logLevelAlias.js.map +1 -0
  14. package/dist/core/context.d.ts +10 -0
  15. package/dist/core/context.d.ts.map +1 -1
  16. package/dist/core/context.js +10 -1
  17. package/dist/core/context.js.map +1 -1
  18. package/dist/core/worker.js +1 -1
  19. package/dist/core/worker.js.map +1 -1
  20. package/dist/linter/rules/enrichment-rules.d.ts +3 -2
  21. package/dist/linter/rules/enrichment-rules.d.ts.map +1 -1
  22. package/dist/linter/rules/enrichment-rules.js +35 -7
  23. package/dist/linter/rules/enrichment-rules.js.map +1 -1
  24. package/dist/linter/rules/format-parity-rules.d.ts +8 -4
  25. package/dist/linter/rules/format-parity-rules.d.ts.map +1 -1
  26. package/dist/linter/rules/format-parity-rules.js +72 -20
  27. package/dist/linter/rules/format-parity-rules.js.map +1 -1
  28. package/dist/linter/rules/index.d.ts +1 -1
  29. package/dist/linter/rules/index.d.ts.map +1 -1
  30. package/dist/linter/rules/index.js +1 -1
  31. package/dist/linter/rules/index.js.map +1 -1
  32. package/dist/linter/rules/prompt-rules.d.ts.map +1 -1
  33. package/dist/linter/rules/prompt-rules.js +6 -3
  34. package/dist/linter/rules/prompt-rules.js.map +1 -1
  35. package/dist/linter/rules/resource-rules.d.ts.map +1 -1
  36. package/dist/linter/rules/resource-rules.js +11 -5
  37. package/dist/linter/rules/resource-rules.js.map +1 -1
  38. package/dist/linter/rules/schema-rules.d.ts +21 -2
  39. package/dist/linter/rules/schema-rules.d.ts.map +1 -1
  40. package/dist/linter/rules/schema-rules.js +110 -2
  41. package/dist/linter/rules/schema-rules.js.map +1 -1
  42. package/dist/linter/rules/tool-rules.d.ts.map +1 -1
  43. package/dist/linter/rules/tool-rules.js +11 -5
  44. package/dist/linter/rules/tool-rules.js.map +1 -1
  45. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
  46. package/dist/mcp-server/tools/utils/toolHandlerFactory.js +44 -10
  47. package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
  48. package/dist/services/mirror/sqlite/sqliteMirrorStore.d.ts +10 -10
  49. package/dist/services/mirror/sqlite/sqliteMirrorStore.d.ts.map +1 -1
  50. package/dist/services/mirror/sqlite/sqliteMirrorStore.js +29 -24
  51. package/dist/services/mirror/sqlite/sqliteMirrorStore.js.map +1 -1
  52. package/dist/storage/core/storageValidation.d.ts +4 -4
  53. package/dist/storage/core/storageValidation.d.ts.map +1 -1
  54. package/dist/storage/core/storageValidation.js +4 -20
  55. package/dist/storage/core/storageValidation.js.map +1 -1
  56. package/dist/testing/fuzz.d.ts.map +1 -1
  57. package/dist/testing/fuzz.js +57 -2
  58. package/dist/testing/fuzz.js.map +1 -1
  59. package/dist/testing/index.d.ts +45 -13
  60. package/dist/testing/index.d.ts.map +1 -1
  61. package/dist/testing/index.js +29 -76
  62. package/dist/testing/index.js.map +1 -1
  63. package/dist/testing/vitest.d.ts +1 -1
  64. package/dist/utils/formatting/diffFormatter.d.ts +5 -5
  65. package/dist/utils/formatting/diffFormatter.d.ts.map +1 -1
  66. package/dist/utils/formatting/diffFormatter.js +1 -1
  67. package/dist/utils/formatting/diffFormatter.js.map +1 -1
  68. package/dist/utils/formatting/tableFormatter.d.ts +3 -3
  69. package/dist/utils/formatting/tableFormatter.d.ts.map +1 -1
  70. package/dist/utils/formatting/tableFormatter.js +1 -1
  71. package/dist/utils/formatting/tableFormatter.js.map +1 -1
  72. package/dist/utils/formatting/treeFormatter.d.ts +3 -3
  73. package/dist/utils/formatting/treeFormatter.d.ts.map +1 -1
  74. package/dist/utils/formatting/treeFormatter.js +1 -1
  75. package/dist/utils/formatting/treeFormatter.js.map +1 -1
  76. package/dist/utils/metrics/tokenCounter.d.ts +3 -3
  77. package/dist/utils/metrics/tokenCounter.d.ts.map +1 -1
  78. package/dist/utils/metrics/tokenCounter.js.map +1 -1
  79. package/dist/utils/network/fetchWithTimeout.d.ts +43 -15
  80. package/dist/utils/network/fetchWithTimeout.d.ts.map +1 -1
  81. package/dist/utils/network/fetchWithTimeout.js +163 -44
  82. package/dist/utils/network/fetchWithTimeout.js.map +1 -1
  83. package/dist/utils/network/httpError.d.ts.map +1 -1
  84. package/dist/utils/network/httpError.js +1 -2
  85. package/dist/utils/network/httpError.js.map +1 -1
  86. package/dist/utils/network/responseBody.d.ts +27 -7
  87. package/dist/utils/network/responseBody.d.ts.map +1 -1
  88. package/dist/utils/network/responseBody.js +54 -13
  89. package/dist/utils/network/responseBody.js.map +1 -1
  90. package/dist/utils/network/retry.d.ts +2 -2
  91. package/dist/utils/network/retry.d.ts.map +1 -1
  92. package/dist/utils/overflow/outlineOnOverflow.d.ts +4 -3
  93. package/dist/utils/overflow/outlineOnOverflow.d.ts.map +1 -1
  94. package/dist/utils/overflow/outlineOnOverflow.js +27 -8
  95. package/dist/utils/overflow/outlineOnOverflow.js.map +1 -1
  96. package/dist/utils/pagination/pagination.d.ts +3 -3
  97. package/dist/utils/pagination/pagination.d.ts.map +1 -1
  98. package/dist/utils/pagination/pagination.js.map +1 -1
  99. package/dist/utils/parsing/csvParser.d.ts +2 -2
  100. package/dist/utils/parsing/csvParser.d.ts.map +1 -1
  101. package/dist/utils/parsing/csvParser.js +1 -1
  102. package/dist/utils/parsing/csvParser.js.map +1 -1
  103. package/dist/utils/parsing/dateParser.d.ts +11 -7
  104. package/dist/utils/parsing/dateParser.d.ts.map +1 -1
  105. package/dist/utils/parsing/dateParser.js +8 -4
  106. package/dist/utils/parsing/dateParser.js.map +1 -1
  107. package/dist/utils/parsing/frontmatterParser.d.ts +5 -4
  108. package/dist/utils/parsing/frontmatterParser.d.ts.map +1 -1
  109. package/dist/utils/parsing/frontmatterParser.js +5 -4
  110. package/dist/utils/parsing/frontmatterParser.js.map +1 -1
  111. package/dist/utils/parsing/htmlExtractor.d.ts +5 -4
  112. package/dist/utils/parsing/htmlExtractor.d.ts.map +1 -1
  113. package/dist/utils/parsing/htmlExtractor.js +4 -3
  114. package/dist/utils/parsing/htmlExtractor.js.map +1 -1
  115. package/dist/utils/parsing/inputBudget.d.ts +18 -11
  116. package/dist/utils/parsing/inputBudget.d.ts.map +1 -1
  117. package/dist/utils/parsing/inputBudget.js +20 -17
  118. package/dist/utils/parsing/inputBudget.js.map +1 -1
  119. package/dist/utils/parsing/jsonParser.d.ts +5 -4
  120. package/dist/utils/parsing/jsonParser.d.ts.map +1 -1
  121. package/dist/utils/parsing/jsonParser.js +5 -4
  122. package/dist/utils/parsing/jsonParser.js.map +1 -1
  123. package/dist/utils/parsing/pdfParser.d.ts +38 -24
  124. package/dist/utils/parsing/pdfParser.d.ts.map +1 -1
  125. package/dist/utils/parsing/pdfParser.js +42 -31
  126. package/dist/utils/parsing/pdfParser.js.map +1 -1
  127. package/dist/utils/parsing/xmlParser.d.ts +3 -3
  128. package/dist/utils/parsing/xmlParser.d.ts.map +1 -1
  129. package/dist/utils/parsing/xmlParser.js +3 -6
  130. package/dist/utils/parsing/xmlParser.js.map +1 -1
  131. package/dist/utils/parsing/yamlParser.d.ts +3 -3
  132. package/dist/utils/parsing/yamlParser.d.ts.map +1 -1
  133. package/dist/utils/parsing/yamlParser.js +3 -3
  134. package/dist/utils/parsing/yamlParser.js.map +1 -1
  135. package/dist/utils/security/rateLimiter.d.ts +2 -2
  136. package/dist/utils/security/rateLimiter.d.ts.map +1 -1
  137. package/dist/utils/security/rateLimiter.js +1 -1
  138. package/dist/utils/security/rateLimiter.js.map +1 -1
  139. package/dist/utils/telemetry/trace.d.ts +3 -3
  140. package/dist/utils/telemetry/trace.d.ts.map +1 -1
  141. package/dist/utils/telemetry/trace.js.map +1 -1
  142. package/package.json +1 -1
  143. package/scripts/tree.ts +9 -3
  144. package/skills/add-test/SKILL.md +2 -2
  145. package/skills/api-auth/SKILL.md +5 -5
  146. package/skills/api-context/SKILL.md +14 -12
  147. package/skills/api-linter/SKILL.md +59 -5
  148. package/skills/api-testing/SKILL.md +31 -10
  149. package/skills/api-utils/SKILL.md +4 -2
  150. package/skills/api-utils/references/parsing.md +3 -2
  151. package/skills/setup/SKILL.md +6 -3
  152. package/skills/techniques/SKILL.md +1 -1
  153. package/skills/techniques/references/outline-on-overflow.md +3 -1
  154. package/templates/AGENTS.md +1 -1
  155. package/templates/CLAUDE.md +1 -1
  156. package/templates/Dockerfile +7 -2
  157. package/templates/_tsconfig.build.json +5 -0
  158. package/templates/_tsconfig.json +4 -2
  159. package/templates/package.json +1 -0
  160. package/templates/tests/prompts/echo.prompt.test.ts +4 -3
  161. package/templates/tests/resources/echo.resource.test.ts +11 -3
  162. package/templates/tests/smoke/definitions.smoke.test.ts +8 -4
  163. package/templates/tests/tools/echo.tool.test.ts +23 -4
@@ -13,23 +13,27 @@ import { echoTool } from '@/mcp-server/tools/definitions/echo.tool.js';
13
13
 
14
14
  describe('scaffold definition smoke test', () => {
15
15
  it('executes the shipped tool, resource, and prompt definitions', async () => {
16
- const ctx = createMockContext();
16
+ // `echoTool` declares an error contract, so its handler wants a context
17
+ // typed against it — passing `errors` narrows what `createMockContext` returns.
18
+ const ctx = createMockContext({ errors: echoTool.errors });
17
19
  const toolResult = await echoTool.handler(
18
20
  echoTool.input.parse({ message: 'smoke' }),
19
21
  ctx,
20
22
  );
21
23
  const resourceResult = await echoResource.handler(
22
- echoResource.params.parse({ message: 'smoke' }),
24
+ echoResource.params!.parse({ message: 'smoke' }),
23
25
  ctx,
24
26
  );
25
- const promptMessages = echoPrompt.generate(echoPrompt.args.parse({ message: 'smoke' }));
27
+ const promptMessages = await echoPrompt.generate(
28
+ echoPrompt.args!.parse({ message: 'smoke' }),
29
+ );
26
30
  const appResult = await echoAppTool.handler(
27
31
  echoAppTool.input.parse({ message: 'smoke app' }),
28
32
  ctx,
29
33
  );
30
34
  const appContent = echoAppTool.format?.(appResult);
31
35
  const appHtml = await echoAppUiResource.handler(
32
- echoAppUiResource.params.parse({}),
36
+ echoAppUiResource.params!.parse({}),
33
37
  createMockContext({ uri: new URL('ui://template-echo-app/app.html') }),
34
38
  );
35
39
 
@@ -3,22 +3,41 @@
3
3
  * @module tests/tools/echo.tool.test
4
4
  */
5
5
 
6
+ import type { HandlerContext, ReasonOf } from '@cyanheads/mcp-ts-core';
6
7
  import { describe, expect, it } from 'vitest';
7
8
  import { createMockContext } from '@cyanheads/mcp-ts-core/testing';
8
9
  import { mcpTest } from '@cyanheads/mcp-ts-core/testing/vitest';
9
10
  import { echoTool } from '@/mcp-server/tools/definitions/echo.tool.js';
10
11
 
12
+ /**
13
+ * A tool that declares `errors[]` types its handler's `ctx` against that
14
+ * contract, so tests hand it a context built the same way — `createMockContext`
15
+ * narrows its return type from the `errors` it is given. Drop this if your tool
16
+ * declares no error contract; a bare `createMockContext()` is enough then.
17
+ */
18
+ type EchoContext = HandlerContext<ReasonOf<typeof echoTool.errors>>;
19
+
20
+ const echoContext = () => createMockContext({ errors: echoTool.errors });
21
+
11
22
  // ---------------------------------------------------------------------------
12
23
  // Fixture-based tests (mcpTest) — fresh ctx per test, no manual construction
13
24
  // ---------------------------------------------------------------------------
14
25
 
15
- mcpTest('echoTool: echoes the message back (fixture)', async ({ ctx }) => {
26
+ /** Function form, not a bare value — every test gets its own context. */
27
+ const echoTest = mcpTest.extend<{ ctx: EchoContext }>({
28
+ // biome-ignore lint/correctness/noEmptyPattern: vitest's fixture API requires a destructuring pattern as the first parameter
29
+ ctx: async ({}, use) => {
30
+ await use(echoContext());
31
+ },
32
+ });
33
+
34
+ echoTest('echoTool: echoes the message back (fixture)', async ({ ctx }) => {
16
35
  const input = echoTool.input.parse({ message: 'hello world' });
17
36
  const result = await echoTool.handler(input, ctx);
18
37
  expect(result).toEqual({ message: 'hello world' });
19
38
  });
20
39
 
21
- mcpTest('echoTool: output conforms to declared schema (fixture)', async ({ ctx }) => {
40
+ echoTest('echoTool: output conforms to declared schema (fixture)', async ({ ctx }) => {
22
41
  const input = echoTool.input.parse({ message: 'hello world' });
23
42
  const result = await echoTool.handler(input, ctx);
24
43
  expect(result).toEqual(expect.schemaMatching(echoTool.output));
@@ -30,14 +49,14 @@ mcpTest('echoTool: output conforms to declared schema (fixture)', async ({ ctx }
30
49
 
31
50
  describe('echoTool', () => {
32
51
  it('echoes the message back', async () => {
33
- const ctx = createMockContext();
52
+ const ctx = echoContext();
34
53
  const input = echoTool.input.parse({ message: 'hello world' });
35
54
  const result = await echoTool.handler(input, ctx);
36
55
  expect(result).toEqual({ message: 'hello world' });
37
56
  });
38
57
 
39
58
  it('output conforms to the declared output schema', async () => {
40
- const ctx = createMockContext();
59
+ const ctx = echoContext();
41
60
  const input = echoTool.input.parse({ message: 'hello world' });
42
61
  const result = await echoTool.handler(input, ctx);
43
62
  expect(result).toEqual(expect.schemaMatching(echoTool.output));