File tree Expand file tree Collapse file tree 4 files changed +13
-5
lines changed
Expand file tree Collapse file tree 4 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 3434 "@cloudflare/cabidela" : " ^0.2.4" ,
3535 "@modelcontextprotocol/sdk" : " ^1.25.2" ,
3636 "@valtown/deno-http-worker" : " ^0.0.21" ,
37+ "cookie-parser" : " ^1.4.6" ,
3738 "cors" : " ^2.8.5" ,
3839 "express" : " ^5.1.0" ,
3940 "fuse.js" : " ^7.1.0" ,
4041 "jq-web" : " https://github.com/stainless-api/jq-web/releases/download/v0.8.8/jq-web.tar.gz" ,
42+ "morgan" : " ^1.10.0" ,
4143 "qs" : " ^6.14.1" ,
4244 "typescript" : " 5.8.3" ,
4345 "yargs" : " ^17.7.2" ,
5052 },
5153 "devDependencies" : {
5254 "@anthropic-ai/mcpb" : " ^2.1.2" ,
55+ "@types/cookie-parser" : " ^1.4.10" ,
5356 "@types/cors" : " ^2.8.19" ,
5457 "@types/express" : " ^5.0.3" ,
5558 "@types/jest" : " ^29.4.0" ,
59+ "@types/morgan" : " ^1.9.10" ,
5660 "@types/qs" : " ^6.14.0" ,
5761 "@types/yargs" : " ^17.0.8" ,
5862 "@typescript-eslint/eslint-plugin" : " 8.31.1" ,
Original file line number Diff line number Diff line change 33import { IncomingMessage } from 'node:http' ;
44import { ClientOptions } from '@imagekit/nodejs' ;
55
6- export const parseAuthHeaders = ( req : IncomingMessage ) : Partial < ClientOptions > => {
6+ export const parseAuthHeaders = ( req : IncomingMessage , required ?: boolean ) : Partial < ClientOptions > => {
77 if ( req . headers . authorization ) {
88 const scheme = req . headers . authorization . split ( ' ' ) [ 0 ] ! ;
99 const value = req . headers . authorization . slice ( scheme . length + 1 ) ;
@@ -19,6 +19,8 @@ export const parseAuthHeaders = (req: IncomingMessage): Partial<ClientOptions> =
1919 'Unsupported authorization scheme. Expected the "Authorization" header to be a supported scheme (Basic).' ,
2020 ) ;
2121 }
22+ } else if ( required ) {
23+ throw new Error ( 'Missing required Authorization header; see WWW-Authenticate header for details.' ) ;
2224 }
2325
2426 const privateKey =
Original file line number Diff line number Diff line change 22
33import { McpServer } from '@modelcontextprotocol/sdk/server/mcp' ;
44import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js' ;
5-
65import express from 'express' ;
6+ import morgan from 'morgan' ;
77import { McpOptions } from './options' ;
88import { ClientOptions , initMcpServer , newMcpServer } from './server' ;
99import { parseAuthHeaders } from './headers' ;
@@ -20,7 +20,7 @@ const newServer = ({
2020 const server = newMcpServer ( ) ;
2121
2222 try {
23- const authOptions = parseAuthHeaders ( req ) ;
23+ const authOptions = parseAuthHeaders ( req , false ) ;
2424 initMcpServer ( {
2525 server : server ,
2626 clientOptions : {
@@ -75,14 +75,15 @@ const del = async (req: express.Request, res: express.Response) => {
7575
7676export const streamableHTTPApp = ( {
7777 clientOptions = { } ,
78- mcpOptions = { } ,
78+ mcpOptions,
7979} : {
8080 clientOptions ?: ClientOptions ;
81- mcpOptions ? : McpOptions ;
81+ mcpOptions : McpOptions ;
8282} ) : express . Express => {
8383 const app = express ( ) ;
8484 app . set ( 'query parser' , 'extended' ) ;
8585 app . use ( express . json ( ) ) ;
86+ app . use ( morgan ( 'combined' ) ) ;
8687
8788 app . get ( '/' , get ) ;
8889 app . post ( '/' , post ( { clientOptions, mcpOptions } ) ) ;
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ export function parseCLIOptions(): CLIOptions {
3535 } )
3636 . option ( 'port' , {
3737 type : 'number' ,
38+ default : 3000 ,
3839 description : 'Port to serve on if using http transport' ,
3940 } )
4041 . option ( 'socket' , {
You can’t perform that action at this time.
0 commit comments