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,342 +1,191 @@
1
- # Prompts and Resources
2
-
3
- This document describes MCP prompts and resources provided by FA-MCP-SDK.
4
-
5
- ## Prompts
6
-
7
- Prompts are text instructions that LLM receives when working with your MCP server.
8
- The SDK provides two standard prompts that must be configured for each new MCP server.
9
-
10
- ### Standard Prompts
11
-
12
- #### Agent Brief (`src/prompts/agent-brief.ts`)
13
-
14
- **Level 1: Brief agent description**
15
-
16
- This is a short description shown when LLM selects an agent from a list based on
17
- user query. At this level, LLM doesn't see the list of tools — only the brief description.
18
-
19
- ```typescript
20
- /**
21
- * Level 1: Brief agent description
22
- * Used when LLM selects agents from a list based on user query
23
- * LLM doesn't see tools at this level
24
- */
25
-
26
- export const AGENT_BRIEF = 'Your short agent description here';
27
- ```
28
-
29
- **Example:**
30
- ```typescript
31
- export const AGENT_BRIEF = 'Database management agent for PostgreSQL operations';
32
- ```
33
-
34
- #### Agent Prompt (`src/prompts/agent-prompt.ts`)
35
-
36
- **Level 2: Full agent description**
37
-
38
- This prompt becomes visible to the LLM after the agent router has selected this
39
- agent from among others based on their short descriptions. At this point, the
40
- LLM gains access to the full list of tools and this detailed prompt, which may
41
- include instructions on how to call those tools.
42
-
43
- In simple scenarios, this prompt can be very short or even empty if the tool descriptions alone are sufficient.
44
-
45
- ```typescript
46
- /**
47
- * Level 2: Agent description
48
- * This prompt becomes visible to the LLM after the agent router has selected
49
- * this agent from among others based on their short descriptions.
50
- * At that point, the LLM gains access to the full list of tools and this
51
- * detailed prompt, which may include instructions on how to call those tools.
52
- * In simple scenarios, this prompt can be very short or even empty if the
53
- * tool descriptions alone are sufficient.
54
- */
55
-
56
- export const AGENT_PROMPT = `Your detailed agent instructions here.
57
-
58
- Available tools:
59
- - tool1: description
60
- - tool2: description
61
-
62
- Usage guidelines:
63
- ...
64
- `;
65
- ```
66
-
67
- **Example:**
68
- ```typescript
69
- export const AGENT_PROMPT = `You are a database management assistant for PostgreSQL.
70
-
71
- Guidelines:
72
- - Always check table existence before operations
73
- - Use transactions for multi-step operations
74
- - Return results in JSON format
75
-
76
- Available tools will help you:
77
- - Query data from tables
78
- - Execute DDL/DML statements
79
- - Manage database schema
80
- `;
81
- ```
82
-
83
- ### Custom Prompts
84
-
85
- You can add additional prompts in `src/prompts/custom-prompts.ts`. These prompts
86
- are exposed via the MCP `prompts/list` and `prompts/get` endpoints.
87
-
88
- #### Interface
89
-
90
- ```typescript
91
- interface IPromptData {
92
- name: string; // Prompt identifier
93
- description: string; // Description shown in prompts list
94
- arguments: []; // Prompt arguments (currently empty array)
95
- content: IPromptContent;// Static string or function returning content
96
- requireAuth?: boolean; // If true, prompt requires authentication
97
- }
98
-
99
- type TPromptContentFunction = (request: IGetPromptRequest) => string | Promise<string>;
100
- type IPromptContent = string | TPromptContentFunction;
101
-
102
- interface IGetPromptRequest {
103
- id?: string | number;
104
- method: 'prompts/get' | 'prompts/content';
105
- params: {
106
- name: string;
107
- arguments?: Record<string, string>;
108
- };
109
- }
110
- ```
111
-
112
- #### Example
113
-
114
- ```typescript
115
- import { IPromptData, IGetPromptRequest } from '../../core/index.js';
116
-
117
- export const customPrompts: IPromptData[] = [
118
- // Simple static prompt
119
- {
120
- name: 'greeting',
121
- description: 'Standard greeting message',
122
- arguments: [],
123
- content: 'Hello! How can I help you today?',
124
- },
125
-
126
- // Dynamic prompt with function
127
- {
128
- name: 'context_prompt',
129
- description: 'Context-aware prompt',
130
- arguments: [],
131
- content: (request: IGetPromptRequest) => {
132
- const args = request.params.arguments || {};
133
- return `Processing request with context: ${JSON.stringify(args)}`;
134
- },
135
- },
136
-
137
- // Protected prompt requiring authentication
138
- {
139
- name: 'admin_instructions',
140
- description: 'Administrative instructions',
141
- arguments: [],
142
- content: 'Admin-only instructions for system management...',
143
- requireAuth: true, // Requires valid authentication
144
- },
145
- ];
146
- ```
147
-
148
- #### Connecting Custom Prompts
149
-
150
- Pass custom prompts to `initMcpServer()` via `McpServerData`:
151
-
152
- ```typescript
153
- import { initMcpServer, McpServerData } from 'fa-mcp-sdk';
154
- import { customPrompts } from './prompts/custom-prompts.js';
155
-
156
- const serverData: McpServerData = {
157
- tools,
158
- toolHandler: handleToolCall,
159
- agentBrief: AGENT_BRIEF,
160
- agentPrompt: AGENT_PROMPT,
161
- customPrompts, // Add custom prompts here
162
- };
163
-
164
- await initMcpServer(serverData);
165
- ```
166
-
167
- ---
168
-
169
- ## Resources
170
-
171
- Resources are data exposed via MCP `resources/list` and `resources/read` endpoints.
172
- The SDK provides standard resources and supports custom resources.
173
-
174
- ### Standard Resources
175
-
176
- The SDK automatically provides the following resources:
177
-
178
- | URI | Name | Description |
179
- |---------------------------|------|-------------|
180
- | `project://id` | project-id | Stable project identifier. Used for MCP server identification in registries and JWT authorization |
181
- | `project://name` | product-name | Human-readable product name for UI display |
182
- | `doc://readme` | README.md | Project documentation from README.md file. Used by RAG systems in MCP registries for search |
183
- | `required://http-headers` | Required http headers | List of required HTTP headers (if configured via `requiredHttpHeaders`) |
184
-
185
- **Resource content sources:**
186
- - `project://id` → `appConfig.name` from configuration
187
- - `project://name` `appConfig.productName` from configuration
188
- - `doc://readme` → `README.md` file from project root
189
- - `required://http-headers` `requiredHttpHeaders` array from `McpServerData`
190
-
191
- ### Custom Resources
192
-
193
- Add custom resources in `src/custom-resources.ts`.
194
-
195
- #### Interface
196
-
197
- ```typescript
198
- interface IResourceInfo {
199
- uri: string; // Resource URI (e.g., 'custom://my-resource')
200
- name: string; // Resource name
201
- title?: string; // Optional title
202
- description: string; // Description shown in resources list
203
- mimeType: string; // MIME type (e.g., 'text/plain', 'application/json')
204
- requireAuth?: boolean; // If true, resource requires authentication
205
- }
206
-
207
- interface IResourceData extends IResourceInfo {
208
- content: IResourceContent;
209
- }
210
-
211
- type TResourceContentFunction = (uri: string) => string | Promise<string>;
212
- type IResourceContent = string | object | TResourceContentFunction;
213
- ```
214
-
215
- #### Example
216
-
217
- ```typescript
218
- import { IResourceData } from '../core/index.js';
219
-
220
- export const customResources: IResourceData[] = [
221
- // Simple static resource
222
- {
223
- uri: 'custom://config-info',
224
- name: 'Configuration Info',
225
- description: 'Server configuration summary',
226
- mimeType: 'text/plain',
227
- content: 'Server version: 1.0.0\nEnvironment: production',
228
- },
229
-
230
- // JSON resource
231
- {
232
- uri: 'custom://api-schema',
233
- name: 'API Schema',
234
- description: 'API schema definition',
235
- mimeType: 'application/json',
236
- content: {
237
- version: '1.0',
238
- endpoints: ['/api/users', '/api/orders'],
239
- },
240
- },
241
-
242
- // Dynamic resource with async function
243
- {
244
- uri: 'custom://status',
245
- name: 'Server Status',
246
- description: 'Current server status',
247
- mimeType: 'application/json',
248
- content: async (uri: string) => {
249
- const status = await getServerStatus();
250
- return JSON.stringify(status);
251
- },
252
- },
253
-
254
- // Protected resource requiring authentication
255
- {
256
- uri: 'custom://secrets',
257
- name: 'Secret Configuration',
258
- description: 'Protected configuration data',
259
- mimeType: 'application/json',
260
- content: { apiKeys: ['...'], credentials: {...} },
261
- requireAuth: true, // Requires valid authentication
262
- },
263
- ];
264
- ```
265
-
266
- #### Connecting Custom Resources
267
-
268
- Pass custom resources to `initMcpServer()` via `McpServerData`:
269
-
270
- ```typescript
271
- import { initMcpServer, McpServerData } from 'fa-mcp-sdk';
272
- import { customResources } from './custom-resources.js';
273
-
274
- const serverData: McpServerData = {
275
- tools,
276
- toolHandler: handleToolCall,
277
- agentBrief: AGENT_BRIEF,
278
- agentPrompt: AGENT_PROMPT,
279
- customResources, // Add custom resources here
280
- };
281
-
282
- await initMcpServer(serverData);
283
- ```
284
-
285
- ### Required HTTP Headers
286
-
287
- You can define required HTTP headers that clients must send when making requests:
288
-
289
- ```typescript
290
- interface IRequiredHttpHeader {
291
- name: string; // Header name (e.g., "Authorization")
292
- description: string; // Description (e.g., "JWT Token issued on request")
293
- isOptional?: boolean; // If true, header is optional
294
- }
295
- ```
296
-
297
- **Example:**
298
- ```typescript
299
- const serverData: McpServerData = {
300
- tools,
301
- toolHandler: handleToolCall,
302
- agentBrief: AGENT_BRIEF,
303
- agentPrompt: AGENT_PROMPT,
304
- requiredHttpHeaders: [
305
- {
306
- name: 'Authorization',
307
- description: 'JWT token in Bearer format',
308
- },
309
- {
310
- name: 'X-Request-ID',
311
- description: 'Optional request tracking ID',
312
- isOptional: true,
313
- },
314
- ],
315
- };
316
- ```
317
-
318
- When `requiredHttpHeaders` is configured, the resource `required://http-headers` becomes available with this information.
319
-
320
- ---
321
-
322
- ## Access Control with requireAuth
323
-
324
- Both prompts and resources support the `requireAuth` property for access control:
325
-
326
- ```typescript
327
- {
328
- // ... other properties
329
- requireAuth: true, // Requires valid authentication
330
- }
331
- ```
332
-
333
- When `requireAuth: true`:
334
- - The prompt/resource is only accessible to authenticated users
335
- - Unauthenticated requests receive an error
336
- - Works with any authentication method configured in your server (JWT, Basic, NTLM, etc.)
337
-
338
- **Use cases:**
339
- - Sensitive configuration data
340
- - Admin-only instructions
341
- - Internal documentation
342
- - API keys and credentials
1
+ # Prompts and Resources
2
+
3
+ ## Prompts
4
+
5
+ ### Standard Prompts
6
+
7
+ #### Agent Brief (`src/prompts/agent-brief.ts`)
8
+
9
+ **Level 1**: Short description for agent selection. LLM doesn't see tools at this level.
10
+
11
+ ```typescript
12
+ export const AGENT_BRIEF = 'Database management agent for PostgreSQL operations';
13
+ ```
14
+
15
+ #### Agent Prompt (`src/prompts/agent-prompt.ts`)
16
+
17
+ **Level 2**: Full instructions shown after agent selection. LLM sees tools list.
18
+
19
+ ```typescript
20
+ export const AGENT_PROMPT = `You are a database management assistant.
21
+ - Check table existence before operations
22
+ - Use transactions for multi-step operations
23
+ - Return results in JSON format`;
24
+ ```
25
+
26
+ ### Custom Prompts
27
+
28
+ Add in `src/prompts/custom-prompts.ts`:
29
+
30
+ ```typescript
31
+ import { IPromptData, IGetPromptRequest } from 'fa-mcp-sdk';
32
+
33
+ export const customPrompts: IPromptData[] = [
34
+ { name: 'greeting', description: 'Greeting message', arguments: [],
35
+ content: 'Hello! How can I help?' },
36
+
37
+ { name: 'context_prompt', description: 'Context-aware', arguments: [],
38
+ content: (req: IGetPromptRequest) => `Context: ${JSON.stringify(req.params.arguments)}` },
39
+
40
+ { name: 'admin_only', description: 'Admin instructions', arguments: [],
41
+ content: 'Admin-only content', requireAuth: true },
42
+ ];
43
+ ```
44
+
45
+ Pass to server:
46
+ ```typescript
47
+ const serverData: McpServerData = { ..., customPrompts };
48
+ ```
49
+
50
+ ### Dynamic Prompts (Function)
51
+
52
+ For dynamic prompt lists based on transport type, headers, or user:
53
+
54
+ ```typescript
55
+ import { IPromptData, IGetPromptsArgs } from 'fa-mcp-sdk';
56
+
57
+ export const customPrompts = async (args: IGetPromptsArgs): Promise<IPromptData[]> => {
58
+ const { transport, headers, payload } = args;
59
+
60
+ const prompts: IPromptData[] = [
61
+ { name: 'greeting', description: 'Greeting message', arguments: [],
62
+ content: 'Hello! How can I help?' },
63
+ ];
64
+
65
+ // Add user-specific prompts
66
+ if (payload?.user) {
67
+ prompts.push({
68
+ name: 'user_context',
69
+ description: `Context for ${payload.user}`,
70
+ arguments: [],
71
+ content: `You are assisting user: ${payload.user}`,
72
+ });
73
+ }
74
+
75
+ // Add transport-specific prompts
76
+ if (transport === 'http') {
77
+ prompts.push({
78
+ name: 'http_mode',
79
+ description: 'HTTP-specific instructions',
80
+ arguments: [],
81
+ content: 'Respond in JSON format for HTTP clients',
82
+ });
83
+ }
84
+
85
+ return prompts;
86
+ };
87
+ ```
88
+
89
+ `IGetPromptsArgs` includes:
90
+ - `transport`: `'stdio' | 'sse' | 'http'`
91
+ - `headers`: HTTP headers (only for HTTP/SSE transport)
92
+ - `payload`: Auth payload with user info (if authenticated)
93
+
94
+ ## Resources
95
+
96
+ ### Standard Resources
97
+
98
+ | URI | Description |
99
+ |-----|-------------|
100
+ | `project://id` | Service identifier (`appConfig.name`) |
101
+ | `project://name` | Display name (`appConfig.productName`) |
102
+ | `doc://readme` | README.md content |
103
+ | `use://http-headers` | Required HTTP headers (from `usedHttpHeaders`) |
104
+
105
+ ### Custom Resources
106
+
107
+ Add in `src/custom-resources.ts`:
108
+
109
+ ```typescript
110
+ import { IResourceData } from 'fa-mcp-sdk';
111
+
112
+ export const customResources: IResourceData[] = [
113
+ { uri: 'custom://config', name: 'Config', description: 'Server config',
114
+ mimeType: 'text/plain', content: 'Version: 1.0.0' },
115
+
116
+ { uri: 'custom://schema', name: 'API Schema', description: 'API schema',
117
+ mimeType: 'application/json',
118
+ content: { version: '1.0', endpoints: ['/api/users'] } },
119
+
120
+ { uri: 'custom://status', name: 'Status', description: 'Live status',
121
+ mimeType: 'application/json',
122
+ content: async (uri) => JSON.stringify(await getStatus()) },
123
+
124
+ { uri: 'custom://secrets', name: 'Secrets', description: 'Protected',
125
+ mimeType: 'application/json', content: {}, requireAuth: true },
126
+ ];
127
+ ```
128
+
129
+ Pass to server:
130
+ ```typescript
131
+ const serverData: McpServerData = { ..., customResources };
132
+ ```
133
+
134
+ ### Dynamic Resources (Function)
135
+
136
+ For dynamic resource lists based on transport type, headers, or user:
137
+
138
+ ```typescript
139
+ import { IResourceData, IGetResourcesArgs } from 'fa-mcp-sdk';
140
+
141
+ export const customResources = async (args: IGetResourcesArgs): Promise<IResourceData[]> => {
142
+ const { transport, headers, payload } = args;
143
+
144
+ const resources: IResourceData[] = [
145
+ { uri: 'custom://config', name: 'Config', description: 'Server config',
146
+ mimeType: 'text/plain', content: 'Version: 1.0.0' },
147
+ ];
148
+
149
+ // Add user-specific resources
150
+ if (payload?.user) {
151
+ resources.push({
152
+ uri: `user://${payload.user}/preferences`,
153
+ name: 'User Preferences',
154
+ description: `Preferences for ${payload.user}`,
155
+ mimeType: 'application/json',
156
+ content: await getUserPreferences(payload.user),
157
+ });
158
+ }
159
+
160
+ return resources;
161
+ };
162
+ ```
163
+
164
+ `IGetResourcesArgs` includes:
165
+ - `transport`: `'stdio' | 'sse' | 'http'`
166
+ - `headers`: HTTP headers (only for HTTP/SSE transport)
167
+ - `payload`: Auth payload with user info (if authenticated)
168
+
169
+ ### Used HTTP Headers
170
+
171
+ Define required client headers:
172
+
173
+ ```typescript
174
+ const serverData: McpServerData = {
175
+ ...,
176
+ usedHttpHeaders: [
177
+ { name: 'Authorization', description: 'JWT token in Bearer format' },
178
+ { name: 'X-Request-ID', description: 'Request tracking ID', isOptional: true },
179
+ ],
180
+ };
181
+ ```
182
+
183
+ Exposed via `use://http-headers` resource.
184
+
185
+ ## requireAuth
186
+
187
+ Both prompts and resources support `requireAuth: true`:
188
+
189
+ - Requires valid authentication to access
190
+ - Unauthenticated requests get error
191
+ - Works with any configured auth method (JWT, Basic, etc.)