How to Use the Fetch MCP Server for API Integration
Enable your AI agent to fetch content from any URL or API endpoint. Perfect for reading documentation, consuming REST APIs, and gathering web content.
Use the Fetch MCP Server for API Integration
The Fetch MCP server is the simplest yet most versatile tool you can give your AI agent. It provides the ability to retrieve content from any HTTP/HTTPS URL, bridging the gap between your agent's frozen training data and the live internet.
Configuration Setup
Add this configuration to your MCP client:
{
"mcpServers": {
"fetch": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-fetch"]
}
}
}Available Tools
The server exposes a single, highly flexible tool:
| Tool | Description |
|---|---|
fetch | Retrieve content from a URL via GET or POST |
Supported Content Types
The server acts as a middleware, automatically transforming raw data into formats easily digestible by LLMs:
- ▸HTML pages → Converted to clean Markdown, stripping out ads, scripts, and CSS.
- ▸JSON responses → Returned as minified, structured data.
- ▸Plain text → Returned as-is.
- ▸XML/RSS → Parsed and formatted into readable hierarchies.
Example Workflows
- ▸Reading Documentation: "Fetch the React documentation page about hooks from their website and summarize the key concepts."
- ▸API Consumption: "Fetch the latest exchange rates from
api.exchangerate-api.com/v4/latest/USDand calculate the conversion for 500 Euros." - ▸Content Analysis: "Fetch the content from this blog post URL and create a bullet-point summary of the author's arguments."
Request Configuration
The fetch tool is not just for GET requests. Your agent can configure complex requests, including:
- ▸Custom Headers: Injecting
Authorization: Bearer <token>to hit protected REST APIs. - ▸Request Body: Sending JSON payloads for
POSTrequests.
Limitations & Troubleshooting
- ▸Payload Too Large: If the agent fetches a massive webpage, the resulting Markdown may exceed the LLM's context window. The Fetch server attempts to truncate enormous responses, but targeted APIs are always better than full HTML scrapes.
- ▸403 Forbidden / Cloudflare Blocks: Many modern websites employ Cloudflare or WAF bot-protection. Since the
fetchtool uses a standard Node.js HTTP client, it will often be blocked by these firewalls. Use the Puppeteer MCP Server for scraping heavily protected sites. - ▸Client-Side Rendering: If the agent fetches a React/Vue SPA URL, it will likely just return
<div id="root"></div>. Fetch cannot execute JavaScript. Again, use Puppeteer if you need JS rendering.
Using with OpenAI Codex
To use this MCP server with the OpenAI Codex CLI, you can add it to your configuration using the codex mcp add command:
codex mcp add --name fetch --command "npx @modelcontextprotocol/server-fetch"(Note: Depending on the server, you may need to append arguments or use --env flags for environment variables as described in the configuration section above)
Related Guides
How to Set Up the Brave Search MCP Server for Web Research
Enable your AI agent to search the web using Brave Search API through MCP. Perfect for research, fact-checking, and gathering real-time information.
APIsHow to Use Stripe's Machine Payments Protocol (MPP) as an MCP Client
Learn how to configure your AI agent as an MCP client that can automatically pay per tool usage using Stripe's Machine Payments Protocol — enabling access to premium, monetized MCP servers.
APIsHow to Accept Stripe's Machine Payments Protocol (MPP) in Your MCP Server
Monetize your MCP server by accepting per-tool-call payments using Stripe's Machine Payments Protocol. This guide covers pricing schemas, payment verification, and webhook handling.