@@ -21,6 +21,7 @@ export async function startServer(args: string[] = process.argv) {
2121 let transport = 'stdio' ; // default
2222 let port = 3000 ;
2323 let authToken : string | undefined ;
24+ let disableAuth = false ;
2425
2526 for ( let i = 0 ; i < args . length ; i ++ ) {
2627 if ( args [ i ] === '--transport' && i + 1 < args . length ) {
@@ -32,6 +33,8 @@ export async function startServer(args: string[] = process.argv) {
3233 } else if ( args [ i ] === '--auth-token' && i + 1 < args . length ) {
3334 authToken = args [ i + 1 ] ;
3435 i ++ ; // skip next argument
36+ } else if ( args [ i ] === '--disable-auth' ) {
37+ disableAuth = true ;
3538 } else if ( args [ i ] === '--help' || args [ i ] === '-h' ) {
3639 console . log ( `
3740Usage: notion-mcp-server [options]
@@ -40,6 +43,7 @@ Options:
4043 --transport <type> Transport type: 'stdio' or 'http' (default: stdio)
4144 --port <number> Port for HTTP server when using Streamable HTTP transport (default: 3000)
4245 --auth-token <token> Bearer token for HTTP transport authentication (optional)
46+ --disable-auth Disable bearer token authentication for HTTP transport
4347 --help, -h Show this help message
4448
4549Environment Variables:
@@ -53,14 +57,15 @@ Examples:
5357 notion-mcp-server --transport http # Use Streamable HTTP transport on port 3000
5458 notion-mcp-server --transport http --port 8080 # Use Streamable HTTP transport on port 8080
5559 notion-mcp-server --transport http --auth-token mytoken # Use Streamable HTTP transport with custom auth token
60+ notion-mcp-server --transport http --disable-auth # Use Streamable HTTP transport without authentication
5661 AUTH_TOKEN=mytoken notion-mcp-server --transport http # Use Streamable HTTP transport with auth token from env var
5762` ) ;
5863 process . exit ( 0 ) ;
5964 }
6065 // Ignore unrecognized arguments (like command name passed by Docker)
6166 }
6267
63- return { transport : transport . toLowerCase ( ) , port, authToken } ;
68+ return { transport : transport . toLowerCase ( ) , port, authToken, disableAuth } ;
6469 }
6570
6671 const options = parseArgs ( )
@@ -76,11 +81,14 @@ Examples:
7681 const app = express ( )
7782 app . use ( express . json ( ) )
7883
79- // Generate or use provided auth token (from CLI arg or env var)
80- const authToken = options . authToken || process . env . AUTH_TOKEN || randomBytes ( 32 ) . toString ( 'hex' )
81- if ( ! options . authToken && ! process . env . AUTH_TOKEN ) {
82- console . log ( `Generated auth token: ${ authToken } ` )
83- console . log ( `Use this token in the Authorization header: Bearer ${ authToken } ` )
84+ // Generate or use provided auth token (from CLI arg or env var) only if auth is enabled
85+ let authToken : string | undefined
86+ if ( ! options . disableAuth ) {
87+ authToken = options . authToken || process . env . AUTH_TOKEN || randomBytes ( 32 ) . toString ( 'hex' )
88+ if ( ! options . authToken && ! process . env . AUTH_TOKEN ) {
89+ console . log ( `Generated auth token: ${ authToken } ` )
90+ console . log ( `Use this token in the Authorization header: Bearer ${ authToken } ` )
91+ }
8492 }
8593
8694 // Authorization middleware
@@ -125,8 +133,10 @@ Examples:
125133 } )
126134 } )
127135
128- // Apply authentication to all /mcp routes
129- app . use ( '/mcp' , authenticateToken )
136+ // Apply authentication to all /mcp routes only if auth is enabled
137+ if ( ! options . disableAuth ) {
138+ app . use ( '/mcp' , authenticateToken )
139+ }
130140
131141 // Map to store transports by session ID
132142 const transports : { [ sessionId : string ] : StreamableHTTPServerTransport } = { }
@@ -219,9 +229,13 @@ Examples:
219229 console . log ( `MCP Server listening on port ${ port } ` )
220230 console . log ( `Endpoint: http://0.0.0.0:${ port } /mcp` )
221231 console . log ( `Health check: http://0.0.0.0:${ port } /health` )
222- console . log ( `Authentication: Bearer token required` )
223- if ( options . authToken ) {
224- console . log ( `Using provided auth token` )
232+ if ( options . disableAuth ) {
233+ console . log ( `Authentication: Disabled` )
234+ } else {
235+ console . log ( `Authentication: Bearer token required` )
236+ if ( options . authToken ) {
237+ console . log ( `Using provided auth token` )
238+ }
225239 }
226240 } )
227241
0 commit comments