Skip to content

Commit bfa75e8

Browse files
committed
Add CLI argument parsing and Config refactoring to Knowledge Base MCP Server #7805
1 parent 4120324 commit bfa75e8

6 files changed

Lines changed: 183 additions & 14 deletions

File tree

.github/.sync-metadata.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"lastSync": "2025-11-19T11:12:57.463Z",
3-
"releasesLastFetched": "2025-11-19T11:12:57.466Z",
2+
"lastSync": "2025-11-19T11:20:56.964Z",
3+
"releasesLastFetched": "2025-11-19T11:20:56.967Z",
44
"pushFailures": [],
55
"issues": {
66
"3789": {
@@ -6549,11 +6549,18 @@
65496549
"contentHash": "5e272ed54318561523081c173d02c04775496f48d0587d1f760780efcc92ee46"
65506550
},
65516551
"7804": {
6552-
"state": "OPEN",
6552+
"state": "CLOSED",
65536553
"path": "/Users/Shared/github/neomjs/neo/.github/ISSUE/issue-7804.md",
6554+
"closedAt": "2025-11-19T11:18:52Z",
6555+
"updatedAt": "2025-11-19T11:18:52Z",
6556+
"contentHash": "9792b3df9bcaddd79ce2d286fccd4afc76f49c38af1716e92ba195c184d2f077"
6557+
},
6558+
"7805": {
6559+
"state": "OPEN",
6560+
"path": "/Users/Shared/github/neomjs/neo/.github/ISSUE/issue-7805.md",
65546561
"closedAt": null,
6555-
"updatedAt": "2025-11-19T11:12:48Z",
6556-
"contentHash": "8052a661db66b032062fd4e4f15bfef4d41cd57484dd33bf0c9e1cbd8c3065e7"
6562+
"updatedAt": "2025-11-19T11:20:50Z",
6563+
"contentHash": "a3f1497067170cfd5f0a5b08372efea4fe72b010a4a2fb46baf6fa78f8d3f353"
65576564
}
65586565
},
65596566
"releases": {

.github/ISSUE/issue-7804.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
22
id: 7804
33
title: Add CLI argument parsing and Config refactoring to Memory Core MCP Server
4-
state: OPEN
4+
state: CLOSED
55
labels:
66
- enhancement
77
- ai
88
- refactoring
9-
assignees: []
9+
assignees:
10+
- tobiu
1011
createdAt: '2025-11-19T11:12:48Z'
11-
updatedAt: '2025-11-19T11:12:48Z'
12+
updatedAt: '2025-11-19T11:18:52Z'
1213
githubUrl: 'https://github.com/neomjs/neo/issues/7804'
1314
author: tobiu
1415
commentsCount: 0
@@ -18,6 +19,7 @@ subIssuesCompleted: 0
1819
subIssuesTotal: 0
1920
blockedBy: []
2021
blocking: []
22+
closedAt: '2025-11-19T11:18:52Z'
2123
---
2224
# Add CLI argument parsing and Config refactoring to Memory Core MCP Server
2325

@@ -42,4 +44,7 @@ Standardize the configuration and startup logic across MCP servers for better ma
4244
- 2025-11-19 @tobiu added the `enhancement` label
4345
- 2025-11-19 @tobiu added the `ai` label
4446
- 2025-11-19 @tobiu added the `refactoring` label
47+
- 2025-11-19 @tobiu assigned to @tobiu
48+
- 2025-11-19 @tobiu referenced in commit `4120324` - "Add CLI argument parsing and Config refactoring to Memory Core MCP Server #7804"
49+
- 2025-11-19 @tobiu closed this issue
4550

.github/ISSUE/issue-7805.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
id: 7805
3+
title: Add CLI argument parsing and Config refactoring to Knowledge Base MCP Server
4+
state: OPEN
5+
labels:
6+
- enhancement
7+
- ai
8+
- refactoring
9+
assignees: []
10+
createdAt: '2025-11-19T11:20:50Z'
11+
updatedAt: '2025-11-19T11:20:50Z'
12+
githubUrl: 'https://github.com/neomjs/neo/issues/7805'
13+
author: tobiu
14+
commentsCount: 0
15+
parentIssue: null
16+
subIssues: []
17+
subIssuesCompleted: 0
18+
subIssuesTotal: 0
19+
blockedBy: []
20+
blocking: []
21+
---
22+
# Add CLI argument parsing and Config refactoring to Knowledge Base MCP Server
23+
24+
Apply the same configuration and CLI argument parsing improvements to the Knowledge Base MCP server as were done for the GitHub Workflow and Memory Core servers.
25+
26+
**Tasks:**
27+
1. Refactor `ai/mcp/server/knowledge-base/config.mjs` to:
28+
- Use the Proxy pattern to expose configuration data.
29+
- Implement a `load(filePath)` method that supports both JSON and JS/MJS files.
30+
- Store configuration values in a `data` property on the singleton instance.
31+
2. Update `ai/mcp/server/knowledge-base/mcp-stdio.mjs` to:
32+
- Use `commander` for CLI argument parsing.
33+
- Support `-c, --config <path>` to load a custom configuration file.
34+
- Support `-d, --debug` to enable debug logging (and update `aiConfig.data.debug`).
35+
3. Update `ai/mcp/server/knowledge-base/logger.mjs` (if applicable) to rely solely on `aiConfig.debug`.
36+
37+
**Goal:**
38+
Standardize the configuration and startup logic across all three MCP servers (GitHub Workflow, Memory Core, Knowledge Base).
39+
40+
## Activity Log
41+
42+
- 2025-11-19 @tobiu added the `enhancement` label
43+
- 2025-11-19 @tobiu added the `ai` label
44+
- 2025-11-19 @tobiu added the `refactoring` label
45+

ai/mcp/server/knowledge-base/config.mjs

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
import fs from 'fs/promises';
12
import path from 'path';
3+
import Base from '../../../../src/core/Base.mjs';
24

3-
const config = {
5+
/**
6+
* Default configuration object.
7+
* Defines the structure and default values for the server configuration.
8+
*/
9+
const defaultConfig = {
410
/**
511
* Global debug flag for all MCP servers.
612
* @type {boolean}
@@ -79,4 +85,85 @@ const config = {
7985
}
8086
};
8187

82-
export default config;
88+
/**
89+
* Configuration manager for the Knowledge Base MCP server.
90+
* Supports loading configuration from a custom file and merging with defaults.
91+
* @class Neo.ai.mcp.server.knowledge-base.Config
92+
* @extends Neo.core.Base
93+
* @singleton
94+
*/
95+
class Config extends Base {
96+
static config = {
97+
/**
98+
* @member {String} className='Neo.ai.mcp.server.knowledge-base.Config'
99+
* @protected
100+
*/
101+
className: 'Neo.ai.mcp.server.knowledge-base.Config',
102+
/**
103+
* @member {Boolean} singleton=true
104+
* @protected
105+
*/
106+
singleton: true
107+
}
108+
109+
/**
110+
* The current configuration object.
111+
* Starts with defaults and can be updated via load().
112+
* @member {Object} data
113+
*/
114+
data = null;
115+
116+
/**
117+
* Initializes the configuration object by deep cloning the defaults.
118+
* @param {Object} config
119+
*/
120+
construct(config) {
121+
super.construct(config);
122+
this.data = Neo.clone(defaultConfig, true);
123+
}
124+
125+
/**
126+
* Loads configuration from a JSON file and merges it with defaults.
127+
* @param {string} filePath - The path to the configuration file.
128+
* @returns {Promise<void>}
129+
*/
130+
async load(filePath) {
131+
if (!filePath) return;
132+
133+
try {
134+
const absolutePath = path.resolve(filePath);
135+
const ext = path.extname(absolutePath);
136+
let customConfig;
137+
138+
if (ext === '.mjs' || ext === '.js') {
139+
const module = await import(absolutePath);
140+
customConfig = module.default;
141+
} else {
142+
const content = await fs.readFile(absolutePath, 'utf-8');
143+
customConfig = JSON.parse(content);
144+
}
145+
146+
// Deep merge custom config into the data object
147+
Neo.merge(this.data, customConfig);
148+
149+
console.log(`[Config] Loaded custom configuration from ${absolutePath}`);
150+
151+
} catch (error) {
152+
console.error(`[Config] Failed to load configuration from ${filePath}:`, error.message);
153+
throw error;
154+
}
155+
}
156+
}
157+
158+
const instance = Neo.setupClass(Config);
159+
160+
export default new Proxy(instance, {
161+
get(target, prop, receiver) {
162+
// 1. Prefer properties/methods on the instance itself (e.g. load, className)
163+
if (Reflect.has(target, prop)) {
164+
return Reflect.get(target, prop, receiver);
165+
}
166+
// 2. Fallback to the data object (e.g. port, batchSize)
167+
return target.data[prop];
168+
}
169+
});

ai/mcp/server/knowledge-base/logger.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import aiConfig from './config.mjs';
66
*/
77
const logger = {};
88

9-
// Check for --debug flag in command line arguments
10-
const isDebugFlagSet = process.argv.includes('--debug');
11-
129
const createLogMethod = (level) => {
1310
return (...args) => {
14-
if (aiConfig.debug || isDebugFlagSet) {
11+
if (aiConfig.debug) {
1512
console.error(`[${level.toUpperCase()}]`, ...args);
1613
}
1714
};

ai/mcp/server/knowledge-base/mcp-stdio.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
11
import {Server} from '@modelcontextprotocol/sdk/server/index.js';
22
import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js';
33
import {CallToolRequestSchema, ListToolsRequestSchema} from '@modelcontextprotocol/sdk/types.js';
4+
import {Command} from 'commander';
45
import Neo from '../../../../src/Neo.mjs';
56
import * as core from '../../../../src/core/_export.mjs';
67
import InstanceManager from '../../../../src/manager/Instance.mjs';
8+
import aiConfig from './config.mjs';
79
import logger from './logger.mjs';
810
import DatabaseService from './services/DatabaseService.mjs';
911
import HealthService from './services/HealthService.mjs';
1012
import {listTools, callTool} from './services/toolService.mjs';
1113

14+
const program = new Command();
15+
16+
program
17+
.name('neo-knowledge-base-mcp')
18+
.description('Neo.mjs Knowledge Base MCP Server')
19+
.option('-c, --config <path>', 'Path to the configuration file')
20+
.option('-d, --debug', 'Enable debug logging')
21+
.parse(process.argv);
22+
23+
const options = program.opts();
24+
25+
// Apply debug flag
26+
if (options.debug) {
27+
aiConfig.data.debug = true;
28+
}
29+
30+
// Load custom configuration if provided
31+
if (options.config) {
32+
try {
33+
await aiConfig.load(options.config);
34+
} catch (error) {
35+
console.error('Failed to load configuration:', error);
36+
process.exit(1);
37+
}
38+
}
39+
1240
const server = new Server({
1341
name: 'neo-knowledge-base',
1442
version: '1.0.0',

0 commit comments

Comments
 (0)