> For the complete documentation index, see [llms.txt](https://agpt.co/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://agpt.co/docs/integrations/block-integrations/block.md).

# Mcp Block

Blocks for connecting to and executing tools on MCP (Model Context Protocol) servers.

## MCP Tool

### What it is

Connect to any MCP server and execute its tools. Provide a server URL, select a tool, and pass arguments dynamically.

### How it works

The block uses JSON-RPC 2.0 over HTTP to communicate with MCP servers. When configuring, it sends an `initialize` request followed by `tools/list` to discover available tools and their input schemas. On execution, it calls `tools/call` with the selected tool name and arguments, then extracts text, image, or resource content from the response.

Authentication is handled via OAuth 2.0 when the server requires it. The block supports optional credentials — public servers work without authentication, while protected servers trigger a standard OAuth flow with PKCE. Tokens are automatically refreshed when they expire.

### Inputs

| Input           | Description                                                                                         | Type            | Required |
| --------------- | --------------------------------------------------------------------------------------------------- | --------------- | -------- |
| server\_url     | URL of the MCP server (Streamable HTTP endpoint)                                                    | str             | Yes      |
| selected\_tool  | The MCP tool to execute                                                                             | str             | No       |
| tool\_arguments | Arguments to pass to the selected MCP tool. The fields here are defined by the tool's input schema. | Dict\[str, Any] | No       |

### Outputs

| Output | Description                           | Type   |
| ------ | ------------------------------------- | ------ |
| error  | Error message if the tool call failed | str    |
| result | The result returned by the MCP tool   | Result |

### Possible use case

* **Connecting to third-party APIs**: Use an MCP server like Sentry or Linear to query issues, create tickets, or manage projects without building custom integrations.
* **AI-powered tool execution**: Chain MCP tool calls with AI blocks to let agents dynamically discover and use external tools based on task requirements.
* **Data retrieval from knowledge bases**: Connect to MCP servers like DeepWiki to search documentation, retrieve code context, or query structured knowledge bases.

***


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://agpt.co/docs/integrations/block-integrations/block.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
