Skip to content

Commit 39bbb85

Browse files
committed
fix: revert to working server version that stays running
1 parent 5fff0a3 commit 39bbb85

1 file changed

Lines changed: 11 additions & 40 deletions

File tree

src/index.ts

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ import { VERSION, PACKAGE_NAME } from './utils/constants.util.js';
99
import { runCli } from './cli/index.js';
1010

1111
// Import Jira-specific tools
12-
import atlassianIssuesTools from './tools/atlassian.issues.tool.js';
1312
import atlassianProjectsTools from './tools/atlassian.projects.tool.js';
13+
import atlassianIssuesTools from './tools/atlassian.issues.tool.js';
1414
import atlassianStatusesTools from './tools/atlassian.statuses.tool.js';
1515

1616
// Create a contextualized logger for this file
1717
const indexLogger = Logger.forContext('index.ts');
1818

1919
// Log initialization at debug level
2020
indexLogger.debug('Jira MCP server module loaded');
21-
indexLogger.info(`Initializing ${PACKAGE_NAME} v${VERSION}`);
2221

2322
let serverInstance: McpServer | null = null;
2423
let transportInstance: SSEServerTransport | StdioServerTransport | null = null;
@@ -66,12 +65,12 @@ export async function startServer(mode: 'stdio' | 'sse' = 'stdio') {
6665
// Register tools
6766
serverLogger.info('Registering MCP tools...');
6867

69-
atlassianIssuesTools.registerTools(serverInstance);
70-
serverLogger.debug('Registered Issues tools');
71-
7268
atlassianProjectsTools.registerTools(serverInstance);
7369
serverLogger.debug('Registered Projects tools');
7470

71+
atlassianIssuesTools.registerTools(serverInstance);
72+
serverLogger.debug('Registered Issues tools');
73+
7574
atlassianStatusesTools.registerTools(serverInstance);
7675
serverLogger.debug('Registered Statuses tools');
7776

@@ -95,56 +94,28 @@ export async function startServer(mode: 'stdio' | 'sse' = 'stdio') {
9594
* Determines whether to run in CLI or server mode based on command-line arguments
9695
*/
9796
async function main() {
97+
// Create method-level logger with more specific context
9898
const mainLogger = Logger.forContext('index.ts', 'main');
99-
config.load();
10099

101-
// Track whether we're in server mode
102-
let isServerMode = false;
103-
104-
// --- Start: Add Graceful Shutdown ---
105-
const shutdown = async (signal: string) => {
106-
mainLogger.info(`Received ${signal}. Shutting down gracefully...`);
107-
108-
// If we're in server mode and we have an active server instance,
109-
// attempt to disconnect properly
110-
if (isServerMode && serverInstance) {
111-
try {
112-
mainLogger.info('Disconnecting server instance...');
113-
// Allow time for ongoing operations to complete
114-
setTimeout(() => {
115-
process.exit(0);
116-
}, 500);
117-
} catch (err) {
118-
mainLogger.error('Error during graceful shutdown', err);
119-
process.exit(1);
120-
}
121-
} else {
122-
// Not in server mode, so safe to exit immediately
123-
process.exit(0);
124-
}
125-
};
126-
127-
process.on('SIGINT', () => shutdown('SIGINT')); // Ctrl+C
128-
process.on('SIGTERM', () => shutdown('SIGTERM')); // kill command
129-
// --- End: Add Graceful Shutdown ---
100+
// Load configuration
101+
config.load();
130102

103+
// Check if arguments are provided (CLI mode)
131104
if (process.argv.length > 2) {
105+
// CLI mode: Pass arguments to CLI runner
132106
mainLogger.info('Starting in CLI mode');
133107
await runCli(process.argv.slice(2));
134108
mainLogger.info('CLI execution completed');
135109
} else {
110+
// MCP Server mode: Start server with default STDIO
136111
mainLogger.info('Starting in server mode');
137-
isServerMode = true;
138112
await startServer();
139113
mainLogger.info('Server is now running');
140-
// Server mode keeps running until signaled
141114
}
142115
}
143116

144117
// If this file is being executed directly (not imported), run the main function
145-
// Use a check suitable for both CommonJS and ESM contexts
146-
const isMainModule = process.argv[1] && process.argv[1].endsWith('index.js');
147-
if (isMainModule) {
118+
if (require.main === module) {
148119
main().catch((err) => {
149120
indexLogger.error('Unhandled error in main process', err);
150121
process.exit(1);

0 commit comments

Comments
 (0)