Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions bin/mantis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node

import fs from 'node:fs';
import path from 'node:path';

import { Command } from 'commander';
Expand All @@ -12,14 +11,7 @@ import { getContainer } from '../lib/container.js';

import { parseUseCommand } from '../lib/utils/tool-args.js';

import { PACKAGE_ROOT } from '../lib/utils/package-root.js';



// single source of truth for the version: package.json (never hardcode)
const { version: VERSION } = JSON.parse(
fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf8'),
);
import { PACKAGE_VERSION as VERSION } from '../lib/utils/package-root.js';

const c = getContainer();

Expand Down
3 changes: 2 additions & 1 deletion lib/impl/mcp-client-service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';

import { PACKAGE_VERSION } from '../utils/package-root.js';
import { mcpUrl } from '../utils/url.js';

export class McpClientService {
Expand All @@ -24,7 +25,7 @@ export class McpClientService {
const transport = new StreamableHTTPClientTransport(new URL(mcpUrl(cfg)), {
requestInit: { headers: this._headers(cfg) },
});
const client = new Client({ name: 'mantisai-cli', version: '3.1.0' });
const client = new Client({ name: 'mantisai-cli', version: PACKAGE_VERSION });
await client.connect(transport);
try {
return await fn(client);
Expand Down
5 changes: 5 additions & 0 deletions lib/utils/package-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ function findPackageRoot(start) {

export const PACKAGE_ROOT = findPackageRoot(__dirname);
export const SKILLS_DIR = path.join(PACKAGE_ROOT, 'skills');

// single source of truth for the version: package.json (never hardcode)
export const PACKAGE_VERSION = JSON.parse(
fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf8'),
).version;
40 changes: 40 additions & 0 deletions test/mcp-client-service.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import http from 'node:http';
import test from 'node:test';

import { McpClientService } from '../lib/impl/mcp-client-service.js';

const { version: packageVersion } = JSON.parse(
fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
);

test('MCP handshake reports the package.json version', async (t) => {
// Stand-in MCP endpoint: records the initialize request, then refuses it.
let clientInfo;
const server = http.createServer((req, res) => {
let body = '';
req.on('data', (chunk) => { body += chunk; });
req.on('end', () => {
try {
const messages = [].concat(JSON.parse(body));
clientInfo ??= messages.find((m) => m.method === 'initialize')?.params?.clientInfo;
} catch { /* not JSON */ }
res.writeHead(401, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'refused by test server' }));
});
});
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
t.after(() => new Promise((resolve) => server.close(resolve)));

const mcp = new McpClientService({
requireAuth: () => ({
apiBaseUrl: `http://127.0.0.1:${server.address().port}`,
apiKey: 'test-key',
spaceStateId: 'test-thread',
}),
});

await assert.rejects(mcp.listTools());
assert.deepEqual(clientInfo, { name: 'mantisai-cli', version: packageVersion });
});