fa-mcp-sdk 0.2.125 → 0.2.132

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 (58) hide show
  1. package/bin/fa-mcp.js +46 -12
  2. package/cli-template/config/_local.yaml +29 -11
  3. package/cli-template/config/custom-environment-variables.yaml +0 -6
  4. package/cli-template/config/default.yaml +34 -14
  5. package/cli-template/fa-mcp-sdk-spec.md +396 -189
  6. package/dist/core/_types_/config.d.ts +4 -17
  7. package/dist/core/_types_/config.d.ts.map +1 -1
  8. package/dist/core/_types_/types.d.ts +12 -15
  9. package/dist/core/_types_/types.d.ts.map +1 -1
  10. package/dist/core/auth/middleware.d.ts +9 -37
  11. package/dist/core/auth/middleware.d.ts.map +1 -1
  12. package/dist/core/auth/middleware.js +31 -146
  13. package/dist/core/auth/middleware.js.map +1 -1
  14. package/dist/core/auth/multi-auth.d.ts +10 -14
  15. package/dist/core/auth/multi-auth.d.ts.map +1 -1
  16. package/dist/core/auth/multi-auth.js +133 -220
  17. package/dist/core/auth/multi-auth.js.map +1 -1
  18. package/dist/core/auth/types.d.ts +1 -7
  19. package/dist/core/auth/types.d.ts.map +1 -1
  20. package/dist/core/auth/types.js +1 -10
  21. package/dist/core/auth/types.js.map +1 -1
  22. package/dist/core/bootstrap/init-config.d.ts.map +1 -1
  23. package/dist/core/bootstrap/init-config.js +4 -0
  24. package/dist/core/bootstrap/init-config.js.map +1 -1
  25. package/dist/core/index.d.ts +6 -6
  26. package/dist/core/index.d.ts.map +1 -1
  27. package/dist/core/index.js +5 -4
  28. package/dist/core/index.js.map +1 -1
  29. package/dist/core/utils/utils.d.ts +6 -0
  30. package/dist/core/utils/utils.d.ts.map +1 -1
  31. package/dist/core/utils/utils.js +25 -0
  32. package/dist/core/utils/utils.js.map +1 -1
  33. package/dist/core/web/server-http.d.ts.map +1 -1
  34. package/dist/core/web/server-http.js +32 -18
  35. package/dist/core/web/server-http.js.map +1 -1
  36. package/package.json +1 -1
  37. package/cli-template/src/_examples/custom-basic-auth-example.ts +0 -252
  38. package/cli-template/src/_examples/multi-auth-examples.ts +0 -333
  39. package/cli-template/src/_types_/common.d.ts +0 -27
  40. package/cli-template/src/api/router.ts +0 -35
  41. package/cli-template/src/api/swagger.ts +0 -167
  42. package/cli-template/src/asset/favicon.svg +0 -3
  43. package/cli-template/src/custom-resources.ts +0 -12
  44. package/cli-template/src/prompts/agent-brief.ts +0 -8
  45. package/cli-template/src/prompts/agent-prompt.ts +0 -10
  46. package/cli-template/src/prompts/custom-prompts.ts +0 -12
  47. package/cli-template/src/start.ts +0 -71
  48. package/cli-template/src/tools/handle-tool-call.ts +0 -55
  49. package/cli-template/src/tools/tools.ts +0 -88
  50. package/cli-template/tests/jest-simple-reporter.js +0 -10
  51. package/cli-template/tests/mcp/sse/mcp-sse-client-handling.md +0 -111
  52. package/cli-template/tests/mcp/sse/test-sse-npm-package.js +0 -96
  53. package/cli-template/tests/mcp/test-cases.js +0 -143
  54. package/cli-template/tests/mcp/test-http.js +0 -63
  55. package/cli-template/tests/mcp/test-sse.js +0 -67
  56. package/cli-template/tests/mcp/test-stdio.js +0 -78
  57. package/cli-template/tests/utils.ts +0 -154
  58. package/cli-template/yarn.lock +0 -6375
@@ -1,78 +0,0 @@
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
- });
@@ -1,154 +0,0 @@
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
- };