1- import { type Transport } from "@modelcontextprotocol/sdk/shared/transport.js" ;
2- import { type JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js" ;
3- import { Hono } from "hono" ;
4- import { HTTPException } from "hono/http-exception" ;
1+ import { type Transport } from "@modelcontextprotocol/sdk/shared/transport.js"
2+ import { type JSONRPCMessage } from "@modelcontextprotocol/sdk/types.js"
3+ import { Hono } from "hono"
4+ import { HTTPException } from "hono/http-exception"
55
66class OpenControlTransport implements Transport {
77 constructor ( private cb : ( response : JSONRPCMessage ) => void ) { }
88 async start ( ) : Promise < void > { }
99 async send ( message : JSONRPCMessage ) : Promise < void > {
10- this . cb ( message ) ;
10+ this . cb ( message )
1111 }
1212 async close ( ) : Promise < void > { }
13- onclose ?: ( ( ) => void ) | undefined ;
14- onerror ?: ( ( error : Error ) => void ) | undefined ;
15- onmessage ?: ( ( message : JSONRPCMessage ) => void ) | undefined ;
13+ onclose ?: ( ( ) => void ) | undefined
14+ onerror ?: ( ( error : Error ) => void ) | undefined
15+ onmessage ?: ( ( message : JSONRPCMessage ) => void ) | undefined
1616}
1717
1818export interface OpenControlOptions {
19- key ?: string ;
19+ key ?: string
2020}
2121
2222export function create (
@@ -26,24 +26,24 @@ export function create(
2626 return new Hono ( )
2727 . use ( ( c , next ) => {
2828 if ( options ?. key ) {
29- const authorization = c . req . header ( "Authorization" ) ;
29+ const authorization = c . req . header ( "Authorization" )
3030 if ( authorization !== `Bearer ${ options ?. key } ` ) {
31- throw new HTTPException ( 401 ) ;
31+ throw new HTTPException ( 401 )
3232 }
3333 }
34- return next ( ) ;
34+ return next ( )
3535 } )
3636 . post ( "/mcp" , async ( c ) => {
37- const body = await c . req . json ( ) ;
38- console . log ( "<-" , body ) ;
37+ const body = await c . req . json ( )
38+ console . log ( "<-" , body )
3939 const response = await new Promise < any > ( async ( resolve ) => {
40- const transport = new OpenControlTransport ( resolve ) ;
41- console . log ( "connecting to transport" ) ;
42- await server . connect ( transport ) ;
43- console . log ( "connected to transport" ) ;
44- transport . onmessage ?.( body ) ;
45- } ) ;
46- console . log ( "->" , JSON . stringify ( response , null , 2 ) ) ;
47- return c . json ( response ) ;
48- } ) ;
40+ const transport = new OpenControlTransport ( resolve )
41+ console . log ( "connecting to transport" )
42+ await server . connect ( transport )
43+ console . log ( "connected to transport" )
44+ transport . onmessage ?.( body )
45+ } )
46+ console . log ( "->" , JSON . stringify ( response , null , 2 ) )
47+ return c . json ( response )
48+ } )
4949}
0 commit comments