3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Amazon Bedrock AgentCore Runtime に 自作 MCP サーバーをデプロイして ClaudeCode から呼び出してみる

Posted at

はじめに

ローカルで MCP サーバーを動かすことも可能かと思いますが、環境の差異などにより動く動かないなどの問題が生じるかと思います。

そこで今回は独自開発した MCP サーバーを Amazon Bedrock AgentCore Runtime に公開してみていきたいと思います。

スクリーンショット 2025-11-09 16.38.16.png

ちなみに過去には 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.pyrequirements.txt を準備しておきます。

task_manager.py
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")
requirements.txt
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 URLClient ID は 【認証用の Cognito ユーザープールの設定】 で控えたものを指定します。

agentcore configure -e task_manager.py --protocol MCP

スクリーンショット 2025-11-11 23.53.50.png
スクリーンショット 2025-11-11 23.54.09.png

Amazon Bedrock AgentCore Runtime のデプロイ

agentcore launch でデプロイし、Agent ARN を控えておきます。

agentcore launch

スクリーンショット 2025-11-11 23.55.46.png

ClaudeCode から使う

【Amazon Bedrock AgentCore Runtime のデプロイ】 で控えておいた Agent ARN を設定し、次のコマンドで、MCP サーバーの URL を取得します。

mcp_url.py
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>"

ClaudeCode を起動し、/mcp コマンドで MCP サーバーが起動しているか確しておきます。
スクリーンショット 2025-11-12 0.07.59.png

では、最後に ClaudeCode に質問して、MCP サーバーが動作するか動作確認してみましょう。
スクリーンショット 2025-11-12 1.57.27.png

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?