6. Adding a new tool
4m

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 for a specific listing to our MCP server
  • See how the Apollo MCP server accounts for 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 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 in the Sandbox Explorer.

The GraphOS Sandbox Explorer running on port 4000

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 a specific listing; it accepts an id of type ID!. If we click beside the listing , the boilerplate for this will automatically be added to the Operation panel.

The Sandbox Operation panel updated with the basic scaffold for a listing query

Let's add all the listing to this . 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 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 as well as fields that return with fields of their own.

The Operation panel updated to show the recursive field selection option in the fields dropdown

That's quite a ! Let's rename it to GetListing, and copy the before jumping back into our server code.

The GetListing query
query GetListing($listingId: ID!) {
listing(id: $listingId) {
id
title
description
photoThumbnail
photoInHexagonShape
numOfBeds
costPerNight
locationType
host {
id
}
amenities {
id
category
name
}
coordinates {
latitude
longitude
nickname
}
}
}

Adding the operation

Back in our project directory, we'll add another file called listing.graphql.

πŸ“‚ odyssey-apollo-mcp
┣ πŸ“‚ operations
┃ ┣ πŸ“„ featuredListings.graphql
+ ┃ β”— πŸ“„ listing.graphql
β”— πŸ“„ supergraph.yaml

Create the file, then paste in the 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 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!

A screenshot of the MCP Inspector, reflecting two tools in the List

Note: If you're not seeing the new GetListing , 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 to run this . Inside of the box is a description for what kind of value should be provided.

The MCP Inspector, highlighting the new input field for a listing ID

Let's stick in the value listing-3 and run the tool. And...wahoo! Lots of good data.

The MCP Inspector, showing a successful response for listing-3

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.

The Claude interface, showing the airlock tools updated now to include GetListing

Let's reenact that conversation from earlier. We'll start off with the same question about those featured listings we saw earlier.

Starting the conversation
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.

A follow-up for Claude
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!

The Claude interface, showing the modal asking 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 .

The Claude interface, showing how the listing ID was automatically inserted into the request

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.

Requesting more detail
What more can you tell me about the host?

The Claude interface, responding to our question about the host

There's not much here Claude can tell us about the host of the listing; and that's because the only available to from the listings API is a host's id. There's simply no other information available in our .

The listings schema
# ... other types and fields
type 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

What information did Claude use to request more data about a specific listing?

Key takeaways

  • To add a new to our MCP server, we create a new file that contains the 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

beta
. Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.

You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.