fa-mcp-sdk 0.2.38 → 0.2.78

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 (121) hide show
  1. package/bin/fa-mcp.js +781 -0
  2. package/cli-template/.editorconfig +13 -0
  3. package/cli-template/.env.example +29 -0
  4. package/cli-template/.envrc +3 -0
  5. package/cli-template/.run/== START ==.run.xml +14 -0
  6. package/cli-template/.run/TEST HTTP.run.xml +5 -0
  7. package/cli-template/.run/TEST SSE.run.xml +5 -0
  8. package/cli-template/.run/TEST STDIO.run.xml +5 -0
  9. package/cli-template/.run/TEST search.run.xml +11 -0
  10. package/cli-template/.run/cb.run.xml +12 -0
  11. package/cli-template/.run/ci.run.xml +12 -0
  12. package/cli-template/.run/kill-port 3030.run.xml +5 -0
  13. package/cli-template/.run/lint.run.xml +12 -0
  14. package/cli-template/.run/lint_fix.run.xml +12 -0
  15. package/cli-template/.run/reinstall.run.xml +12 -0
  16. package/cli-template/.run/remove-nul.js.run.xml +5 -0
  17. package/cli-template/LICENSE +21 -0
  18. package/cli-template/config/_local.yaml +64 -0
  19. package/cli-template/config/custom-environment-variables.yaml +33 -0
  20. package/cli-template/config/default.yaml +101 -0
  21. package/cli-template/config/development.yaml +4 -0
  22. package/cli-template/config/production.yaml +4 -0
  23. package/cli-template/config/test.yaml +26 -0
  24. package/cli-template/deploy/.gitkeep +0 -0
  25. package/cli-template/deploy/config.example.yml +3 -0
  26. package/cli-template/deploy/mcp-template.com.conf +58 -0
  27. package/cli-template/deploy/pm2.config.js +30 -0
  28. package/cli-template/deploy/pm2reg.sh +49 -0
  29. package/cli-template/deploy/srv.sh +359 -0
  30. package/cli-template/deploy/srv.sh.readme.md +347 -0
  31. package/cli-template/eslint.config.js +139 -0
  32. package/cli-template/jest.config.js +30 -0
  33. package/cli-template/package.json +73 -0
  34. package/cli-template/scripts/kill-port.js +107 -0
  35. package/cli-template/scripts/npm/patch_node_modules.js +9 -0
  36. package/cli-template/scripts/npm/run.js +31 -0
  37. package/cli-template/scripts/npm/yarn-ci.ps1 +16 -0
  38. package/cli-template/scripts/npm/yarn-ci.sh +8 -0
  39. package/cli-template/scripts/npm/yarn-reinstall.ps1 +54 -0
  40. package/cli-template/scripts/npm/yarn-reinstall.sh +10 -0
  41. package/cli-template/scripts/pre-commit +58 -0
  42. package/cli-template/scripts/remove-nul.js +53 -0
  43. package/cli-template/src/_types_/common.d.ts +27 -0
  44. package/cli-template/src/api/router.ts +35 -0
  45. package/cli-template/src/api/swagger.ts +167 -0
  46. package/cli-template/src/asset/favicon.svg +4 -0
  47. package/cli-template/src/custom-resources.ts +11 -0
  48. package/cli-template/src/prompts/agent-brief.ts +8 -0
  49. package/cli-template/src/prompts/agent-prompt.ts +1 -0
  50. package/cli-template/src/prompts/custom-prompts.ts +12 -0
  51. package/cli-template/src/start.ts +84 -0
  52. package/cli-template/src/tools/handle-tool-call.ts +55 -0
  53. package/cli-template/src/tools/tools.ts +88 -0
  54. package/cli-template/tests/jest-simple-reporter.js +10 -0
  55. package/cli-template/tests/mcp/sse/mcp-sse-client-handling.md +111 -0
  56. package/cli-template/tests/mcp/sse/test-sse-npm-package.js +96 -0
  57. package/cli-template/tests/mcp/test-cases.js +143 -0
  58. package/cli-template/tests/mcp/test-http.js +63 -0
  59. package/cli-template/tests/mcp/test-sse.js +67 -0
  60. package/cli-template/tests/mcp/test-stdio.js +78 -0
  61. package/cli-template/tests/utils.ts +154 -0
  62. package/cli-template/tsconfig.json +48 -0
  63. package/cli-template/update.cjs +631 -0
  64. package/dist/core/_types_/active-directory-config.d.ts +24 -0
  65. package/dist/core/_types_/active-directory-config.d.ts.map +1 -0
  66. package/dist/core/_types_/active-directory-config.js +2 -0
  67. package/dist/core/_types_/active-directory-config.js.map +1 -0
  68. package/dist/core/bootstrap/init-config.d.ts.map +1 -1
  69. package/dist/core/bootstrap/init-config.js +14 -3
  70. package/dist/core/bootstrap/init-config.js.map +1 -1
  71. package/dist/core/bootstrap/startup-info.js +1 -1
  72. package/dist/core/bootstrap/startup-info.js.map +1 -1
  73. package/dist/core/index.d.ts +3 -2
  74. package/dist/core/index.d.ts.map +1 -1
  75. package/dist/core/index.js +5 -2
  76. package/dist/core/index.js.map +1 -1
  77. package/dist/core/init-mcp-server.js +1 -1
  78. package/dist/core/init-mcp-server.js.map +1 -1
  79. package/dist/core/token/gen-token-app/gen-token-server.d.ts.map +1 -1
  80. package/dist/core/token/gen-token-app/gen-token-server.js +85 -9
  81. package/dist/core/token/gen-token-app/gen-token-server.js.map +1 -1
  82. package/dist/core/token/gen-token-app/html.d.ts +8 -1
  83. package/dist/core/token/gen-token-app/html.d.ts.map +1 -1
  84. package/dist/core/token/gen-token-app/html.js +98 -2
  85. package/dist/core/token/gen-token-app/html.js.map +1 -1
  86. package/dist/core/token/gen-token-app/ntlm-auth-options.d.ts +4 -0
  87. package/dist/core/token/gen-token-app/ntlm-auth-options.d.ts.map +1 -0
  88. package/dist/core/token/gen-token-app/ntlm-auth-options.js +94 -0
  89. package/dist/core/token/gen-token-app/ntlm-auth-options.js.map +1 -0
  90. package/dist/core/token/gen-token-app/ntlm-domain-config.d.ts +16 -0
  91. package/dist/core/token/gen-token-app/ntlm-domain-config.d.ts.map +1 -0
  92. package/dist/core/token/gen-token-app/ntlm-domain-config.js +71 -0
  93. package/dist/core/token/gen-token-app/ntlm-domain-config.js.map +1 -0
  94. package/dist/core/token/gen-token-app/ntlm-integration.d.ts +3 -0
  95. package/dist/core/token/gen-token-app/ntlm-integration.d.ts.map +1 -0
  96. package/dist/core/token/gen-token-app/ntlm-integration.js +69 -0
  97. package/dist/core/token/gen-token-app/ntlm-integration.js.map +1 -0
  98. package/dist/core/token/gen-token-app/ntlm-session-storage.d.ts +16 -0
  99. package/dist/core/token/gen-token-app/ntlm-session-storage.d.ts.map +1 -0
  100. package/dist/core/token/gen-token-app/ntlm-session-storage.js +74 -0
  101. package/dist/core/token/gen-token-app/ntlm-session-storage.js.map +1 -0
  102. package/dist/core/token/gen-token-app/ntlm-templates.d.ts +21 -0
  103. package/dist/core/token/gen-token-app/ntlm-templates.d.ts.map +1 -0
  104. package/dist/core/token/gen-token-app/ntlm-templates.js +246 -0
  105. package/dist/core/token/gen-token-app/ntlm-templates.js.map +1 -0
  106. package/dist/core/token/{token.d.ts → token-auth.d.ts} +1 -1
  107. package/dist/core/token/token-auth.d.ts.map +1 -0
  108. package/dist/core/token/{token.js → token-auth.js} +4 -6
  109. package/dist/core/token/token-auth.js.map +1 -0
  110. package/dist/core/token/token-core.d.ts +5 -1
  111. package/dist/core/token/token-core.d.ts.map +1 -1
  112. package/dist/core/token/token-core.js +13 -3
  113. package/dist/core/token/token-core.js.map +1 -1
  114. package/dist/core/web/about-page/render.d.ts.map +1 -1
  115. package/dist/core/web/about-page/render.js +26 -3
  116. package/dist/core/web/about-page/render.js.map +1 -1
  117. package/dist/core/web/server-http.js +1 -1
  118. package/dist/core/web/server-http.js.map +1 -1
  119. package/package.json +10 -3
  120. package/dist/core/token/token.d.ts.map +0 -1
  121. package/dist/core/token/token.js.map +0 -1
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Shared test cases for the template MCP server (src/template)
5
+ * Covers: prompts, resources, tools
6
+ *
7
+ * Each test case is a function(client) -> Promise<{ name, passed, details? }>
8
+ * where client provides methods:
9
+ * - listPrompts(), getPrompt(name, args?)
10
+ * - listResources(), readResource(uri)
11
+ * - listTools(), callTool(name, args?)
12
+ */
13
+
14
+ const ok = (name, details) => ({ name, passed: true, details });
15
+ const fail = (name, details) => ({ name, passed: false, details });
16
+
17
+ // Utility: extract system text from prompts/get response
18
+ const extractPromptText = (resp) => {
19
+ // resp may be raw result or wrapped; support both shapes used by clients
20
+ const r = resp?.result || resp;
21
+ const msg = r?.messages?.[0];
22
+ const text = msg?.content?.text || msg?.content?.[0]?.text || r?.messages?.[0]?.content?.[0]?.text;
23
+ return typeof text === 'string' ? text : undefined;
24
+ };
25
+
26
+ export const TEMPLATE_TESTS = {
27
+ prompts: [
28
+ async (client) => {
29
+ const name = 'List prompts contains agent_brief and agent_prompt';
30
+ try {
31
+ const list = await client.listPrompts();
32
+ const prompts = list?.prompts || list;
33
+ const names = Array.isArray(prompts) ? prompts.map(p => p.name) : [];
34
+ const okBrief = names.includes('agent_brief');
35
+ const okPrompt = names.includes('agent_prompt');
36
+ return (okBrief && okPrompt) ? ok(name, { names }) : fail(name, { names });
37
+ } catch (e) {
38
+ return fail(name, { error: e?.message });
39
+ }
40
+ },
41
+ async (client) => {
42
+ const name = 'Get agent_brief returns text';
43
+ try {
44
+ const resp = await client.getPrompt('agent_brief');
45
+ const text = extractPromptText(resp);
46
+ return text ? ok(name, { text }) : fail(name, { text });
47
+ } catch (e) {
48
+ return fail(name, { error: e?.message });
49
+ }
50
+ },
51
+ async (client) => {
52
+ const name = 'Get agent_prompt returns text';
53
+ try {
54
+ const resp = await client.getPrompt('agent_prompt');
55
+ const text = extractPromptText(resp);
56
+ return text ? ok(name, { text }) : fail(name, { text });
57
+ } catch (e) {
58
+ return fail(name, { error: e?.message });
59
+ }
60
+ },
61
+ async (client) => {
62
+ const name = 'Get custom_prompt returns dynamic text';
63
+ try {
64
+ const resp = await client.getPrompt('custom_prompt', { sample: '1' });
65
+ const text = extractPromptText(resp);
66
+ const hasWord = typeof text === 'string' && text.includes('Custom prompt content');
67
+ return hasWord ? ok(name, { text }) : fail(name, { text });
68
+ } catch (e) {
69
+ return fail(name, { error: e?.message });
70
+ }
71
+ },
72
+ ],
73
+
74
+ resources: [
75
+ async (client) => {
76
+ const name = 'List resources contains custom-resource://resource1';
77
+ try {
78
+ const list = await client.listResources();
79
+ const resources = list?.resources || list;
80
+ const uris = Array.isArray(resources) ? resources.map(r => r.uri) : [];
81
+ const found = uris.includes('custom-resource://resource1');
82
+ return found ? ok(name, { uris }) : fail(name, { uris });
83
+ } catch (e) {
84
+ return fail(name, { error: e?.message });
85
+ }
86
+ },
87
+ async (client) => {
88
+ const name = 'Read resource custom-resource://resource1 returns content';
89
+ try {
90
+ const resp = await client.readResource('custom-resource://resource1');
91
+ // Different clients return differently; normalize
92
+ const r = resp?.result || resp;
93
+ const text = r?.resource?.text || r?.contents?.[0]?.text || r?.text || r?.resource?.content;
94
+ const okText = typeof text === 'string' && text.length > 0;
95
+ return okText ? ok(name, { text }) : fail(name, { response: r });
96
+ } catch (e) {
97
+ return fail(name, { error: e?.message });
98
+ }
99
+ },
100
+ ],
101
+
102
+ tools: [
103
+ async (client) => {
104
+ const name = 'List tools contains example_tool and example_search';
105
+ try {
106
+ const list = await client.listTools();
107
+ const tools = list?.tools || list;
108
+ const names = Array.isArray(tools) ? tools.map(t => t.name) : [];
109
+ const ok1 = names.includes('example_tool');
110
+ const ok2 = names.includes('example_search');
111
+ return (ok1 && ok2) ? ok(name, { names }) : fail(name, { names });
112
+ } catch (e) {
113
+ return fail(name, { error: e?.message });
114
+ }
115
+ },
116
+ async (client) => {
117
+ const name = 'Call example_tool returns formatted result';
118
+ try {
119
+ const resp = await client.callTool('example_tool', { query: 'ping' });
120
+ const r = resp?.result || resp;
121
+ // Both structuredContent and text are acceptable; check message echo
122
+ const structured = r?.structuredContent;
123
+ const text = r?.content?.[0]?.text;
124
+ const hasProcessed = (structured && structured.message?.includes('Processed query'))
125
+ || (typeof text === 'string' && text.includes('Processed query'));
126
+ return hasProcessed ? ok(name, { response: r }) : fail(name, { response: r });
127
+ } catch (e) {
128
+ return fail(name, { error: e?.message });
129
+ }
130
+ },
131
+ async (client) => {
132
+ const name = 'Call example_tool without query should fail';
133
+ try {
134
+ await client.callTool('example_tool', {});
135
+ return fail(name, { error: 'Expected failure, got success' });
136
+ } catch (e) {
137
+ return ok(name, { error: e?.message });
138
+ }
139
+ },
140
+ ],
141
+ };
142
+
143
+ export default TEMPLATE_TESTS;
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * HTTP transport tests for the template MCP server (src/template)
5
+ * Uses McpHttpClient (simple POST requests)
6
+ */
7
+
8
+ import { appConfig, McpHttpClient } from 'fa-mcp-sdk';
9
+ import TEMPLATE_TESTS from './test-cases.js';
10
+
11
+ const baseUrl = (process.env.TEST_MCP_SERVER_URL || `http://localhost:${appConfig.webServer.port}`).replace(/\/+$/,'');
12
+
13
+ async function runTestGroup (title, tests, client) {
14
+ console.log(`\n${title}:`);
15
+ let passed = 0;
16
+ for (const test of tests) {
17
+ try {
18
+ const res = await test(client);
19
+ if (res.passed) {
20
+ console.log(` ✅ ${res.name}`);
21
+ passed++;
22
+ } else {
23
+ console.log(` ❌ ${res.name}`);
24
+ if (res.details) {
25
+ console.log(' ', res.details);
26
+ }
27
+ }
28
+ } catch (e) {
29
+ console.log(` ❌ ${(await test).name || 'test'}:`, e.message);
30
+ }
31
+ }
32
+ console.log(` Result: ${passed}/${tests.length} passed`);
33
+ return passed;
34
+ }
35
+
36
+ async function main () {
37
+ console.log('🧪 HTTP tests for template MCP server');
38
+ console.log('='.repeat(60));
39
+
40
+ const client = new McpHttpClient(baseUrl);
41
+ try {
42
+ await client.initialize({
43
+ protocolVersion: '2024-11-05',
44
+ capabilities: { tools: {} },
45
+ clientInfo: { name: 'http-test', version: '1.0.0' },
46
+ });
47
+
48
+ const p1 = await runTestGroup('Prompts', TEMPLATE_TESTS.prompts, client);
49
+ const p2 = await runTestGroup('Resources', TEMPLATE_TESTS.resources, client);
50
+ const p3 = await runTestGroup('Tools', TEMPLATE_TESTS.tools, client);
51
+
52
+ const total = TEMPLATE_TESTS.prompts.length + TEMPLATE_TESTS.resources.length + TEMPLATE_TESTS.tools.length;
53
+ const sum = p1 + p2 + p3;
54
+ console.log(`\nSummary: ${sum}/${total} tests passed`);
55
+ } finally {
56
+ await client.close().catch(() => undefined);
57
+ }
58
+ }
59
+
60
+ main().catch((e) => {
61
+ console.error('Test failed:', e?.message || e);
62
+ process.exit(1);
63
+ });
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * SSE transport tests for the template MCP server (src/template)
5
+ * Uses McpSseClient to send requests via HTTP and receive responses via SSE
6
+ */
7
+
8
+ import { appConfig, McpSseClient } from 'fa-mcp-sdk';
9
+ import TEMPLATE_TESTS from './test-cases.js';
10
+
11
+ const baseUrl = (process.env.TEST_MCP_SERVER_URL || `http://localhost:${appConfig.webServer.port}`).replace(/\/+$/,'');
12
+
13
+ async function runTestGroup (title, tests, client) {
14
+ console.log(`\n${title}:`);
15
+ let passed = 0;
16
+ for (const test of tests) {
17
+ try {
18
+ const res = await test(client);
19
+ if (res.passed) {
20
+ console.log(` ✅ ${res.name}`);
21
+ passed++;
22
+ } else {
23
+ console.log(` ❌ ${res.name}`);
24
+ if (res.details) {
25
+ console.log(' ', res.details);
26
+ }
27
+ }
28
+ } catch (e) {
29
+ console.log(` ❌ ${test.name || 'test'}:`, e.message);
30
+ }
31
+ }
32
+ console.log(` Result: ${passed}/${tests.length} passed`);
33
+ return passed;
34
+ }
35
+
36
+ async function main () {
37
+ console.log('🧪 SSE tests for template MCP server');
38
+ console.log('='.repeat(60));
39
+
40
+ const client = new McpSseClient(baseUrl);
41
+ try {
42
+ // Health check (optional)
43
+ await client.health().catch(() => undefined);
44
+
45
+ // Initialize over RPC channel used by SSE client (POST /rpc)
46
+ await client.sendRequest('initialize', {
47
+ protocolVersion: '2024-11-05',
48
+ capabilities: { tools: {} },
49
+ clientInfo: { name: 'sse-test', version: '1.0.0' },
50
+ }).catch(() => undefined);
51
+
52
+ const p1 = await runTestGroup('Prompts', TEMPLATE_TESTS.prompts, client);
53
+ const p2 = await runTestGroup('Resources', TEMPLATE_TESTS.resources, client);
54
+ const p3 = await runTestGroup('Tools', TEMPLATE_TESTS.tools, client);
55
+
56
+ const total = TEMPLATE_TESTS.prompts.length + TEMPLATE_TESTS.resources.length + TEMPLATE_TESTS.tools.length;
57
+ const sum = p1 + p2 + p3;
58
+ console.log(`\nSummary: ${sum}/${total} tests passed`);
59
+ } finally {
60
+ await client.close().catch(() => undefined);
61
+ }
62
+ }
63
+
64
+ main().catch((e) => {
65
+ console.error('Test failed:', e?.message || e);
66
+ process.exit(1);
67
+ });
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * STDIO transport tests for the template MCP server (src/template)
5
+ * Uses a minimal NDJSON JSON-RPC client over child_process stdio
6
+ */
7
+
8
+ import { spawn } from 'child_process';
9
+ import { fileURLToPath } from 'url';
10
+ import { dirname, join } from 'path';
11
+ import TEMPLATE_TESTS from './test-cases.js';
12
+ import { McpStdioClient } from 'fa-mcp-sdk';
13
+
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = dirname(__filename);
16
+ const projectRoot = join(__dirname, '../../../');
17
+
18
+ const serverPath = join(projectRoot, 'dist/template/start.js');
19
+
20
+ async function runTestGroup (title, tests, client) {
21
+ console.log(`\n${title}:`);
22
+ let passed = 0;
23
+ for (const test of tests) {
24
+ const name = (await test).name || 'test';
25
+ try {
26
+ const res = await test(client);
27
+ if (res.passed) {
28
+ console.log(` ✅ ${res.name}`);
29
+ passed++;
30
+ } else {
31
+ console.log(` ❌ ${res.name}`);
32
+ if (res.details) {
33
+ console.log(' ', res.details);
34
+ }
35
+ }
36
+ } catch (e) {
37
+ console.log(` ❌ ${name}:`, e.message);
38
+ }
39
+ }
40
+ console.log(` Result: ${passed}/${tests.length} passed`);
41
+ return passed;
42
+ }
43
+
44
+ async function main () {
45
+ console.log('🧪 STDIO tests for template MCP server');
46
+ console.log('='.repeat(60));
47
+
48
+ const proc = spawn('node', [serverPath, 'stdio'], {
49
+ stdio: ['pipe', 'pipe', 'pipe'],
50
+ env: { ...process.env, NODE_ENV: 'test' },
51
+ });
52
+
53
+ const client = new McpStdioClient(proc);
54
+
55
+ try {
56
+ // Initialize handshake (optional for stdio server; safe to send)
57
+ await client.send('initialize', {
58
+ protocolVersion: '2024-11-05',
59
+ capabilities: { tools: {} },
60
+ clientInfo: { name: 'stdio-test', version: '1.0.0' },
61
+ }).catch(() => undefined);
62
+
63
+ const p1 = await runTestGroup('Prompts', TEMPLATE_TESTS.prompts, client);
64
+ const p2 = await runTestGroup('Resources', TEMPLATE_TESTS.resources, client);
65
+ const p3 = await runTestGroup('Tools', TEMPLATE_TESTS.tools, client);
66
+
67
+ const total = TEMPLATE_TESTS.prompts.length + TEMPLATE_TESTS.resources.length + TEMPLATE_TESTS.tools.length;
68
+ const sum = p1 + p2 + p3;
69
+ console.log(`\nSummary: ${sum}/${total} tests passed`);
70
+ } finally {
71
+ try { proc.kill(); } catch {}
72
+ }
73
+ }
74
+
75
+ main().catch((e) => {
76
+ console.error('Test failed:', e?.message || e);
77
+ process.exit(1);
78
+ });
@@ -0,0 +1,154 @@
1
+ import '../src/core/bootstrap/dotenv.js';
2
+ import fsp from 'fs/promises';
3
+ import fss from 'fs';
4
+ import path from 'path';
5
+ import chalk from 'chalk';
6
+
7
+ const testResultLogsDir = process.env.TEST_RESULT_LOGS_DIR || '_logs/mcp';
8
+
9
+ const RESULTS_DIR = path.join(process.cwd(), testResultLogsDir);
10
+
11
+ if (!fss.existsSync(RESULTS_DIR)) {
12
+ fss.mkdirSync(RESULTS_DIR, { recursive: true });
13
+ }
14
+
15
+ export interface ITestResult {
16
+ // Test / tool identifiers
17
+ fullId: string;
18
+ toolName: string;
19
+ description: string;
20
+
21
+ // Tool invocation parameters
22
+ parameters: unknown | null;
23
+
24
+ // Temporal metadata
25
+ timestamp: string; // ISO string
26
+ duration: number; // milliseconds
27
+
28
+ // Execution status
29
+ status: 'pending' | 'passed' | 'failed' | 'skipped' | 'expected_failure';
30
+
31
+ // Marker icon for logs (may be absent in "pending")
32
+ marker?: string;
33
+
34
+ // MCP response
35
+ response: unknown | null;
36
+
37
+ // Error (human-readable message)
38
+ error: string | null;
39
+
40
+ // Additional error details (structured)
41
+ errorDetails?: unknown | null;
42
+
43
+ // Full MCP response on error (JSON-RPC response)
44
+ fullMcpResponse?: unknown;
45
+
46
+ // Request headers used for the MCP server call
47
+ requestHeaders?: Record<string, string>;
48
+ }
49
+
50
+ /**
51
+ * Format test result as Markdown
52
+ */
53
+ export const formatResultAsMarkdown = (result: ITestResult) => {
54
+ const t = '```';
55
+ const mdText = (s: string | null) => `${t}\n${s}\n${t}`;
56
+ const mdDescr = (s: string) => `${t}description\n${s}\n${t}`;
57
+ const mdJson = (v: any) => `${t}json\n${v && JSON.stringify(v, null, 2)}\n${t}`;
58
+
59
+ let resultStatus = '⚠️ RESULT STATUS UNKNOWN';
60
+ let errorText = '';
61
+ // md += `## Response\n\n\`\`\`json\n${JSON.stringify(result.response, null, 2)}\n\`\`\`\n\n`;
62
+
63
+ if (result.status === 'passed') {
64
+ resultStatus = '✅ PASSED';
65
+ } else {
66
+ // Show full MCP response as seen by the agent, or fallback to separate sections
67
+ if (result.fullMcpResponse) {
68
+ errorText = `## MCP Response (as seen by agent)\n\n${mdJson(result.fullMcpResponse)}\n\n`;
69
+ } else {
70
+ errorText = `## Error\n\n${mdText(result.error)}\n\n`;
71
+ // Add detailed error information if available
72
+ if (result.errorDetails) {
73
+ errorText += `## Error Details\n\n${mdJson(result.errorDetails)}\n\n`;
74
+ }
75
+ }
76
+ if (result.status === 'expected_failure') {
77
+ resultStatus = '⚠️ Expected failure - test validation successful';
78
+ } else {
79
+ resultStatus = '❌ FAILED';
80
+ }
81
+ }
82
+
83
+ let requestHeaders = '';
84
+ if (result.requestHeaders && Object.keys(result.requestHeaders).length > 0) {
85
+ requestHeaders = `\nHeaders:\n${Object.entries(result.requestHeaders).map(([k, v]) => ` ${k}: ${v}`).join('\n')}\n`;
86
+ }
87
+
88
+ // Format response section
89
+ let responseText = '';
90
+ if (result.response !== null && result.response !== undefined) {
91
+ try {
92
+ let parsedResponse: any = result.response;
93
+ let isJsonParsed = false;
94
+
95
+ // If response is a string, try to parse as JSON first
96
+ if (typeof result.response === 'string') {
97
+ try {
98
+ parsedResponse = JSON.parse(result.response);
99
+ isJsonParsed = true;
100
+ } catch {
101
+ // If not valid JSON, treat as text
102
+ responseText = `## Response\n\n${mdText(result.response)}\n\n`;
103
+ }
104
+ } else if (typeof result.response === 'object') {
105
+ isJsonParsed = true;
106
+ }
107
+
108
+ // If we have a successfully parsed or original object
109
+ if (isJsonParsed && typeof parsedResponse === 'object') {
110
+ let text = parsedResponse;
111
+ let addText = '';
112
+ // Check if response has content[0].text structure and extract text
113
+ if (Array.isArray(parsedResponse?.content) && parsedResponse.content[0]?.text) {
114
+ const textContent = parsedResponse.content[0].text;
115
+ parsedResponse.content[0].text = '📋';
116
+ text = parsedResponse;
117
+ addText = `## Formatted Text 📋\n${mdText(textContent)}\n\n`;
118
+ }
119
+ responseText = `## Response\n\n${mdJson(text)}\n\n${addText}`;
120
+ }
121
+
122
+ } catch {
123
+ // Fallback to text if any parsing errors
124
+ responseText = `## Response\n\n${mdText(String(result.response))}\n\n`;
125
+ }
126
+ }
127
+
128
+ return `${resultStatus} / ${result.timestamp} / ${result.duration}ms
129
+ # ${result.toolName}
130
+ ${requestHeaders}
131
+ ${mdDescr(result.description)}
132
+
133
+ parameters:
134
+ ${mdJson(result.parameters)}
135
+
136
+ ${responseText}${errorText}`;
137
+ };
138
+
139
+ /**
140
+ * Log test result to individual file
141
+ */
142
+ export const logResultToFile = async (result: ITestResult) => {
143
+ // const filename = `${result.fullId}_${result.toolName}.md`;
144
+ const filename = `${result.toolName}.md`;
145
+ const filepath = path.join(RESULTS_DIR, filename);
146
+
147
+ const content = formatResultAsMarkdown(result);
148
+
149
+ try {
150
+ await fsp.writeFile(filepath, content, 'utf-8');
151
+ } catch (error: Error | any) {
152
+ console.log(chalk.red(` Failed to write log file: ${error.message}`));
153
+ }
154
+ };
@@ -0,0 +1,48 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true,
16
+ "removeComments": false,
17
+ "noImplicitAny": true,
18
+ "noImplicitReturns": true,
19
+ "noFallthroughCasesInSwitch": true,
20
+ "noUncheckedIndexedAccess": true,
21
+ "exactOptionalPropertyTypes": true,
22
+ "noImplicitOverride": true,
23
+ "allowSyntheticDefaultImports": true,
24
+ "resolveJsonModule": true,
25
+ "isolatedModules": true,
26
+ "baseUrl": "./"
27
+ },
28
+ "include": [
29
+ "src/**/*",
30
+ "tests/**/*"
31
+ ],
32
+ "exclude": [
33
+ ".claude",
34
+ ".idea",
35
+ ".run",
36
+ "_misc",
37
+ "_tmp",
38
+ "config",
39
+ "deploy",
40
+ "dist",
41
+ "doc",
42
+ "node_modules",
43
+ "coverage"
44
+ ],
45
+ "ts-node": {
46
+ "esm": true
47
+ }
48
+ }