关于 AWS Knowledge Base MCP Server
这是一个通过 AWS Bedrock 知识库检索文档的 MCP 服务,并附带基础设施部署配置和示例客户端。适合需要让 AI 助手搜索已索引文档的场景。
主要功能
- 01提供 search_knowledge_base 工具
- 02通过 AWS Bedrock 检索文档
- 03支持 SSE 和 streamable HTTP
- 04包含基础设施配置与示例客户端
适用场景
- 01让 AI 助手检索已索引的文档
- 02通过示例客户端测试 MCP 工具
MCP 相关
该 MCP 服务向客户端提供 search_knowledge_base 工具,以查询索引文档;支持 SSE 和 streamable HTTP 传输。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
AWS Knowledge Base MCP 服务
用法
| Claude Desktop | GitHub Copilot |
|
|
|
|
|
此 Model Context Protocol(MCP)服务实现可让 AI 助手通过 AWS Bedrock 和 Cloudflare Workers 搜索知识库。本项目由三个主要组件构成:
架构
-
基础设施(
/cdk):配置以下资源:- 用于文档嵌入的 AWS Bedrock 知识库
- 用于高效文档搜索的 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
- 作为 MCP 客户端,同时支持 SSE 和可流式 HTTP 传输
- 通过工具调用流式传输文本响应
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 服务提供 search_knowledge_base 工具,AI 助手可以使用它搜索已建立索引的文档。该工具接收查询字符串,并返回相关文档。
根据 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 客户端
此客户端演示如何连接到 MCP 服务并使用其工具,同时支持 SSE 和可流式 HTTP 传输。
设置
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 次请求
- 每次请求耗费 5ms CPU 时间 / 200ms 实际耗时
- 每次查询约 100 个令牌
- 每次请求返回 10 份文档
| 服务 | SKU | 标价 | 每月用量 | 每月费用(USD) |
|---|---|---|---|---|
| AWS Bedrock | Titan Embeddings(索引) | $0.00002 / 1K 个令牌 | 75,000K | $1.5 |
| Titan Embeddings(查询) | $0.00002 / 1K 个令牌 | 300K | $0.006 | |
| AWS Lambda | 请求 | $0.2 / 1M 次请求 | 0.003M | $0.0006 |
| ARM64 运行时长 | $0.0000133334 / GB-s | 75 GB-s | $0.001 | |
| 出站数据传输 | $0.09 / GB | 0.15 GB | $0.0135 | |
| AWS S3 | 标准存储 | $0.023 / GB-month | 0.01 GB | $0.00023 |
| LIST 请求 | $0.005 / 1K 次请求 | 6K | $0.03 | |
| GET 请求 | $0.0004 / 1K 次请求 | 60K | $0.024 | |
| CloudFlare | 标准 | $5 / 月 | 1 | $5 |
| 请求 | $0.30 / 百万次 | 0.003 | $0.0009 | |
| CPU 时间 | $0.00002 / CPU 秒 | 15 | $0.0003 | |
| Pinecone | 标准 | $25 / 月 | 1 | $25 |
| 向量存储 | $0.33 / GB-month | 0.008 GB | $0.003 | |
| 向量插入(写入) | $4 / 百万次写入 | 0.06M | $0.24 | |
| 向量查询(读取) | $16 / 百万次读取 | 0.03M | $0.48 |
- https://aws.amazon.com/bedrock/pricing/
- https://aws.amazon.com/s3/pricing/
- https://aws.amazon.com/lambda/pricing/
- CloudFlare 标准套餐包含 10M 次请求和 3K CPU 秒。
- Pinecone 标准套餐包含 $15/月的使用额度。替代方案:
- Aurora PostgreSQL Serverless,每月 $180,包含 1 个写入器、1 个读取器、2 个 NAT 网关等(参见 分支
aurora) - Amazon OpenSearch Serverless,最低每月 $350,因为至少需要 1 个索引 OCU 和 1 个搜索 OCU,价格为 $0.24 / OCU-hour
- Aurora PostgreSQL Serverless,每月 $180,包含 1 个写入器、1 个读取器、2 个 NAT 网关等(参见 分支
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。

