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
package/bin/fa-mcp.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import fs from 'fs/promises';
4
+ import fss from 'fs';
4
5
  import path from 'path';
5
6
  import { fileURLToPath } from 'url';
6
7
  import readline from 'readline';
@@ -11,6 +12,7 @@ import yaml from 'js-yaml';
11
12
  const __filename = fileURLToPath(import.meta.url);
12
13
  const __dirname = path.dirname(__filename);
13
14
  const PRINT_FILLED = true;
15
+ const PROJ_ROOT = path.join(__dirname, '..');
14
16
 
15
17
  const hl = (v) => chalk.bgGreen.black(v);
16
18
  const hly = (v) => chalk.bgYellow.black(v);
@@ -26,6 +28,10 @@ const printFilled = (paramName, paramValue) => {
26
28
  }
27
29
  };
28
30
 
31
+ const pjContent = fss.readFileSync(path.join(PROJ_ROOT, 'package.json'));
32
+
33
+ const faMcpSdkVersion = JSON.parse(pjContent).version;
34
+
29
35
  const getAsk = () => {
30
36
  const rl = readline.createInterface({
31
37
  input: process.stdin,
@@ -100,9 +106,29 @@ const parseConfigFile = (filePath, content) => {
100
106
  }
101
107
  };
102
108
 
109
+ const removeIfExists = async (targetPath, relPath, options = {}) => {
110
+ const fullPath = path.join(targetPath, relPath);
111
+
112
+ try {
113
+ let finalOptions = { force: true, ...options };
114
+
115
+ try {
116
+ const stat = await fs.lstat(fullPath);
117
+ if (stat.isDirectory() && finalOptions.recursive === undefined) {
118
+ finalOptions = { ...finalOptions, recursive: true };
119
+ }
120
+ } catch {
121
+ // lstat упадёт, если файла/папки нет — это ок, просто пойдем в rm с теми же опциями
122
+ }
123
+
124
+ await fs.rm(fullPath, finalOptions);
125
+ } catch {
126
+ // игнорируем любые ошибки удаления
127
+ }
128
+ };
129
+
103
130
  class MCPGenerator {
104
131
  constructor () {
105
- this.templateDir = path.join(__dirname, '..', 'cli-template');
106
132
  this.lastConfigPath = path.join(process.cwd(), '~last-cli-config.json');
107
133
  this.requiredParams = [
108
134
  {
@@ -753,7 +779,7 @@ certificate's public and private keys`,
753
779
  delete packageJson.author;
754
780
  }
755
781
  }
756
-
782
+ packageJson.dependencies['fa-mcp-sdk'] = `^${faMcpSdkVersion}`;
757
783
  return JSON.stringify(packageJson, null, 2);
758
784
  } catch (error) {
759
785
  throw new Error(`Error processing package.json: ${error.message}`);
@@ -806,6 +832,11 @@ certificate's public and private keys`,
806
832
  modified = true;
807
833
  }
808
834
  }
835
+ content = content.replace(/'[^']+\/core\/index.js'/g, 'fa-mcp-sdk');
836
+ }
837
+ if (filePath.endsWith('test-sse-npm-package.js')) {
838
+ content = content.replace(/http:\/\/localhost:9876/g, `http://localhost:${config.port}`);
839
+ modified = true;
809
840
  }
810
841
 
811
842
  if (modified) {
@@ -857,8 +888,10 @@ certificate's public and private keys`,
857
888
  async createProject (config) {
858
889
  const targetPath = config.projectAbsPath;
859
890
  // Copy template files
860
- await this.copyDirectory(this.templateDir, targetPath);
861
- await fs.copyFile(path.join(targetPath, '.env.example'), path.join(targetPath, '.env')); // VVT
891
+ await this.copyDirectory(path.join(PROJ_ROOT, 'cli-template'), targetPath);
892
+ await this.copyDirectory(path.join(PROJ_ROOT, 'src/template'), path.join(targetPath, 'src'));
893
+ await this.copyDirectory(path.join(PROJ_ROOT, 'src/tests'), path.join(targetPath, 'tests'));
894
+ await fs.copyFile(path.join(targetPath, '.env.example'), path.join(targetPath, '.env'));
862
895
 
863
896
  // Rename mcp-template.com.conf if mcp.domain is provided
864
897
  const mcpDomain = config['mcp.domain'];
@@ -918,15 +951,16 @@ certificate's public and private keys`,
918
951
  console.log('⚠️ Warning: Could not create config/_local.yaml file:', error.message);
919
952
  }
920
953
  }
954
+ const pathsToRemove = [
955
+ { rel: 'node_modules' },
956
+ { rel: 'yarn.lock' },
957
+ { rel: 'package-lock.json' },
958
+ { rel: 'src/index-to-remove.ts' },
959
+ ];
921
960
 
922
- // Remove node_modules from project if it exists
923
- try {
924
- const nodeModulesPath = path.join(targetPath, 'node_modules');
925
- await fs.access(nodeModulesPath);
926
- await fs.rm(nodeModulesPath, { recursive: true, force: true });
927
- } catch {
928
- // node_modules doesn't exist, which is fine
929
- }
961
+ await Promise.all(
962
+ pathsToRemove.map(({ rel, options }) => removeIfExists(targetPath, rel, options)),
963
+ );
930
964
  }
931
965
 
932
966
  async run () {
@@ -75,22 +75,40 @@ webServer:
75
75
  port: {{port}}
76
76
  # array of hosts that CORS skips
77
77
  originHosts: ['localhost', '0.0.0.0']
78
+ # Authentication is configured here only when accessing the MCP server
79
+ # Authentication in services that enable tools, resources, and prompts
80
+ # is implemented more deeply. To do this, you need to use the information passed in HTTP headers
81
+ # You can also use a custom authorization function
78
82
  auth:
79
83
  enabled: {{webServer.auth.enabled}} # Enables/disables token authorization
80
- # An array of fixed tokens that pass to the MCP (use only for MCPs with green data or for development)
84
+ # ========================================================================
85
+ # PERMANENT SERVER TOKENS
86
+ # Static tokens for server-to-server communication
87
+ # CPU cost: O(1) - fastest authentication method
88
+ #
89
+ # To enable this authentication, you need to set auth.enabled = true
90
+ # and set one token of at least 20 characters in length
91
+ # ========================================================================
81
92
  permanentServerTokens: []
93
+ # ========================================================================
94
+ # JWT TOKEN WITH SYMMETRIC ENCRYPTION
95
+ # Custom JWT tokens with AES-256 encryption
96
+ # CPU cost: Medium - decryption + JSON parsing
97
+ #
98
+ # To enable this authentication, you need to set auth.enabled = true and set
99
+ # encryptKey to at least 20 characters
100
+ # ========================================================================
82
101
  jwtToken:
83
102
  # Symmetric encryption key to generate a token for this MCP
84
103
  encryptKey: '{{webServer.auth.token.encryptKey}}'
85
104
  # If webServer.auth.enabled and the parameter true, the service name and the service specified in the token will be checked
86
105
  checkMCPName: {{webServer.auth.token.checkMCPName}}
87
- #basic:
88
- # username: '***'
89
- # password: '***'
90
- #oauth2:
91
- # type: 'oauth2';
92
- # clientId: '***'
93
- # clientSecret: '***'
94
- # redirectUri?: 'string'
95
- # tokenEndpoint?: string # For custom OAuth providers // VVR
96
- #pat: string;
106
+ # ========================================================================
107
+ # Basic Authentication - Base64 encoded username:password
108
+ # CPU cost: Medium - Base64 decoding + string comparison
109
+ # To enable this authentication, you need to set auth.enabled = true
110
+ # and set username and password to valid values
111
+ # ========================================================================
112
+ basic:
113
+ username: ''
114
+ password: '***'
@@ -40,9 +40,3 @@ webServer:
40
40
  basic:
41
41
  username: WS_AUTH_BASIC_USERNAME
42
42
  password: WS_AUTH_BASIC_PASSWORD
43
- oauth2:
44
- clientId: WS_AUTH_OAUTH2_CLIENT_ID
45
- clientSecret: WS_AUTH_OAUTH2_CLIENT_SECRET
46
- redirectUri: WS_AUTH_OAUTH2_REDIRECT_URI
47
- tokenEndpoint: WS_AUTH_OAUTH2_TOKEN_ENDPOINT # For custom OAuth providers // VVR
48
- pat: WS_AUTH_PAT
@@ -110,22 +110,42 @@ webServer:
110
110
  port: {{port}}
111
111
  # array of hosts that CORS skips
112
112
  originHosts: ['localhost', '0.0.0.0']
113
+ # Authentication is configured here only when accessing the MCP server
114
+ # Authentication in services that enable tools, resources, and prompts
115
+ # is implemented more deeply. To do this, you need to use the information passed in HTTP headers
116
+ # You can also use a custom authorization function
113
117
  auth:
114
- enabled: false # Enables/disables token authorization
115
- # An array of fixed tokens that pass to the MCP (use only for MCPs with green data or for development)
116
- permanentServerTokens: []
118
+ enabled: false # Enables/disables authorization
119
+ # ========================================================================
120
+ # PERMANENT SERVER TOKENS
121
+ # Static tokens for server-to-server communication
122
+ # CPU cost: O(1) - fastest authentication method
123
+ #
124
+ # To enable this authentication, you need to set auth.enabled = true
125
+ # and set one token of at least 20 characters in length
126
+ # ========================================================================
127
+ permanentServerTokens: [ ] # Add your server tokens here: ['token1', 'token2']
128
+
129
+ # ========================================================================
130
+ # JWT TOKEN WITH SYMMETRIC ENCRYPTION
131
+ # Custom JWT tokens with AES-256 encryption
132
+ # CPU cost: Medium - decryption + JSON parsing
133
+ #
134
+ # To enable this authentication, you need to set auth.enabled = true and set
135
+ # encryptKey to at least 20 characters
136
+ # ========================================================================
117
137
  jwtToken:
118
- # Symmetric encryption key to generate a token for this MCP
138
+ # Symmetric encryption key to generate a token for this MCP (minimum 8 chars)
119
139
  encryptKey: '***'
120
140
  # If webServer.auth.enabled and the parameter true, the service name and the service specified in the token will be checked
121
141
  checkMCPName: true
122
- #basic:
123
- # username: '***'
124
- # password: '***'
125
- #oauth2:
126
- # type: 'oauth2';
127
- # clientId: '***'
128
- # clientSecret: '***'
129
- # redirectUri?: 'string'
130
- # tokenEndpoint?: string # For custom OAuth providers // VVR
131
- #pat: string;
142
+
143
+ # ========================================================================
144
+ # Basic Authentication - Base64 encoded username:password
145
+ # CPU cost: Medium - Base64 decoding + string comparison
146
+ # To enable this authentication, you need to set auth.enabled = true
147
+ # and set username and password to valid values
148
+ # ========================================================================
149
+ basic:
150
+ username: ''
151
+ password: '***'