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.
- package/cli-template/FA-MCP-SDK-DOC/00-FA-MCP-SDK-index.md +45 -161
- package/cli-template/FA-MCP-SDK-DOC/01-getting-started.md +71 -226
- package/cli-template/FA-MCP-SDK-DOC/02-1-tools-and-api.md +80 -360
- package/cli-template/FA-MCP-SDK-DOC/02-2-prompts-and-resources.md +191 -342
- package/cli-template/FA-MCP-SDK-DOC/03-configuration.md +141 -279
- package/cli-template/FA-MCP-SDK-DOC/04-authentication.md +73 -522
- package/cli-template/FA-MCP-SDK-DOC/05-ad-authorization.md +68 -419
- package/cli-template/FA-MCP-SDK-DOC/06-utilities.md +64 -447
- package/cli-template/FA-MCP-SDK-DOC/07-testing-and-operations.md +39 -196
- package/cli-template/package.json +2 -1
- package/config/local.yaml +1 -1
- package/dist/core/_types_/types.d.ts +36 -10
- package/dist/core/_types_/types.d.ts.map +1 -1
- package/dist/core/auth/admin-auth.js +1 -1
- package/dist/core/auth/admin-auth.js.map +1 -1
- package/dist/core/auth/middleware.js +8 -8
- package/dist/core/auth/middleware.js.map +1 -1
- package/dist/core/auth/multi-auth.d.ts.map +1 -1
- package/dist/core/auth/multi-auth.js +15 -14
- package/dist/core/auth/multi-auth.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/mcp/create-mcp-server.js +8 -9
- package/dist/core/mcp/create-mcp-server.js.map +1 -1
- package/dist/core/mcp/prompts.d.ts +10 -5
- package/dist/core/mcp/prompts.d.ts.map +1 -1
- package/dist/core/mcp/prompts.js +17 -15
- package/dist/core/mcp/prompts.js.map +1 -1
- package/dist/core/mcp/resources.d.ts +4 -4
- package/dist/core/mcp/resources.d.ts.map +1 -1
- package/dist/core/mcp/resources.js +21 -20
- package/dist/core/mcp/resources.js.map +1 -1
- package/dist/core/utils/utils.d.ts +2 -1
- package/dist/core/utils/utils.d.ts.map +1 -1
- package/dist/core/utils/utils.js +2 -2
- package/dist/core/utils/utils.js.map +1 -1
- package/dist/core/web/home-api.d.ts.map +1 -1
- package/dist/core/web/home-api.js +4 -3
- package/dist/core/web/home-api.js.map +1 -1
- package/dist/core/web/server-http.d.ts.map +1 -1
- package/dist/core/web/server-http.js +36 -21
- package/dist/core/web/server-http.js.map +1 -1
- package/package.json +1 -1
- package/scripts/update-doc.js +21 -0
- package/src/template/start.ts +1 -1
|
@@ -1,342 +1,191 @@
|
|
|
1
|
-
# Prompts and Resources
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
```typescript
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
-
|
|
190
|
-
|
|
191
|
-
|
|
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.)
|