fa-mcp-sdk 0.2.249 → 0.2.258

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 (46) hide show
  1. package/cli-template/FA-MCP-SDK-DOC/00-FA-MCP-SDK-index.md +45 -161
  2. package/cli-template/FA-MCP-SDK-DOC/01-getting-started.md +71 -226
  3. package/cli-template/FA-MCP-SDK-DOC/02-1-tools-and-api.md +80 -360
  4. package/cli-template/FA-MCP-SDK-DOC/02-2-prompts-and-resources.md +191 -342
  5. package/cli-template/FA-MCP-SDK-DOC/03-configuration.md +141 -279
  6. package/cli-template/FA-MCP-SDK-DOC/04-authentication.md +73 -522
  7. package/cli-template/FA-MCP-SDK-DOC/05-ad-authorization.md +68 -419
  8. package/cli-template/FA-MCP-SDK-DOC/06-utilities.md +64 -447
  9. package/cli-template/FA-MCP-SDK-DOC/07-testing-and-operations.md +39 -196
  10. package/cli-template/package.json +2 -1
  11. package/config/local.yaml +1 -1
  12. package/dist/core/_types_/types.d.ts +36 -10
  13. package/dist/core/_types_/types.d.ts.map +1 -1
  14. package/dist/core/auth/admin-auth.js +1 -1
  15. package/dist/core/auth/admin-auth.js.map +1 -1
  16. package/dist/core/auth/middleware.js +8 -8
  17. package/dist/core/auth/middleware.js.map +1 -1
  18. package/dist/core/auth/multi-auth.d.ts.map +1 -1
  19. package/dist/core/auth/multi-auth.js +15 -14
  20. package/dist/core/auth/multi-auth.js.map +1 -1
  21. package/dist/core/index.d.ts +1 -1
  22. package/dist/core/index.d.ts.map +1 -1
  23. package/dist/core/index.js.map +1 -1
  24. package/dist/core/mcp/create-mcp-server.js +8 -9
  25. package/dist/core/mcp/create-mcp-server.js.map +1 -1
  26. package/dist/core/mcp/prompts.d.ts +10 -5
  27. package/dist/core/mcp/prompts.d.ts.map +1 -1
  28. package/dist/core/mcp/prompts.js +17 -15
  29. package/dist/core/mcp/prompts.js.map +1 -1
  30. package/dist/core/mcp/resources.d.ts +4 -4
  31. package/dist/core/mcp/resources.d.ts.map +1 -1
  32. package/dist/core/mcp/resources.js +21 -20
  33. package/dist/core/mcp/resources.js.map +1 -1
  34. package/dist/core/utils/utils.d.ts +2 -1
  35. package/dist/core/utils/utils.d.ts.map +1 -1
  36. package/dist/core/utils/utils.js +2 -2
  37. package/dist/core/utils/utils.js.map +1 -1
  38. package/dist/core/web/home-api.d.ts.map +1 -1
  39. package/dist/core/web/home-api.js +4 -3
  40. package/dist/core/web/home-api.js.map +1 -1
  41. package/dist/core/web/server-http.d.ts.map +1 -1
  42. package/dist/core/web/server-http.js +36 -21
  43. package/dist/core/web/server-http.js.map +1 -1
  44. package/package.json +1 -1
  45. package/scripts/update-doc.js +21 -0
  46. package/src/template/start.ts +1 -1
@@ -1,324 +1,191 @@
1
1
  # Configuration, Cache, and Database
2
2
 
3
- ## Configuration Management
3
+ ## Configuration
4
4
 
5
- ### Using `appConfig`
6
-
7
- Access configuration in your code:
5
+ ### appConfig Access
8
6
 
9
7
  ```typescript
10
8
  import { appConfig } from 'fa-mcp-sdk';
11
9
 
12
- // Access configuration values
13
- const serverPort = appConfig.webServer.port;
10
+ const port = appConfig.webServer.port;
14
11
  const dbEnabled = appConfig.isMainDBUsed;
15
12
  const transport = appConfig.mcp.transportType; // 'stdio' | 'http'
16
13
  ```
17
14
 
18
15
  ### Service Identification
19
16
 
20
- The SDK uses two primary identifiers for the service:
21
-
22
- #### SERVICE_NAME `appConfig.name`
23
-
24
- **Formation:**
25
- ```
26
- process.env.SERVICE_NAME || package.json.name
27
- ```
28
-
29
- A derivative value `appConfig.shortName` is also created by removing "mcp" from the name:
30
- ```typescript
31
- shortName = name.replace(/[\s\-]*\bmcp\b[\s\-]*/ig, '');
32
- // Example: "my-mcp-service" → "my-service"
33
- ```
34
-
35
- **Usage locations:**
36
-
37
- | Component | Property | Purpose |
38
- |--------------|-----------------------|-----------------------------------------|
39
- | Consul | `consul.service.name` | Service registration in Consul |
40
- | MCP Server | Server name | MCP protocol server identifier |
41
- | Logger | File prefix | Log file naming (`<name>.log`) |
42
- | JWT Auth | `expectedService` | Token validation - checks service claim |
43
- | Admin API | `serviceName` | Service identification in API responses |
44
- | MCP Resource | `project://id` | Returns service identifier |
45
- | Cache | `keyPrefix` | Uses `shortName` for cache key prefixes |
46
- | PM2 | Process name | `<name>[--<SERVICE_INSTANCE>]` |
47
-
48
- #### PRODUCT_NAME → `appConfig.productName`
49
-
50
- **Formation:**
51
- ```
52
- process.env.PRODUCT_NAME || package.json.productName
53
- ```
54
-
55
- This is the human-readable display name for the service.
56
-
57
- **Usage locations:**
58
-
59
- | Component | Purpose |
60
- |-----------------|---------------------------------------|
61
- | OpenAPI/Swagger | API title in documentation |
62
- | Home page | Service title in web UI header |
63
- | Server startup | Displayed in console startup message |
64
- | MCP Resource | `project://name` returns product name |
65
-
66
- #### Environment Variables
17
+ | Variable | Source | Usage |
18
+ |----------|--------|-------|
19
+ | `appConfig.name` | `SERVICE_NAME` env or `package.json.name` | Consul, JWT, logs, MCP server ID |
20
+ | `appConfig.shortName` | name without "mcp" | Cache key prefix |
21
+ | `appConfig.productName` | `PRODUCT_NAME` env or `package.json.productName` | Swagger title, UI header |
67
22
 
68
- Set these in `.env` file to override `package.json` values:
23
+ ### config/default.yaml
69
24
 
70
- ```bash
71
- # Service identifier (technical name)
72
- SERVICE_NAME=my-mcp-service
73
-
74
- # Human-readable display name
75
- PRODUCT_NAME=My MCP Service
76
- ```
77
-
78
- ### Configuration Files
79
-
80
- **`config/default.yaml`** - Base configuration:
81
25
  ```yaml
82
26
  accessPoints:
83
27
  myService:
84
- title: 'My remote service'
28
+ title: 'Remote service'
85
29
  host: <host>
86
30
  port: 9999
87
31
  token: '***'
88
- noConsul: true # Use if the service developers do not provide registration in consul
89
- consulServiceName: <consulServiceName>
32
+ noConsul: true
33
+ consulServiceName: <name>
90
34
 
91
- # --------------------------------------------------
92
- # CACHING Reduces API calls by caching responses
93
- # --------------------------------------------------
94
35
  cache:
95
- # Default Cache TTL in seconds
96
- ttlSeconds: 300
97
- # Default maximum number of cached items
98
- maxItems: 1000
36
+ ttlSeconds: 300
37
+ maxItems: 1000
99
38
 
100
39
  consul:
101
- check:
102
- interval: '10s'
103
- timeout: '5s'
104
- deregistercriticalserviceafter: '3m'
105
- agent:
106
- # Credentials for getting information about services in the DEV DC
107
- dev:
108
- dc: '{{consul.agent.dev.dc}}'
109
- host: '{{consul.agent.dev.host}}'
110
- port: 443
111
- secure: true
112
- # Token for getting information about DEV services
113
- token: '***'
114
- # Credentials for getting information about services in the PROD DC
115
- prd:
116
- dc: '{{consul.agent.prd.dc}}'
117
- host: '{{consul.agent.prd.host}}'
118
- port: 443
119
- secure: true
120
- # Token for obtaining information about PROD services
121
- token: '***'
122
- # Credentials for registering the service with Consul
123
- reg:
124
- # The host of the consul agent where the service will be registered. If not specified, the server on which the service is running is used
125
- host: null
126
- port: 8500
127
- secure: false
128
- # Token for registering the service in the consul agent
129
- token: '***'
130
- service:
131
- enable: {{consul.service.enable}} # true - Allows registration of the service with the consul
132
- name: <name> # <name> will be replaced by <package.json>.name at initialization
133
- instance: '{{SERVICE_INSTANCE}}' # This value will be specified as a suffix in the id of the service
134
- version: <version> # <version> will be replaced by <package.json>.version at initialization
135
- description: <description> # <description> will be replaced by <package.json>.description at initialization
136
- tags: [] # If null or empty array - Will be pulled up from package.keywords at initialization
137
- meta:
138
- # "Home" page link template
139
- who: 'http://{address}:{port}/'
140
- envCode: # Used to generate the service ID
141
- prod: {{consul.envCode.prod}} # Production environment code
142
- dev: {{consul.envCode.dev}} # Development environment code
40
+ check:
41
+ interval: '10s'
42
+ timeout: '5s'
43
+ deregistercriticalserviceafter: '3m'
44
+ agent:
45
+ # Credentials for getting information about services in the DEV DC
46
+ dev:
47
+ dc: '{{consul.agent.dev.dc}}'
48
+ host: '{{consul.agent.dev.host}}'
49
+ port: 443
50
+ secure: true
51
+ # Token for getting information about DEV services
52
+ token: '***'
53
+ # Credentials for getting information about services in the PROD DC
54
+ prd:
55
+ dc: '{{consul.agent.prd.dc}}'
56
+ host: '{{consul.agent.prd.host}}'
57
+ port: 443
58
+ secure: true
59
+ # Token for obtaining information about PROD services
60
+ token: '***'
61
+ # Credentials for registering the service with Consul
62
+ reg:
63
+ # The host of the consul agent where the service will be registered. If not specified, the server on which the service is running is used
64
+ host: null
65
+ port: 8500
66
+ secure: false
67
+ # Token for registering the service in the consul agent
68
+ token: '***'
69
+ service:
70
+ enable: {{consul.service.enable}} # true - Allows registration of the service with the consul
71
+ name: <name> # <name> will be replaced by <package.json>.name at initialization
72
+ instance: '{{SERVICE_INSTANCE}}' # This value will be specified as a suffix in the id of the service
73
+ version: <version> # <version> will be replaced by <package.json>.version at initialization
74
+ description: <description> # <description> will be replaced by <package.json>.description at initialization
75
+ tags: [] # If null or empty array - Will be pulled up from package.keywords at initialization
76
+ meta:
77
+ # "Home" page link template
78
+ who: 'http://{address}:{port}/'
79
+ envCode: # Used to generate the service ID
80
+ prod: {{consul.envCode.prod}} # Production environment code
81
+ dev: {{consul.envCode.dev}} # Development environment code
143
82
 
144
83
  db:
145
- postgres:
146
- dbs:
147
- main:
148
- label: 'My Database'
149
- host: '' # To exclude the use of the database, you need to set host = ''
150
- port: 5432
151
- database: <database>
152
- user: <user>
153
- password: <password>
154
- usedExtensions: []
84
+ postgres:
85
+ dbs:
86
+ main:
87
+ label: 'My Database'
88
+ host: '' # Empty = DB disabled
89
+ port: 5432
90
+ database: <database>
91
+ user: <user>
92
+ password: <password>
155
93
 
156
94
  logger:
157
- level: info
158
- useFileLogger: {{logger.useFileLogger}} # To use or not to use logging to a file
159
- # Absolute path to the folder where logs will be written. Default <proj_root>/../logs
160
- dir: '{{logger.dir}}'
95
+ level: info
96
+ useFileLogger: {{logger.useFileLogger}}
97
+ dir: '{{logger.dir}}'
161
98
 
162
99
  mcp:
163
- transportType: http # stdio | http
164
- # Response format configuration.
165
- # - structuredContent - default - the response in result.structuredContent returns JSON
166
- # - text - in the response, serialized JSON is returned in result.content[0].text
167
- toolAnswerAs: text # text | structuredContent
168
- rateLimit:
169
- maxRequests: 100
170
- windowMs: 60000 # 1 minute
100
+ transportType: http # stdio | http
101
+ toolAnswerAs: text # text | structuredContent
102
+ rateLimit:
103
+ maxRequests: 100
104
+ windowMs: 60000
171
105
 
172
106
  swagger:
173
- servers: # An array of servers that will be added to swagger docs
174
- # - url: http://localhost:9020
175
- # description: "Development server (localhost)"
176
- # - url: http://0.0.0.0:9020
177
- # description: "Development server (all interfaces)"
178
- # - url: http://<prod_server_host_or_ip>:{{port}}
179
- # description: "PROD server"
180
- - url: https://{{mcp.domain}}
181
- description: "PROD server"
107
+ servers:
108
+ - url: https://{{mcp.domain}}
109
+ description: "PROD server"
182
110
 
183
111
  uiColor:
184
- # Font color of the header and a number of interface elements on the HOME page
185
- primary: '#0f65dc'
112
+ # Font color of the header and a number of interface elements on the HOME page
113
+ primary: '#0f65dc'
186
114
 
187
115
  webServer:
188
- host: '0.0.0.0'
189
- port: {{port}}
190
- # array of hosts that CORS skips
191
- originHosts: ['localhost', '0.0.0.0']
192
- # Authentication is configured here only when accessing the MCP server
193
- # Authentication in services that enable tools, resources, and prompts
194
- # is implemented more deeply. To do this, you need to use the information passed in HTTP headers
195
- # You can also use a custom authorization function
196
- auth:
197
- enabled: false # Enables/disables authorization
198
- # ========================================================================
199
- # PERMANENT SERVER TOKENS
200
- # Static tokens for server-to-server communication
201
- # CPU cost: O(1) - fastest authentication method
202
- #
203
- # To enable this authentication, you need to set auth.enabled = true
204
- # and set one token of at least 20 characters in length
205
- # ========================================================================
206
- permanentServerTokens: [ ] # Add your server tokens here: ['token1', 'token2']
207
-
208
- # ========================================================================
209
- # JWT TOKEN WITH SYMMETRIC ENCRYPTION
210
- # Custom JWT tokens with AES-256 encryption
211
- # CPU cost: Medium - decryption + JSON parsing
212
- #
213
- # To enable this authentication, you need to set auth.enabled = true and set
214
- # encryptKey to at least 20 characters
215
- # ========================================================================
216
- jwtToken:
217
- # Symmetric encryption key to generate a token for this MCP (minimum 8 chars)
218
- encryptKey: '***'
219
- # If webServer.auth.enabled and the parameter true, the service name and the service specified in the token will be checked
220
- checkMCPName: true
221
-
222
- # ========================================================================
223
- # Basic Authentication - Base64 encoded username:password
224
- # CPU cost: Medium - Base64 decoding + string comparison
225
- # To enable this authentication, you need to set auth.enabled = true
226
- # and set username and password to valid values
227
- # ========================================================================
228
- basic:
229
- username: ''
230
- password: '***'
231
- ```
232
-
233
- **`config/local.yaml`** - local overrides. Usually contains secrets.
234
-
235
- ---
236
-
237
- ## Cache Management
238
-
239
- ### `getCache(options?): CacheManager`
116
+ host: '0.0.0.0'
117
+ port: {{port}}
118
+ # array of hosts that CORS skips
119
+ originHosts: ['localhost', '0.0.0.0']
120
+ # Authentication is configured here only when accessing the MCP server
121
+ # Authentication in services that enable tools, resources, and prompts
122
+ # is implemented more deeply. To do this, you need to use the information passed in HTTP headers
123
+ # You can also use a custom authorization function
124
+ auth:
125
+ enabled: false # Enables/disables authorization
126
+ # ========================================================================
127
+ # PERMANENT SERVER TOKENS
128
+ # Static tokens for server-to-server communication
129
+ # CPU cost: O(1) - fastest authentication method
130
+ #
131
+ # To enable this authentication, you need to set auth.enabled = true
132
+ # and set one token of at least 20 characters in length
133
+ # ========================================================================
134
+ permanentServerTokens: [ ] # Add your server tokens here: ['token1', 'token2']
135
+
136
+ # ========================================================================
137
+ # JWT TOKEN WITH SYMMETRIC ENCRYPTION
138
+ # Custom JWT tokens with AES-256 encryption
139
+ # CPU cost: Medium - decryption + JSON parsing
140
+ #
141
+ # To enable this authentication, you need to set auth.enabled = true and set
142
+ # encryptKey to at least 20 characters
143
+ # ========================================================================
144
+ jwtToken:
145
+ # Symmetric encryption key to generate a token for this MCP (minimum 8 chars)
146
+ encryptKey: '***'
147
+ # If webServer.auth.enabled and the parameter true, the service name and the service specified in the token will be checked
148
+ checkMCPName: true
149
+
150
+ # ========================================================================
151
+ # Basic Authentication - Base64 encoded username:password
152
+ # CPU cost: Medium - Base64 decoding + string comparison
153
+ # To enable this authentication, you need to set auth.enabled = true
154
+ # and set username and password to valid values
155
+ # ========================================================================
156
+ basic:
157
+ username: ''
158
+ password: '***'
240
159
 
241
- Get or create a global cache instance for your MCP server.
242
-
243
- ```typescript
244
- import { getCache, CacheManager } from 'fa-mcp-sdk';
245
-
246
- // Create default cache instance
247
- const cache = getCache();
248
-
249
- // Create cache with custom options
250
- const customCache = getCache({
251
- ttlSeconds: 600, // Default TTL: 10 minutes
252
- maxItems: 5000, // Max cached items
253
- checkPeriod: 300, // Cleanup interval in seconds
254
- verbose: true // Enable debug logging
255
- });
256
160
  ```
257
161
 
258
- ### Cache Methods
259
-
260
- The `CacheManager` provides the following methods:
261
-
262
- | Method | Description | Example |
263
- |--------|-------------|---------|
264
- | `get<T>(key)` | Get value from cache | `const user = cache.get<User>('user:123');` |
265
- | `set<T>(key, value, ttl?)` | Set value in cache | `cache.set('user:123', userData, 300);` |
266
- | `has(key)` | Check if key exists | `if (cache.has('user:123')) { ... }` |
267
- | `del(key)` | Delete key from cache | `cache.del('user:123');` |
268
- | `take<T>(key)` | Get and delete (single use) | `const otp = cache.take<string>('otp:123');` |
269
- | `mget<T>(keys[])` | Get multiple values | `const users = cache.mget(['user:1', 'user:2']);` |
270
- | `mset(items[])` | Set multiple values | `cache.mset([{key: 'a', val: 1}, {key: 'b', val: 2}]);` |
271
- | `getOrSet<T>(key, factory, ttl?)` | Get or compute value | `const data = await cache.getOrSet('key', () => fetchData());` |
272
- | `keys()` | List all keys | `const allKeys = cache.keys();` |
273
- | `flush()` | Clear all entries | `cache.flush();` |
274
- | `ttl(key, seconds)` | Update key TTL | `cache.ttl('user:123', 600);` |
275
- | `getTtl(key)` | Get remaining TTL | `const remaining = cache.getTtl('user:123');` |
276
- | `getStats()` | Get cache statistics | `const stats = cache.getStats();` |
277
- | `close()` | Close cache resources | `cache.close();` |
278
-
279
- ### Usage Examples
162
+ ## Cache
280
163
 
281
164
  ```typescript
282
165
  import { getCache } from 'fa-mcp-sdk';
283
166
 
284
- const cache = getCache();
285
-
286
- // Basic caching
287
- cache.set('user:123', { name: 'John', email: 'john@example.com' });
288
- const user = cache.get<User>('user:123');
289
-
290
- // Cache with TTL (time to live)
291
- cache.set('session:abc', sessionData, 1800); // 30 minutes
292
-
293
- // Single-use values (OTP, tokens)
294
- cache.set('otp:user123', '123456', 300);
295
- const otp = cache.take('otp:user123'); // Gets and deletes
167
+ const cache = getCache(); // Default options
168
+ const cache = getCache({ ttlSeconds: 600, maxItems: 5000 });
169
+
170
+ // Methods
171
+ cache.set('key', value, ttlSeconds?);
172
+ cache.get<T>('key');
173
+ cache.has('key');
174
+ cache.del('key');
175
+ cache.take<T>('key'); // Get and delete
176
+ cache.mget<T>(['k1', 'k2']);
177
+ cache.mset([{ key: 'a', val: 1 }, { key: 'b', val: 2, ttl: 600 }]);
178
+ cache.keys();
179
+ cache.flush();
180
+ cache.ttl('key', seconds); // Update TTL
181
+ cache.getTtl('key');
182
+ cache.getStats(); // { hitRate, keys, vsize }
183
+ cache.close();
296
184
 
297
185
  // Get-or-set pattern
298
- const expensiveData = await cache.getOrSet(
299
- 'computation:key',
300
- async () => {
301
- // This function runs only on cache miss
302
- return await performExpensiveOperation();
303
- },
304
- 3600 // Cache for 1 hour
305
- );
306
-
307
- // Batch operations
308
- const userData = cache.mget(['user:1', 'user:2', 'user:3']);
309
- cache.mset([
310
- { key: 'user:1', val: user1Data },
311
- { key: 'user:2', val: user2Data, ttl: 600 }
312
- ]);
313
-
314
- // Cache monitoring
315
- const stats = cache.getStats();
316
- console.log(`Hit rate: ${(stats.hitRate * 100).toFixed(1)}%`);
317
- console.log(`Keys: ${stats.keys}, Memory: ${stats.vsize} bytes`);
186
+ const data = await cache.getOrSet('key', async () => await fetchData(), 3600);
318
187
  ```
319
188
 
320
- ---
321
-
322
189
  ## Database Integration
323
190
 
324
191
  To disable the use of the database, you need to set appConfig.db.postgres.dbs.main.host to an empty value.
@@ -328,12 +195,7 @@ In this case, when the configuration is formed, appConfig.isMainDBUsed is set to
328
195
  If you enable database support (`isMainDBUsed: true` in config):
329
196
 
330
197
  ```typescript
331
- import {
332
- queryMAIN,
333
- execMAIN,
334
- oneRowMAIN,
335
- getMainDBConnectionStatus
336
- } from 'fa-mcp-sdk';
198
+ import { queryMAIN, execMAIN, oneRowMAIN, queryRsMAIN, checkMainDB } from 'fa-mcp-sdk';
337
199
 
338
200
  // Check database connection. If there is no connection, the application stops
339
201
  await checkMainDB();