Persisted queries
Another way to secure the MCP server is to use a safelist of persisted queries as tools for your MCP server.
With persisted queries, clients can send operation identifiers instead of full operations. Additionally, we can configure a safelist of IDs to allow, configured in GraphOS. When you enable safelisting, the router rejects any incoming operations not registered in its persisted query list.
The MCP server can then execute an operation by providing its persisted query ID instead of the entire operation string.
Requesting by ID can significantly reduce latency and bandwidth usage for large operation strings.
Exercise 2: Persisted queries (⏳ 5 min)
Goal: Configure the MCP server to use GraphOS-managed persisted queries as the source for tools. Configure the router to only allow queries that are in the persisted query safelist.
Steps
Configure the MCP server to use GraphOS-managed persisted queries as the source for tools.
mcp.yamloperations:source: uplinkConfigure the router to enable persisted queries.
graph/router.yamlpersisted_queries:enabled: trueRestart the
rover devprocess to pick up the changes. You'll see more new tools load in. Test this new source using MCP Inspector.
Try to run an operation using the execute tool:
query {featuredListings {title}}
The router still accepts it.
Configure the router to only allow queries that are in the persisted query safelist.
graph/router.yamlpersisted_queries:enabled: truesafelist:enabled: true # Router will reject any operations that are not registered in the persisted queries listlog_unknown: true # Router will log any operations that are not registered in the persisted queries listapq:enabled: false # to enable safelist, APQs must be disabledTest this new configuration using MCP Inspector. Use the
executetool and run the same query as before. The router now rejects it.