Skip to content

Commit 16416bd

Browse files
committed
Fix linting issues
1 parent 27bdf61 commit 16416bd

File tree

10 files changed

+40
-59
lines changed

10 files changed

+40
-59
lines changed

examples/mcp-client/agent-framework/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ MCP_SERVER_AWS_SERVICE="bedrock-agentcore"
66
MCP_SERVER_REGION="us-west-2"
77

88
# Your OpenAI API key for the agent's language model
9-
OPENAI_API_KEY="sk-..."
9+
OPENAI_API_KEY="sk-..."

examples/mcp-client/agent-framework/main.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Example: Using MCP Proxy for AWS as a client for Microsoft Agent Framework integration
1+
"""Example: Using MCP Proxy for AWS as a client for Microsoft Agent Framework integration.
32
43
This example demonstrates how to use the aws_iam_mcp_client with the Microsoft Agent Framework
54
to connect an AI agent to an MCP server using AWS IAM authentication.
@@ -25,12 +24,10 @@
2524
import asyncio
2625
import dotenv
2726
import os
28-
from contextlib import asynccontextmanager
29-
3027
from agent_framework import ChatAgent
31-
from agent_framework.openai import OpenAIChatClient
3228
from agent_framework._mcp import MCPStreamableHTTPTool
33-
29+
from agent_framework.openai import OpenAIChatClient
30+
from contextlib import asynccontextmanager
3431
from mcp_proxy_for_aws.client import aws_iam_mcp_client
3532

3633

@@ -51,19 +48,18 @@
5148

5249
@asynccontextmanager
5350
async def create_agent():
54-
"""
55-
Create an Agent Framework agent with AWS IAM-authenticated MCP server access.
51+
"""Create an Agent Framework agent with AWS IAM-authenticated MCP server access.
5652
5753
This function demonstrates the key integration pattern:
58-
1. Configure an aws_iam_mcp_client factory with the MCP server details
54+
1. Define an aws_iam_mcp_client factory function with the MCP server details
5955
2. Initialize an MCPStreamableHTTPTool and add the client factory
6056
3. Create an agent with access to the tools provided by the MCP server
6157
4. Return a callable interface to communicate with the agent
6258
"""
63-
# Configure the MCP client with AWS IAM authentication
64-
mcp_client_factory = lambda: aws_iam_mcp_client(
65-
endpoint=MCP_URL, aws_region=MCP_REGION, aws_service=MCP_SERVICE
66-
)
59+
60+
# Define MCP client factory function for AWS IAM authentication
61+
def mcp_client_factory():
62+
return aws_iam_mcp_client(endpoint=MCP_URL, aws_region=MCP_REGION, aws_service=MCP_SERVICE)
6763

6864
# Create an Agent Framework MCP and add the client
6965
mcp_tools = MCPStreamableHTTPTool(name='MCP Tools', url=MCP_URL)
@@ -87,7 +83,6 @@ async def agent_callable(user_input: str) -> str:
8783

8884
async def main():
8985
"""Run the agent example by asking it to list its available tools."""
90-
9186
# Validate required environment variables
9287
if not MCP_URL or not MCP_REGION or not MCP_SERVICE or not OPENAI_API_KEY:
9388
raise ValueError(

examples/mcp-client/langchain/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ MCP_SERVER_URL="https://example-mcp-server.gateway.bedrock-agentcore.us-west-2.a
33
# The AWS service hosting the MCP server
44
MCP_SERVER_AWS_SERVICE="bedrock-agentcore"
55
# The AWS region where the MCP server is hosted
6-
MCP_SERVER_REGION="us-west-2"
6+
MCP_SERVER_REGION="us-west-2"

examples/mcp-client/langchain/main.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Example: Using MCP Proxy for AWS as a client for LangChain Agent integration
1+
"""Example: Using MCP Proxy for AWS as a client for LangChain Agent integration.
32
43
This example demonstrates how to use the aws_iam_mcp_client with LangChain
54
to connect an AI agent to an MCP server using AWS IAM authentication.
@@ -13,6 +12,12 @@
1312
- MCP_REGION: AWS region where the MCP server is hosted (e.g., "us-west-2")
1413
3. Run: `uv run main.py`
1514
15+
Example .env file:
16+
==================
17+
MCP_SERVER_URL=https://example.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp
18+
MCP_SERVER_AWS_SERVICE=bedrock-agentcore
19+
MCP_SERVER_REGION=us-west-2
20+
1621
Example .env file:
1722
==================
1823
MCP_SERVER_URL=https://example.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp
@@ -24,12 +29,10 @@
2429
import dotenv
2530
import os
2631
from contextlib import asynccontextmanager
27-
28-
from langchain_aws import ChatBedrock
2932
from langchain.agents import create_agent as create_langchain_agent
33+
from langchain_aws import ChatBedrock
3034
from langchain_mcp_adapters.tools import load_mcp_tools
3135
from mcp.client.session import ClientSession
32-
3336
from mcp_proxy_for_aws.client import aws_iam_mcp_client
3437

3538

@@ -47,8 +50,7 @@
4750

4851
@asynccontextmanager
4952
async def create_agent():
50-
"""
51-
Create a LangChain agent with AWS IAM-authenticated MCP server access.
53+
"""Create a LangChain agent with AWS IAM-authenticated MCP server access.
5254
5355
This function demonstrates the key integration pattern:
5456
1. Configure an aws_iam_mcp_client with the MCP server details
@@ -86,7 +88,6 @@ async def agent_callable(user_input: str) -> str:
8688

8789
async def main():
8890
"""Run the agent example by asking it to list its available tools."""
89-
9091
# Validate required environment variables
9192
if not MCP_URL or not MCP_REGION or not MCP_SERVICE:
9293
raise ValueError(

examples/mcp-client/llamaindex/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ MCP_SERVER_AWS_SERVICE="bedrock-agentcore"
66
MCP_SERVER_REGION="us-west-2"
77

88
# Your OpenAI API key for the agent's language model
9-
OPENAI_API_KEY="sk-..."
9+
OPENAI_API_KEY="sk-..."

examples/mcp-client/llamaindex/main.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Example: Using MCP Proxy for AWS as a client for LlamaIndex Agent integration
1+
"""Example: Using MCP Proxy for AWS as a client for LlamaIndex Agent integration.
32
43
This example demonstrates how to use the aws_iam_mcp_client with LlamaIndex
54
to connect an AI agent to an MCP server using AWS IAM authentication.
@@ -22,24 +21,22 @@
2221
OPENAI_API_KEY=sk-...
2322
"""
2423

25-
# Ignore Pydantic UserWarnings that are not relevant to this example
26-
import warnings
27-
28-
warnings.filterwarnings('ignore', category=UserWarning, module='pydantic.*')
29-
3024
import asyncio
3125
import dotenv
3226
import os
27+
import warnings
3328
from contextlib import asynccontextmanager
34-
3529
from llama_index.core.agent.workflow import ReActAgent
3630
from llama_index.llms.openai import OpenAI
3731
from llama_index.tools.mcp import McpToolSpec
3832
from mcp.client.session import ClientSession
39-
4033
from mcp_proxy_for_aws.client import aws_iam_mcp_client
4134

4235

36+
# Ignore Pydantic UserWarnings that are not relevant to this example
37+
warnings.filterwarnings('ignore', category=UserWarning, module='pydantic.*')
38+
39+
4340
# Load configuration from .env file (if present)
4441
dotenv.load_dotenv()
4542

@@ -57,8 +54,7 @@
5754

5855
@asynccontextmanager
5956
async def create_agent():
60-
"""
61-
Create a LlamaIndex agent with AWS IAM-authenticated MCP server access.
57+
"""Create a LlamaIndex agent with AWS IAM-authenticated MCP server access.
6258
6359
This function demonstrates the key integration pattern:
6460
1. Configure an aws_iam_mcp_client with the MCP server details
@@ -96,7 +92,6 @@ async def agent_callable(user_input: str) -> str:
9692

9793
async def main():
9894
"""Run the agent example by asking it to list its available tools."""
99-
10095
# Validate required environment variables
10196
if not MCP_URL or not MCP_REGION or not MCP_SERVICE or not OPENAI_API_KEY:
10297
raise ValueError(

examples/mcp-client/strands/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ MCP_SERVER_URL="https://example-mcp-server.gateway.bedrock-agentcore.us-west-2.a
33
# The AWS service hosting the MCP server
44
MCP_SERVER_AWS_SERVICE="bedrock-agentcore"
55
# The AWS region where the MCP server is hosted
6-
MCP_SERVER_REGION="us-west-2"
6+
MCP_SERVER_REGION="us-west-2"

examples/mcp-client/strands/main.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Example: Using MCP Proxy for AWS as a client for Strands Agent integration
1+
"""Example: Using MCP Proxy for AWS as a client for Strands Agent integration.
32
43
This example demonstrates how to use the aws_iam_mcp_client with the Strands SDK
54
to connect an AI agent to an MCP server using AWS IAM authentication.
@@ -24,12 +23,10 @@
2423
import dotenv
2524
import os
2625
from contextlib import asynccontextmanager
27-
26+
from mcp_proxy_for_aws.client import aws_iam_mcp_client
2827
from strands import Agent
2928
from strands.tools.mcp.mcp_client import MCPClient
3029

31-
from mcp_proxy_for_aws.client import aws_iam_mcp_client
32-
3330

3431
# Load configuration from .env file (if present)
3532
dotenv.load_dotenv()
@@ -42,20 +39,19 @@
4239

4340
@asynccontextmanager
4441
async def create_agent():
45-
"""
46-
Create a Strands agent with AWS IAM-authenticated MCP server access.
42+
"""Create a Strands agent with AWS IAM-authenticated MCP server access.
4743
4844
This function demonstrates the key integration pattern:
49-
1. Configure an aws_iam_mcp_client factory with the MCP server details
45+
1. Define an aws_iam_mcp_client factory function with the MCP server details
5046
2. Initialize a Strands MCPClient with the client factory
5147
3. Retrieve the available tools from the MCP server
5248
4. Create an agent with access to those tools
5349
5. Return a callable interface to communicate with the agent
5450
"""
55-
# Configure the MCP client with AWS IAM authentication
56-
mcp_client_factory = lambda: aws_iam_mcp_client(
57-
endpoint=MCP_URL, aws_region=MCP_REGION, aws_service=MCP_SERVICE
58-
)
51+
52+
# Define MCP client factory function for AWS IAM authentication
53+
def mcp_client_factory():
54+
return aws_iam_mcp_client(endpoint=MCP_URL, aws_region=MCP_REGION, aws_service=MCP_SERVICE)
5955

6056
# Create a Strands MCP client and retrieve the tools from the server
6157
with MCPClient(mcp_client_factory) as mcp_client:
@@ -75,7 +71,6 @@ async def agent_callable(user_input: str) -> str:
7571

7672
async def main():
7773
"""Run the agent example by asking it to list its available tools."""
78-
7974
# Validate required environment variables
8075
if not MCP_URL or not MCP_REGION or not MCP_SERVICE:
8176
raise ValueError(

mcp_proxy_for_aws/client.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414

1515
import boto3
1616
import logging
17-
1817
from datetime import timedelta
19-
from typing import Optional
20-
2118
from mcp.client.streamable_http import streamablehttp_client
2219
from mcp.shared._httpx_utils import McpHttpClientFactory, create_mcp_http_client
23-
2420
from mcp_proxy_for_aws.sigv4_helper import SigV4HTTPXAuth
21+
from typing import Optional
2522

2623

2724
logger = logging.getLogger(__name__)
@@ -38,8 +35,7 @@ def aws_iam_mcp_client(
3835
terminate_on_close: bool = True,
3936
httpx_client_factory: McpHttpClientFactory = create_mcp_http_client,
4037
):
41-
"""
42-
Create an AWS IAM-authenticated MCP streamable HTTP client.
38+
"""Create an AWS IAM-authenticated MCP streamable HTTP client.
4339
4440
This function creates a context manager for connecting to an MCP server using AWS IAM
4541
authentication via SigV4 signing. Use with 'async with' to manage the connection lifecycle.

tests/unit/test_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
"""Unit tests for the client, parameterized by internal call."""
1616

1717
import pytest
18-
1918
from datetime import timedelta
20-
from unittest.mock import AsyncMock, Mock, patch
2119
from mcp_proxy_for_aws.client import aws_iam_mcp_client
20+
from unittest.mock import AsyncMock, Mock, patch
2221

2322

2423
@pytest.fixture

0 commit comments

Comments
 (0)