Generate GraphQL queries with the MCP server
Ask a coding agent connected to the Azion observe MCP server for a GraphQL query that answers a data goal, then run the query with the GraphQL API.
You can ask a coding agent connected to the observe server of the Azion MCP servers for a GraphQL API query that answers a goal, such as the traffic of your workloads by location or the cache status of your images. You then run the query with the GraphQL API and read the rows it returns. To write and run a query without an agent, refer to GraphQL API quickstart.
Prerequisites
- A coding agent connected to the observe server,
https://observe-mcp.azion.com/mcp. To connect one, refer to MCP server quickstart. - A personal token, to run the query with the GraphQL API. To create one, refer to Personal tokens.
Generate a query with your agent
The observe server writes queries with its create_graphql_query tool. The tool takes two inputs: query, the goal in plain words, and dataSource, the data the query reads. A language model writes the query, and the tool runs it against the GraphQL API of your account, with your token, to validate it. These validation queries only read data. To generate a query:
Describe the data you want, the time window, and how to group the rows. Name the data source the goal reads: real-time-metrics, real-time-events, accounting, or consumption. The agent adjusts the date ranges and filters to your requirements.
The tool returns a query that runs on your account, or this text when no attempt produces one:
The text then points to the GraphQL API documentation. A language model writes each query, so two calls with the same goal can return different queries. When the tool returns this text, refer to Troubleshoot the MCP server.
Send the query to the GraphQL API endpoint of its dataset with your personal token, or paste it into GraphiQL. For both routes, refer to GraphQL API quickstart and GraphiQL Playground.
The data key of the response holds one array per dataset, with one object per row. For what each field carries, refer to Real-Time Metrics fields and Real-Time Events fields.
The response carries the rows that answer your goal. The two sections that follow each give a goal, the request to the agent, and a query that answers it, so you can check a proposal or run the query when the tool returns no query.
Query the traffic of your workloads by location
This goal asks for the requests of the last seven days, grouped by the Azion location that received them. Ask your agent:
A query that answers this goal reads workloadMetrics, a metrics dataset, so it runs on the metrics endpoint, https://api.azion.com/v4/metrics/graphql. It adds up requests per sourceLocPop, the location of the Azion server that received the request, and returns up to 10 locations, the ones with the most requests first. Before you run it, replace the two tsRange dates with the last seven days:
The endpoint returns HTTP 200 and one row per location, with the request total in sum. The response below is cut after the third row:
Query the cache status of your images
This goal asks how the cache answered requests for image files. Ask your agent:
A query that answers this goal reads workloadEvents, an events dataset, so it runs on the events endpoint, https://api.azion.com/v4/events/graphql. It keeps the requests whose URI matches %.jpg, %.png, or %.webp in requestUriLike, and counts them per upstreamCacheStatus. Events datasets keep records for about seven days, so replace the tsRange dates with a window inside the last week:
The endpoint returns HTTP 200 and one row per cache status, with the request count in count. The response holds:
Compare the count of each status with the total of all rows. For every status value of upstreamCacheStatus, such as HIT and MISS, refer to Real-Time Events fields.