# Read a calendar with Pydantic AI and Pear MCP

Give a Python agent three calendar lookup tools, then check one day of iCloud or Outlook events against your calendar.

[Canonical walkthrough](https://pearmcp.com/use-cases/pydantic-ai-calendar)

## Before you start

- A private Python environment with pydantic-ai installed and credentials for a model you can already use. Set AGENT_MODEL to its provider-qualified model name.
- Connect one iCloud or Microsoft 365 calendar in Pear. Create a project API key in Settings and load it into PEAR_API_KEY in the server process.
- Choose a day with a known event and a calendar you can open in Apple Calendar or Outlook.

## 1. Limit the agent to calendar reads

Pydantic AI can filter its MCP toolset before each model step. This script makes only account status, calendar discovery and event listing available to the model. Run it locally and enter your request at the prompt.

```python
import os
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPToolset

pear = MCPToolset(
    "https://pearmcp.com/api/mcp",
    headers={"Authorization": f"Bearer {os.environ['PEAR_API_KEY']}"},
)
reads = {"pear_provider_status", "pear_list_calendars", "pear_list_events"}
agent = Agent(
    os.environ["AGENT_MODEL"],
    toolsets=[pear.filtered(lambda ctx, tool: tool.name in reads)],
)
print(agent.run_sync(input("Calendar request: ")).output)
```

> Call pear_provider_status and pear_list_calendars. Which calendars can this account read?

Match the account and calendar names to your source app. Keep the results in the private terminal.

## 2. Check one day of events

Run the script again. Give the calendar name, date and timezone in the same request so the agent can resolve the calendar on this run.

> Using my Work calendar, list the events on 30 November 2026 in Australia/Sydney. Include start and end times, and identify all-day events separately. Say if a calendar read fails.

Substitute your calendar and date. Compare one known event, including the local start time, with Apple Calendar or Outlook before relying on the summary.

## Troubleshooting

**The Python import fails** — Use a Pydantic AI release that documents MCPToolset. Check which Python interpreter runs the script and install pydantic-ai into that environment.

**A known event is missing** — Check which account owns the event, whether the calendar appeared in discovery and which timezone the date range used.

The SDK documents this connection method. A live Pear account test with Pydantic AI is pending. Calendar details returned to the agent go to the model provider you configure. Revoke the project key in Pear when you retire the script.

[How Pear handles your data](https://pearmcp.com/data-handling)

- [Pydantic AI MCP client documentation](https://pydantic.dev/docs/ai/mcp/client/)
- [Pydantic AI toolset filters](https://pydantic.dev/docs/ai/tools-toolsets/toolsets/#filtering-tools)
- [Connect another agent SDK](https://pearmcp.com/guides/developer-sdks)
- [Compare work and personal calendars](https://pearmcp.com/use-cases/work-personal-calendar)
