@@ -17,6 +17,16 @@ import {
1717 ReadResourceRequestSchema ,
1818} from '@modelcontextprotocol/sdk/types.js' ;
1919import axios from 'axios' ;
20+ import { readFileSync } from 'fs' ;
21+ import { dirname , join } from 'path' ;
22+ import { fileURLToPath } from 'url' ;
23+
24+ // Get version from package.json
25+ const __filename = fileURLToPath ( import . meta. url ) ;
26+ const __dirname = dirname ( __filename ) ;
27+ const packageJsonPath = join ( __dirname , '../../package.json' ) ;
28+ const packageJson = JSON . parse ( readFileSync ( packageJsonPath , 'utf8' ) ) ;
29+ const VERSION = packageJson . version ;
2030
2131// Configure logging to stderr to avoid interfering with stdio protocol
2232const logger = {
@@ -105,8 +115,8 @@ class ReadsbMCPServer {
105115
106116 logger . debug ( 'Creating MCP Server instance...' ) ;
107117 this . server = new Server ( {
108- name : 'readsb -mcp' ,
109- version : '1.0.0' ,
118+ name : 'adsb -mcp-server ' ,
119+ version : VERSION ,
110120 } , {
111121 capabilities : {
112122 resources : { } ,
@@ -129,12 +139,18 @@ class ReadsbMCPServer {
129139 const response = {
130140 protocolVersion : '2025-06-18' ,
131141 capabilities : {
132- resources : { } ,
133- tools : { } ,
142+ resources : {
143+ subscribe : false ,
144+ listChanged : false
145+ } ,
146+ tools : {
147+ listChanged : false
148+ } ,
149+ experimental : { } ,
134150 } ,
135151 serverInfo : {
136- name : 'readsb -mcp' ,
137- version : '1.0.0' ,
152+ name : 'adsb -mcp-server ' ,
153+ version : VERSION ,
138154 } ,
139155 } ;
140156 logger . info ( `Sending initialize response: ${ JSON . stringify ( response ) } ` ) ;
@@ -1157,11 +1173,23 @@ async function main() {
11571173 logger . debug ( 'server finished' ) ;
11581174}
11591175
1160- if ( import . meta. url === `file://${ process . argv [ 1 ] } ` ) {
1161- logger . debug ( 'Starting MCP server main process...' ) ;
1176+ // Check if this file is being run directly (not imported)
1177+ // Handle URL encoding differences between import.meta.url and process.argv[1]
1178+ const currentFileUrl = import . meta. url . replace ( / % 2 0 / g, ' ' ) ;
1179+ const scriptPath = process . argv [ 1 ] ;
1180+ const isMainModule = currentFileUrl === `file://${ scriptPath } ` ||
1181+ currentFileUrl . endsWith ( scriptPath ) ||
1182+ currentFileUrl . includes ( scriptPath . replace ( / \\ / g, '/' ) ) ;
1183+
1184+ if ( isMainModule ) {
1185+ logger . info ( 'Starting MCP server main process...' ) ;
11621186 main ( ) . catch ( ( error ) => {
11631187 logger . error ( `Server error: ${ error } ` ) ;
11641188 logger . error ( `Error stack: ${ error instanceof Error ? error . stack : 'No stack trace' } ` ) ;
11651189 process . exit ( 1 ) ;
11661190 } ) ;
1191+ } else {
1192+ logger . debug ( `scriptPath: ${ scriptPath } ` ) ;
1193+ logger . debug ( `currentFileUrl: ${ currentFileUrl } ` ) ;
1194+ logger . debug ( 'Importing MCP server as a module...' ) ;
11671195}
0 commit comments