Skip to content

Getting Started

Jeffrie Budde edited this page Nov 25, 2025 · 1 revision

Getting Started

Build an MCP server in minutes with FastRMCP.

Install

  • CLI (recommended): cargo install fastrmcp-clifastrmcp new my-server [--template complete|sse|websocket|middleware|subscriptions]
  • Manual: add to Cargo.toml
[dependencies]
fastrmcp = "0.2"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = "0.3"

First Server (tools + resource + prompt)

use fastrmcp::prelude::*;
use fastrmcp_macros::{prompt, resource, tool};

#[tool]
async fn add(a: i64, b: i64) -> Result<i64> { Ok(a + b) }

// URI template parameters map into arguments; Context is optional and injects client/server info
#[resource("echo://{value}")]
async fn echo(value: String, ctx: Context) -> Result<String> {
    ctx.log_info(format!("echo called by {:?}", ctx.client_info)).await.ok();
    Ok(value)
}

#[prompt]
async fn review() -> Result<PromptResult> {
    Ok(PromptResult {
        description: Some("Simple review prompt".into()),
        messages: vec![PromptMessage::user("Please review the provided content.")],
    })
}

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt().init();
    FastMCP::new("my-server").version("0.1.0").description("First FastRMCP server").run().await
}

Run over STDIO:

cargo run
# in another shell
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"cli","version":"1.0.0"}}}' | cargo run

Call a tool:

{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"add","arguments":{"a":2,"b":3}}}

Read a resource:

{"jsonrpc":"2.0","id":3,"method":"resources/read","params":{"uri":"echo://hi"}}

Fetch a prompt:

{"jsonrpc":"2.0","id":4,"method":"prompts/get","params":{"name":"review","arguments":{}}}

Next steps: see Core Concepts for Context/State/registries and Transports Guide for SSE/WS.

Back to Home

Clone this wiki locally