AWS Labs Bedrock KB Retrieval MCP Server

1.0.19 · active · verified Fri Apr 17

The `awslabs-bedrock-kb-retrieval-mcp-server` library provides an AWS Labs Model Context Protocol (MCP) server specifically designed for integrating with Amazon Bedrock Knowledge Bases. It allows other MCP-compliant applications to retrieve information from a Bedrock Knowledge Base via a standard HTTP API. As part of the AWS Labs ecosystem, it typically receives updates driven by Bedrock feature enhancements and MCP protocol evolution, currently at version 1.0.19.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate and run the `BedrockKBRetrievalMCPServer` using Uvicorn. It requires AWS credentials configured in the environment or AWS shared credentials file, and a valid Amazon Bedrock Knowledge Base ID. The server will expose an HTTP endpoint for MCP retrieval requests.

import os
import uvicorn
from bedrock_kb_retrieval_mcp_server.server import BedrockKBRetrievalMCPServer

# --- Configuration --- #
# Ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION are set in your environment
# or via ~/.aws/credentials. You also need a Bedrock Knowledge Base ID.
KNOWLEDGE_BASE_ID = os.environ.get("BEDROCK_KB_ID", "YOUR_KNOWLEDGE_BASE_ID")
REGION_NAME = os.environ.get("AWS_REGION", "us-east-1") # e.g., 'us-east-1', 'us-west-2'

if KNOWLEDGE_BASE_ID == "YOUR_KNOWLEDGE_BASE_ID":
    print("WARNING: BEDROCK_KB_ID environment variable not set. Using placeholder.")
    print("Please set BEDROCK_KB_ID to a valid Amazon Bedrock Knowledge Base ID.")
    exit(1)

print(f"Initializing Bedrock KB Retrieval MCP Server for KB ID: {KNOWLEDGE_BASE_ID}")
print(f"In AWS Region: {REGION_NAME}")

# Initialize the server instance
try:
    server = BedrockKBRetrievalMCPServer(
        knowledge_base_id=KNOWLEDGE_BASE_ID,
        region_name=REGION_NAME
    )
    # Get the FastAPI application instance
    fastapi_app = server.get_fastapi_app()

    # Run the server using Uvicorn
    # The server will be accessible at http://127.0.0.1:8000
    if __name__ == "__main__":
        print("Starting Uvicorn server on http://127.0.0.1:8000")
        uvicorn.run(fastapi_app, host="127.0.0.1", port=8000)

except Exception as e:
    print(f"Error initializing or running server: {e}")
    print("Ensure AWS credentials, region, and Bedrock Knowledge Base ID are correctly configured.")

view raw JSON →