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,50 +1,6 @@
|
|
|
1
1
|
# FA-MCP-SDK Documentation Index
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
The FA-MCP-SDK is a comprehensive TypeScript framework for building Model Context
|
|
6
|
-
Protocol (MCP) servers. This is the documentation index - read the relevant
|
|
7
|
-
sections based on your task.
|
|
8
|
-
|
|
9
|
-
## Using with Claude Code
|
|
10
|
-
|
|
11
|
-
This project includes a specialized agent `.claude/agents/fa-mcp-sdk.md` for
|
|
12
|
-
Claude Code. The agent automatically reads relevant documentation sections and
|
|
13
|
-
follows SDK patterns.
|
|
14
|
-
|
|
15
|
-
### Example Prompts
|
|
16
|
-
|
|
17
|
-
**Creating tools:**
|
|
18
|
-
```
|
|
19
|
-
Use the fa-mcp-sdk subagent to add a tool "get_user" that fetches user data by ID from the database
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
**Adding REST API:**
|
|
23
|
-
```
|
|
24
|
-
Use the fa-mcp-sdk subagent to create REST endpoint POST /api/users for user registration with validation
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**Setting up authentication:**
|
|
28
|
-
```
|
|
29
|
-
Use the fa-mcp-sdk subagent to configure JWT authentication with 1 hour token expiration
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
**Database integration:**
|
|
33
|
-
```
|
|
34
|
-
Use the fa-mcp-sdk subagent to add PostgreSQL integration and create a tool to query orders table
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**Complex tasks:**
|
|
38
|
-
```
|
|
39
|
-
Use the fa-mcp-sdk subagent to create an MCP server for managing TODO lists with:
|
|
40
|
-
- tools: add_todo, list_todos, complete_todo, delete_todo
|
|
41
|
-
- PostgreSQL storage
|
|
42
|
-
- JWT authentication
|
|
43
|
-
- REST API for web client
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
The agent will read the appropriate documentation files and implement the
|
|
47
|
-
functionality following SDK conventions.
|
|
3
|
+
TypeScript framework for building MCP servers.
|
|
48
4
|
|
|
49
5
|
## Quick Start
|
|
50
6
|
|
|
@@ -54,104 +10,43 @@ npm install fa-mcp-sdk
|
|
|
54
10
|
|
|
55
11
|
## Documentation Structure
|
|
56
12
|
|
|
57
|
-
| File
|
|
58
|
-
|
|
59
|
-
| [01-getting-started
|
|
60
|
-
| [02-1-tools-and-api
|
|
61
|
-
| [02-2-prompts-and-resources
|
|
62
|
-
| [03-configuration
|
|
63
|
-
| [04-authentication
|
|
64
|
-
| [05-ad-authorization
|
|
65
|
-
| [06-utilities
|
|
66
|
-
| [07-testing-and-operations
|
|
67
|
-
|
|
68
|
-
## Common Tasks Quick Reference
|
|
69
|
-
|
|
70
|
-
### Create a new MCP server
|
|
71
|
-
Read: `01-getting-started.md` → `02-1-tools-and-api.md`
|
|
72
|
-
|
|
73
|
-
### Add MCP tools
|
|
74
|
-
Read: `02-1-tools-and-api.md` (Tool Development section)
|
|
75
|
-
|
|
76
|
-
### Add REST API endpoints
|
|
77
|
-
Read: `02-1-tools-and-api.md` (REST API Endpoints section)
|
|
78
|
-
- Use tsoa decorators (`@Route`, `@Get`, `@Post`, `@Tags`)
|
|
79
|
-
- Swagger generates automatically if `swagger/openapi.yaml` doesn't exist
|
|
80
|
-
|
|
81
|
-
### Configure prompts
|
|
82
|
-
Read: `02-2-prompts-and-resources.md`
|
|
83
|
-
- Standard: `agent-brief.ts` (short description), `agent-prompt.ts` (full instructions)
|
|
84
|
-
- Custom: add to `customPrompts` array in `src/prompts/custom-prompts.ts`
|
|
85
|
-
- Use `requireAuth: true` to protect prompts
|
|
86
|
-
|
|
87
|
-
### Configure resources
|
|
88
|
-
Read: `02-2-prompts-and-resources.md`
|
|
89
|
-
- Standard: `project://id`, `project://name`, `doc://readme`, `required://http-headers`
|
|
90
|
-
- Custom: add to `customResources` array in `src/custom-resources.ts`
|
|
91
|
-
- Use `requireAuth: true` to protect resources
|
|
92
|
-
|
|
93
|
-
### Configure authentication
|
|
94
|
-
Read: `04-authentication.md`
|
|
95
|
-
- Enable in `config/default.yaml` under `webServer.auth`
|
|
96
|
-
- Options: `permanentServerTokens`, `jwtToken`, `basic`, custom validator
|
|
97
|
-
|
|
98
|
-
### Add AD group authorization
|
|
99
|
-
Read: `05-ad-authorization.md`
|
|
100
|
-
- HTTP level (block at entry)
|
|
101
|
-
- Tool level (restrict all or specific tools)
|
|
102
|
-
|
|
103
|
-
### Use database
|
|
104
|
-
Read: `03-configuration.md` (Database Integration section)
|
|
105
|
-
- Set `db.postgres.dbs.main.host` in config
|
|
106
|
-
- Use `queryMAIN()`, `execMAIN()`, `oneRowMAIN()`
|
|
107
|
-
|
|
108
|
-
### Use caching
|
|
109
|
-
Read: `03-configuration.md` (Cache Management section)
|
|
110
|
-
- `getCache()` → `cache.get()`, `cache.set()`, `cache.getOrSet()`
|
|
111
|
-
|
|
112
|
-
### Write tests
|
|
113
|
-
Read: `07-testing-and-operations.md`
|
|
114
|
-
- Use `McpHttpClient`, `McpStdioClient`, `McpSseClient`
|
|
115
|
-
- Use `getAuthHeadersForTests()` for auth headers
|
|
116
|
-
|
|
117
|
-
## Key Exports from fa-mcp-sdk
|
|
13
|
+
| File | Content | Read When |
|
|
14
|
+
|------|---------|-----------|
|
|
15
|
+
| [01-getting-started](01-getting-started.md) | `initMcpServer()`, `McpServerData`, `IPromptData`, `IResourceData`, `AppConfig` | Starting new project |
|
|
16
|
+
| [02-1-tools-and-api](02-1-tools-and-api.md) | Tool definitions, `toolHandler`, REST API with tsoa, OpenAPI/Swagger | Creating tools, REST endpoints |
|
|
17
|
+
| [02-2-prompts-and-resources](02-2-prompts-and-resources.md) | Standard/custom prompts, resources, `requireAuth` | Configuring prompts/resources |
|
|
18
|
+
| [03-configuration](03-configuration.md) | `appConfig`, YAML config, cache, PostgreSQL | Server configuration, DB |
|
|
19
|
+
| [04-authentication](04-authentication.md) | JWT, Basic auth, server tokens, `createAuthMW()`, Token Generator | Authentication setup |
|
|
20
|
+
| [05-ad-authorization](05-ad-authorization.md) | AD group authorization at HTTP/tool levels | AD group restrictions |
|
|
21
|
+
| [06-utilities](06-utilities.md) | `ServerError`, `normalizeHeaders`, logging, Consul, graceful shutdown | Error handling, utilities |
|
|
22
|
+
| [07-testing-and-operations](07-testing-and-operations.md) | Test clients (STDIO, HTTP, SSE, Streamable HTTP) | Testing, deployment |
|
|
118
23
|
|
|
119
|
-
|
|
120
|
-
// Initialization
|
|
121
|
-
import { initMcpServer, McpServerData } from 'fa-mcp-sdk';
|
|
24
|
+
## Key Exports
|
|
122
25
|
|
|
123
|
-
|
|
124
|
-
|
|
26
|
+
```typescript
|
|
27
|
+
// Core
|
|
28
|
+
import { initMcpServer, McpServerData, appConfig, getProjectData, getSafeAppConfig, ROOT_PROJECT_DIR } from 'fa-mcp-sdk';
|
|
125
29
|
|
|
126
|
-
//
|
|
30
|
+
// Auth
|
|
127
31
|
import { createAuthMW, generateToken, getAuthHeadersForTests, TTokenType, generateTokenApp } from 'fa-mcp-sdk';
|
|
128
32
|
|
|
129
|
-
// Tools
|
|
130
|
-
import { formatToolResult, ToolExecutionError, getTools } from 'fa-mcp-sdk';
|
|
131
|
-
|
|
132
|
-
// Errors
|
|
133
|
-
import { ServerError, BaseMcpError, ValidationError } from 'fa-mcp-sdk';
|
|
134
|
-
|
|
135
|
-
// Database
|
|
136
|
-
import { queryMAIN, execMAIN, oneRowMAIN, checkMainDB } from 'fa-mcp-sdk';
|
|
33
|
+
// Tools & Errors
|
|
34
|
+
import { formatToolResult, ToolExecutionError, ServerError, BaseMcpError, ValidationError, getTools } from 'fa-mcp-sdk';
|
|
137
35
|
|
|
138
|
-
// Cache
|
|
139
|
-
import { getCache } from 'fa-mcp-sdk';
|
|
140
|
-
|
|
141
|
-
// Logging
|
|
142
|
-
import { logger, fileLogger } from 'fa-mcp-sdk';
|
|
36
|
+
// Database & Cache
|
|
37
|
+
import { queryMAIN, execMAIN, oneRowMAIN, checkMainDB, getCache } from 'fa-mcp-sdk';
|
|
143
38
|
|
|
144
39
|
// Utilities
|
|
145
|
-
import { trim, ppj, toError, toStr, normalizeHeaders } from 'fa-mcp-sdk';
|
|
40
|
+
import { logger, fileLogger, trim, ppj, toError, toStr, normalizeHeaders } from 'fa-mcp-sdk';
|
|
146
41
|
|
|
147
|
-
// Test
|
|
42
|
+
// Test Clients
|
|
148
43
|
import { McpHttpClient, McpStdioClient, McpSseClient, McpStreamableHttpClient } from 'fa-mcp-sdk';
|
|
149
44
|
|
|
150
45
|
// AD Groups
|
|
151
46
|
import { initADGroupChecker, IADConfig, IDcConfig } from 'fa-mcp-sdk';
|
|
152
47
|
|
|
153
|
-
// OpenAPI
|
|
154
|
-
import { configureOpenAPI,
|
|
48
|
+
// OpenAPI
|
|
49
|
+
import { configureOpenAPI, OpenAPISpecResponse, SwaggerUIConfig } from 'fa-mcp-sdk';
|
|
155
50
|
```
|
|
156
51
|
|
|
157
52
|
## Project Structure
|
|
@@ -159,33 +54,27 @@ import { configureOpenAPI, createSwaggerUIAssetsMiddleware, OpenAPISpecResponse,
|
|
|
159
54
|
```
|
|
160
55
|
my-mcp-server/
|
|
161
56
|
├── config/
|
|
162
|
-
│ ├── default.yaml
|
|
163
|
-
│ ├── development.yaml
|
|
164
|
-
│ ├── local.yaml
|
|
165
|
-
│ └── production.yaml
|
|
57
|
+
│ ├── default.yaml # Base configuration
|
|
58
|
+
│ ├── development.yaml # Dev overrides
|
|
59
|
+
│ ├── local.yaml # Local secrets (gitignored)
|
|
60
|
+
│ └── production.yaml # Prod overrides
|
|
166
61
|
├── src/
|
|
167
62
|
│ ├── _types_/
|
|
168
|
-
│ │
|
|
169
|
-
│ │ └── custom-config.ts # Custom config interface
|
|
63
|
+
│ │ └── custom-config.ts # Custom config interface
|
|
170
64
|
│ ├── api/
|
|
171
|
-
│ │ └── router.ts
|
|
172
|
-
│ ├── asset/
|
|
173
|
-
│ │ └── logo.svg # Static assets
|
|
65
|
+
│ │ └── router.ts # REST endpoints (tsoa)
|
|
174
66
|
│ ├── prompts/
|
|
175
|
-
│ │ ├── agent-brief.ts
|
|
176
|
-
│ │ ├── agent-prompt.ts
|
|
177
|
-
│ │ └── custom-prompts.ts
|
|
67
|
+
│ │ ├── agent-brief.ts # Short agent description
|
|
68
|
+
│ │ ├── agent-prompt.ts # Full agent prompt
|
|
69
|
+
│ │ └── custom-prompts.ts # Additional prompts
|
|
178
70
|
│ ├── tools/
|
|
179
|
-
│ │ ├── handle-tool-call.ts
|
|
180
|
-
│ │ └── tools.ts
|
|
181
|
-
│ ├── custom-resources.ts
|
|
182
|
-
│ └── start.ts
|
|
183
|
-
├── swagger/
|
|
184
|
-
│ └── openapi.yaml # Auto-generated (gitignored)
|
|
71
|
+
│ │ ├── handle-tool-call.ts # Tool execution
|
|
72
|
+
│ │ └── tools.ts # Tool definitions
|
|
73
|
+
│ ├── custom-resources.ts # Custom MCP resources
|
|
74
|
+
│ └── start.ts # Entry point
|
|
185
75
|
└── tests/
|
|
186
76
|
```
|
|
187
77
|
|
|
188
|
-
|
|
189
78
|
## Minimal Example
|
|
190
79
|
|
|
191
80
|
**`src/start.ts`:**
|
|
@@ -208,19 +97,15 @@ await initMcpServer(serverData);
|
|
|
208
97
|
```typescript
|
|
209
98
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
210
99
|
|
|
211
|
-
export const tools: Tool[] = [
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
name: { type: 'string', description: 'Name to greet' }
|
|
219
|
-
},
|
|
220
|
-
required: ['name']
|
|
221
|
-
}
|
|
100
|
+
export const tools: Tool[] = [{
|
|
101
|
+
name: 'hello',
|
|
102
|
+
description: 'Say hello',
|
|
103
|
+
inputSchema: {
|
|
104
|
+
type: 'object',
|
|
105
|
+
properties: { name: { type: 'string', description: 'Name to greet' } },
|
|
106
|
+
required: ['name']
|
|
222
107
|
}
|
|
223
|
-
];
|
|
108
|
+
}];
|
|
224
109
|
```
|
|
225
110
|
|
|
226
111
|
**`src/tools/handle-tool-call.ts`:**
|
|
@@ -229,7 +114,6 @@ import { formatToolResult, ToolExecutionError } from 'fa-mcp-sdk';
|
|
|
229
114
|
|
|
230
115
|
export const handleToolCall = async (params: { name: string; arguments?: any }): Promise<any> => {
|
|
231
116
|
const { name, arguments: args } = params;
|
|
232
|
-
|
|
233
117
|
switch (name) {
|
|
234
118
|
case 'hello':
|
|
235
119
|
return formatToolResult({ message: `Hello, ${args.name}!` });
|
|
@@ -1,295 +1,140 @@
|
|
|
1
|
-
# Getting Started
|
|
1
|
+
# Getting Started
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## initMcpServer(data: McpServerData): Promise<void>
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
Protocol (MCP) servers. This documentation covers how to use the SDK
|
|
7
|
-
to create your own MCP server project.
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm install fa-mcp-sdk
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Project Structure
|
|
16
|
-
|
|
17
|
-
When creating a new MCP server, your project structure should follow this pattern:
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
my-mcp-server/
|
|
21
|
-
├── config/ # Environment configurations
|
|
22
|
-
│ ├── default.yaml # Base configuration
|
|
23
|
-
│ ├── development.yaml # Development settings
|
|
24
|
-
│ ├── production.yaml # Production settings
|
|
25
|
-
│ └── test.yaml # Test environment
|
|
26
|
-
├── src/ # Source code
|
|
27
|
-
│ ├── _types_/ # TypeScript type definitions
|
|
28
|
-
│ ├── api/ # REST API routes (HTTP transport)
|
|
29
|
-
│ │ └── router.ts # Express router with tsoa controllers
|
|
30
|
-
│ ├── prompts/ # Agent prompts
|
|
31
|
-
│ │ ├── agent-brief.ts # Agent brief
|
|
32
|
-
│ │ ├── agent-prompt.ts # Main agent prompt
|
|
33
|
-
│ │ └── custom-prompts.ts # Custom prompts
|
|
34
|
-
│ ├── tools/ # MCP tool implementations
|
|
35
|
-
│ │ ├── handle-tool-call.ts # Tool execution handler
|
|
36
|
-
│ │ └── tools.ts # Tool definitions
|
|
37
|
-
│ ├── custom-resources.ts # Custom MCP resources
|
|
38
|
-
│ └── start.ts # Application entry point
|
|
39
|
-
├── tests/ # Test suites
|
|
40
|
-
│ ├── mcp/ # MCP protocol tests
|
|
41
|
-
│ └── utils.ts # Test utilities
|
|
42
|
-
├── .env # Environment variables
|
|
43
|
-
├── package.json # NPM package configuration
|
|
44
|
-
└── tsconfig.json # TypeScript configuration
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Main Initialization Function
|
|
48
|
-
|
|
49
|
-
### `initMcpServer(data: McpServerData): Promise<void>`
|
|
50
|
-
|
|
51
|
-
The primary function for starting your MCP server.
|
|
52
|
-
|
|
53
|
-
**Example Usage in `src/start.ts`:**
|
|
5
|
+
Primary function for starting your MCP server.
|
|
54
6
|
|
|
55
7
|
```typescript
|
|
56
8
|
import { initMcpServer, McpServerData, CustomAuthValidator } from 'fa-mcp-sdk';
|
|
57
9
|
import { tools } from './tools/tools.js';
|
|
58
10
|
import { handleToolCall } from './tools/handle-tool-call.js';
|
|
59
|
-
import { AGENT_BRIEF } from './prompts/agent-brief.js';
|
|
60
|
-
import { AGENT_PROMPT } from './prompts/agent-prompt.js';
|
|
61
|
-
|
|
62
|
-
// Optional: Custom Authentication validator (black box function)
|
|
63
|
-
const customAuthValidator: CustomAuthValidator = async (req): Promise<AuthResult> => {
|
|
64
|
-
// Your custom authentication logic here - full request object available
|
|
65
|
-
// Can access headers, IP, user-agent, etc.
|
|
66
|
-
const authHeader = req.headers.authorization;
|
|
67
|
-
const userID = req.headers['x-user-id'];
|
|
68
|
-
const clientIP = req.headers['x-real-ip'] || req.connection?.remoteAddress;
|
|
69
|
-
|
|
70
|
-
// Implement any authentication logic (database, LDAP, API, custom rules, etc.)
|
|
71
|
-
const isAuthenticated = await authenticateRequest(req);
|
|
72
|
-
|
|
73
|
-
if (isAuthenticated) {
|
|
74
|
-
return {
|
|
75
|
-
success: true,
|
|
76
|
-
authType: 'basic',
|
|
77
|
-
username: userID || 'unknown',
|
|
78
|
-
};
|
|
79
|
-
} else {
|
|
80
|
-
return {
|
|
81
|
-
success: false,
|
|
82
|
-
error: 'Custom authentication failed',
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
11
|
|
|
87
12
|
const serverData: McpServerData = {
|
|
88
13
|
tools,
|
|
89
14
|
toolHandler: handleToolCall,
|
|
90
|
-
agentBrief:
|
|
91
|
-
agentPrompt:
|
|
92
|
-
|
|
93
|
-
// Optional: Provide custom authentication function
|
|
94
|
-
customAuthValidator: customAuthValidator,
|
|
95
|
-
|
|
96
|
-
// ... other configuration
|
|
15
|
+
agentBrief: 'My agent description',
|
|
16
|
+
agentPrompt: 'Full agent instructions',
|
|
17
|
+
customAuthValidator: async (req) => { /* custom auth logic */ },
|
|
97
18
|
};
|
|
98
19
|
|
|
99
20
|
await initMcpServer(serverData);
|
|
100
21
|
```
|
|
101
22
|
|
|
102
|
-
## Core Types
|
|
103
|
-
|
|
104
|
-
### `McpServerData`
|
|
23
|
+
## Core Types
|
|
105
24
|
|
|
106
|
-
|
|
25
|
+
### McpServerData
|
|
107
26
|
|
|
108
27
|
```typescript
|
|
109
28
|
interface McpServerData {
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// Authentication
|
|
124
|
-
customAuthValidator?: CustomAuthValidator; // Custom authentication validator function
|
|
125
|
-
tokenGenAuthHandler?: TokenGenAuthHandler; // Custom authorization for Token Generator admin page
|
|
126
|
-
|
|
127
|
-
// HTTP Server Components (for HTTP transport)
|
|
128
|
-
httpComponents?: {
|
|
129
|
-
apiRouter?: Router | null; // Express router for additional endpoints
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// UI Assets
|
|
133
|
-
assets?: {
|
|
134
|
-
logoSvg?: string; // SVG content for logo/favicon
|
|
135
|
-
maintainerHtml?: string; // Support contact HTML snippet
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// Consul Integration
|
|
139
|
-
getConsulUIAddress?: (serviceId: string) => string; // Function to generate Consul UI URLs
|
|
29
|
+
tools: Tool[] | (() => Promise<Tool[]>); // Tool definitions
|
|
30
|
+
toolHandler: (params: IToolHandlerParams) => Promise<any>;
|
|
31
|
+
agentBrief: string; // Brief description
|
|
32
|
+
agentPrompt: string; // System prompt
|
|
33
|
+
customPrompts?: IPromptData[]; // Additional prompts
|
|
34
|
+
usedHttpHeaders?: IUsedHttpHeader[] | null; // HTTP headers for auth
|
|
35
|
+
customResources?: IResourceData[] | null; // Custom resources
|
|
36
|
+
customAuthValidator?: CustomAuthValidator; // Custom auth function
|
|
37
|
+
tokenGenAuthHandler?: TokenGenAuthHandler; // Token Generator auth
|
|
38
|
+
httpComponents?: { apiRouter?: Router | null }; // Express router
|
|
39
|
+
assets?: { logoSvg?: string; maintainerHtml?: string };
|
|
40
|
+
getConsulUIAddress?: (serviceId: string) => string;
|
|
140
41
|
}
|
|
141
42
|
|
|
142
43
|
interface IToolHandlerParams {
|
|
143
44
|
name: string;
|
|
144
45
|
arguments?: any;
|
|
145
46
|
headers?: Record<string, string>;
|
|
146
|
-
payload?: { user: string; [key: string]: any }
|
|
47
|
+
payload?: { user: string; [key: string]: any }; // JWT payload if authenticated
|
|
48
|
+
transport?: 'stdio' | 'sse' | 'http';
|
|
147
49
|
}
|
|
148
50
|
```
|
|
149
51
|
|
|
150
|
-
###
|
|
52
|
+
### IPromptData
|
|
151
53
|
|
|
152
|
-
|
|
54
|
+
For custom prompts in `src/prompts/custom-prompts.ts`:
|
|
153
55
|
|
|
154
56
|
```typescript
|
|
155
57
|
interface IPromptData {
|
|
156
|
-
name: string;
|
|
157
|
-
description: string;
|
|
158
|
-
arguments: [];
|
|
159
|
-
content:
|
|
160
|
-
requireAuth?: boolean;
|
|
58
|
+
name: string;
|
|
59
|
+
description: string;
|
|
60
|
+
arguments: [];
|
|
61
|
+
content: string | ((request: IGetPromptRequest) => string | Promise<string>);
|
|
62
|
+
requireAuth?: boolean;
|
|
161
63
|
}
|
|
162
64
|
|
|
163
|
-
|
|
164
|
-
|
|
65
|
+
// Example:
|
|
66
|
+
export const customPrompts: IPromptData[] = [{
|
|
67
|
+
name: 'custom_prompt',
|
|
68
|
+
description: 'A custom prompt',
|
|
69
|
+
arguments: [],
|
|
70
|
+
content: (request) => `Content with param: ${request.params.arguments?.sample}`,
|
|
71
|
+
}];
|
|
165
72
|
```
|
|
166
73
|
|
|
167
|
-
|
|
168
|
-
```typescript
|
|
169
|
-
import { IPromptData } from 'fa-mcp-sdk';
|
|
74
|
+
### IResourceData
|
|
170
75
|
|
|
171
|
-
|
|
172
|
-
{
|
|
173
|
-
name: 'custom_prompt',
|
|
174
|
-
description: 'A custom prompt for specific tasks',
|
|
175
|
-
arguments: [],
|
|
176
|
-
content: (request) => {
|
|
177
|
-
const { sample } = request.params.arguments || {};
|
|
178
|
-
return `Custom prompt content with parameter: ${sample}`;
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
];
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### `IResourceData`
|
|
185
|
-
|
|
186
|
-
Configuration for custom resources in `src/custom-resources.ts`.
|
|
76
|
+
For custom resources in `src/custom-resources.ts`:
|
|
187
77
|
|
|
188
78
|
```typescript
|
|
189
79
|
interface IResourceData {
|
|
190
|
-
uri: string;
|
|
191
|
-
name: string;
|
|
192
|
-
title?: string;
|
|
193
|
-
description: string;
|
|
194
|
-
mimeType: string;
|
|
195
|
-
content:
|
|
196
|
-
requireAuth?: boolean;
|
|
80
|
+
uri: string; // e.g., "custom-resource://data1"
|
|
81
|
+
name: string;
|
|
82
|
+
title?: string;
|
|
83
|
+
description: string;
|
|
84
|
+
mimeType: string; // e.g., "text/plain", "application/json"
|
|
85
|
+
content: string | object | ((uri: string) => string | Promise<string>);
|
|
86
|
+
requireAuth?: boolean;
|
|
197
87
|
}
|
|
198
88
|
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
export const customResources: IResourceData[] = [
|
|
209
|
-
{
|
|
210
|
-
uri: 'custom-resource://resource1',
|
|
211
|
-
name: 'resource1',
|
|
212
|
-
description: 'Example resource with dynamic content',
|
|
213
|
-
mimeType: 'text/plain',
|
|
214
|
-
content: (uri) => {
|
|
215
|
-
return `Dynamic content for ${uri} at ${new Date().toISOString()}`;
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
];
|
|
89
|
+
// Example:
|
|
90
|
+
export const customResources: IResourceData[] = [{
|
|
91
|
+
uri: 'custom-resource://resource1',
|
|
92
|
+
name: 'resource1',
|
|
93
|
+
description: 'Dynamic content example',
|
|
94
|
+
mimeType: 'text/plain',
|
|
95
|
+
content: (uri) => `Dynamic content for ${uri}`,
|
|
96
|
+
}];
|
|
219
97
|
```
|
|
220
98
|
|
|
221
|
-
---
|
|
222
|
-
|
|
223
99
|
## Configuration API
|
|
224
100
|
|
|
225
|
-
###
|
|
101
|
+
### appConfig
|
|
226
102
|
|
|
227
|
-
|
|
103
|
+
Singleton with merged configuration from YAML files and environment variables:
|
|
228
104
|
|
|
229
105
|
```typescript
|
|
230
106
|
import { appConfig, AppConfig } from 'fa-mcp-sdk';
|
|
231
107
|
|
|
232
|
-
// appConfig is a singleton with merged configuration from:
|
|
233
|
-
// - config/default.yaml (base)
|
|
234
|
-
// - config/{NODE_ENV}.yaml (environment-specific)
|
|
235
|
-
// - Environment variables (highest priority)
|
|
236
|
-
|
|
237
|
-
// Access configuration values
|
|
238
108
|
const port = appConfig.webServer.port;
|
|
239
109
|
const serviceName = appConfig.name;
|
|
240
110
|
const isAuthEnabled = appConfig.webServer.auth.enabled;
|
|
241
111
|
```
|
|
242
112
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
|
246
|
-
|
|
247
|
-
| `
|
|
248
|
-
| `
|
|
249
|
-
| `
|
|
250
|
-
| `
|
|
251
|
-
| `
|
|
252
|
-
| `
|
|
253
|
-
| `logger` | object | Logging configuration (level, useFileLogger) |
|
|
254
|
-
| `ad` | object | Active Directory configuration |
|
|
255
|
-
| `consul` | object | Consul service discovery settings |
|
|
113
|
+
| Property | Description |
|
|
114
|
+
|----------|-------------|
|
|
115
|
+
| `name` | Package name from package.json |
|
|
116
|
+
| `shortName` | Name without 'mcp' suffix |
|
|
117
|
+
| `version` | Package version |
|
|
118
|
+
| `webServer` | HTTP server config (host, port, auth) |
|
|
119
|
+
| `mcp` | MCP settings (transportType, rateLimit) |
|
|
120
|
+
| `logger` | Logging config |
|
|
121
|
+
| `ad` | Active Directory config |
|
|
122
|
+
| `consul` | Service discovery settings |
|
|
256
123
|
|
|
257
|
-
###
|
|
124
|
+
### getProjectData(): McpServerData
|
|
258
125
|
|
|
259
|
-
|
|
126
|
+
Returns the data passed to `initMcpServer()`.
|
|
260
127
|
|
|
261
128
|
```typescript
|
|
262
|
-
import { getProjectData, McpServerData } from 'fa-mcp-sdk';
|
|
263
|
-
|
|
264
|
-
// Function Signature:
|
|
265
|
-
function getProjectData(): McpServerData;
|
|
266
|
-
|
|
267
|
-
// Example - Access project data from anywhere in your application:
|
|
268
129
|
const projectData = getProjectData();
|
|
269
|
-
console.log(
|
|
270
|
-
console.log('Tools count:', projectData.tools.length);
|
|
130
|
+
console.log(projectData.agentBrief, projectData.tools.length);
|
|
271
131
|
```
|
|
272
132
|
|
|
273
|
-
###
|
|
133
|
+
### getSafeAppConfig(): any
|
|
274
134
|
|
|
275
|
-
Returns
|
|
135
|
+
Returns config clone with sensitive data masked. Use for logging:
|
|
276
136
|
|
|
277
137
|
```typescript
|
|
278
|
-
import { getSafeAppConfig } from 'fa-mcp-sdk';
|
|
279
|
-
|
|
280
|
-
// Function Signature:
|
|
281
|
-
function getSafeAppConfig(): any;
|
|
282
|
-
|
|
283
|
-
// Example - Log configuration safely:
|
|
284
138
|
const safeConfig = getSafeAppConfig();
|
|
285
|
-
console.log(
|
|
286
|
-
|
|
287
|
-
// Sensitive values are masked:
|
|
288
|
-
// - Database passwords: '[MASKED]'
|
|
289
|
-
// - JWT keys, API tokens, etc.
|
|
139
|
+
console.log(JSON.stringify(safeConfig, null, 2)); // passwords masked
|
|
290
140
|
```
|
|
291
|
-
|
|
292
|
-
**Typical Use Cases:**
|
|
293
|
-
- Debugging configuration issues
|
|
294
|
-
- Audit logging of startup parameters
|
|
295
|
-
- Displaying configuration in admin interfaces
|