fa-mcp-sdk 0.2.125 → 0.2.131

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 +43 -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
@@ -11,6 +11,7 @@ import yaml from 'js-yaml';
11
11
  const __filename = fileURLToPath(import.meta.url);
12
12
  const __dirname = path.dirname(__filename);
13
13
  const PRINT_FILLED = true;
14
+ const PROJ_ROOT = path.join(__dirname, '..');
14
15
 
15
16
  const hl = (v) => chalk.bgGreen.black(v);
16
17
  const hly = (v) => chalk.bgYellow.black(v);
@@ -26,6 +27,8 @@ const printFilled = (paramName, paramValue) => {
26
27
  }
27
28
  };
28
29
 
30
+ const faMcpSdkVersion = require(path.join(PROJ_ROOT, 'package.json')).version;
31
+
29
32
  const getAsk = () => {
30
33
  const rl = readline.createInterface({
31
34
  input: process.stdin,
@@ -100,9 +103,29 @@ const parseConfigFile = (filePath, content) => {
100
103
  }
101
104
  };
102
105
 
106
+ const removeIfExists = async (targetPath, relPath, options = {}) => {
107
+ const fullPath = path.join(targetPath, relPath);
108
+
109
+ try {
110
+ let finalOptions = { force: true, ...options };
111
+
112
+ try {
113
+ const stat = await fs.lstat(fullPath);
114
+ if (stat.isDirectory() && finalOptions.recursive === undefined) {
115
+ finalOptions = { ...finalOptions, recursive: true };
116
+ }
117
+ } catch {
118
+ // lstat упадёт, если файла/папки нет — это ок, просто пойдем в rm с теми же опциями
119
+ }
120
+
121
+ await fs.rm(fullPath, finalOptions);
122
+ } catch {
123
+ // игнорируем любые ошибки удаления
124
+ }
125
+ };
126
+
103
127
  class MCPGenerator {
104
128
  constructor () {
105
- this.templateDir = path.join(__dirname, '..', 'cli-template');
106
129
  this.lastConfigPath = path.join(process.cwd(), '~last-cli-config.json');
107
130
  this.requiredParams = [
108
131
  {
@@ -753,7 +776,7 @@ certificate's public and private keys`,
753
776
  delete packageJson.author;
754
777
  }
755
778
  }
756
-
779
+ packageJson.dependencies['fa-mcp-sdk'] = `^${faMcpSdkVersion}`;
757
780
  return JSON.stringify(packageJson, null, 2);
758
781
  } catch (error) {
759
782
  throw new Error(`Error processing package.json: ${error.message}`);
@@ -806,6 +829,11 @@ certificate's public and private keys`,
806
829
  modified = true;
807
830
  }
808
831
  }
832
+ content = content.replace(/'[^']+\/core\/index.js'/g, 'fa-mcp-sdk');
833
+ }
834
+ if (filePath.endsWith('test-sse-npm-package.js')) {
835
+ content = content.replace(/http:\/\/localhost:9876/g, `http://localhost:${config.port}`);
836
+ modified = true;
809
837
  }
810
838
 
811
839
  if (modified) {
@@ -857,8 +885,10 @@ certificate's public and private keys`,
857
885
  async createProject (config) {
858
886
  const targetPath = config.projectAbsPath;
859
887
  // Copy template files
860
- await this.copyDirectory(this.templateDir, targetPath);
861
- await fs.copyFile(path.join(targetPath, '.env.example'), path.join(targetPath, '.env')); // VVT
888
+ await this.copyDirectory(path.join(PROJ_ROOT, 'cli-template'), targetPath);
889
+ await this.copyDirectory(path.join(PROJ_ROOT, 'src/template'), path.join(targetPath, 'src'));
890
+ await this.copyDirectory(path.join(PROJ_ROOT, 'src/tests'), path.join(targetPath, 'tests'));
891
+ await fs.copyFile(path.join(targetPath, '.env.example'), path.join(targetPath, '.env'));
862
892
 
863
893
  // Rename mcp-template.com.conf if mcp.domain is provided
864
894
  const mcpDomain = config['mcp.domain'];
@@ -918,15 +948,16 @@ certificate's public and private keys`,
918
948
  console.log('⚠️ Warning: Could not create config/_local.yaml file:', error.message);
919
949
  }
920
950
  }
951
+ const pathsToRemove = [
952
+ { rel: 'node_modules' },
953
+ { rel: 'yarn.lock' },
954
+ { rel: 'package-lock.json' },
955
+ { rel: 'src/index-to-remove.ts' },
956
+ ];
921
957
 
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
- }
958
+ await Promise.all(
959
+ pathsToRemove.map(({ rel, options }) => removeIfExists(targetPath, rel, options)),
960
+ );
930
961
  }
931
962
 
932
963
  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: '***'