Skip to main content
Glama
AWSWSA-MCP

AWSWSA-MCP

by mirecekd
README.md
<img src="https://capsule-render.vercel.app/api?type=waving&height=200&color=0:202323,55:303635,100:e7ac80&text=AWSWSA-MCP&fontColor=f1d6b4&fontSize=58&fontAlignY=38&desc=AWS%20Web%20Search%20API%20MCP%20%E2%80%94%20a%20complement%20to%20Tavily&descSize=20&descColor=f1d6b4&descAlignY=60" width="100%" alt="" />

<div align="center">

[![Python](https://img.shields.io/badge/Python-3.13-e7ac80?style=for-the-badge&logo=python&logoColor=e7ac80&labelColor=303635)](https://www.python.org/)
[![MCP](https://img.shields.io/badge/MCP-streamable%20HTTP-e7ac80?style=for-the-badge&labelColor=303635)](https://modelcontextprotocol.io/)
[![AWS](https://img.shields.io/badge/AWS-AgentCore%20Web%20Search-e7ac80?style=for-the-badge&logo=amazonwebservices&logoColor=e7ac80&labelColor=303635)](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/web-search-api.html)
[![Docker](https://img.shields.io/badge/Docker-multi--arch-e7ac80?style=for-the-badge&logo=docker&logoColor=e7ac80&labelColor=303635)](https://github.com/mirecekd/awswsa-mcp/pkgs/container/awswsa-mcp)
[![License MIT](https://img.shields.io/badge/License-MIT-e7ac80?style=for-the-badge&labelColor=303635)](LICENSE)
[![Tests](https://img.shields.io/github/actions/workflow/status/mirecekd/awswsa-mcp/tests.yml?branch=main&style=for-the-badge&label=TESTS&color=e7ac80&labelColor=303635)](https://github.com/mirecekd/awswsa-mcp/actions)
[![Release](https://img.shields.io/github/v/release/mirecekd/awswsa-mcp?style=for-the-badge&label=RELEASE&color=e7ac80&labelColor=303635)](https://github.com/mirecekd/awswsa-mcp/releases)

[![Buy Me a Beer](https://img.shields.io/badge/If%20you%20like%20my%20work%20you%20can-Buy%20Me%20a%20Beer%20%F0%9F%8D%BA-e7ac80?style=for-the-badge&labelColor=303635)](https://buymeacoffee.com/mirecekd) [![PayPal](https://img.shields.io/badge/or%20send%20me%20a%20tip%20via-PayPal-e7ac80?style=for-the-badge&logo=paypal&logoColor=e7ac80&labelColor=303635)](https://www.paypal.me/mirecekd)

</div>

## ๐Ÿš€ What is AWSWSA-MCP?

A small MCP server with one tool, `aws_web_search`, that wraps the Amazon Bedrock AgentCore **Web Search API** (`InvokeWebSearch`). Your agent gets ranked web results with a text extract, the source URL and the publication date, and the query is served from an Amazon-operated web index inside AWS.

It is meant as a **complement to a basic web search such as Tavily**, not a replacement. It only searches. It does not fetch whole pages, map or crawl a site, or run multi-step research. Keep Tavily (or any fetch tool) for that and add this server as a second, independent source.

## ๐Ÿง  How it works?

### 1. Listen
- An MCP client (Claude, pi, MCPHub, LiteLLM, any streamable-HTTP client) connects to `/mcp`. Optional bearer authentication protects the endpoint; `/health` is always open.

### 2. Think
- The tool validates the request (query 1-200 characters, 1-25 results, optional domain include/exclude lists, optional date range, optional country) before anything is sent to AWS.

### 3. Search
- `InvokeWebSearch` is called with the default boto3 credential chain, so the server needs **no API key of its own**: an EC2 instance profile is enough.

### 4. Show
- The result is a numbered markdown list with title, URL, publication date and a text extract, ending with a reminder to cite the sources (required by the AWS acceptable-use terms).

## โœจ Features

- One tool, `aws_web_search`: query, `max_results`, `include_domains`, `exclude_domains`, `published_after`, `published_before`, `country`
- No third-party search key: IAM only, queries stay inside AWS
- Works with an **EC2 instance profile**, environment keys, session tokens, `*_FILE` secrets or a shared profile
- Optional bearer token, constant-time comparison, `/health` for container checks
- Small multi-arch Docker image, runs as a non-root user
- Fast: about 0.5 s per search in our tests, results carry a publication date

## ๐Ÿ› ๏ธ Technology Stack

| Layer | Technology |
| --- | --- |
| Language | Python 3.13 |
| MCP | official `mcp` SDK, FastMCP, streamable HTTP |
| AWS | `boto3` (Amazon Bedrock AgentCore data plane) |
| Server | `uvicorn` / Starlette |
| Container | Docker, `linux/amd64` and `linux/arm64` |

## ๐Ÿ—๏ธ Architecture

```mermaid
flowchart LR
    A[Agent / MCP client] -->|POST /mcp, Bearer| B[awswsa-mcp]
    B -->|InvokeWebSearch, SigV4| C[AgentCore Web Search]
    C --> D[(Amazon web index)]
    E[Instance profile / keys] -.credentials.-> B
```

```text
client --MCP--> awswsa-mcp --boto3--> bedrock-agentcore: InvokeWebSearch
```

## ๐Ÿ“ฆ Get the image

```bash
docker pull ghcr.io/mirecekd/awswsa-mcp:latest
```

Or build it yourself:

```bash
docker build -t awswsa-mcp .
```

## โš™๏ธ Setup

### 1. Allow the call in IAM

The caller needs one action on one resource, nothing else:

```json
{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": "bedrock-agentcore:InvokeWebSearch",
    "Resource": "arn:aws:bedrock-agentcore:*:aws:tool/web-search.v1"
  }]
}
```

Attach it to the EC2 instance role, or to the IAM user whose keys you pass in.

### 2. Run it

On EC2 with the policy above, **no keys are needed**:

```bash
docker run -d --name awswsa-mcp -p 127.0.0.1:8080:8080 \
  -e AWS_REGION=eu-west-1 \
  -e AWSWSA_BEARER_TOKEN="$(openssl rand -hex 24)" \
  ghcr.io/mirecekd/awswsa-mcp:latest
```

With keys instead (any of these, in this order of precedence):

```bash
# environment, including temporary session credentials
docker run ... -e AWS_ACCESS_KEY_ID=... -e AWS_SECRET_ACCESS_KEY=... -e AWS_SESSION_TOKEN=... ...

# files (Docker or Compose secrets), nothing visible in `docker inspect`
docker run ... -v ./secrets:/run/secrets:ro \
  -e AWS_ACCESS_KEY_ID_FILE=/run/secrets/access_key \
  -e AWS_SECRET_ACCESS_KEY_FILE=/run/secrets/secret_key ...

# a shared profile
docker run ... -v ./aws-config:/app/aws:ro -e AWS_CONFIG_FILE=/app/aws/config -e AWS_SHARED_CREDENTIALS_FILE=/app/aws/credentials -e AWS_PROFILE=my-profile ...
```

When none of them is set, boto3 falls back to the EC2 instance profile. On a plain Docker host the instance metadata endpoint must be reachable from the container (IMDSv2 hop limit of 2).

### 3. Connect a client

The MCP endpoint is `http://<host>:8080/mcp` with the header `Authorization: Bearer <token>`. In MCPHub add a `streamable-http` server with that URL and header.

## ๐Ÿ”ง Configuration

| Variable | Default | Meaning |
| --- | --- | --- |
| `AWSWSA_HOST` | `0.0.0.0` | Listen address |
| `AWSWSA_PORT` | `8080` | Listen port |
| `AWSWSA_BEARER_TOKEN` | empty | When set, `/mcp` requires `Authorization: Bearer <token>`. When empty there is no authentication and a warning is logged |
| `AWSWSA_ALLOWED_HOSTS` | empty | Comma list of accepted `Host` headers; empty disables the DNS-rebinding check (use behind a reverse proxy) |
| `AWS_REGION` / `AWS_DEFAULT_REGION` | `eu-west-1` | Region of the Web Search API |
| `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN` | unset | Static or temporary credentials |
| `AWS_ACCESS_KEY_ID_FILE`, `AWS_SECRET_ACCESS_KEY_FILE`, `AWS_SESSION_TOKEN_FILE` | unset | Read the value from a file when the plain variable is not set |
| `AWS_PROFILE` | unset | Shared credentials profile |

## ๐Ÿงช When to use it, and when not

We ran the same nine queries (English, Czech, news; five results each) through this server and through Tavily Search (default settings, no topic or date options) on 2026-12-01. It is a small, informal comparison, not a benchmark.

| | AWS Web Search | Tavily |
| --- | --- | --- |
| Latency | about 0.5 s | about 1.6 s |
| Publication date in the result | 41 of 45 | 0 of 45 in the default (general) mode |
| English queries | good | good |
| News | good, recent sources | usable, age unknown |
| Czech queries | weak | good |
| Tools | search only | search, extract, map, crawl, research |

- **Use it** for English queries and news, when you want the publication date, when queries must not leave AWS, or as a second source (the two returned almost completely different domains: 4 shared of about 44).
- **Do not use it** for Czech or other small-language queries. It returned German, French and Dutch pages for Czech questions, with or without diacritics and with `country` set. Tavily returned Czech sources.
- **Do not expect** page extraction, site mapping or crawling. Pair it with a fetch tool.

## ๐Ÿ”’ Security

- No default credentials in the image. The server uses what you give it, or the instance profile.
- Least privilege: one IAM action on one resource (see Setup).
- Secrets are never logged. The `*_FILE` variables keep keys out of `docker inspect`.
- Set `AWSWSA_BEARER_TOKEN` and do not publish the port. Without a token anyone who can reach the port can spend your search quota.
- The container runs as a non-root user.

## ๐Ÿ’ฐ Cost and limits

- The first 5,000 queries per month are free, then about 7 USD per 1,000 queries. Check the [AgentCore pricing](https://aws.amazon.com/bedrock/agentcore/pricing/) for current numbers.
- Default quota: 10 requests per second per Region.
- Available Regions: us-east-1, us-east-2, us-west-2, eu-west-1, ap-southeast-2, ap-northeast-1.
- Acceptable use: keep and show the source citation for every result you surface, and do not bulk-extract content or build a competing index.

## ๐Ÿงญ Versioning and releases

Versions are `YYYYMMDD.X`, the build day and the counter of that day. A push to `main` runs the tests, computes the next version with `scripts/release.py`, tags it, creates a GitHub release and publishes `ghcr.io/mirecekd/awswsa-mcp:<version>` and `:latest` for `linux/amd64` and `linux/arm64`. See `CHANGELOG.md`.

## ๐Ÿงช Development

```bash
python3 -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt -r requirements-dev.txt
ruff check .
pytest -q tests scripts
python3 scripts/privacy_scan.py --tree
bash scripts/install-hooks.sh   # refuses private files and key-like strings on commit
```

The tests need no network and no AWS account.

## โ˜• Support

<div align="center">

[![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/mirecekd) [![PayPal.me](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate/?business=LJ5ZF7Q9KMTRW&no_recurring=0&currency_code=USD)

</div>

## ๐Ÿ“„ License

MIT License - see the `LICENSE` file for details.

## ๐Ÿ‘ค Author

Miroslav Dvorak - mirecekd@gmail.com

<img src="https://capsule-render.vercel.app/api?type=waving&height=110&section=footer&color=0:e7ac80,55:303635,100:202323" width="100%" alt="" />