Skip to content

Conversation

@asararatnakar
Copy link
Collaborator

Description

This snippet shows how to use prescribed tool using @tool directive to define operations with descriptions.
also demonstrates how these descriptions help create MCP tools that AI models can understand and use.

Ratnakar Asara added 2 commits November 4, 2025 10:54
Signed-off-by: Ratnakar Asara <rasara@us.ibm.com>
Signed-off-by: Ratnakar Asara <rasara@us.ibm.com>
Copy link
Contributor

@ddebrunner ddebrunner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice snippet, I think some minor cleanup to better introduce the concept, as it's totally new.

@@ -0,0 +1,110 @@
# Prescribed Tools with Descriptions

This sample demonstrates how to use the `@tool` directive with prescribed operations that contains descriptions that can be used through to create MCP (Model Context Protocol) tools.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"prescribed tools"
"persisted operations"

are the terms

Not "prescribed operations"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to qualify "operation" as "GraphQL operation" (with a link to the spec) as the first mention.


## Overview

The sample implements a mock weather service API with a simple operations, Weather forecast for a city
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"simple operations"

Remove "simple", and there's only a single operation right?

- The `@sdl` directive that includes persisted operations

2. An operations file (`operations.graphql`) that contains:
- Documented GraphQL operations with descriptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Documented ... with descriptions" is redundant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a single operation though?

# Prescribed Tools with Descriptions

This sample demonstrates how to use the `@tool` directive with prescribed operations that contains descriptions that can be used through to create MCP (Model Context Protocol) tools.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an overview of what a "prescribed tool" is would be essential at this point.

)
```

The operation itself can include descriptions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "(new to GraphQL September 2025)"

@@ -0,0 +1,183 @@
schema
@sdl(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a useful comment

files: []
executables: [{ document: "operations.graphql", persist: true }]
)
@tool(name: "weather-lookup", prescribed: "WeatherForecast") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a useful comment

},
forecast: [
{
date: forecastDates[0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test is subject to failure if it's run around midnight

@ddebrunner
Copy link
Contributor

@asararatnakar Can you "refactor" this a little to just be how to define a prescribed tool, and drop the mentions of "with descriptions (i.e. put it in executables/prescribed folder, update readme and anywhere else that is needed).

I think this is the way we want to encourage prescribed tool definitions, thus the "with descriptions" is not really important, though it is important that we show operations having descriptions.

Then in the future I could see a "with descriptions" variant, that shows how descriptions in @tool can be used to provide LLM specific descriptions if the operation's descriptions are insufficient.

Signed-off-by: Ratnakar Asara <rasara@us.ibm.com>
Copy link
Contributor

@ddebrunner ddebrunner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GTG - the link to persisted docs in the spec is wrong though

@@ -0,0 +1,141 @@
# Prescribed Tools

A **prescribed tool** is a tool that maps to a specific [GraphQL operation](https://spec.graphql.org/September2025/#sec-Language.Operations) in a [persisted document](https://spec.graphql.org/September2025/#sec-Persisted-Documents). The `@tool(prescribed:)` argument links the tool definition to an operation name in a persisted document. This approach provides a structured way to expose specific GraphQL operations as tools that can be called by AI models.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

persisted document is not a GraphQL spec concept, at least not that spec, maybe a reference to the persisted snippet.

@asararatnakar asararatnakar merged commit 448aba6 into stepzen-dev:main Nov 5, 2025
1 check passed
@asararatnakar asararatnakar deleted the tools-with-descriptions branch November 12, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants