Skip to main content
Glama

json_get_value

Retrieve specific values from JSON files using field paths and dot notation, including nested properties and array indices. Requires file path and byte size limit, ensuring secure access within permitted directories.

Instructions

Get a specific value from a JSON file using a field path. Supports dot notation for accessing nested properties and array indices. Requires maxBytes parameter (default 10KB). Returns the value directly, properly formatted. The path must be within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldYesPath to the field to retrieve (e.g., "user.address.city" or "items[0].name")
maxBytesYesMaximum bytes to read from the file. Must be a positive integer. Handler default: 10KB.
pathYesPath to the JSON file

Implementation Reference

  • Main handler function for 'json_get_value' tool. Parses input arguments using the schema, validates and reads the JSON file, extracts the specified field using lodash.get (aliased as getProp), and returns the value as a formatted JSON string in the expected MCP response format. Handles cases where the field is not found.
    export async function handleJsonGetValue( args: unknown, allowedDirectories: string[], symlinksMap: Map<string, string>, noFollowSymlinks: boolean ) { const parsed = parseArgs(JsonGetValueArgsSchema, args, 'json_get_value'); const validPath = await validatePath(parsed.path, allowedDirectories, symlinksMap, noFollowSymlinks); const jsonData = await readJsonFile(validPath, parsed.maxBytes); try { const value = getProp(jsonData, parsed.field); if (value === undefined) { throw new Error(`Field "${parsed.field}" not found in JSON data`); } return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }], }; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get JSON value: ${error.message}`); } throw error; } }
  • TypeBox schema definition for input arguments of json_get_value tool, including path to JSON file, field path (dot notation or JSONPath-like), and optional maxBytes limit.
    export const JsonGetValueArgsSchema = Type.Object({ path: Type.String({ description: 'Path to the JSON file' }), field: Type.String({ description: 'Path to the field to retrieve (e.g., "user.address.city" or "items[0].name")' }), maxBytes: Type.Integer({ minimum: 1, description: 'Maximum bytes to read from the file. Must be a positive integer. Handler default: 10KB.' }) }); export type JsonGetValueArgs = Static<typeof JsonGetValueArgsSchema>;
  • index.ts:285-286 (registration)
    Registers the 'json_get_value' tool handler in the toolHandlers object, binding it to handleJsonGetValue with server context (allowedDirectories, symlinksMap, noFollowSymlinks).
    json_get_value: (a: unknown) => handleJsonGetValue(a, allowedDirectories, symlinksMap, noFollowSymlinks),
  • index.ts:329-329 (registration)
    Declares the tool metadata (name and description) in the allTools array used for MCP server registration.
    { name: "json_get_value", description: "Get value from JSON" },
  • Re-exports the JsonGetValueArgsSchema in the central toolSchemas index for use in server registration.
    json_get_value: JsonGetValueArgsSchema,

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/rawr-ai/mcp-filesystem'

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