Skip to main content
Glama
rawr-ai

Filesystem MCP Server

xml_query

Extract specific data from large XML files using XPath 1.0 queries, efficiently searching elements, attributes, and text content without loading the entire file into memory.

Instructions

Query XML file using XPath expressions. Provides powerful search capabilities without reading the entire file into memory. Supports standard XPath 1.0 query syntax for finding elements, attributes, and text content. Requires maxBytes parameter (default 10KB). Can be used to extract specific data from large XML files with precise queries. The path must be within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
includeAttributesNoWhether to include attribute information in the results
maxBytesYesMaximum bytes to read from the file. Must be a positive integer. Handler default: 10KB.
pathYesPath to the XML file to query
queryNoXPath query to execute against the XML file
structureOnlyNoIf true, returns only tag names and structure instead of executing query

Implementation Reference

  • Main handler function for the 'xml_query' tool. Validates input args using schema, checks path permissions, reads XML file, processes it with XPath query or structure analysis, handles response size limits, and returns formatted results.
    export async function handleXmlQuery(
      args: unknown,
      allowedDirectories: string[],
      symlinksMap: Map<string, string>,
      noFollowSymlinks: boolean
    ): Promise<{ content: Array<{ type: string; text: string }> }> {
      const parsed = parseArgs(XmlQueryArgsSchema, args, 'xml_query');
    
      const validPath = await validatePath(
        parsed.path,
        allowedDirectories,
        symlinksMap,
        noFollowSymlinks
      );
    
      try {
        const xmlContent = await fs.readFile(validPath, 'utf8');
    
        try {
          const responseLimit =
            (parsed as any).maxResponseBytes ?? parsed.maxBytes ?? 200 * 1024; // 200KB default
          const result = processXmlContent(
            xmlContent,
            parsed.query,
            parsed.structureOnly,
            parsed.includeAttributes,
            responseLimit
          );
          return result;
        } catch (err) {
          const errorMessage = err instanceof Error ? err.message : String(err);
          throw new Error(`Failed to process XML: ${errorMessage}`);
        }
      } catch (err) {
        const errorMessage = err instanceof Error ? err.message : String(err);
        throw new Error(`Failed to query XML file: ${errorMessage}`);
      }
    }
  • TypeBox schema definition for 'xml_query' tool input parameters, including path to XML, optional XPath query, structure-only flag, response size limits, and attribute inclusion.
    export const XmlQueryArgsSchema = Type.Object({
      path: Type.String({ description: 'Path to the XML file to query' }),
      query: Type.Optional(Type.String({ description: 'XPath query to execute against the XML file' })),
      structureOnly: Type.Optional(Type.Boolean({ default: false, description: 'If true, returns only tag names and structure instead of executing query' })),
      maxBytes: Type.Optional(Type.Integer({
        minimum: 1,
        description: '[Deprecated semantics] Previously limited file bytes read; now treated as a response size cap in bytes.'
      })),
      maxResponseBytes: Type.Optional(Type.Integer({
        minimum: 1,
        description: 'Maximum size, in bytes, of the returned content. Parsing reads full file; response may be truncated to respect this limit.'
      })),
      includeAttributes: Type.Optional(Type.Boolean({ default: true, description: 'Whether to include attribute information in the results' }))
    });
    export type XmlQueryArgs = Static<typeof XmlQueryArgsSchema>;
  • index.ts:257-258 (registration)
    Maps the 'xml_query' tool name to the handleXmlQuery execution function in the central toolHandlers object, passing server context like allowed directories.
    xml_query: (a: unknown) =>
      handleXmlQuery(a, allowedDirectories, symlinksMap, noFollowSymlinks),
  • index.ts:321-321 (registration)
    Includes 'xml_query' in the allTools array with its name and description, used to conditionally register tools based on permissions before adding to the MCP server.
    { name: "xml_query", description: "Query XML" },
  • Re-exports and maps the XmlQueryArgsSchema to 'xml_query' key in the central toolSchemas object, imported and used in index.ts for tool parameter schemas.
    xml_query: XmlQueryArgsSchema,
Behavior4/5

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

With no annotations provided, the description carries the full burden and does well by disclosing key behavioral traits: powerful search without reading entire files into memory, support for XPath 1.0 syntax, default maxBytes of 10KB, and path restrictions. It doesn't cover error handling, performance characteristics, or output format details.

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 efficiently structured with 4 sentences that each add value: states purpose, explains capabilities, specifies parameter requirement, and provides usage context. No wasted words, and key information is front-loaded.

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?

For a query tool with 5 parameters, no annotations, and no output schema, the description is adequate but has gaps. It covers the core functionality and constraints well, but doesn't describe what the output looks like (structure, format, error cases) or provide examples of effective XPath queries.

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 100%, so the schema already documents all 5 parameters thoroughly. The description adds minimal value beyond the schema - it mentions the maxBytes parameter and default, but doesn't provide additional semantic context about how parameters interact or affect results.

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

Purpose5/5

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

The description clearly states the tool's purpose: 'Query XML file using XPath expressions' with specific capabilities like finding elements, attributes, and text content. It distinguishes from siblings like xml_structure (structure analysis) and xml_to_json_string (format conversion) by emphasizing search/extraction functionality.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: for extracting specific data from large XML files with precise queries. It mentions the requirement for paths within allowed directories, but doesn't explicitly state when NOT to use it or name alternatives like xml_structure for structural analysis.

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

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

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