Skip to content

Commit b8d5fea

Browse files
committed
Feat: Implement MCP Client CLI and NPM Script #7937
1 parent 769c819 commit b8d5fea

File tree

5 files changed

+159
-8
lines changed

5 files changed

+159
-8
lines changed

.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-29T22:45:13.523Z",
3-
"releasesLastFetched": "2025-11-29T22:45:13.530Z",
2+
"lastSync": "2025-11-29T22:49:00.189Z",
3+
"releasesLastFetched": "2025-11-29T22:49:00.196Z",
44
"pushFailures": [],
55
"issues": {
66
"3789": {
@@ -11715,11 +11715,18 @@
1171511715
"contentHash": "c9085bdc5672d6db2d504d5939ecda7e9fa87d8a5fa2e0b14ac986f195a671ca"
1171611716
},
1171711717
"7936": {
11718-
"state": "OPEN",
11718+
"state": "CLOSED",
1171911719
"path": "/Users/Shared/github/neomjs/neo/.github/ISSUE/issue-7936.md",
11720+
"closedAt": "2025-11-29T22:46:23Z",
11721+
"updatedAt": "2025-11-29T22:46:23Z",
11722+
"contentHash": "5d23aba34d5f68eefd0a686ef6e80efb03920836ee8220b1484e4edfdff7bdff"
11723+
},
11724+
"7937": {
11725+
"state": "OPEN",
11726+
"path": "/Users/Shared/github/neomjs/neo/.github/ISSUE/issue-7937.md",
1172011727
"closedAt": null,
11721-
"updatedAt": "2025-11-29T22:44:54Z",
11722-
"contentHash": "895c1558f45d7fc4cc4f11446856cd98fbc8ddebdea8556e1ae9cdc5ca0176ef"
11728+
"updatedAt": "2025-11-29T22:48:47Z",
11729+
"contentHash": "b5da383aedbc147b8a6378f368ef0faea62227b0e9c6c30148749c3cba360508"
1172311730
}
1172411731
},
1172511732
"releases": {

.github/ISSUE/issue-7936.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
---
22
id: 7936
33
title: 'Feat: Implement MCP Client Configuration'
4-
state: OPEN
4+
state: CLOSED
55
labels:
66
- enhancement
77
- ai
88
assignees:
99
- tobiu
1010
createdAt: '2025-11-29T22:44:54Z'
11-
updatedAt: '2025-11-29T22:44:54Z'
11+
updatedAt: '2025-11-29T22:46:23Z'
1212
githubUrl: 'https://github.com/neomjs/neo/issues/7936'
1313
author: tobiu
14-
commentsCount: 0
14+
commentsCount: 1
1515
parentIssue: 7931
1616
subIssues: []
1717
subIssuesCompleted: 0
1818
subIssuesTotal: 0
1919
blockedBy: []
2020
blocking: []
21+
closedAt: '2025-11-29T22:46:23Z'
2122
---
2223
# Feat: Implement MCP Client Configuration
2324

@@ -30,9 +31,24 @@ This task implements the client-side configuration system for MCP servers, allow
3031
* Loads `command` and `args` from the `ClientConfig.mcpServers` map.
3132
3. **Demo Agent Update:** Modify `ai/agents/mcp-demo-agent.mjs` to demonstrate loading server configurations via `serverName_` instead of hardcoding connection details.
3233

34+
## Comments
35+
36+
### @tobiu - 2025-11-29 22:46
37+
38+
**Input from Gemini 2.5:**
39+
40+
> ✦ I have implemented the MCP Client Configuration:
41+
>
42+
> ### Deliverables Completed
43+
> 1. **Client Configuration File:** Created `ai/mcp/client/config.mjs` following the `Neo.core.Base` singleton pattern, defining `mcpServers` for various MCP server endpoints.
44+
> 2. **Client Integration:** Updated `Neo.ai.mcp.client.Client` to utilize the `ClientConfig` singleton. It now uses a `serverName_` config to load command and arguments from the `ClientConfig.mcpServers` map.
45+
> 3. **Demo Agent Update:** Modified `ai/agents/mcp-demo-agent.mjs` to demonstrate loading server configurations via `serverName_` instead of hardcoding connection details.
46+
3347
## Activity Log
3448

3549
- 2025-11-29 @tobiu assigned to @tobiu
3650
- 2025-11-29 @tobiu added the `enhancement` label
3751
- 2025-11-29 @tobiu added the `ai` label
52+
- 2025-11-29 @tobiu referenced in commit `769c819` - "Feat: Implement MCP Client Configuration #7936"
53+
- 2025-11-29 @tobiu closed this issue
3854

.github/ISSUE/issue-7937.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
id: 7937
3+
title: 'Feat: Implement MCP Client CLI and NPM Script'
4+
state: OPEN
5+
labels:
6+
- enhancement
7+
- ai
8+
assignees:
9+
- tobiu
10+
createdAt: '2025-11-29T22:48:47Z'
11+
updatedAt: '2025-11-29T22:48:47Z'
12+
githubUrl: 'https://github.com/neomjs/neo/issues/7937'
13+
author: tobiu
14+
commentsCount: 0
15+
parentIssue: 7931
16+
subIssues: []
17+
subIssuesCompleted: 0
18+
subIssuesTotal: 0
19+
blockedBy: []
20+
blocking: []
21+
---
22+
# Feat: Implement MCP Client CLI and NPM Script
23+
24+
This task implements a command-line interface (CLI) for the MCP Client and integrates it into the project''s NPM scripts. This will allow for easy testing and interaction with MCP servers directly from the command line.
25+
26+
### Deliverables
27+
1. **MCP Client CLI Script:** Create `ai/mcp/client/mcp-cli.mjs`.
28+
* Uses `commander` to parse CLI arguments for server selection, tool listing, and tool invocation.
29+
* Bootstraps the `Neo.mjs` framework.
30+
* Instantiates `Neo.ai.mcp.client.Client` to interact with specified MCP servers.
31+
2. **NPM Script Integration:** Add a new script `ai:mcp-client` to `package.json` that executes `node ai/mcp/client/mcp-cli.mjs`.
32+
33+
## Activity Log
34+
35+
- 2025-11-29 @tobiu assigned to @tobiu
36+
- 2025-11-29 @tobiu added the `enhancement` label
37+
- 2025-11-29 @tobiu added the `ai` label
38+

ai/mcp/client/mcp-cli.mjs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Neo.mjs MCP Client CLI
5+
*
6+
* This script provides a command-line interface to interact with MCP servers
7+
* using the Neo.ai.mcp.client.Client.
8+
*
9+
* Usage:
10+
* node ai/mcp/client/mcp-cli.mjs --server <serverName> --list-tools
11+
* node ai/mcp/client/mcp-cli.mjs --server <serverName> --call-tool <toolName> --args '{"key": "value"}'
12+
*/
13+
14+
import { Command } from 'commander';
15+
import Neo from '../../../src/Neo.mjs';
16+
import * as core from '../../../src/core/_export.mjs'; // For Neo.core.Base setup
17+
import InstanceManager from '../../../src/manager/Instance.mjs'; // For Neo.core.Base setup
18+
import Client from './Client.mjs';
19+
import ClientConfig from './config.mjs';
20+
import path from 'path';
21+
import { fileURLToPath } from 'url';
22+
import dotenv from 'dotenv';
23+
24+
// Load environment variables from project root
25+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
26+
dotenv.config({ path: path.resolve(__dirname, '../../../.env') });
27+
28+
const program = new Command();
29+
30+
program
31+
.name('mcp-cli')
32+
.description('CLI for interacting with MCP servers')
33+
.requiredOption('-s, --server <name>', 'Logical name of the MCP server to connect to (e.g., github-workflow)')
34+
.option('-l, --list-tools', 'List available tools on the server')
35+
.option('-c, --call-tool <toolName>', 'Name of the tool to call')
36+
.option('-a, --args <json>', 'JSON string of arguments for --call-tool', '{}')
37+
.option('-d, --debug', 'Enable debug logging');
38+
39+
program.parse(process.argv);
40+
41+
const options = program.opts();
42+
43+
async function run() {
44+
console.log(`🤖 MCP Client CLI starting for server: ${options.server}`);
45+
console.log('GH_TOKEN present:', !!process.env.GH_TOKEN); // Debug info
46+
47+
const mcpClient = Neo.create(Client, {
48+
clientName: 'Neo.ai.MCP.CLI',
49+
serverName: options.server,
50+
env: process.env // Pass environment variables
51+
});
52+
53+
try {
54+
await mcpClient.connect();
55+
console.log(`✅ Connected to ${options.server} MCP server.`);
56+
57+
if (options.listTools) {
58+
console.log('\n🛠️ Listing tools...');
59+
const tools = await mcpClient.listTools();
60+
tools.forEach(tool => {
61+
console.log(` - ${tool.name}: ${tool.description || 'No description.'}`);
62+
});
63+
console.log(`\nFound ${tools.length} tools.`);
64+
} else if (options.callTool) {
65+
console.log(`\nCalling tool: ${options.callTool} with args: ${options.args}`);
66+
const args = JSON.parse(options.args);
67+
const result = await mcpClient.callTool(options.callTool, args);
68+
69+
if (result.isError) {
70+
console.error(`\n❌ Tool call failed:`);
71+
result.content.forEach(c => console.error(c.text));
72+
} else {
73+
console.log(`\n✅ Tool call successful:`);
74+
result.content.forEach(c => console.log(c.text));
75+
}
76+
} else {
77+
console.log('\n🤷 No action specified. Use --list-tools or --call-tool.');
78+
}
79+
80+
} catch (error) {
81+
console.error('\n💥 MCP CLI Error:', error.message);
82+
process.exit(1);
83+
} finally {
84+
await mcpClient.close();
85+
console.log('\n🔌 Connection closed.');
86+
}
87+
}
88+
89+
run();

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"ai:mcp-server-github-workflow": "node ./ai/mcp/server/github-workflow/mcp-stdio.mjs",
1717
"ai:mcp-server-knowledge-base" : "node ./ai/mcp/server/knowledge-base/mcp-stdio.mjs",
1818
"ai:mcp-server-memory-core" : "node ./ai/mcp/server/memory-core/mcp-stdio.mjs",
19+
"ai:mcp-client" : "node ./ai/mcp/client/mcp-cli.mjs",
1920
"ai:server" : "chroma run --path ./chroma-neo-knowledge-base",
2021
"ai:server-memory" : "chroma run --path ./chroma-neo-memory-core --port 8001",
2122
"build-all" : "node ./buildScripts/buildAll.mjs -f -n",

0 commit comments

Comments
 (0)