Skip to main content
Glama
claude-bedrock-mcp-server

claude-bedrock-mcp-server

by Code-Ninety
README.md
<!-- mcp-name: io.github.Code-Ninety/claude-bedrock-mcp-server -->

# Claude on AWS Bedrock MCP Server

[![CI](https://github.com/Code-Ninety/claude-bedrock-mcp-server/actions/workflows/ci.yml/badge.svg)](https://github.com/Code-Ninety/claude-bedrock-mcp-server/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)

Open-source reference architecture and Model Context Protocol (MCP) server for governing **Anthropic Claude** models on **AWS Bedrock** (`converse`, `apply_guardrail`, and Knowledge Bases `retrieve`), paired with a deterministic citation-grounded RAG evaluation CLI (`bedrock-rag-eval`).

## Architecture

```mermaid
flowchart LR
    Client["MCP Host (Claude Desktop / IDE / Agent)"] --> Server["MCPServer (stdio)"]
    Server --> Guard["GuardrailEnforcer (PII Redaction + Injection Block)"]
    Guard --> Budget["BudgetLedger (Pre-flight Decimal USD Cap)"]
    Budget --> Gateway["BedrockGateway (Retries + Bounded Pagination)"]
    Gateway -->|BEDROCK_MODE=sandbox| Sandbox["Deterministic Finance/Compliance KB Sandbox"]
    Gateway -->|BEDROCK_MODE=live| AWS["AWS Bedrock Runtime & Agent Runtime"]
    Gateway --> Eval["FaithfulnessEvaluator (Citation & Overlap Gate)"]
    Server --> Audit["AuditLogger (Bounded Deque + SHA-256 JSON)"]
```

## Capabilities

- **Exact AWS Bedrock Contracts:** Typed protocols for `bedrock-runtime` (`converse`, `apply_guardrail`) and `bedrock-agent-runtime` (`retrieve`) with bounded `nextToken` pagination (`BEDROCK_MAX_PAGES`), cyclic cursor detection, and exponential backoff on `ThrottlingException`, `ServiceUnavailableException`, and `ModelTimeoutException`.
- **Pre-Flight `Decimal` USD Cost Control:** Computes worst-case call spend using `decimal.Decimal` across Claude Opus 4, Sonnet 4, 3.7/3.5 Sonnet, and 3.5/3 Haiku (including `us.`, `eu.`, `apac.`, and `global.` inference profiles), failing closed with `BedrockBudgetError` before calling AWS if `BEDROCK_MAX_SESSION_USD` would be exceeded.
- **Dual-Layer Guardrails & PII Redaction:** Recursively masks AWS access keys (`AKIA...` / `ASIA...`), IBANs, SSNs, CNICs, emails, and phone numbers; blocks prompt-injection signatures locally; and optionally delegates `INPUT` and `OUTPUT` checks to AWS Bedrock Guardrails.
- **Bounded Zero-PII Audit Log:** Stores SHA-256 parameter digests and `Decimal` cost totals in a `collections.deque(maxlen=1000)` and emits structured JSON telemetry to `stderr` without logging raw prompts.
- **Citation-Grounded RAG Evaluation:** Verifies `[cite:CHUNK_ID]` references against retrieved chunks, rejects hallucinated citations, measures claim-level token grounding, and exposes a CI exit-code gate via `bedrock-rag-eval`.

## Exposed MCP Tools

| Tool Name | Purpose | Key Controls |
| --- | --- | --- |
| `bedrock_retrieve_knowledge` | Paginated Knowledge Base retrieval | `BEDROCK_MAX_PAGES` cap, cyclic cursor check, chunk PII redaction |
| `bedrock_converse_claude` | Governed Claude on Bedrock invocation | Prompt-injection block, pre-flight `Decimal` budget gate, output redaction |
| `bedrock_grounded_rag` | Retrieve -> cite -> Claude -> score pipeline | Inline `[cite:CHUNK_ID]` prompting + automatic `EvalReport` |
| `bedrock_evaluate_rag_response` | Standalone citation & faithfulness scorer | Flags hallucinated citations and unsupported claims |
| `bedrock_get_budget_status` | Live FinOps & audit snapshot | Returns `Decimal` USD totals and bounded SHA-256 audit history |

## Quickstart (30-Second Zero-Credential Sandbox)

Run the server and RAG evaluation suite locally with zero AWS credentials:

```bash
pip install claude-bedrock-mcp-server
bedrock-rag-eval --dataset examples/golden_eval_set.jsonl
claude-bedrock-mcp-server
```

For live AWS Bedrock execution, install the `[aws]` extra and configure environment variables:

```bash
pip install "claude-bedrock-mcp-server[aws]"
export BEDROCK_MODE=live
export AWS_REGION=us-east-1
export BEDROCK_KNOWLEDGE_BASE_ID=YOUR10CHARID
export BEDROCK_MODEL_ID=us.anthropic.claude-sonnet-4-20250514-v1:0
export BEDROCK_MAX_SESSION_USD=5.00
claude-bedrock-mcp-server
```

### MCP Client Configuration (`claude_desktop_config.json`)

```json
{
  "mcpServers": {
    "claude-bedrock": {
      "command": "claude-bedrock-mcp-server",
      "env": {
        "BEDROCK_MODE": "sandbox",
        "BEDROCK_MAX_SESSION_USD": "5.00"
      }
    }
  }
}
```

## CI RAG Evaluation Gate (`bedrock-rag-eval`)

Run the golden JSONL dataset in CI pipelines to fail builds (`exit 1`) on citation hallucinations or faithfulness regressions:

```bash
bedrock-rag-eval \
  --dataset examples/golden_eval_set.jsonl \
  --min-faithfulness 0.70 \
  --min-coverage 0.80 \
  --json
```

Each JSONL row supports either precomputed evaluation (`answer` + `chunks`) or end-to-end RAG execution (`query`), with `expected_pass` (`true`/`false`) to keep both positive grounding cases and negative hallucination traps under regression control.

## AWS Bedrock Native Agents & Knowledge Bases vs. Governed MCP Middleware

AWS provides managed [Amazon Bedrock Agents](https://docs.aws.amazon.com/bedrock/latest/userguide/agents.html) and [Bedrock Knowledge Bases](https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-bases.html) (`RetrieveAndGenerate`) out of the box. Choose the right layer for your architecture:

| Dimension | Native AWS Bedrock Agents / `RetrieveAndGenerate` | Governed MCP Middleware (`claude-bedrock-mcp-server`) |
| --- | --- | --- |
| **Best fit** | AWS-native workflows orchestrated wholly inside Bedrock console/SDKs | IDE assistants, Claude Desktop, and multi-system MCP hosts needing portable tools |
| **Cost governance** | Account-level AWS Budgets & CloudWatch alarms (reactive) | Synchronous pre-flight `Decimal` session USD cap failing closed before API calls |
| **PII & secret masking** | Managed Bedrock Guardrails regex/PII filters | Deterministic local redaction (AWS keys, IBAN, CNIC, SSN) + optional AWS Guardrails |
| **RAG verification** | Managed citations without built-in CI regression exit gates | Deterministic `FaithfulnessEvaluator` + `bedrock-rag-eval` CLI gate for pull requests |
| **Local dev / CI** | Requires live AWS IAM credentials and provisioned KB/OpenSearch resources | Zero-credential deterministic sandbox mode for 30-second local and CI verification |

If your workloads live entirely inside AWS Step Functions or Bedrock Agents and only need AWS-native IAM and Guardrails, use the managed AWS services directly. Use this middleware when MCP clients invoke Claude on Bedrock across developer workstations or regulated enterprise pipelines that require pre-flight `Decimal` budget caps, local secret redaction, and automated CI faithfulness gates.

## Architecture Decisions & Security

- [ADR-001: Protocol-Typed AWS Bedrock Gateway and Lazy boto3 Loading](docs/adr/ADR-001.md)
- [ADR-002: Pre-Flight Decimal FinOps Budget Caps and Bounded Audit Logging](docs/adr/ADR-002.md)
- [ADR-003: Deterministic Citation-Grounded RAG Faithfulness Gate](docs/adr/ADR-003.md)
- [Security Policy](SECURITY.md) | [Contributing Guide](CONTRIBUTING.md) | [Changelog](CHANGELOG.md)

Built by [Code Ninety](https://codeninety.com/services/anthropic-partner). Licensed under [MIT](LICENSE).

TDQS

A3.5/5.0

Scored across 5 tools

Disambiguation4/5

Each tool targets a distinct layer: raw retrieval, raw model invocation, an end-to-end RAG pipeline, an offline-style evaluator, and budget introspection. The only real overlap is that bedrock_grounded_rag internally does what bedrock_retrieve_knowledge and bedrock_converse_claude do, so an agent must decide between primitive and composite paths; descriptions do clarify this but not perfectly.

Naming Consistency4/5

All five names use a uniform bedrock_ prefix and snake_case, which makes the set immediately recognizable. Minor deviation: retrieve_knowledge/get_budget_status follow verb_noun cleanly, while grounded_rag is adjective_noun and converse_claude uses an unusual verb.

Tool Count5/5

Five tools is well-scoped for a Bedrock RAG/inference server: retrieve, invoke, orchestrate, evaluate, and monitor. Each tool has a clear reason to exist and no tool feels like filler.

Completeness4/5

The core lifecycle (retrieve, generate, orchestrate with citations, evaluate grounding, inspect budget) is fully covered with no dead ends for the main workflow. Gaps are minor: no knowledge-base discovery/listing, no budget reset or configuration, and no guardrail listing, but agents can work around these.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues