Skip to main content
Glama

Read Shelf File

read_shelf_file
Read-only

Retrieve a specific file from a Shelv shelf by providing the shelf identifier and file path to access its contents.

Instructions

Read a single file from a shelf

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
shelf_idYes
pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
bytesYes
contentYes
shelf_idYes
truncatedYes
content_typeYes

Implementation Reference

  • The main handler function that executes the read_shelf_file tool. It validates the path, creates a client, retrieves the file content, truncates if necessary, and returns the result with metadata including content type, bytes, and truncation status.
    async (input, extra) => {
      try {
        const normalizedPath = ensureRelativePath(input.path);
        const apiKey = context.getApiKey(extra);
        const client = context.createShelvClient(apiKey);
        const raw = await client.getFile(input.shelf_id, normalizedPath);
    
        const truncated = truncateUtf8(raw, context.config.readMaxBytes);
    
        return successResult(
          truncated.truncated
            ? `Read ${normalizedPath} (truncated to ${truncated.bytes} bytes)`
            : `Read ${normalizedPath}`,
          {
            shelf_id: input.shelf_id,
            path: normalizedPath,
            content_type: inferContentType(normalizedPath),
            content: truncated.value,
            bytes: truncated.bytes,
            truncated: truncated.truncated,
          },
        );
      } catch (error) {
        return errorResult(error);
      }
    },
  • Schema definitions for the read_shelf_file tool. Input schema requires shelf_id and path strings. Output schema defines the structure of the response including shelf_id, path, content_type, content, bytes, and truncated flag.
    const inputSchema = {
      shelf_id: z.string().min(1),
      path: z.string().min(1),
    };
    
    const outputSchema = {
      shelf_id: z.string(),
      path: z.string(),
      content_type: z.string(),
      content: z.string(),
      bytes: z.number(),
      truncated: z.boolean(),
    };
  • The registerReadShelfFileTool function that registers the tool with the MCP server, defining its title, description, input/output schemas, and annotations (readOnlyHint). This function is exported and called from the tools index.
    export function registerReadShelfFileTool(
      server: McpServer,
      context: ToolContext,
    ): void {
      server.registerTool(
        "read_shelf_file",
        {
          title: "Read Shelf File",
          description: "Read a single file from a shelf",
          inputSchema,
          outputSchema,
          annotations: { readOnlyHint: true },
        },
        async (input, extra) => {
          try {
            const normalizedPath = ensureRelativePath(input.path);
            const apiKey = context.getApiKey(extra);
            const client = context.createShelvClient(apiKey);
            const raw = await client.getFile(input.shelf_id, normalizedPath);
    
            const truncated = truncateUtf8(raw, context.config.readMaxBytes);
    
            return successResult(
              truncated.truncated
                ? `Read ${normalizedPath} (truncated to ${truncated.bytes} bytes)`
                : `Read ${normalizedPath}`,
              {
                shelf_id: input.shelf_id,
                path: normalizedPath,
                content_type: inferContentType(normalizedPath),
                content: truncated.value,
                bytes: truncated.bytes,
                truncated: truncated.truncated,
              },
            );
          } catch (error) {
            return errorResult(error);
          }
        },
      );
    }
  • Import and registration of the read_shelf_file tool in the main tools index. The registerReadShelfFileTool is imported and called within the registerShelvTools function to initialize the tool.
    import { registerReadShelfFileTool } from "./read-shelf-file";
    import { registerSearchShelfTool } from "./search-shelf";
    
    export function registerShelvTools(
      server: McpServer,
      context: ToolContext,
    ): void {
      registerListShelvesTool(server, context);
      registerGetShelfTreeTool(server, context);
      registerReadShelfFileTool(server, context);
  • The truncateUtf8 helper function used by read_shelf_file to limit output size. It uses binary search to efficiently truncate UTF-8 content to a maximum byte size while preserving valid UTF-8 encoding.
    export function truncateUtf8(
      content: string,
      maxBytes: number,
    ): { value: string; truncated: boolean; bytes: number } {
      const totalBytes = Buffer.byteLength(content, "utf8");
      if (totalBytes <= maxBytes) {
        return { value: content, truncated: false, bytes: totalBytes };
      }
    
      let low = 0;
      let high = content.length;
      while (low < high) {
        const mid = Math.ceil((low + high) / 2);
        const candidateBytes = Buffer.byteLength(content.slice(0, mid), "utf8");
        if (candidateBytes <= maxBytes) {
          low = mid;
        } else {
          high = mid - 1;
        }
      }
    
      const value = content.slice(0, low);
      return {
        value,
        truncated: true,
        bytes: Buffer.byteLength(value, "utf8"),
      };
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations declare readOnlyHint=true, indicating a safe read operation, which the description aligns with by using 'Read'. The description adds minimal context beyond this, not detailing aspects like rate limits, authentication needs, or file format handling. With annotations covering the safety profile, a baseline score is appropriate, as the description adds little extra behavioral insight.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words, clearly front-loaded with the core action. It's appropriately sized for the tool's simplicity, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has annotations (readOnlyHint) and an output schema (which handles return values), the description's minimalism is somewhat acceptable. However, for a tool with 2 parameters and 0% schema coverage, it lacks details on parameter meanings and usage context, making it incomplete for full agent understanding without relying heavily on structured fields.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the schema provides no parameter details. The description mentions 'shelf' and 'file' but doesn't explain what 'shelf_id' or 'path' mean, their formats, or examples. It adds minimal semantic value beyond the schema, resulting in a baseline score due to incomplete compensation for the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Read' and the resource 'a single file from a shelf', making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_shelf_tree' or 'search_shelf', which might also involve reading shelf data, so it misses full sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives such as 'get_shelf_tree' for browsing or 'search_shelf' for finding files. It lacks any context on prerequisites, exclusions, or comparisons, leaving usage unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

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/shelv-dev/shelv-mcp'

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