Overview
We've got one tool added to Claude's toolbox. But as far as questions about Airlock go, Claude is always going to have to rely on the same tool to solve every problem. Let's fix that with a brand new tool.
In this lesson, we will:
- Add an operation for a specific listing to our MCP server
- See how the Apollo MCP server accounts for query inputs
- Run Claude to find out more information about a particular listing
Back to Sandbox
We've given our assistant the ability to find out about featured listings, but what if we want to learn more about a specific listing? We'll start by building the query that makes fetching that data possible.
The rover dev
process we started in our MCP server should still be running. (If not, start that up now!) Let's return to http://localhost:4000
to build a new query in the Sandbox Explorer.
Let's click the plus button (+) at the top of the Operation panel to start fresh with a new tab.
Next, in the Documentation panel, we'll find that our Query
type defines an entrypoint that lets us query a specific listing
; it accepts an argument id
of type ID!
. If we click beside the listing
field, the boilerplate for this query will automatically be added to the Operation panel.
Let's add all the listing fields to this query. A more robust query will allow our assistant to provide as much information as possible about a particular listing when a user asks about it.
To add all the fields to the Operation panel, click on the arrow dropdown beside the Fields header. From this menu, click Select all fields recursively. This will take care of adding scalar fields as well as fields that return object types with fields of their own.
That's quite a query! Let's rename it to GetListing
, and copy the operation before jumping back into our server code.
query GetListing($listingId: ID!) {listing(id: $listingId) {idtitledescriptionphotoThumbnailphotoInHexagonShapenumOfBedscostPerNightlocationTypehost {id}amenities {idcategoryname}coordinates {latitudelongitudenickname}}}
Adding the operation
Back in our project directory, we'll add another operation file called listing.graphql
.
π odyssey-apollo-mcpβ£ π operationsβ β£ π featuredListings.graphql+ β β π listing.graphqlβ π supergraph.yaml
Create the file, then paste in the operation we copied. Now let's return to the terminal.
Locate the window where your rover dev
process is running, and stop it now. We'll append our new operation file, listing.graphql
, and restart it.
rover dev --supergraph-config ./supergraph.yaml \--mcp --mcp-operations ./operations/featuredListings.graphql ./operations/listing.graphql
When that process finishes, we'll return to the browser where the MCP Inspector is running. We don't have to restart the process, but we should reconnect the Inspector to our running server so it picks up the updates. Refresh the browser, then click the Connect button.
Now, under List Tools, we should see both GetFeaturedListings
and GetListing
!
Note: If you're not seeing the new GetListing
operation, try doing a hard refresh on http://127.0.0.1:6274
before reconnecting the server.
Test run: listing tool
If we click into the GetListing
tool, we'll see the same kind of information as before, with one key difference. Just above the Run Tool button, we'll find an input for listingId
: the required argument to run this query. Inside of the box is a description for what kind of value should be provided.
Let's stick in the value listing-3
and run the tool. And...wahoo! Lots of good data.
Now that we've tested it out, let's go for the real thing and equip Claude with our new tool.
Configuring Claude
Returning to Claude, the only thing we need to do here is restart the application!
When we restart Claude, we can confirm that our new tool has been added to the assistant's dashboard.
Let's reenact that conversation from earlier. We'll start off with the same question about those featured listings we saw earlier.
What are the featured listings today?
Again, we'll be prompted to permit Claude to run our tool; click Allow once in the modal. Claude will summarize those three featured listings for us, just like it did before.
Now for the cool partβlet's pick one of these listings and ask a follow-up question.
Can you tell me about the location and host of the Repurposed Aircraft Spaceship?
Now Claude puts together its plan to use a different tool: we'll see a modal again, this time asking us for permission to use the GetListing
tool!
Let's Allow once and see what happens next.
As Claude processes, we'll see that part of the parameters for this request included the particular ID of the listing that we asked about. Take note that we, as the users, didn't have to provide the id
itself! And in a real-world scenario, we definitely wouldn't expect customers to provide a listing's ID just to get more information about it. Claude was able to deduce which listing we wanted more information about, and automatically inserted its id
value to make the complete query.
As a result, we as users can keep our conversation natural and goal-oriented. The assistant, along with the tools we've equipped it with, takes care of the rest!
Follow-up question
What happens if we ask for some more information about this listing that falls outside of the API's domain?
Let's try it with a new question.
What more can you tell me about the host?
There's not much here Claude can tell us about the host of the listing; and that's because the only field available to query from the listings API is a host's id
. There's simply no other information available in our API schema.
# ... other types and fieldstype Host @key(fields: "id", resolvable: false) {id: ID!}
Let's add some more information to our APIβby introducing a whole new data source, all about users.
Practice
Key takeaways
- To add a new operation to our MCP server, we create a new file that contains the GraphQL operation then include it in the list passed to the
--mcp-operations
flag. - Claude can automatically supply parameters to tools, such as a listing's
id
, to request more specific information.
Up next
Let's equip our MCP server with a whole new API about users.
Share your questions and comments about this lesson
This course is currently in
You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.