1- import { Hono } from "hono" ;
1+ import { Hono , Context , Next } from "hono" ;
22import { cors } from "hono/cors" ;
33// Remove unused imports
44import { getConfig , Config } from "../config.js" ;
@@ -33,7 +33,7 @@ export function createMCPRoutes(): Hono {
3333 ) ;
3434
3535 // Middleware to validate Authorization header
36- const authMiddleware = async ( c : any , next : any ) => {
36+ const authMiddleware = async ( c : Context , next : Next ) => {
3737 const authHeader = c . req . header ( "Authorization" ) ;
3838 const expectedToken = process . env . MCP_AUTH_TOKEN ;
3939
@@ -83,18 +83,20 @@ export function createMCPRoutes(): Hono {
8383 const body = await c . req . json ( ) ;
8484 console . log ( "🔍 Received MCP request:" , JSON . stringify ( body , null , 2 ) ) ;
8585
86+ const bodyObj = body as Record < string , unknown > ;
87+
8688 // Handle JSON-RPC request
87- if ( body . jsonrpc !== "2.0" ) {
88- console . log ( "❌ Invalid JSON-RPC version:" , body . jsonrpc ) ;
89+ if ( bodyObj . jsonrpc !== "2.0" ) {
90+ console . log ( "❌ Invalid JSON-RPC version:" , bodyObj . jsonrpc ) ;
8991 return c . json ( {
9092 jsonrpc : "2.0" ,
9193 error : { code : - 32600 , message : "Invalid Request" } ,
92- id : body . id || null
94+ id : bodyObj . id || null
9395 } , 400 ) ;
9496 }
9597
96- console . log ( "📋 Method:" , body . method , "ID:" , body . id ) ;
97- switch ( body . method ) {
98+ console . log ( "📋 Method:" , bodyObj . method , "ID:" , bodyObj . id ) ;
99+ switch ( bodyObj . method ) {
98100 case "initialize" :
99101 console . log ( "🔧 Handling initialize" ) ;
100102 return handleInitialize ( c , body ) ;
@@ -112,7 +114,7 @@ export function createMCPRoutes(): Hono {
112114 return c . json ( {
113115 jsonrpc : "2.0" ,
114116 error : { code : - 32601 , message : "Method not found" } ,
115- id : body . id || null
117+ id : bodyObj . id || null
116118 } , 400 ) ;
117119 }
118120 } catch ( error ) {
@@ -153,9 +155,10 @@ export function createMCPRoutes(): Hono {
153155 return app ;
154156}
155157
156- function handleInitialize ( c : any , body : any ) {
158+ function handleInitialize ( c : Context , body : unknown ) {
157159 try {
158- console . log ( "🚀 Initializing MCP server with params:" , body . params ) ;
160+ const bodyObj = body as Record < string , unknown > ;
161+ console . log ( "🚀 Initializing MCP server with params:" , bodyObj . params ) ;
159162
160163 return c . json ( {
161164 jsonrpc : "2.0" ,
@@ -169,19 +172,19 @@ function handleInitialize(c: any, body: any) {
169172 version : "2.0.0"
170173 }
171174 } ,
172- id : body . id
175+ id : bodyObj . id
173176 } ) ;
174177 } catch ( error ) {
175178 console . error ( "Error during initialization:" , error ) ;
176179 return c . json ( {
177180 jsonrpc : "2.0" ,
178181 error : { code : - 32603 , message : "Internal error" } ,
179- id : body . id || null
182+ id : ( body as Record < string , unknown > ) . id || null
180183 } , 500 ) ;
181184 }
182185}
183186
184- function handleInitializedNotification ( c : any , body : any ) {
187+ function handleInitializedNotification ( c : Context , body : unknown ) {
185188 try {
186189 console . log ( "📢 Received initialized notification" ) ;
187190 // Notifications don't require a response, but we return 202 Accepted
@@ -191,14 +194,14 @@ function handleInitializedNotification(c: any, body: any) {
191194 return c . json ( {
192195 jsonrpc : "2.0" ,
193196 error : { code : - 32603 , message : "Internal error" } ,
194- id : body . id || null
197+ id : ( body as Record < string , unknown > ) . id || null
195198 } , 500 ) ;
196199 }
197200}
198201
199- function handleToolsList ( c : any , body : any ) {
202+ function handleToolsList ( c : Context , body : unknown ) {
200203 try {
201- console . log ( "📋 Listing tools for request ID:" , body . id ) ;
204+ console . log ( "📋 Listing tools for request ID:" , ( body as Record < string , unknown > ) . id ) ;
202205 const tools = [
203206 {
204207 name : "leave_general_comment" ,
@@ -394,29 +397,30 @@ function handleToolsList(c: any, body: any) {
394397 return c . json ( {
395398 jsonrpc : "2.0" ,
396399 result : { tools } ,
397- id : body . id
400+ id : ( body as Record < string , unknown > ) . id
398401 } ) ;
399402 } catch ( error ) {
400403 console . error ( "Error listing tools:" , error ) ;
401404 return c . json ( {
402405 jsonrpc : "2.0" ,
403406 error : { code : - 32603 , message : "Internal error" } ,
404- id : body . id || null
407+ id : ( body as Record < string , unknown > ) . id || null
405408 } , 500 ) ;
406409 }
407410}
408411
409- async function handleToolsCall ( c : any , body : any , config : Config , githubClient : GitHubClient ) {
412+ async function handleToolsCall ( c : Context , body : unknown , config : Config , githubClient : GitHubClient ) {
413+ const bodyObj = body as Record < string , unknown > ;
410414 try {
411- console . log ( "🔧 Tool call params:" , JSON . stringify ( body . params , null , 2 ) ) ;
412- const { name, arguments : args } = body . params || { } ;
415+ console . log ( "🔧 Tool call params:" , JSON . stringify ( bodyObj . params , null , 2 ) ) ;
416+ const { name, arguments : args } = ( bodyObj . params as Record < string , unknown > ) || { } ;
413417
414418 if ( ! name ) {
415419 console . log ( "❌ Missing tool name in params" ) ;
416420 return c . json ( {
417421 jsonrpc : "2.0" ,
418422 error : { code : - 32602 , message : "Invalid params: missing tool name" } ,
419- id : body . id || null
423+ id : bodyObj . id || null
420424 } , 400 ) ;
421425 }
422426
@@ -484,15 +488,15 @@ async function handleToolsCall(c: any, body: any, config: Config, githubClient:
484488 return c . json ( {
485489 jsonrpc : "2.0" ,
486490 error : { code : - 32601 , message : `Unknown tool: ${ name } ` } ,
487- id : body . id || null
491+ id : bodyObj . id || null
488492 } , 400 ) ;
489493 }
490494
491495 console . log ( "✅ Tool call successful, result:" , JSON . stringify ( result , null , 2 ) ) ;
492496 return c . json ( {
493497 jsonrpc : "2.0" ,
494498 result,
495- id : body . id
499+ id : bodyObj . id
496500 } ) ;
497501 } catch ( error ) {
498502 console . error ( "Error calling tool:" , error ) ;
@@ -502,7 +506,7 @@ async function handleToolsCall(c: any, body: any, config: Config, githubClient:
502506 code : - 32603 ,
503507 message : error instanceof Error ? error . message : "Unknown error"
504508 } ,
505- id : body . id || null
509+ id : bodyObj . id || null
506510 } , 500 ) ;
507511 }
508512}
0 commit comments