Skip to main content
Glama

Rust MCP Filesystem

tail_file.rs1.39 kB
use std::path::Path; use rust_mcp_sdk::{ macros::{JsonSchema, mcp_tool}, schema::{CallToolResult, TextContent, schema_utils::CallToolError}, }; use crate::fs_service::FileSystemService; // tail_file #[mcp_tool( name = "tail_file", title="Tail file", description = concat!("Reads and returns the last N lines of a text file.", "This is useful for quickly previewing file contents without loading the entire file into memory.", "If the file has fewer than N lines, the entire file will be returned.", "Only works within allowed directories."), destructive_hint = false, idempotent_hint = false, open_world_hint = false, read_only_hint = true )] #[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug, JsonSchema)] pub struct TailFile { /// The path of the file to get information for. pub path: String, /// The number of lines to read from the beginning of the file. pub lines: u64, } impl TailFile { pub async fn run_tool( params: Self, context: &FileSystemService, ) -> std::result::Result<CallToolResult, CallToolError> { let result = context .tail_file(Path::new(&params.path), params.lines as usize) .await .map_err(CallToolError::new)?; Ok(CallToolResult::text_content(vec![TextContent::from( result, )])) } }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rust-mcp-stack/rust-mcp-filesystem'

If you have feedback or need assistance with the MCP directory API, please join our Discord server