> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/guides-and-quickstarts/using-tools-and-actions/mcp-tools-in-an-agent.md).

# MCP tools in an agent

Model Context Protocol (MCP) servers make external tools available to an agent. An agent can use those tools to retrieve information or perform actions while answering a request.

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2Frm1axa1Lt3J23crsTPpP%2FG051.mp4?alt=media&token=f53669cc-5a9a-4332-a6c1-8de53e10ce0e>" %}

## Before you start

Open an editable agent. For a catalog server, have an account with the required provider access. For a custom server, obtain its endpoint, authentication requirements, and required headers from its owner before setup. Review [Give an agent tools](/guides-and-quickstarts/agent-builder-and-skills/give-an-agent-tools.md) for the agent-side tool configuration.

## Describe how the agent should use tools

Give the agent a clear instruction for when to use the external tools.

![Agent tool use instructions](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/ikZ0Z92EIgIPsj8zaXGg/assets/g051-g051-01-prompt.png)

State whether it should only retrieve information or may also change records.

## Connect a catalog MCP server

In MCP Servers, add the required catalog integration.

![Catalog MCP server connection](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/cUyVy4YMGliaCa0wXt4j/assets/g051-g051-02-catalog.png)

A catalog entry identifies the service but does not by itself authorize an account.

Complete the provider authorization with the intended account.

![Catalog MCP server connection](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/63yEXgPve5gBwAaaQWX6/assets/g051-g051-03-consent.png)

Review the requested access before making the server available to the agent.

Inspect the server's available tools and connection mode.

![Catalog MCP server connection](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/UlMzdNHWXGwIOEqDPHnO/assets/g051-g051-04-tools.png)

Confirm that the agent has the tools needed for its task and understand which account they use.

## Review a tool call

Run a request that requires a tool and expand the tool trace.

![Agent tool call trace](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/E0sWnrjERxJzfk101ev1/assets/g051-g051-05-trace.png)

Check the tool name, arguments, and returned data against the final answer.

## Connect a custom MCP server

Choose Add custom MCP configuration for your own server.

![Custom MCP server configuration](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/Du818qn1UEEUkrNPIv9u/assets/g051-g051-06-custom.png)

Enter its authorized endpoint, a stable label, and a description of when the agent should use it.

Use the supported secret reference for authentication.

![Custom MCP server configuration](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/wX2ipXuPONZMoZnOhhXq/assets/g051-g051-07-secret.png)

Keep the credential in the designated secret store rather than in instructions or shared text.

Add the headers required by the server and save the configuration.

![Custom MCP server configuration](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/sbQRdTIf2aodadeTZEAS/assets/g051-g051-08-headers.png)

Check header names and values against that server's connection requirements.

## Check and review the custom connection

Run a request through the custom server and inspect the tool response.

![Custom MCP connection verification](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/xfrBo4Lrjvp3Dw4woyAI/assets/g051-g051-09-custom-trace.png)

Verify both endpoint access and the data used by the agent's answer.

Reopen the saved configuration to review the endpoint, label, authentication reference, and headers.

![Custom MCP connection verification](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/1ub31NLf9bpKAiikwkp8/assets/g051-g051-10-review.png)

Confirm the saved values before using the server in a broader workflow.

## Important behavior

MCP lets an agent discover and call tools exposed by another service. The server and connected account determine which operations and data are available.

Store authentication credentials in the supported secret store. Reference those secrets in the server configuration.

## Continue

* [End user connections](/guides-and-quickstarts/using-tools-and-actions/end-user-connections.md)
* [Give an agent tools](/guides-and-quickstarts/agent-builder-and-skills/give-an-agent-tools.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/guides-and-quickstarts/using-tools-and-actions/mcp-tools-in-an-agent.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
