url-content-mcp

url-content-mcp

MCP server that fetches raw HTML content from a given URL to provide web context to LLMs.

Category
访问服务器

README

URL Content MCP Server

This repository provides a Model Context Protocol (MCP) server that retrieves the raw HTML content from a given URL to provide context to Large Language Models (LLMs). It acts as a tool for LLMs to fetch real-time web page content beyond their training data.

Overview

The URL Content MCP server serves as a bridge between LLMs and the web. Through a standardized MCP interface, an LLM can request the content of a specific URL and receive the HTML content of that page. This allows AI assistants to access up-to-date web content on demand.

Features

  • Fetch Web Page Content: Retrieve the HTML content of a web page given its URL.
  • Real-Time Data: Access current information directly from web pages in real time.
  • Optional Caching: Optionally cache fetched content in memory to avoid repeated network calls for the same URL during the server's runtime.
  • STDIO and SSE Support: Run the server in stdio mode for integration as a subprocess, or in sse (HTTP Server-Sent Events) mode to serve requests over HTTP.

Requirements

  • Python 3.8+ – The server is written in Python and requires version 3.8 or higher.
  • Internet Access – The server needs network access to fetch web pages from the internet.

Note: This server fetches raw HTML content. Ensure the target URL is accessible and returns text/HTML content. Some websites may block automated requests or require specific user-agent headers.

Installation

Clone this repository and install the package along with its dependencies:

git clone https://github.com/artryazanov/url-content-mcp.git
cd url-content-mcp
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

This will install the necessary Python packages as listed in requirements.txt. You can also install the package in editable mode (e.g., pip install -e .) if you plan to modify the code.

Usage

After installation, you can run the MCP server using the provided console script url-content-mcp or by executing the module. The server supports two modes of operation: STDIO (for direct integration with an MCP-compatible client) and SSE (for running as an HTTP server).

Running the Server (STDIO Mode)

By default, the server runs in stdio mode. In this mode, the server reads MCP requests from standard input and writes responses to standard output. This mode is suitable for integrating with applications that manage the server as a subprocess and communicate via MCP protocol (such as certain AI assistant platforms).

Example (running in stdio mode):

url-content-mcp

When running in stdio mode, the server will start and wait for incoming MCP requests via stdin (typically from an AI client). Each request (formatted according to the MCP protocol) will be processed, and the server will output the result to stdout as JSON.

Running the Server (SSE/HTTP Mode)

To run the server as an HTTP service, use the --transport sse option. In SSE mode, the server will start an HTTP server and provide a RESTful endpoint for fetching URL content.

Example (running in SSE mode on port 8080):

url-content-mcp --transport sse --host 0.0.0.0 --port 8080 --enable-cache

This starts the server in SSE mode, listening on all interfaces (0.0.0.0) at port 8080, with caching enabled. In this mode, you can send HTTP GET requests to the server's /fetch/{url} endpoint to retrieve content. Note: The {url} in the path should be URL-encoded.

For example, to fetch the content of http://example.com, encode the URL and request:

http://localhost:8080/fetch/http%3A%2F%2Fexample.com

This will return a JSON response containing the URL and the HTML content of the page. The response structure looks like:

{
  "url": "http://example.com",
  "content": "<!DOCTYPE html>...</html>"
}

If an error occurs during fetching (for example, a network error or a non-200 HTTP status), the response will include an "error" field with a message, and the "content" may be an empty string.

Note: When running in Docker or other container environments, use --host 0.0.0.0 to bind to all interfaces, and ensure the container's port is published (e.g., -p 8080:8080).

Command-Line Options

  • --transport, -t (string): Transport protocol for the server. Either stdio (default) or sse (to run an HTTP server for SSE).
  • --host (string): Host address to bind the HTTP server in SSE mode (default: 127.0.0.1).
  • --port (int): Port number for SSE mode (default: 8080).
  • --enable-cache (flag): Enable in-memory caching of fetched content. If this flag is set, the server will cache the content of each URL after the first fetch during its runtime.

Run url-content-mcp --help to see the usage information.

Available MCP Tool

This server provides one MCP tool that the LLM can use:

fetch_url

  • Description: Fetches the content of a web page at the given URL and returns the HTML content.
  • Parameters:
    • url (string, required) – The web page URL to fetch.
  • Returns: A JSON object with the following structure:
    • url: The URL that was fetched.
    • content: The HTML content of the page as a string. (This will contain the raw HTML, including tags.)
    • error: optional – An error message string, if an error occurred during fetching. This field is only present if there was an error (on success it is omitted).

The fetch_url tool is registered with the MCP server, so an LLM client can call this function to retrieve web page content. In stdio mode, the function is invoked via MCP tool calls in the protocol. In sse (HTTP) mode, the server exposes a GET endpoint /fetch/{url} (with the URL percent-encoded) that returns the same data.

Testing

This project includes a test suite to ensure the server works correctly.

  1. Install test dependencies: pip install -r requirements-dev.txt (includes pytest).
  2. Run all tests: pytest

Docker

A Dockerfile is provided to containerize the MCP server. To build the Docker image:

docker build -t url-content-mcp .

To run the server via Docker (exposing port 8080 for SSE mode):

docker run --rm -it -p 8080:8080 url-content-mcp --transport sse --host 0.0.0.0

This will start the MCP server inside a container. You can then interact with it via HTTP requests to http://localhost:8080 (for SSE mode) or attach it to an MCP-compatible client in stdio mode.

License

This project is licensed under the Unlicense license. See the LICENSE file for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选