fa-mcp-sdk 0.4.3 → 0.4.6
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.
- package/bin/fa-mcp.js +1040 -1039
- package/cli-template/eslint.config.js +16 -136
- package/cli-template/package.json +9 -10
- package/cli-template/tsconfig.json +1 -0
- package/dist/core/_types_/active-directory-config.d.ts.map +1 -1
- package/dist/core/_types_/config.d.ts +1 -1
- package/dist/core/_types_/config.d.ts.map +1 -1
- package/dist/core/_types_/types.d.ts.map +1 -1
- package/dist/core/ad/group-checker.d.ts.map +1 -1
- package/dist/core/ad/group-checker.js.map +1 -1
- package/dist/core/agent-tester/agent-tester-router.d.ts.map +1 -1
- package/dist/core/agent-tester/agent-tester-router.js +8 -8
- package/dist/core/agent-tester/agent-tester-router.js.map +1 -1
- package/dist/core/agent-tester/check-llm.d.ts.map +1 -1
- package/dist/core/agent-tester/check-llm.js +1 -1
- package/dist/core/agent-tester/check-llm.js.map +1 -1
- package/dist/core/agent-tester/services/TesterAgentService.d.ts.map +1 -1
- package/dist/core/agent-tester/services/TesterAgentService.js +53 -53
- package/dist/core/agent-tester/services/TesterAgentService.js.map +1 -1
- package/dist/core/agent-tester/services/TesterMcpClientService.d.ts.map +1 -1
- package/dist/core/agent-tester/services/TesterMcpClientService.js +2 -2
- package/dist/core/agent-tester/services/TesterMcpClientService.js.map +1 -1
- package/dist/core/auth/admin-auth.d.ts.map +1 -1
- package/dist/core/auth/admin-auth.js +3 -3
- package/dist/core/auth/admin-auth.js.map +1 -1
- package/dist/core/auth/basic.d.ts.map +1 -1
- package/dist/core/auth/basic.js.map +1 -1
- package/dist/core/auth/jwt.d.ts.map +1 -1
- package/dist/core/auth/jwt.js +6 -16
- package/dist/core/auth/jwt.js.map +1 -1
- package/dist/core/auth/middleware.d.ts.map +1 -1
- package/dist/core/auth/middleware.js +3 -2
- package/dist/core/auth/middleware.js.map +1 -1
- package/dist/core/auth/multi-auth.d.ts +0 -3
- package/dist/core/auth/multi-auth.d.ts.map +1 -1
- package/dist/core/auth/multi-auth.js +10 -7
- package/dist/core/auth/multi-auth.js.map +1 -1
- package/dist/core/auth/permanent.d.ts.map +1 -1
- package/dist/core/auth/permanent.js +1 -1
- package/dist/core/auth/permanent.js.map +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-auth-options.d.ts.map +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-auth-options.js +2 -2
- package/dist/core/auth/token-generator/ntlm/ntlm-auth-options.js.map +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-domain-config.d.ts.map +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-domain-config.js +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-domain-config.js.map +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-integration.d.ts.map +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-integration.js +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-integration.js.map +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-templates.d.ts.map +1 -1
- package/dist/core/auth/token-generator/ntlm/ntlm-templates.js +222 -221
- package/dist/core/auth/token-generator/ntlm/ntlm-templates.js.map +1 -1
- package/dist/core/auth/token-generator/server.d.ts.map +1 -1
- package/dist/core/auth/token-generator/server.js +8 -8
- package/dist/core/auth/token-generator/server.js.map +1 -1
- package/dist/core/bootstrap/init-config.d.ts.map +1 -1
- package/dist/core/bootstrap/init-config.js +4 -4
- package/dist/core/bootstrap/init-config.js.map +1 -1
- package/dist/core/bootstrap/startup-info.d.ts.map +1 -1
- package/dist/core/bootstrap/startup-info.js +4 -4
- package/dist/core/bootstrap/startup-info.js.map +1 -1
- package/dist/core/cache/cache.d.ts.map +1 -1
- package/dist/core/cache/cache.js +3 -3
- package/dist/core/cache/cache.js.map +1 -1
- package/dist/core/consul/access-points-updater.d.ts.map +1 -1
- package/dist/core/consul/access-points-updater.js +3 -3
- package/dist/core/consul/access-points-updater.js.map +1 -1
- package/dist/core/consul/deregister.d.ts.map +1 -1
- package/dist/core/consul/deregister.js +1 -1
- package/dist/core/consul/deregister.js.map +1 -1
- package/dist/core/consul/get-consul-api.d.ts.map +1 -1
- package/dist/core/consul/get-consul-api.js +3 -3
- package/dist/core/consul/get-consul-api.js.map +1 -1
- package/dist/core/db/pg-db.d.ts +1 -1
- package/dist/core/db/pg-db.d.ts.map +1 -1
- package/dist/core/db/pg-db.js +2 -2
- package/dist/core/db/pg-db.js.map +1 -1
- package/dist/core/debug.js +1 -1
- package/dist/core/debug.js.map +1 -1
- package/dist/core/init-mcp-server.d.ts.map +1 -1
- package/dist/core/init-mcp-server.js +9 -9
- package/dist/core/init-mcp-server.js.map +1 -1
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +3 -3
- package/dist/core/logger.js.map +1 -1
- package/dist/core/mcp/create-mcp-server.d.ts.map +1 -1
- package/dist/core/mcp/create-mcp-server.js +1 -1
- package/dist/core/mcp/create-mcp-server.js.map +1 -1
- package/dist/core/mcp/prompts.d.ts.map +1 -1
- package/dist/core/mcp/prompts.js +1 -3
- package/dist/core/mcp/prompts.js.map +1 -1
- package/dist/core/mcp/resources.d.ts.map +1 -1
- package/dist/core/mcp/resources.js +8 -10
- package/dist/core/mcp/resources.js.map +1 -1
- package/dist/core/mcp/server-stdio.d.ts.map +1 -1
- package/dist/core/mcp/server-stdio.js.map +1 -1
- package/dist/core/utils/formatToolResult.d.ts.map +1 -1
- package/dist/core/utils/formatToolResult.js +1 -3
- package/dist/core/utils/formatToolResult.js.map +1 -1
- package/dist/core/utils/port-checker.d.ts.map +1 -1
- package/dist/core/utils/port-checker.js +1 -1
- package/dist/core/utils/port-checker.js.map +1 -1
- package/dist/core/utils/rate-limit.js +2 -2
- package/dist/core/utils/testing/McpSseClient.d.ts.map +1 -1
- package/dist/core/utils/testing/McpSseClient.js.map +1 -1
- package/dist/core/utils/testing/McpStdioClient.d.ts.map +1 -1
- package/dist/core/utils/testing/McpStdioClient.js.map +1 -1
- package/dist/core/utils/utils.d.ts.map +1 -1
- package/dist/core/utils/utils.js.map +1 -1
- package/dist/core/web/admin-router.d.ts.map +1 -1
- package/dist/core/web/admin-router.js +4 -4
- package/dist/core/web/admin-router.js.map +1 -1
- package/dist/core/web/cors.d.ts.map +1 -1
- package/dist/core/web/cors.js.map +1 -1
- package/dist/core/web/favicon-svg.d.ts.map +1 -1
- package/dist/core/web/favicon-svg.js.map +1 -1
- package/dist/core/web/home-api.d.ts.map +1 -1
- package/dist/core/web/home-api.js +4 -4
- package/dist/core/web/home-api.js.map +1 -1
- package/dist/core/web/openapi.d.ts.map +1 -1
- package/dist/core/web/openapi.js.map +1 -1
- package/dist/core/web/server-http.d.ts.map +1 -1
- package/dist/core/web/server-http.js +20 -22
- package/dist/core/web/server-http.js.map +1 -1
- package/dist/core/web/static/agent-tester/script.js +1503 -1513
- package/dist/core/web/static/home/script.js +646 -646
- package/dist/core/web/static/token-gen/script.js +561 -561
- package/dist/core/web/svg-icons.d.ts.map +1 -1
- package/dist/core/web/svg-icons.js +1 -1
- package/dist/core/web/svg-icons.js.map +1 -1
- package/package.json +2 -6
- package/scripts/copy-static.js +31 -31
- package/scripts/kill-port.js +107 -107
- package/scripts/npm/patch_node_modules.js +8 -8
- package/scripts/npm/run.js +31 -31
- package/scripts/remove-nul.js +53 -53
- package/scripts/update-doc.js +18 -18
- package/src/template/_types_/custom-config.ts +83 -83
- package/src/template/api/router.ts +86 -89
- package/src/template/custom-resources.ts +11 -11
- package/src/template/prompts/agent-brief.ts +8 -8
- package/src/template/prompts/agent-prompt.ts +10 -10
- package/src/template/prompts/custom-prompts.ts +12 -12
- package/src/template/start.ts +71 -72
- package/src/template/tools/handle-tool-call.ts +57 -56
- package/src/template/tools/tools.ts +89 -88
- package/src/tests/jest-simple-reporter.js +10 -10
- package/src/tests/mcp/sse/test-sse-npm-package.js +96 -96
- package/src/tests/mcp/test-cases.js +143 -143
- package/src/tests/mcp/test-http.js +76 -75
- package/src/tests/mcp/test-sse.js +80 -79
- package/src/tests/mcp/test-stdio.js +83 -81
- package/src/tests/utils.ts +157 -156
|
@@ -1,56 +1,57 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
error
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
import { logger as lgr, formatToolResult, ToolExecutionError } from '../../core/index.js';
|
|
4
|
+
|
|
5
|
+
const logger = lgr.getSubLogger({ name: chalk.bgGrey('tools') });
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Template tool handler - customize this for your specific tools
|
|
9
|
+
* This handles MCP tool execution requests
|
|
10
|
+
*/
|
|
11
|
+
export const handleToolCall = async (params: { name: string, arguments?: any }): Promise<any> => {
|
|
12
|
+
const { name, arguments: args } = params;
|
|
13
|
+
|
|
14
|
+
logger.info(`Tool called: ${name}`);
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
// TODO: Implement your tool routing logic here
|
|
18
|
+
switch (name) {
|
|
19
|
+
case 'example_tool':
|
|
20
|
+
return await handleExampleTool(args);
|
|
21
|
+
|
|
22
|
+
default:
|
|
23
|
+
throw new ToolExecutionError(name, `Unknown tool: ${name}`);
|
|
24
|
+
}
|
|
25
|
+
} catch (error: Error | any) {
|
|
26
|
+
logger.error(`Tool execution failed for ${name}:`, error);
|
|
27
|
+
error.printed = true;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Example tool implementation
|
|
34
|
+
* Replace this with your actual tool logic
|
|
35
|
+
*/
|
|
36
|
+
async function handleExampleTool (args: any): Promise<string> {
|
|
37
|
+
const { query } = args || {};
|
|
38
|
+
|
|
39
|
+
if (!query) {
|
|
40
|
+
throw new ToolExecutionError('example_tool', 'Query parameter is required');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Simulate some work
|
|
44
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
45
|
+
|
|
46
|
+
const result = {
|
|
47
|
+
message: `Processed query: ${query}`,
|
|
48
|
+
timestamp: new Date().toISOString(),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return formatToolResult(result);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// TODO: Add more tool handlers here
|
|
55
|
+
// async function handleAnotherTool(args: any): Promise<string> {
|
|
56
|
+
// // Your implementation
|
|
57
|
+
// }
|
|
@@ -1,88 +1,89 @@
|
|
|
1
|
-
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
1
|
+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
|
|
3
|
+
import { IToolInputSchema, IToolProperties } from '../../core/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Template tools configuration for MCP Server
|
|
7
|
+
* Define your tools according to your server's functionality
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const getGenericInputSchema = (
|
|
12
|
+
queryDescription?: string,
|
|
13
|
+
additionalProperties?: IToolProperties,
|
|
14
|
+
): IToolInputSchema => {
|
|
15
|
+
const properties = {
|
|
16
|
+
query: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: queryDescription || 'Input query or text',
|
|
19
|
+
},
|
|
20
|
+
...additionalProperties,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties,
|
|
26
|
+
required: ['query'],
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getSearchInputSchema = (): IToolInputSchema => {
|
|
31
|
+
return {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
query: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
description: 'Search query',
|
|
37
|
+
},
|
|
38
|
+
limit: {
|
|
39
|
+
type: 'number',
|
|
40
|
+
description: 'Maximum number of results to return (1-100, default: 20)',
|
|
41
|
+
minimum: 1,
|
|
42
|
+
maximum: 100,
|
|
43
|
+
},
|
|
44
|
+
threshold: {
|
|
45
|
+
type: 'number',
|
|
46
|
+
description: 'Minimum similarity threshold (0-1)',
|
|
47
|
+
minimum: 0,
|
|
48
|
+
maximum: 1,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
required: ['query'],
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Template tools - customize according to your needs
|
|
56
|
+
export const tools: Tool[] = [
|
|
57
|
+
{
|
|
58
|
+
name: 'example_tool',
|
|
59
|
+
description: 'Example tool that processes text input. Replace with your actual tools.',
|
|
60
|
+
inputSchema: getGenericInputSchema('Text to process'),
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: 'example_search',
|
|
64
|
+
description: 'Example search tool with pagination and filtering. Template for search-based tools.',
|
|
65
|
+
inputSchema: getSearchInputSchema(),
|
|
66
|
+
},
|
|
67
|
+
// TODO: Add your actual tools here
|
|
68
|
+
// {
|
|
69
|
+
// name: 'your_tool_name',
|
|
70
|
+
// description: 'Description of what your tool does',
|
|
71
|
+
// inputSchema: getGenericInputSchema('Your query description', {
|
|
72
|
+
// // additional parameters
|
|
73
|
+
// param1: {
|
|
74
|
+
// type: 'string',
|
|
75
|
+
// description: 'Description of param1',
|
|
76
|
+
// },
|
|
77
|
+
// }),
|
|
78
|
+
// },
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
// Helper to get tool by name
|
|
82
|
+
export const getToolByName = (name: string): Tool | undefined => {
|
|
83
|
+
return tools.find(tool => tool.name === name);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Helper to get all tool names
|
|
87
|
+
export const getToolNames = (): string[] => {
|
|
88
|
+
return tools.map(tool => tool.name);
|
|
89
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export default class SimpleReporter {
|
|
2
|
-
onRunComplete (contexts, runResults) {
|
|
3
|
-
const { numPassedTests, numFailedTests, numPendingTests } = runResults;
|
|
4
|
-
const total = numPassedTests + numFailedTests + numPendingTests;
|
|
5
|
-
const actualSuccess = numFailedTests === 0 && total > 0;
|
|
6
|
-
|
|
7
|
-
console.log(`\nTest Results: ${numPassedTests} passed, ${numFailedTests} failed, ${numPendingTests} skipped (${total} total)`);
|
|
8
|
-
console.log(`Status: ${actualSuccess ? 'PASSED' : 'FAILED'}`);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
export default class SimpleReporter {
|
|
2
|
+
onRunComplete (contexts, runResults) {
|
|
3
|
+
const { numPassedTests, numFailedTests, numPendingTests } = runResults;
|
|
4
|
+
const total = numPassedTests + numFailedTests + numPendingTests;
|
|
5
|
+
const actualSuccess = numFailedTests === 0 && total > 0;
|
|
6
|
+
|
|
7
|
+
console.log(`\nTest Results: ${numPassedTests} passed, ${numFailedTests} failed, ${numPendingTests} skipped (${total} total)`);
|
|
8
|
+
console.log(`Status: ${actualSuccess ? 'PASSED' : 'FAILED'}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Example of using fa-mcp-sdk as an npm package without unhandledRejection issues
|
|
5
|
-
*
|
|
6
|
-
* To use this example:
|
|
7
|
-
* 1. Install fa-mcp-sdk: npm install fa-mcp-sdk
|
|
8
|
-
* 2. Start MCP server: npm run template:start (in fa-mcp-sdk project)
|
|
9
|
-
* 3. Run this example: node test-npm-package.js
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { McpSseClient } from 'fa-mcp-sdk';
|
|
13
|
-
|
|
14
|
-
const SERVER_URL = 'http://localhost:9876';
|
|
15
|
-
|
|
16
|
-
async function testMcpClient () {
|
|
17
|
-
console.log('🧪 Testing MCP client as npm package');
|
|
18
|
-
console.log('='.repeat(50));
|
|
19
|
-
|
|
20
|
-
// Use the new method that handles unhandledRejection
|
|
21
|
-
const client = McpSseClient.createWithErrorHandler(SERVER_URL);
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
// Health check
|
|
25
|
-
console.log('1. Health check...');
|
|
26
|
-
try {
|
|
27
|
-
const health = await client.health();
|
|
28
|
-
console.log('✅ Health check passed:', health.status);
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.log('⚠️ Health check failed:', error.message);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Initialize
|
|
34
|
-
console.log('2. Initializing...');
|
|
35
|
-
await client.sendRequest('initialize', {
|
|
36
|
-
protocolVersion: '2024-11-05',
|
|
37
|
-
capabilities: { tools: {} },
|
|
38
|
-
clientInfo: { name: 'npm-test', version: '1.0.0' },
|
|
39
|
-
});
|
|
40
|
-
console.log('✅ Initialized successfully');
|
|
41
|
-
|
|
42
|
-
// List tools
|
|
43
|
-
console.log('3. Listing tools...');
|
|
44
|
-
const tools = await client.listTools();
|
|
45
|
-
const toolNames = tools.tools?.map(t => t.name) || [];
|
|
46
|
-
console.log('✅ Available tools:', toolNames.join(', '));
|
|
47
|
-
|
|
48
|
-
// Test successful tool call
|
|
49
|
-
console.log('4. Testing successful tool call...');
|
|
50
|
-
try {
|
|
51
|
-
const response = await client.callTool('example_tool', { query: 'ping' });
|
|
52
|
-
console.log('✅ Tool call successful:', response.result?.structuredContent?.message || response.result?.content?.[0]?.text);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
console.log('❌ Tool call failed:', error.message);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Test expected error (like the test case in test-cases.js)
|
|
58
|
-
console.log('5. Testing expected error handling...');
|
|
59
|
-
try {
|
|
60
|
-
await client.callTool('example_tool', {}); // Missing query parameter
|
|
61
|
-
console.log('❌ Expected error but got success');
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.log('✅ Expected error caught:', error.message);
|
|
64
|
-
// This error should NOT cause unhandledRejection
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Test with invalid tool name
|
|
68
|
-
console.log('6. Testing invalid tool name...');
|
|
69
|
-
try {
|
|
70
|
-
await client.callTool('nonexistent_tool', {});
|
|
71
|
-
console.log('❌ Expected error but got success');
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.log('✅ Expected error caught:', error.message);
|
|
74
|
-
// This error should NOT cause unhandledRejection
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
console.log('\n🎉 All tests completed successfully!');
|
|
78
|
-
console.log('✨ No unhandledRejection errors occurred');
|
|
79
|
-
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error('❌ Unexpected error:', error.message);
|
|
82
|
-
} finally {
|
|
83
|
-
await client.close();
|
|
84
|
-
console.log('🔚 Client closed');
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Global handler for any unexpected unhandled rejections
|
|
89
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
90
|
-
console.error('💥 UNHANDLED REJECTION (this should not happen):');
|
|
91
|
-
console.error('Reason:', reason);
|
|
92
|
-
console.error('Promise:', promise);
|
|
93
|
-
process.exit(1);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
testMcpClient().catch(console.error);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Example of using fa-mcp-sdk as an npm package without unhandledRejection issues
|
|
5
|
+
*
|
|
6
|
+
* To use this example:
|
|
7
|
+
* 1. Install fa-mcp-sdk: npm install fa-mcp-sdk
|
|
8
|
+
* 2. Start MCP server: npm run template:start (in fa-mcp-sdk project)
|
|
9
|
+
* 3. Run this example: node test-npm-package.js
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { McpSseClient } from 'fa-mcp-sdk';
|
|
13
|
+
|
|
14
|
+
const SERVER_URL = 'http://localhost:9876';
|
|
15
|
+
|
|
16
|
+
async function testMcpClient () {
|
|
17
|
+
console.log('🧪 Testing MCP client as npm package');
|
|
18
|
+
console.log('='.repeat(50));
|
|
19
|
+
|
|
20
|
+
// Use the new method that handles unhandledRejection
|
|
21
|
+
const client = McpSseClient.createWithErrorHandler(SERVER_URL);
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
// Health check
|
|
25
|
+
console.log('1. Health check...');
|
|
26
|
+
try {
|
|
27
|
+
const health = await client.health();
|
|
28
|
+
console.log('✅ Health check passed:', health.status);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.log('⚠️ Health check failed:', error.message);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Initialize
|
|
34
|
+
console.log('2. Initializing...');
|
|
35
|
+
await client.sendRequest('initialize', {
|
|
36
|
+
protocolVersion: '2024-11-05',
|
|
37
|
+
capabilities: { tools: {} },
|
|
38
|
+
clientInfo: { name: 'npm-test', version: '1.0.0' },
|
|
39
|
+
});
|
|
40
|
+
console.log('✅ Initialized successfully');
|
|
41
|
+
|
|
42
|
+
// List tools
|
|
43
|
+
console.log('3. Listing tools...');
|
|
44
|
+
const tools = await client.listTools();
|
|
45
|
+
const toolNames = tools.tools?.map(t => t.name) || [];
|
|
46
|
+
console.log('✅ Available tools:', toolNames.join(', '));
|
|
47
|
+
|
|
48
|
+
// Test successful tool call
|
|
49
|
+
console.log('4. Testing successful tool call...');
|
|
50
|
+
try {
|
|
51
|
+
const response = await client.callTool('example_tool', { query: 'ping' });
|
|
52
|
+
console.log('✅ Tool call successful:', response.result?.structuredContent?.message || response.result?.content?.[0]?.text);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.log('❌ Tool call failed:', error.message);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Test expected error (like the test case in test-cases.js)
|
|
58
|
+
console.log('5. Testing expected error handling...');
|
|
59
|
+
try {
|
|
60
|
+
await client.callTool('example_tool', {}); // Missing query parameter
|
|
61
|
+
console.log('❌ Expected error but got success');
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.log('✅ Expected error caught:', error.message);
|
|
64
|
+
// This error should NOT cause unhandledRejection
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Test with invalid tool name
|
|
68
|
+
console.log('6. Testing invalid tool name...');
|
|
69
|
+
try {
|
|
70
|
+
await client.callTool('nonexistent_tool', {});
|
|
71
|
+
console.log('❌ Expected error but got success');
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.log('✅ Expected error caught:', error.message);
|
|
74
|
+
// This error should NOT cause unhandledRejection
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.log('\n🎉 All tests completed successfully!');
|
|
78
|
+
console.log('✨ No unhandledRejection errors occurred');
|
|
79
|
+
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('❌ Unexpected error:', error.message);
|
|
82
|
+
} finally {
|
|
83
|
+
await client.close();
|
|
84
|
+
console.log('🔚 Client closed');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Global handler for any unexpected unhandled rejections
|
|
89
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
90
|
+
console.error('💥 UNHANDLED REJECTION (this should not happen):');
|
|
91
|
+
console.error('Reason:', reason);
|
|
92
|
+
console.error('Promise:', promise);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
testMcpClient().catch(console.error);
|