はじめに
ローカルで MCP サーバーを動かすことも可能かと思いますが、環境の差異などにより動く動かないなどの問題が生じるかと思います。
そこで今回は独自開発した MCP サーバーを Amazon Bedrock AgentCore Runtime に公開してみていきたいと思います。
ちなみに過去には Amazon Bedrock AgentCore Runtime へ AI エージェントを公開した実装は以下の通りであるので参考までに。
やってみる
認証用の Cognito ユーザープールの設定
AWS ドキュメントに Cognito ユーザープールの作成がスクリプト化(setup_cognito.sh)されているものがあるので、これをそのまま使いデプロイします。
デプロイが完了したら後で以下の情報を使うので、控えておきます。
Pool id: us-west-2_UNw...
Discovery URL: https://cognito-idp.us-west-2.amazonaws.com/us-west-2_UNw.../.well-known/openid-configuration
Client ID: 75v...
Bearer Token: eyJ...
準備するソースコード と requirements
task_manager.py と requirements.txt を準備しておきます。
from fastmcp import FastMCP
mcp = FastMCP(host="0.0.0.0", stateless_http=True)
@mcp.tool()
def add_numbers(a: int, b: int) -> int:
"""
足し算
"""
return a + b
@mcp.tool()
def multiply_numbers(a: int, b: int) -> int:
"""
かけ算
"""
return a * b
if __name__ == "__main__":
mcp.run(transport="streamable-http")
fastmcp
bedrock-agentcore-starter-toolkit
agentcore コマンドでデプロイするために bedrock-agentcore-starter-toolkit をインストールしておきます。
python3 -m venv venv
source venv/bin/activate
pip install bedrock-agentcore-starter-toolkit
Amazon Bedrock AgentCore Runtime の設定ファイルの作成
agentcore configure -e コマンドで対話的に設定ファイルを作成していきます。
この時に Discovery URL と Client ID は 【認証用の Cognito ユーザープールの設定】 で控えたものを指定します。
agentcore configure -e task_manager.py --protocol MCP
Amazon Bedrock AgentCore Runtime のデプロイ
agentcore launch でデプロイし、Agent ARN を控えておきます。
agentcore launch
ClaudeCode から使う
【Amazon Bedrock AgentCore Runtime のデプロイ】 で控えておいた Agent ARN を設定し、次のコマンドで、MCP サーバーの URL を取得します。
agent_arn = "<Agent ARN>"
encoded_arn = agent_arn.replace(':', '%3A').replace('/', '%2F')
mcp_url = f"https://bedrock-agentcore.us-west-2.amazonaws.com/runtimes/{encoded_arn}/invocations?qualifier=DEFAULT"
print(f"MCP_URL: {mcp_url}")
先程取得した MCP サーバーの URL と【認証用の Cognito ユーザープールの設定】で控えておいた Bearer Token を設定し、ClaudeCode に MCP サーバーを追加します。
claude mcp add --transport http \
task-manager-mcp-server "<MCP サーバーの URL>" \
--header "Authorization: Bearer <Bearer Token>"





