AWS Knowledge Base MCP Server について
AWS Bedrock Knowledge Baseにインデックスされた文書を検索するMCPサーバーで、インフラ構成とデモクライアントも含みます。AIアシスタントから関連文書を検索する用途向けです。
主な機能
- 01search_knowledge_baseツールの提供
- 02AWS Bedrock経由で文書を検索
- 03SSEとstreamable HTTPに対応
- 04インフラ構成とデモクライアントを同梱
活用シーン
- 01AIアシスタントからインデックス済み文書を検索
- 02デモクライアントでMCPツールをテスト
MCP 対応
インデックス済み文書を検索するsearch_knowledge_baseツールをMCPクライアントに公開し、SSEとstreamable HTTPに対応します。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
ツール
ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。
詳細
AWS Knowledge Base MCP Server
使用方法
| Claude Desktop | GitHub Copilot |
|
|
|
|
|
AWS Bedrock と Cloudflare Workers を使用して、AI アシスタントがナレッジベースを検索できるようにする、Model Context Protocol(MCP)サーバーの実装です。このプロジェクトは、次の 3 つの主要コンポーネントで構成されています。
アーキテクチャ
-
インフラストラクチャ(
/cdk):次のリソースをセットアップします。- ドキュメントの埋め込み用 AWS Bedrock Knowledge Base
- 効率的なドキュメント検索のための Pinecone
- ドキュメントファイルを保存する AWS S3 バケット
- ストリーム可能な HTTP トランスポートを使用する MCP サーバー用 AWS Lambda 関数
- API アクセス用の AWS IAM ユーザーとポリシー
-
MCP サーバー(
/cloudflare-mcp-server):次の機能を持つ MCP サーバーを実装します。- AI アシスタント向けに
search_knowledge_baseツールを提供します - ドキュメントの取得に AWS Bedrock を統合します
- SSE(非推奨)とストリーム可能な HTTP トランスポートの両方をサポートします
- Node.js 互換環境で Cloudflare Workers 上で実行されます
- AI アシスタント向けに
-
MCP クライアント(
/ai-sdk-mcp-client):次の機能を持つデモ用クライアントです。- Nova Pro モデルで Vercel の AI SDK を使用します
- SSE とストリーム可能な HTTP トランスポートの両方をサポートする MCP クライアントとして動作します
- ツール呼び出しを含むテキスト応答をストリーミングします
graph TD
subgraph AWS
S3[S3 Bucket] -->|Stores Documents| KnowledgeBase
TitanModel[Titan Embed Text V2] -->|Embedding Model| KnowledgeBase
Lambda -->|Retrieve API| KnowledgeBase
NovaPro[Nova Pro]
end
subgraph Pinecone
KnowledgeBase[Bedrock Knowledge Base] -->|Vector Embeddings| PineconeDb[Vector Database]
end
subgraph Cloudflare
Worker -->|Retrieve API| KnowledgeBase
end
Demo -->|InvokeModel API| NovaPro
Demo -->|MCP<br />Streamable HTTP| Lambda
Demo -->|MCP<br />Server Sent Event| Worker
Demo -->|MCP<br />Streamable HTTP| Worker
インフラストラクチャ
セットアップ
cd cdk
npm install
# Unique identifier for the CDK stack
export CDK_APP_ID="DocsMcpServer"
# Pinecone credentials to manage vector databases
export PINECONE_API_KEY="pcsk_foo"
# Deploy the stack
npx cdk deploy
出力例
DocsMcpServer.AwsAccessKeyId = AKI123
DocsMcpServer.AwsRegion = us-east-1
DocsMcpServer.AwsSecretAccessKey = 4cQ456
DocsMcpServer.DataSourceId = OD6LTXXUNH
DocsMcpServer.DocsBucketName = docsmcpserver-docsbucketa5ce02e3-gg8g3crhlo1j
DocsMcpServer.KnowledgeBaseId = GZUYX1EGMF
DocsMcpServer.McpServerUrl = https://vc7ejtu4kk3ayeiqofkmxxzada0uwpzr.lambda-url.us-east-1.on.aws/
ドキュメントの更新
/docs ディレクトリには、ナレッジベースを最新のドキュメントで更新するためのスクリプトが含まれています。
cd docs
# Set environment variables from the CDK output
export DATA_SOURCE_ID="OD6LTXXUNH"
export DOCS_BUCKET_NAME="docsmcpserver-docsbucketa5ce02e3-gg8g3crhlo1j"
export KNOWLEDGE_BASE_ID="GZUYX1EGMF"
# Run the update script
./update.sh
このスクリプトは次の処理を行います。
- CloudFlare と MCP のウェブサイトから最新のドキュメントをダウンロードします
- ファイルを S3 にアップロードします
- ナレッジベースを更新するための新しい取り込みジョブを開始します
MCP サーバー
MCP サーバーは、AI アシスタントがインデックス化されたドキュメントを検索するために使用できる search_knowledge_base ツールを提供します。このツールはクエリー文字列を受け取り、関連するドキュメントを返します。
CDK の出力から次の変数を設定して、.dev.vars を作成します。
AWS_ACCESS_KEY_ID=AKI123
AWS_REGION=us-east-1
AWS_SECRET_ACCESS_KEY=4cQ456
KNOWLEDGE_BASE_ID=GZUYX1EGMF
セットアップ
cd cloudflare-mcp-server
npm install
npm run cf-typegen
# run locally
npm run dev
# or deploy to Cloudflare
npm run deploy
MCP クライアント
このクライアントは、SSE とストリーム可能な HTTP トランスポートの両方をサポートしながら、MCP サーバーに接続してそのツールを使用する方法を示します。
セットアップ
cd ai-sdk-mcp-client
npm install
# Set environment variables from the CDK output
export AWS_ACCESS_KEY_ID="AKI123"
export AWS_REGION="us-east-1"
export AWS_SECRET_ACCESS_KEY="4cQ456"
# Test connection to CloudFlare with SSE transport
npm start -- https://aws-knowledge-base-mcp-server.daohoangson.workers.dev/sse
# Test connection to CloudFlare with streamable HTTP transport
npm start -- https://aws-knowledge-base-mcp-server.daohoangson.workers.dev/mcp
# Test connection to Lambda
npm start -- https://vc7ejtu4kk3ayeiqofkmxxzada0uwpzr.lambda-url.us-east-1.on.aws/mcp
出力例
Created MCP client
{ tools: [ 'search_knowledge_base' ] }
<thinking> To determine if CloudFlare works with the Model Context Protocol (MCP), I need to search the knowledge base for relevant documentation. </thinking>
Tool call: search_knowledge_base {
"query": "Does CloudFlare work with Model Context Protocol (MCP)?"
}
ツールの結果
{
"content": [
{
"type": "text",
"text": "includes(\"special_feature\")) { this.server.tool(\"specialTool\", \"Special feature\", {}, async () => { // This tool only appears for users with the special_feature permission }); } } ``` Benefits: - Authorization check at the tool level ensures proper access control - Allows you to define permission checks once and reuse them across tools - Provides clear feedback to users when permission is denied - Can choose to only present tools that the agent is able to call ## Next steps - [Learn how to use the Workers OAuth Provider Library](https://github.com/cloudflare/workers-oauth-provider) - Learn how to use a third-party OAuth provider, using the [GitHub](/agents/guides/remote-mcp-server/#add-authentication) example MCP server. --- # Model Context Protocol (MCP) URL: https://developers.cloudflare.com/agents/model-context-protocol/ You can build and deploy [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers on Cloudflare. ## What is the Model Context Protocol (MCP)? [Model Context Protocol (MCP)](https://modelcontextprotocol.io) is an open standard that connects AI systems with external applications. Think of MCP like a USB-C port for AI applications."
},
{
"type": "text",
"text": "can call. When you build MCP Servers with the `@cloudflare/model-context-protocol` package, you can define tools the [same way as shown in the `@modelcontextprotocol/typescript-sdk` package's examples](https://github.com/modelcontextprotocol/typescript-sdk?tab=readme-ov-file#tools)."
},
{
"type": "text",
"text": "See our [list of example servers](https://modelcontextprotocol.io/examples), or [get started building your own server](https://modelcontextprotocol.io/quickstart/server). # Introduction Source: https://modelcontextprotocol.io/introduction Get started with the Model Context Protocol (MCP) <Note>C# SDK released! Check out [what else is new.](/development/updates)</Note> MCP is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools. ## Why MCP? MCP helps you build agents and complex workflows on top of LLMs. LLMs frequently need to integrate with data and tools, and MCP provides: * A growing list of pre-built integrations that your LLM can directly plug into * The flexibility to switch between LLM providers and vendors * Best practices for securing your data within your infrastructure ### General architecture At its core, MCP follows a client-server architecture where a host application can connect to multiple servers: ```mermaid flowchart LR subgraph \"Your Computer\" Host[\"Host with MCP Client\\n(Claude, IDEs, Tools)\"] S1[\"MCP Server A\"] S2[\"MCP Server B"
},
{
"type": "text",
"text": "). - **Local MCP connections**: MCP clients connect to MCP servers on the same machine, using [stdio](https://spec.modelcontextprotocol.io/specification/draft/basic/transports/#stdio) as a local transport method. ### Get Started Go to the [Getting Started](/agents/guides/remote-mcp-server/) guide to learn how to build and deploy your first remote MCP server to Cloudflare. --- # McpAgent — API Reference URL: https://developers.cloudflare.com/agents/model-context-protocol/mcp-agent-api/ import { Render, TypeScriptExample } from \"~/components\"; When you build MCP Servers on Cloudflare, you extend the [`McpAgent` class](https://github.com/cloudflare/agents/blob/5881c5d23a7f4580600029f69307cfc94743e6b8/packages/agents/src/mcp.ts), from the Agents SDK, like this: <TypeScriptExample> ```ts title=\"src/index.ts\" import { McpAgent } from \"agents/mcp\"; import { DurableMCP } from \"@cloudflare/model-context-protocol\"; export class MyMCP extends McpAgent { \tserver = new McpServer({ name: \"Demo\", version: \"1.0.0\" }); \tasync init() { \t\tthis.server.tool( \t\t\t\"add\", \t\t\t{ a: z.number(), b:"
},
{
"type": "text",
"text": "For instance, if the client doesn't have access to Claude models but has Gemini, it might map the sonnet hint to `gemini-1.5-pro` based on similar capabilities. ## Error Handling Clients **SHOULD** return errors for common failure cases: Example error: ```json { \"jsonrpc\": \"2.0\", \"id\": 1, \"error\": { \"code\": -1, \"message\": \"User rejected sampling request\" } } ``` ## Security Considerations 1. Clients **SHOULD** implement user approval controls 2. Both parties **SHOULD** validate message content 3. Clients **SHOULD** respect model preference hints 4. Clients **SHOULD** implement rate limiting 5. Both parties **MUST** handle sensitive data appropriately # Specification Source: https://modelcontextprotocol.io/specification/2025-03-26/index [Model Context Protocol](https://modelcontextprotocol.io) (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you're building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need."
}
]
}
はい、CloudFlare は Model Context Protocol(MCP)をサポートしています。CloudFlare 上で MCP サーバーを構築してデプロイできます。ドキュメントによると、CloudFlare は MCP サーバーを使い始めるのに役立つパッケージやサンプルを提供しています。
詳しい情報については、CloudFlare の Model Context Protocol ドキュメントを参照してください。
コスト見積もり
前提:
us-east-1リージョン- ドキュメント総数 2,000 件
- 各ドキュメントは約 5KB/約 1,250 トークン
- 月に 30 回、すべてを再インデックス化します(実際の実装では増分で処理します)
- 月間リクエスト数 3,000 件
- 各リクエストの CPU 時間は 5ms/実時間は 200ms
- 各クエリは約 100 トークン
- 各リクエストで 10 件のドキュメントを返します
| サービス | SKU | 表示価格 | 月間件数 | 月額コスト(USD) |
|---|---|---|---|---|
| AWS Bedrock | Titan Embeddings(インデックス作成) | $0.00002 / 1K tokens | 75,000K | $1.5 |
| Titan Embeddings(クエリ) | $0.00002 / 1K tokens | 300K | $0.006 | |
| AWS Lambda | リクエスト | $0.2 / 1M requests | 0.003M | $0.0006 |
| ARM64 実行時間 | $0.0000133334 / GB-s | 75 GB-s | $0.001 | |
| データ転送 OUT | $0.09 / GB | 0.15 GB | $0.0135 | |
| AWS S3 | 標準ストレージ | $0.023 / GB-month | 0.01 GB | $0.00023 |
| LIST リクエスト | $0.005 / 1K requests | 6K | $0.03 | |
| GET リクエスト | $0.0004 / 1K requests | 60K | $0.024 | |
| CloudFlare | Standard | $5 / month | 1 | $5 |
| リクエスト | $0.30 / million | 0.003 | $0.0009 | |
| CPU 時間 | $0.00002 / CPU-second | 15 | $0.0003 | |
| Pinecone | Standard | $25 / month | 1 | $25 |
| ベクトルストレージ | $0.33 / GB-month | 0.008 GB | $0.003 | |
| ベクトル挿入(書き込み) | $4 / million writes | 0.06M | $0.24 | |
| ベクトルクエリ(読み取り) | $16 / million reads | 0.03M | $0.48 |
- https://aws.amazon.com/bedrock/pricing/
- https://aws.amazon.com/s3/pricing/
- https://aws.amazon.com/lambda/pricing/
- CloudFlare Standard プランには、1,000 万件のリクエストと 3,000 CPU 秒が含まれます。
- Pinecone Standard プランには、月額 15 ドル分の利用クレジットが含まれます。代替案:
- Aurora PostgreSQL Serverless は、ライター 1 台、リーダー 1 台、NAT ゲートウェイ 2 台などで月額 180 ドルです(ブランチ
auroraを参照)。 - Amazon OpenSearch Serverless は、最低でも月額 350 ドルです。インデックス作成用 OCU 1 台と検索用 OCU 1 台以上が必要で、料金は OCU 時間あたり $0.24です。
- Aurora PostgreSQL Serverless は、ライター 1 台、リーダー 1 台、NAT ゲートウェイ 2 台などで月額 180 ドルです(ブランチ
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。

