-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmain.rs
More file actions
54 lines (47 loc) · 1.69 KB
/
Copy pathmain.rs
File metadata and controls
54 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
mod handler;
mod tools;
use handler::MyServerHandler;
use rust_mcp_sdk::schema::{
Implementation, InitializeResult, ServerCapabilities, ServerCapabilitiesTools,
LATEST_PROTOCOL_VERSION,
};
use rust_mcp_sdk::{
error::SdkResult,
mcp_server::{server_runtime, ServerRuntime},
McpServer, StdioTransport, TransportOptions,
};
#[tokio::main]
async fn main() -> SdkResult<()> {
// STEP 1: Define server details and capabilities
let server_details = InitializeResult {
// server name and version
server_info: Implementation {
name: "Hello World MCP Server".to_string(),
version: "0.1.0".to_string(),
},
capabilities: ServerCapabilities {
// indicates that server support mcp tools
tools: Some(ServerCapabilitiesTools { list_changed: None }),
..Default::default() // Using default values for other fields
},
meta: None,
instructions: Some("server instructions...".to_string()),
protocol_version: LATEST_PROTOCOL_VERSION.to_string(),
};
// STEP 2: create a std transport with default options
let transport = StdioTransport::new(TransportOptions::default())?;
// STEP 3: instantiate our custom handler for handling MCP messages
let handler = MyServerHandler {};
// STEP 4: create a MCP server
let server: ServerRuntime = server_runtime::create_server(server_details, transport, handler);
// STEP 5: Start the server
if let Err(start_error) = server.start().await {
eprintln!(
"{}",
start_error
.rpc_error_message()
.unwrap_or(&start_error.to_string())
);
};
Ok(())
}