Skip to main content
Glama

search_events

Search calendar events within a specified date range using the Microsoft MCP server. Retrieve relevant events by query and account ID, with customizable parameters for days ahead, days back, and result limits.

Instructions

Search calendar events using the modern search API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_idYes
days_aheadNo
days_backNo
limitNo
queryYes

Implementation Reference

  • The handler function implementing the search_events tool logic, including registration via @mcp.tool decorator. Searches events via graph.search_query and applies optional date filtering.
    @mcp.tool
    def search_events(
        query: str,
        account_id: str,
        days_ahead: int = 365,
        days_back: int = 365,
        limit: int = 50,
    ) -> list[dict[str, Any]]:
        """Search calendar events using the modern search API."""
        events = list(graph.search_query(query, ["event"], account_id, limit))
    
        # Filter by date range if needed
        if days_ahead != 365 or days_back != 365:
            now = dt.datetime.now(dt.timezone.utc)
            start = now - dt.timedelta(days=days_back)
            end = now + dt.timedelta(days=days_ahead)
    
            filtered_events = []
            for event in events:
                event_start = dt.datetime.fromisoformat(
                    event.get("start", {}).get("dateTime", "").replace("Z", "+00:00")
                )
                event_end = dt.datetime.fromisoformat(
                    event.get("end", {}).get("dateTime", "").replace("Z", "+00:00")
                )
    
                if event_start <= end and event_end >= start:
                    filtered_events.append(event)
    
            return filtered_events
    
        return events
  • Supporting utility function that performs the actual search query to Microsoft Graph /search/query endpoint, handling pagination and yielding results. Called by search_events.
    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"]
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'modern search API' but doesn't explain what that entails—whether it supports full-text search, filters, sorting, pagination, rate limits, or authentication requirements. For a search tool with 5 parameters, this leaves significant behavioral gaps.

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

Conciseness4/5

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

The description is a single, efficient sentence that gets straight to the point without unnecessary words. It's appropriately sized for a basic tool description, though it could be more informative without sacrificing conciseness.

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?

For a search tool with 5 parameters, 0% schema coverage, no output schema, and no annotations, the description is inadequate. It doesn't explain return values, error conditions, or how parameters interact, leaving the agent with insufficient context to use the tool effectively.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate by explaining parameters. It mentions 'search' but doesn't clarify what 'query' searches (e.g., titles, descriptions, attendees), how date ranges work with 'days_ahead' and 'days_back', or what 'account_id' refers to. The description adds minimal value beyond the bare schema.

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

Purpose3/5

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

The description states the tool searches calendar events using a modern search API, which provides a clear verb ('search') and resource ('calendar events'). However, it doesn't differentiate from sibling tools like 'list_events' or 'unified_search', leaving ambiguity about when to use this specific search tool versus alternatives.

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_events' or 'unified_search'. The description mentions 'modern search API' but doesn't explain what makes it modern or when it's preferable, offering no explicit when/when-not instructions or alternative recommendations.

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