{"id":9534,"library":"awslabs-bedrock-kb-retrieval-mcp-server","title":"AWS Labs Bedrock KB Retrieval MCP Server","description":"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.","status":"active","version":"1.0.19","language":"en","source_language":"en","source_url":"https://github.com/awslabs/mcp.git","tags":["aws","bedrock","knowledge base","mcp","retrieval","llm","server","fastapi","ai"],"install":[{"cmd":"pip install awslabs-bedrock-kb-retrieval-mcp-server","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for Model Context Protocol implementation.","package":"mcp"},{"reason":"AWS SDK for Python, required for interacting with AWS Bedrock and other services.","package":"boto3"},{"reason":"Used for internal retrieval and processing logic.","package":"langchain"},{"reason":"Web framework used to build the server's API.","package":"fastapi"},{"reason":"ASGI server for running the FastAPI application.","package":"uvicorn"},{"reason":"Data validation and settings management.","package":"pydantic"},{"reason":"Environment variable loading, often used for configuration.","package":"python-dotenv","optional":true}],"imports":[{"symbol":"BedrockKBRetrievalMCPServer","correct":"from bedrock_kb_retrieval_mcp_server.server import BedrockKBRetrievalMCPServer"}],"quickstart":{"code":"import os\nimport uvicorn\nfrom bedrock_kb_retrieval_mcp_server.server import BedrockKBRetrievalMCPServer\n\n# --- Configuration --- #\n# Ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION are set in your environment\n# or via ~/.aws/credentials. You also need a Bedrock Knowledge Base ID.\nKNOWLEDGE_BASE_ID = os.environ.get(\"BEDROCK_KB_ID\", \"YOUR_KNOWLEDGE_BASE_ID\")\nREGION_NAME = os.environ.get(\"AWS_REGION\", \"us-east-1\") # e.g., 'us-east-1', 'us-west-2'\n\nif KNOWLEDGE_BASE_ID == \"YOUR_KNOWLEDGE_BASE_ID\":\n    print(\"WARNING: BEDROCK_KB_ID environment variable not set. Using placeholder.\")\n    print(\"Please set BEDROCK_KB_ID to a valid Amazon Bedrock Knowledge Base ID.\")\n    exit(1)\n\nprint(f\"Initializing Bedrock KB Retrieval MCP Server for KB ID: {KNOWLEDGE_BASE_ID}\")\nprint(f\"In AWS Region: {REGION_NAME}\")\n\n# Initialize the server instance\ntry:\n    server = BedrockKBRetrievalMCPServer(\n        knowledge_base_id=KNOWLEDGE_BASE_ID,\n        region_name=REGION_NAME\n    )\n    # Get the FastAPI application instance\n    fastapi_app = server.get_fastapi_app()\n\n    # Run the server using Uvicorn\n    # The server will be accessible at http://127.0.0.1:8000\n    if __name__ == \"__main__\":\n        print(\"Starting Uvicorn server on http://127.0.0.1:8000\")\n        uvicorn.run(fastapi_app, host=\"127.0.0.1\", port=8000)\n\nexcept Exception as e:\n    print(f\"Error initializing or running server: {e}\")\n    print(\"Ensure AWS credentials, region, and Bedrock Knowledge Base ID are correctly configured.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure the AWS principal (user/role) running the server has `bedrock:Retrieve`, `bedrock:InvokeModel` (if using custom models), and `s3:GetObject` (for any S3 buckets used by the knowledge base) permissions for the relevant resources.","message":"Incorrect AWS IAM Permissions: The server requires appropriate IAM permissions to interact with Bedrock Knowledge Bases and associated resources (e.g., S3 buckets for data sources).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify that the `knowledge_base_id` and `region_name` provided to `BedrockKBRetrievalMCPServer` constructor are correct and correspond to an accessible Bedrock Knowledge Base in the specified region. Check the Bedrock console for the exact ID and region.","message":"Invalid or Mismatched Knowledge Base ID/Region: Providing a Knowledge Base ID that does not exist, is in a different region, or is not accessible can lead to `ResourceNotFoundException` errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure AWS credentials (e.g., `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`) are correctly set as environment variables, or configured in `~/.aws/credentials` or IAM instance profiles/roles for EC2/ECS/EKS deployments.","message":"AWS Credentials Not Found or Expired: The `boto3` library used internally relies on standard AWS credential provider chain. If credentials are missing, malformed, or expired, the server will fail to connect to AWS services.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Grant `bedrock:Retrieve` and potentially `s3:GetObject` (if KB data source is S3) permissions to the AWS principal running the server for the target Bedrock Knowledge Base and S3 bucket.","cause":"The IAM role/user running the server lacks necessary permissions to perform Bedrock Knowledge Base retrieval.","error":"botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the Retrieve operation:"},{"fix":"Double-check the Bedrock Knowledge Base ID and the AWS region name. Ensure the KB is active and correctly configured in the Bedrock console.","cause":"The provided `knowledge_base_id` does not exist, is invalid, or is not available in the specified `region_name`.","error":"botocore.exceptions.ClientError: An error occurred (ResourceNotFoundException) when calling the Retrieve operation:"},{"fix":"Install the package using `pip install awslabs-bedrock-kb-retrieval-mcp-server`. Verify that the import statement `from bedrock_kb_retrieval_mcp_server.server import BedrockKBRetrievalMCPServer` is correct.","cause":"The `awslabs-bedrock-kb-retrieval-mcp-server` package is not installed in the current Python environment, or the import path is incorrect.","error":"ModuleNotFoundError: No module named 'bedrock_kb_retrieval_mcp_server'"},{"fix":"Ensure `fastapi_app = server.get_fastapi_app()` is correctly called and its result is passed to `uvicorn.run(fastapi_app, ...)`. The quickstart code snippet demonstrates the correct pattern.","cause":"The `uvicorn.run()` function was not provided with the correct ASGI application object, or `server.get_fastapi_app()` did not return an app.","error":"uvicorn.config.ConfigError: Provided target must be an ASGI application, e.g. 'main:app'."}]}