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
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
* A Model Context Protocol server that provides access to
* Microsoft Outlook through the Microsoft Graph API.
*/

// Handle `--version` / `-v` before requiring anything else so we don't load
// config, auth modules, or emit MCP startup logging just to print a version.
if (process.argv.includes('--version') || process.argv.includes('-v')) {
const pkg = require('./package.json');
process.stdout.write(`${pkg.name} v${pkg.version}\n`);
process.exit(0);
}

const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
const {
StdioServerTransport,
Expand Down
41 changes: 41 additions & 0 deletions test/cli-version.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Tests for `--version` / `-v` CLI flag (GH #68).
*
* Spawns `node index.js` with the flag and asserts:
* - stdout matches `@littlebearapps/outlook-assistant v<version>`
* - exit code is 0
* - no MCP startup output is emitted (we exit before logging)
*/

const path = require('path');
const { spawnSync } = require('child_process');

const ENTRY = path.join(__dirname, '..', 'index.js');
const pkg = require('../package.json');

function runCli(args) {
return spawnSync(process.execPath, [ENTRY, ...args], {
encoding: 'utf8',
timeout: 10_000,
});
}

describe('CLI --version flag', () => {
test('--version prints "<name> v<version>" and exits 0', () => {
const result = runCli(['--version']);
expect(result.status).toBe(0);
expect(result.stdout.trim()).toBe(`${pkg.name} v${pkg.version}`);
});

test('-v shorthand prints "<name> v<version>" and exits 0', () => {
const result = runCli(['-v']);
expect(result.status).toBe(0);
expect(result.stdout.trim()).toBe(`${pkg.name} v${pkg.version}`);
});

test('--version exits before MCP server startup logging', () => {
const result = runCli(['--version']);
expect(result.stderr).not.toMatch(/STARTING/);
expect(result.stderr).not.toMatch(/connected and listening/);
});
});
Loading