-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
Jeffrie Budde edited this page Nov 25, 2025
·
1 revision
Each example lives in examples/ and is runnable. Use them as templates. See Getting Started for initial setup.
- What: Minimal STDIO server using
FastMCP::new(...).run(). - Run:
cd examples/basic && cargo run. - Highlight: Logging via
tracing_subscriber::fmt(); good starting point for CLI integrations.
- What: Server-Sent Events transport on
http://127.0.0.1:3000. - Run:
cd examples/sse && cargo run --features sse. - Highlight: Uses
SseTransport::new()+run_sse_server; shows endpoints/mcp/sse(events) and/mcp/message(POST). First event returnsconnectionId; include it in POSTs.
- What: Bidirectional WebSocket transport on
ws://127.0.0.1:3001. - Run:
cd examples/websocket && cargo run --features websocket. - Highlight:
WebSocketTransport::new()+run_websocket_server; server-initiated messages go to current connection unlessmetadata.connectionIdis provided.
- What: Logging + rate limit + bearer auth middleware chain.
- Run:
cd examples/middleware && RUST_LOG=info cargo run. - Highlight: Demonstrates middleware ordering and error handling; tools
greetandcalculateshow validation withMCPError::InvalidParams.
- What: Subscribable resources (
time://current,counter://value,file:///config.json) plus tools to mutate state. - Run:
cd examples/subscriptions && cargo run. - Highlight: Shows subscription lifecycle (
resources/subscribe, notifications,resources/unsubscribe); includes background ticker to simulate updates.
- What: All features in one place (tools, resources, prompts, state, lifecycle hooks).
- Run:
cd examples/complete && cargo run. - Highlights:
- Tools: math (add/multiply/factorial/is_prime), strings (reverse/uppercase/count_words), complex types (
greet_person,calculate_statswith validation). - Resources:
system://info,server://status(uses shared state). - Prompts: code review, docs, bug analysis.
- State:
StateholdsAppConfig; lifecycle hooks initialize/clean up.
- Tools: math (add/multiply/factorial/is_prime), strings (reverse/uppercase/count_words), complex types (
-
fastrmcp new <name> --template basic|sse|websocket|middleware|subscriptions|completemirrors the above examples. - See
fastrmcp-cli/README.mdin the repo.
Related: Transports Guide for client snippets • Middleware Cookbook for extending the middleware example.