Skip to main content
Glama

search_files

Search for files in OneDrive using the Microsoft Graph API by specifying a query and account ID. Retrieve up to a defined number of results for efficient file management.

Instructions

Search for files in OneDrive using the modern search API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_idYes
limitNo
queryYes

Implementation Reference

  • The main execution function for the 'search_files' tool. Decorated with @mcp.tool for automatic registration in FastMCP. Searches OneDrive files using the graph.search_query helper and formats results into a list of dicts with id, name, type, size, modified, download_url.
    @mcp.tool
    def search_files(
        query: str,
        account_id: str,
        limit: int = 50,
    ) -> list[dict[str, Any]]:
        """Search for files in OneDrive using the modern search API."""
        items = list(graph.search_query(query, ["driveItem"], account_id, limit))
    
        return [
            {
                "id": item["id"],
                "name": item["name"],
                "type": "folder" if "folder" in item else "file",
                "size": item.get("size", 0),
                "modified": item.get("lastModifiedDateTime"),
                "download_url": item.get("@microsoft.graph.downloadUrl"),
            }
            for item in items
        ]
  • Supporting utility function graph.search_query that performs the POST to /search/query Microsoft Graph API, handles pagination via 'from' parameter, and yields resource hits. Called by search_files with entity_types=['driveItem'].
    def search_query(
        query: str,
        entity_types: list[str],
        account_id: str | None = None,
        limit: int = 50,
        fields: list[str] | None = None,
    ) -> Iterator[dict[str, Any]]:
        """Use the modern /search/query API endpoint"""
        payload = {
            "requests": [
                {
                    "entityTypes": entity_types,
                    "query": {"queryString": query},
                    "size": min(limit, 25),
                    "from": 0,
                }
            ]
        }
    
        if fields:
            payload["requests"][0]["fields"] = fields
    
        items_returned = 0
    
        while True:
            result = request("POST", "/search/query", account_id, json=payload)
    
            if not result or "value" not in result:
                break
    
            for response in result["value"]:
                if "hitsContainers" in response:
                    for container in response["hitsContainers"]:
                        if "hits" in container:
                            for hit in container["hits"]:
                                if limit and items_returned >= limit:
                                    return
                                yield hit["resource"]
                                items_returned += 1
    
            if "@odata.nextLink" in result:
                break
    
            has_more = False
            for response in result.get("value", []):
                for container in response.get("hitsContainers", []):
                    if container.get("moreResultsAvailable"):
                        has_more = True
                        break
    
            if not has_more:
                break
    
            payload["requests"][0]["from"] += payload["requests"][0]["size"]
  • Creation of the FastMCP server instance 'mcp' to which all tools including search_files are registered via @mcp.tool decorators.
    mcp = FastMCP("microsoft-mcp")
Behavior2/5

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

With no annotations provided, the description carries full burden but only states it uses the 'modern search API' without detailing behavioral traits like pagination, rate limits, authentication requirements, or what happens on errors. It mentions no constraints or side effects beyond the basic operation.

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 zero waste. It's front-loaded with the core action and resource, making it easy to parse quickly without unnecessary elaboration.

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

Completeness2/5

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

Given 3 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It lacks details on authentication, error handling, return format, and parameter usage, which are critical for a search tool with multiple inputs in this context.

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 descriptions. The tool description adds no parameter-specific information beyond implying 'query' is for search terms and 'account_id' targets OneDrive. It doesn't explain format, constraints, or the 'limit' default behavior, leaving gaps in understanding.

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 ('Search') and resource ('files in OneDrive'), and specifies the API method ('modern search API'). It distinguishes from generic file operations but doesn't explicitly differentiate from sibling tools like 'list_files' or 'unified_search'.

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?

No guidance is provided on when to use this tool versus alternatives like 'list_files' (which might list without search) or 'unified_search' (which might search across multiple resource types). The description implies a search context but offers no explicit usage rules or exclusions.

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/elyxlz/microsoft-mcp'

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