fix(examples): add servers in examples's readme (#229)
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
This commit is contained in:
parent
0ce14186ba
commit
d5a72e43c1
1 changed files with 140 additions and 18 deletions
25
examples/servers/src/counter_stdio.rs
Normal file
25
examples/servers/src/counter_stdio.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use anyhow::Result;
|
||||
use common::counter::Counter;
|
||||
use rmcp::{ServiceExt, transport::stdio};
|
||||
use tracing_subscriber::{self, EnvFilter};
|
||||
mod common;
|
||||
/// npx @modelcontextprotocol/inspector cargo run -p mcp-server-examples --example std_io
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Initialize the tracing subscriber with file and stdout logging
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(EnvFilter::from_default_env().add_directive(tracing::Level::DEBUG.into()))
|
||||
.with_writer(std::io::stderr)
|
||||
.with_ansi(false)
|
||||
.init();
|
||||
|
||||
tracing::info!("Starting MCP server");
|
||||
|
||||
// Create an instance of our counter router
|
||||
let service = Counter::new().serve(stdio()).await.inspect_err(|e| {
|
||||
tracing::error!("serving error: {:?}", e);
|
||||
})?;
|
||||
|
||||
service.waiting().await?;
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Reference in a new issue