Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

26 changes: 0 additions & 26 deletions .eslintrc.cjs

This file was deleted.

27 changes: 0 additions & 27 deletions .github/workflows/publish.yml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# https://semantic-release.gitbook.io/semantic-release/recipes/ci-configurations/github-actions
name: Release
on:
push:
branches:
- main

permissions:
contents: read

jobs:
release:
name: Release

runs-on: ubuntu-latest

permissions:
contents: write
issues: write
pull-requests: write
id-token: write

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 10

- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
run: npm audit signatures

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
26 changes: 12 additions & 14 deletions .github/workflows/ci.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
name: CI
name: Test

on:
push:
branches: [main]
pull_request:
branches: [main]
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Use Node.js ${{ matrix.node-version }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: 'lts/*'

- name: Install pnpm
uses: pnpm/action-setup@v2
Expand All @@ -36,8 +34,8 @@ jobs:
- name: Check formatting
run: pnpm format:check

- name: Run tests
run: pnpm test

- name: Build
run: pnpm build

- name: Run tests
run: pnpm test
4 changes: 4 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
release:
branches:
- main
- next
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Thomas Gambet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Fetch MCP Server

A port of the official [Fetch MCP Server](https://github.com/modelcontextprotocol/servers/tree/main/src/fetch) (python) for Node.js.

## Description

A [Model Context Protocol](https://modelcontextprotocol.io/) server that provides web content fetching capabilities. This server enables LLMs to retrieve and process content from web pages, converting HTML to markdown for easier consumption.

The fetch tool will truncate the response, but by using the `start_index` argument, you can specify where to start the content extraction. This lets models read a webpage in chunks, until they find the information they need.

### Available Tools

- `fetch` - Fetches a URL from the internet and extracts its contents as markdown.
- `url` (string, required): URL to fetch
- `max_length` (integer, optional): Maximum number of characters to return (default: 5000)
- `start_index` (integer, optional): Start content from this character index (default: 0)
- `raw` (boolean, optional): Get raw content without markdown conversion (default: false)

### Available Prompts

- `fetch` - Fetch a URL and extract its contents as markdown
- `url` (string, required): URL to fetch

## Usage

```json
"mcpServers": {
"fetch": {
"command": "npx",
"args": ["mcp-fetch-node"]
}
}
```

```json
"mcpServers": {
"fetch": {
"command": "docker",
"args": ["run", "-i", "--rm", "tgambet/mcp-fetch-node"]
}
}
```

### Customization - robots.txt

By default, the server will obey a websites robots.txt file if the request came from the model (via a tool), but not if
the request was user initiated (via a prompt). This can be disabled by adding the argument `--ignore-robots-txt` to the
`args` list in the configuration.

### Customization - User-agent

By default, depending on if the request came from the model (via a tool), or was user initiated (via a prompt), the
server will use either the user-agent

```
ModelContextProtocol/1.0 (Autonomous; +https://github.com/tgambet/mcp-fetch-node)
```

or

```
ModelContextProtocol/1.0 (User-Specified; +https://github.com/tgambet/mcp-fetch-node)
```

This can be customized by adding the argument `--user-agent=YourUserAgent` to the `args` list in the configuration.

## Features

- [x] Fetch and extract content from a URL
- [x] Respect `robots.txt` (can be disabled)
- [x] User-Agent customization
- [x] Relevant content extraction
- [x] Raw content or markdown conversion
- [x] Pagination
- [ ] In-memory temporary cache for faster responses, especially when paginating
- [ ] Logs and progress

## Development

```bash
pnpm install
pnpm dev
pnpm lint:fix
pnpm format
pnpm test
pnpm build
pnpm start
# test with MCP CLI
pnpx @wong2/mcp-cli --sse http://localhost:8080/sse
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

[MIT](https://choosealicense.com/licenses/mit/)

## TODO

- [ ] Explain key differences with the original mcp/fetch tool
- [ ] Add LRU cache
- [ ] Publish to npm
- [ ] Dockerize and publish to docker hub
- [ ] Integrate semantic release
- [ ] Add user logs and progress
- [ ] Add tests
- [ ] Add documentation & examples
- [ ] Add benchmarks for extraction: cf https://github.com/adbar/trafilatura/blob/master/tests/comparison_small.py
- [ ] Showcase on FastMCP and MCP repositories
21 changes: 21 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
);
21 changes: 0 additions & 21 deletions jest.config.cjs

This file was deleted.

Loading