ferro_api_mcp/server.rs
1use crate::service::ApiMcpService;
2use rmcp::ServiceExt;
3
4/// MCP server that runs the API service over stdio transport.
5pub struct McpServer {
6 service: ApiMcpService,
7}
8
9impl McpServer {
10 pub fn new(service: ApiMcpService) -> Self {
11 Self { service }
12 }
13
14 /// Start the MCP server on stdin/stdout.
15 ///
16 /// Stdout is the MCP JSON-RPC transport; all diagnostic output
17 /// must go to stderr (via tracing or eprintln).
18 pub async fn run(self) -> Result<(), Box<dyn std::error::Error>> {
19 let stdin = tokio::io::stdin();
20 let stdout = tokio::io::stdout();
21
22 let server = self.service.serve((stdin, stdout)).await?;
23 server.waiting().await?;
24
25 Ok(())
26 }
27}