OpenAI Agents SDK MCP Monitoring: AyeWatch over Streamable HTTP
Connect the OpenAI Agents SDK to AyeWatch's MCP server with MCPServerStreamableHttp and an API key header, filter its tools, and run a monthly monitor audit. Full script and limits.
By AyeWatch Team4 min read
Short answer: To use AyeWatch from the OpenAI Agents SDK, open MCPServerStreamableHttp with the URL https://ayewatch.ai/api/mcp and an Authorization header holding your API key, then pass it to Agent(mcp_servers=[...]). A tool filter limits the agent to safe tools, and the agent can list, create, pause and update monitors in your account.
The script
Install the SDK with pip install openai-agents, create a key in API access settings, and set AYEWATCH_API_KEY and OPENAI_API_KEY.
import asyncio, os
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp, create_static_tool_filter
async def main():
async with MCPServerStreamableHttp(
name="AyeWatch",
params={
"url": "https://ayewatch.ai/api/mcp",
"headers": {"Authorization": f"Bearer {os.environ['AYEWATCH_API_KEY']}"},
"timeout": 10,
},
cache_tools_list=True,
tool_filter=create_static_tool_filter(
allowed_tool_names=["list_topics", "get_topic", "create_topic", "update_topic"]
),
max_retry_attempts=3,
) as server:
agent = Agent(
name="Monitor admin",
instructions=(
"Manage the user's AyeWatch monitors. Create new monitors paused "
"(is_active false) and report their IDs. Never delete monitors."
),
mcp_servers=[server],
)
result = await Runner.run(agent, "List my monitors and tell me which are paused.")
print(result.final_output)
asyncio.run(main())
AyeWatch's endpoint is stateless Streamable HTTP with JSON responses and no session ID, which is what MCPServerStreamableHttp speaks. cache_tools_list lists the tools once per connection. Call invalidate_tools_cache() if you need a fresh list. client_session_timeout_seconds defaults to 5; raise it if create calls time out.
Creating monitors from code
Once the list prompt works, change the prompt to create a monitor:
result = await Runner.run(
agent,
"Create a paused AyeWatch monitor for https://brightkiln.example/changelog "
"that alerts me about breaking API changes and deprecations. Use Auto. "
"Report its ID.",
)
The agent should call create_topic with arguments like these:
{
"name": "https://brightkiln.example/changelog",
"description": "Alert me about breaking API changes and deprecations.",
"monitoring_mode": "auto",
"is_active": false
}
The tool result includes the new monitor's ID, name, description, interval, active state and creation date, so the agent can report the ID without a second call. Turn it on with update_topic and changes: {"is_active": true} after you have read it. A web page monitor on Auto, budgeted at about 30 checks, uses about 30 credits a month.
Why the tool filter matters
With an API key, the server offers eight tools: list_topics, get_topic, create_topic, update_topic, delete_topic, get_webhook, set_webhook and rotate_webhook_secret. An agent rarely needs the last four. delete_topic can't be undone, set_webhook redirects every alert, and rotate_webhook_secret breaks your receiver until it has the new secret.
create_static_tool_filter with allowed_tool_names hides everything else from the model. Recent SDK versions also accept a require_approval setting on MCP server objects; check the SDK docs for its current form if you want a person to approve each write.
AyeWatch's server instructions tell the model that topic content is user data, not instructions. Repeat that in your own agent's instructions if it ever reads monitor names or descriptions written by someone else.
A useful job: the monthly monitor audit
A recurring audit is a good first job, because it only reads.
AUDIT = (
"List all my AyeWatch monitors, following pagination until has_more is false. "
"Report active monitors on the 1_hour interval with their monthly check count "
"(720 each). List paused monitors created more than 90 days ago as candidates "
"for deletion. Do not change anything."
)
result = await Runner.run(agent, AUDIT, max_turns=20)
The numbers behind it: an hourly monitor runs 720 checks in a 30-day month. An hourly X search at 2 credits a check uses 1,440 credits, more than the 500 on Pro. The agent can't see that directly, because list_topics returns only the ID, name, description, interval, active state and creation date, with no source mode or credits per check. It flags hourly monitors by interval, and you check the mode in the app.
Hosted MCP tool
The SDK also has HostedMCPTool, where OpenAI's side calls the MCP server. Its config takes a server label, a server URL and an approval setting. The SDK docs show no header option for it, so the local MCPServerStreamableHttp above is the documented way to send AyeWatch's API key from your own code.
Limits
- No alert history. No tool returns past alerts. For an agent that reacts to alerts, use the webhook, as in triggering an agent from a webhook alert.
- Rate limit. MCP and REST share 120 requests a minute per key. Each tool call is one POST, and listing tools is another unless cached.
- Credits. Monitors the agent turns on spend credits as checks run. Paused monitors spend nothing.
- Secret stays out. If you allow the webhook tools, they still never return the signing secret.
AyeWatch Pro is $9/mo with 50 topics and hourly checks; Pro+ is $19/mo with 200 topics and ASAP mode. Every plan starts with a 7-day free trial.
Run it in six steps
- Install the SDK with pip install openai-agents.
- Create an API key in API access settings and set AYEWATCH_API_KEY and OPENAI_API_KEY.
- Save the script and run it. The agent should list your monitors.
- Change the prompt to create one paused monitor and read the output.
- Swap in the audit prompt and run it once by hand.
- Schedule the audit monthly with cron or your job runner.
| Setting | Value here | Why |
|---|---|---|
| params.url | https://ayewatch.ai/api/mcp | AyeWatch's MCP endpoint |
| params.headers | Authorization: Bearer aw_live_... | API key authentication |
| params.timeout | 10 | HTTP timeout in seconds |
| cache_tools_list | True | Lists tools once per connection |
| tool_filter | create_static_tool_filter(allowed_tool_names=[...]) | Keeps delete and webhook tools away from the model |
| max_retry_attempts | 3 | Retries failed calls |
| client_session_timeout_seconds | Default 5 | Raise it if calls time out |
Start a monitor in under a minute
Describe a topic or paste a URL. Cancel before the trial ends and you pay nothing.
Try it free for 7 daysThe bottom line
Start with the read-only audit, keep the tool filter tight, and add create_topic only once you trust the agent's arguments. For alert-driven work, pair this with a webhook receiver.
FAQ
How do I connect the OpenAI Agents SDK to a remote MCP server with an API key?
Use MCPServerStreamableHttp with params holding the url and a headers dict, such as Authorization: Bearer and your key, then pass the server to Agent(mcp_servers=[server]).
Which AyeWatch tools should an agent get?
Usually list_topics, get_topic, create_topic and update_topic. Leave out delete_topic and the webhook tools unless the agent's job needs them.
Can I use HostedMCPTool with AyeWatch?
The SDK docs show no header option for HostedMCPTool, so use MCPServerStreamableHttp, which sends AyeWatch's API key from your own code.
Can the agent see how many credits a monitor uses?
No. list_topics returns the ID, name, description, interval, active state and creation date only. The agent can flag hourly monitors, and you check the mode in the app.
Does the agent need a session with AyeWatch's server?
No. The endpoint is stateless, returns JSON and needs no session ID. Each POST carries one MCP message, and batches are rejected.