this repo has no description
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

mcp_server: keep also stdio transport

Both are supported after all (see https://modelcontextprotocol.io/docs/concepts/architecture)

authored by

mseri.me and committed by
Anil Madhavapeddy
3ce7cd82 37c41d48

+38
+36
lib/mcp_server.ml
··· 435 435 436 436 let log_warning ex = Logs.warn (fun f -> f "%a" Eio.Exn.pp ex) 437 437 438 + (** run the server using http transport *) 438 439 let run_server ?(port = 8080) ?(on_error = log_warning) env server = 439 440 let net = Eio.Stdenv.net env in 440 441 let addr = `Tcp (Eio.Net.Ipaddr.V4.loopback, port) in ··· 451 452 Log.infof "MCP HTTP Server listening on http://localhost:%d" port; 452 453 453 454 Cohttp_eio.Server.run server_socket server_spec ~on_error 455 + 456 + (** run the server using the stdio transport *) 457 + let run_sdtio_server env server = 458 + let stdin = Eio.Stdenv.stdin env in 459 + let stdout = Eio.Stdenv.stdout env in 460 + 461 + Log.debugf "Starting MCP server: %s v%s" (name server) (version server); 462 + Log.debugf "Protocol version: %s" (protocol_version server); 463 + 464 + (* Enable exception backtraces *) 465 + Printexc.record_backtrace true; 466 + 467 + let buf = Eio.Buf_read.of_flow stdin ~initial_size:100 ~max_size:1_000_000 in 468 + 469 + (* Main processing loop *) 470 + try 471 + while true do 472 + Log.debug "Waiting for message..."; 473 + let line = Eio.Buf_read.line buf in 474 + 475 + (* Process the input and send response if needed *) 476 + match process_input_line server line with 477 + | Some response -> send_response stdout response 478 + | None -> Log.debug "No response needed for this message" 479 + done 480 + with 481 + | End_of_file -> 482 + Log.debug "End of file received on stdin"; 483 + () 484 + | Eio.Exn.Io _ as exn -> 485 + Log.errorf "I/O error while reading: %s" (Printexc.to_string exn); 486 + () 487 + | exn -> 488 + Log.errorf "Exception while reading: %s" (Printexc.to_string exn); 489 + ()
+2
mcp.opam
··· 9 9 "dune" {>= "3.17"} 10 10 "ocaml" {>= "5.2.0"} 11 11 "jsonrpc" 12 + "http" 13 + "cohttp-eio" 12 14 "eio_main" 13 15 "eio" 14 16 "odoc" {with-doc}