Skip to main content

This is an AWS Labs Model Context Protocol (MCP) server implementation that enables Independent Software Vendors (ISVs) to interact with Amazon Q Business's search capabilities. The server facilitates searching across enterprise customers' Q index using the SearchRelevantContent API.

Project description

AWS Labs amazon-qindex MCP Server

The AWS Labs amazon-qindex MCP Server is a Model Context Protocol (MCP) server designed to facilitate integration with Amazon Q Business's SearchRelevantContent API. While the server provides essential tools and functions for authentication and search capabilities using Amazon Q index, it currently serves for Independent Software Vendors (ISVs) who are AWS registered data accessors. The server enables cross-account search capabilities, allowing ISVs who are data accessors to search through enterprise customers' Q index and access relevant content across their data sources using specific authentication and authorization flows.

For Amazon Q Business application owners, direct integration support is not yet available. This MCP server represents a comprehensive solution that aims to serve ISVs.

Features

  • Boto3 client implementation for Q Business interactions
  • Support for various authentication methods (IAM credentials, profile-based)
  • MCP server implementation for handling Q index requests
  • Token-based authorization support
  • Error handling and mapping for Q Business API responses

Tools

AuthorizeQIndex

  • Generates OIDC authorization URL for Q index authentication
  • Required Parameters:
    • idc_region (str): AWS region for IAM Identity Center (e.g., us-west-2)
    • isv_redirect_url (str): Redirect URL registered during ISV registration
    • oauth_state (str): Random string for CSRF protection
    • idc_application_arn (str): Amazon Q Business application ID
  • Returns: Authorization URL for user authentication

CreateTokenWithIAM

  • Creates authentication token using authorization code through IAM
  • Required Parameters:
    • idc_application_arn (str): Amazon Q Business application ID
    • redirect_uri (str): Registered redirect URL
    • code (str): Authorization code from OIDC endpoint
    • idc_region (str): AWS region for IAM Identity Center
    • role_arn (str): IAM role ARN to assume
  • Returns: Token information including access token, refresh token, and expiration

AssumeRoleWithIdentityContext

  • Assumes IAM role using identity context from token
  • Required Parameters:
    • role_arn (str): IAM role ARN to assume
    • identity_context (str): Identity context from decoded token
    • role_session_name (str): Session identifier (default: "qbusiness-session")
    • idc_region (str): AWS region for IAM Identity Center
  • Returns: Temporary AWS credentials

SearchRelevantContent

  • Searches content within Amazon Q Business application
  • Required Parameters:
    • application_id (str): Q Business application identifier
    • query_text (str): Search query text
  • Optional Parameters:
    • attribute_filter (AttributeFilter): Document attribute filters
    • content_source (ContentSource): Content source configuration
    • max_results (int): Maximum results to return (1-100)
    • next_token (str): Pagination token
    • qbuiness_region (str): AWS region (default: us-east-1)
    • aws_credentials: Temporary AWS credentials
  • Returns: Search results with relevant content matches

Setup

Pre-Requisites

  • Install uv from Astral or the GitHub README

  • Install Python using uv python install 3.10

  • Two AWS Accounts (one account as ISV running this tester application, another account acting as enterprise customer running Amazon Q Business)

  • Data accessor registered for your ISV

  • IAM Identity Center (IDC) instance setup with user added on enterprise customer AWS account

  • Amazon Q Business application setup with IAM IDC as access management on enterprise customer AWS account

Installation

Cursor VS Code
Install MCP Server Install on VS Code

Configure the MCP server in your MCP client configuration (e.g., for Amazon Q Developer CLI, edit ~/.aws/amazonq/mcp.json):

{
  "mcpServers": {
    "awslabs.amazon_qindex_mcp_server": {
      "command": "uvx",
      "args": ["awslabs.amazon_qindex_mcp_server"],
      "env": {
        "AWS_PROFILE": "your-aws-profile",
        "AWS_REGION": "us-east-1"
      }
    }
  }
}

Windows Installation

For Windows users, the MCP server configuration format is slightly different:

{
  "mcpServers": {
    "awslabs.amazon-qindex-mcp-server": {
      "disabled": false,
      "timeout": 60,
      "type": "stdio",
      "command": "uv",
      "args": [
        "tool",
        "run",
        "--from",
        "awslabs.amazon-qindex-mcp-server@latest",
        "awslabs.amazon-qindex-mcp-server.exe"
      ],
      "env": {
        "FASTMCP_LOG_LEVEL": "ERROR",
        "AWS_PROFILE": "your-aws-profile",
        "AWS_REGION": "us-east-1"
      }
    }
  }
}
# Clone the repository
git clone [repository-url]

# Go to root directory of this server
cd <your repo path>/mcp/src/amazon-qindex-mcp-server/

# Install dependencies
pip install -e .

Usage

  1. Enter a text prompt describing what you want to query from enterprise data
search <your query> on enterprise data
  1. You also need to provide the following details to proceed with the authentication flow in order to process SearchRelevantContent API
application id - (enterprise account's Amazon Q Business application ID)
retriever id - (enterprise account's Amazon Q Business retriever ID)
iam idc arn - (enterprise account's IdC application ARN)
idc region - (Region for the IAM Identity Center instance)
qbuiness region - (enterprise account's Amazon Q Business application region)
redirect url - (ISV's redirect url - this could be anything within allowlisted for the data accessor - ie https://localhost:8081)
iam role arn - (ISV's IAM Role ARN registered with the data accessor)
  1. After providing the data through above two steps, you will be asked to visit the authorization URL on your browser and after successfully authenticated and taken to redirect url with an authorization code in the URL parameters (it will look like ?code=ABC123...&state=xxx), copy and paste the code portion to the client to resume the process.
code is <your authorization code>
  1. This MCP server will then process CreateTokenWithIAM to create authentication token, AssumeRoleWithIdentityContext to assume the role and get temporary credentials, then finally call SearchRelevantContent to searches user queried content within Amazon Q Business application.

Testing

Run tests using pytest:

pytest --cache-clear -v

Security Considerations

This MCP server implementation is for demonstration purposes only to showcase how to access the SearchRelevantContent API through an MCP server with user-aware authentication. For production use, please consider the following security measures:

Authentication & Authorization

  • Never hardcode credentials or sensitive information in the code
  • Implement proper session management and token refresh mechanisms
  • Use strong CSRF protection mechanisms for the OAuth flow
  • Implement proper validation of all authorization codes and tokens
  • Store tokens securely and never log them
  • Implement proper token revocation when sessions end

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

awslabs_amazon_qindex_mcp_server-0.0.5.tar.gz (80.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file awslabs_amazon_qindex_mcp_server-0.0.5.tar.gz.

File metadata

File hashes

Hashes for awslabs_amazon_qindex_mcp_server-0.0.5.tar.gz
Algorithm Hash digest
SHA256 63224c504cb0166a62edfab3c80ebb8ad556a7a83ebf16bbf00d2a59f63f12de
MD5 c6f288001a9786c5c05adc824c4e8d67
BLAKE2b-256 ff6d24663b7f71135239ffbb6d798c7a2e3885b7bd3f22150b7b2420d2a7959e

See more details on using hashes here.

Provenance

The following attestation bundles were made for awslabs_amazon_qindex_mcp_server-0.0.5.tar.gz:

Publisher: release.yml on awslabs/mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file awslabs_amazon_qindex_mcp_server-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for awslabs_amazon_qindex_mcp_server-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d8eadea282c8e6d0bdc807288b5b0a97eb80c013f312865e1755227521e93329
MD5 7ec6be50f858aef7bc6fff81eabb8e97
BLAKE2b-256 ab73bc60b0e38f1b8c5e827a76657e4afe020c3aa361c1629bd07b3699b9e628

See more details on using hashes here.

Provenance

The following attestation bundles were made for awslabs_amazon_qindex_mcp_server-0.0.5-py3-none-any.whl:

Publisher: release.yml on awslabs/mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page