URL Fetch MCP

by aelaguiz
Verified

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Uses Pydantic for type validation of URL parameters and request configuration

URL フェッチ MCP

Claude または任意の LLM が URL からコンテンツを取得できるようにする、クリーンな Model Context Protocol (MCP) 実装。

特徴

  • 任意のURLからコンテンツを取得する
  • 複数のコンテンツ タイプ (HTML、JSON、テキスト、画像) のサポート
  • リクエストパラメータ(ヘッダー、タイムアウト)の制御
  • クリーンなエラー処理
  • Claude CodeとClaude Desktopの両方で動作します

リポジトリ構造

url-fetch-mcp/ ├── examples/ # Example scripts and usage demos ├── scripts/ # Helper scripts (installation, etc.) ├── src/ │ └── url_fetch_mcp/ # Main package code │ ├── __init__.py │ ├── __main__.py │ ├── cli.py # Command-line interface │ ├── fetch.py # URL fetching utilities │ ├── main.py # Core MCP server implementation │ └── utils.py # Helper utilities ├── LICENSE ├── pyproject.toml # Project configuration ├── README.md └── url_fetcher.py # Standalone launcher for Claude Desktop

インストール

# Install from source pip install -e . # Install with development dependencies pip install -e ".[dev]"

使用法

サーバーの実行

# Run with stdio transport (for Claude Code) python -m url_fetch_mcp run # Run with HTTP+SSE transport (for remote connections) python -m url_fetch_mcp run --transport sse --port 8000

Claude Desktopへのインストール

Claude Desktop にインストールするには、次の 3 つの方法があります。

方法1:直接インストール

# Install the package pip install -e . # Install in Claude Desktop using the included script mcp install url_fetcher.py -n "URL Fetcher"

url_fetcher.pyファイルには次の内容が含まれます。

#!/usr/bin/env python """ URL Fetcher MCP Server This is a standalone script for launching the URL Fetch MCP server. It's used for installing in Claude Desktop with the command: mcp install url_fetcher.py -n "URL Fetcher" """ from url_fetch_mcp.main import app if __name__ == "__main__": app.run()

方法2: インストーラースクリプトを使用する

# Install the package pip install -e . # Run the installer script python scripts/install_desktop.py

scripts/install_desktop.pyスクリプト:

#!/usr/bin/env python import os import sys import tempfile import subprocess def install_desktop(): """Install URL Fetch MCP in Claude Desktop.""" print("Installing URL Fetch MCP in Claude Desktop...") # Create a temporary Python file that imports our module temp_dir = tempfile.mkdtemp() temp_file = os.path.join(temp_dir, "url_fetcher.py") with open(temp_file, "w") as f: f.write("""#!/usr/bin/env python # URL Fetcher MCP Server from url_fetch_mcp.main import app if __name__ == "__main__": app.run() """) # Make the file executable os.chmod(temp_file, 0o755) # Run the mcp install command with the file path try: cmd = ["mcp", "install", temp_file, "-n", "URL Fetcher"] print(f"Running: {' '.join(cmd)}") result = subprocess.run(cmd, check=True, text=True) print("Installation successful!") print("You can now use the URL Fetcher tool in Claude Desktop.") return 0 except subprocess.CalledProcessError as e: print(f"Error during installation: {str(e)}") return 1 finally: # Clean up temporary file try: os.unlink(temp_file) os.rmdir(temp_dir) except: pass if __name__ == "__main__": sys.exit(install_desktop())

方法3: CLIコマンドを使用する

# Install the package pip install -e . # Install using the built-in CLI command python -m url_fetch_mcp install-desktop

コア実装

メインの MCP 実装はsrc/url_fetch_mcp/main.pyにあります。

from typing import Annotated, Dict, Optional import base64 import json import httpx from pydantic import AnyUrl, Field from mcp.server.fastmcp import FastMCP, Context # Create the MCP server app = FastMCP( name="URL Fetcher", version="0.1.0", description="A clean MCP implementation for fetching content from URLs", ) @app.tool() async def fetch_url( url: Annotated[AnyUrl, Field(description="The URL to fetch")], headers: Annotated[ Optional[Dict[str, str]], Field(description="Additional headers to send with the request") ] = None, timeout: Annotated[int, Field(description="Request timeout in seconds")] = 10, ctx: Context = None, ) -> str: """Fetch content from a URL and return it as text.""" # Implementation details... @app.tool() async def fetch_image( url: Annotated[AnyUrl, Field(description="The URL to fetch the image from")], timeout: Annotated[int, Field(description="Request timeout in seconds")] = 10, ctx: Context = None, ) -> Dict: """Fetch an image from a URL and return it as an image.""" # Implementation details... @app.tool() async def fetch_json( url: Annotated[AnyUrl, Field(description="The URL to fetch JSON from")], headers: Annotated[ Optional[Dict[str, str]], Field(description="Additional headers to send with the request") ] = None, timeout: Annotated[int, Field(description="Request timeout in seconds")] = 10, ctx: Context = None, ) -> str: """Fetch JSON from a URL, parse it, and return it formatted.""" # Implementation details...

ツールの機能

フェッチURL

URL からコンテンツを取得し、テキストとして返します。

パラメータ:

  • url (必須): 取得するURL
  • headers (オプション): リクエストとともに送信する追加のヘッダー
  • timeout (オプション):リクエストのタイムアウト(秒)(デフォルト:10)

画像の取得

URL から画像を取得し、画像として返します。

パラメータ:

  • url (必須): 画像を取得するURL
  • timeout (オプション):リクエストのタイムアウト(秒)(デフォルト:10)

フェッチ_json

URL から JSON を取得し、解析してフォーマットして返します。

パラメータ:

  • url (必須): JSONを取得するURL
  • headers (オプション): リクエストとともに送信する追加のヘッダー
  • timeout (オプション):リクエストのタイムアウト(秒)(デフォルト:10)

examplesディレクトリにはサンプル スクリプトが含まれています。

  • quick_test.py : MCPサーバーのクイックテスト
  • simple_usage.py : クライアントAPIの使用例
  • interactive_client.py : テスト用の対話型 CLI
# Example of fetching a URL result = await session.call_tool("fetch_url", { "url": "https://example.com" }) # Example of fetching JSON data result = await session.call_tool("fetch_json", { "url": "https://api.example.com/data", "headers": {"Authorization": "Bearer token"} }) # Example of fetching an image result = await session.call_tool("fetch_image", { "url": "https://example.com/image.jpg" })

テスト

基本的な機能をテストするには:

# Run a direct test of URL fetching python direct_test.py # Run a simplified test with the MCP server python examples/quick_test.py

ライセンス

マサチューセッツ工科大学

-
security - not tested
A
license - permissive license
-
quality - not tested

Claude や他の LLM が URL からコンテンツを取得できるようにするモデル コンテキスト プロトコル (MCP) サーバー。構成可能なリクエスト パラメータを使用して HTML、JSON、テキスト、画像をサポートします。

  1. Features
    1. Repository Structure
      1. Installation
        1. Usage
          1. Running the Server
          2. Installing in Claude Desktop
        2. Core Implementation
          1. Tool Capabilities
            1. fetch_url
            2. fetch_image
            3. fetch_json
          2. Examples
            1. Testing
              1. License

                Appeared in Searches

                ID: a7rjk6pfj7