Skip to content

Commit e5130f9

Browse files
authored
feat: update user agent with proxy info (#225)
* Include mcp-proxy-for-aws in the user agent * Update tests * Update uv.lock
1 parent be8506a commit e5130f9

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

mcp_proxy_for_aws/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from fastmcp.server.middleware.error_handling import RetryMiddleware
2929
from fastmcp.server.middleware.logging import LoggingMiddleware
3030
from fastmcp.server.server import FastMCP
31+
from mcp_proxy_for_aws import __version__
3132
from mcp_proxy_for_aws.cli import parse_args
3233
from mcp_proxy_for_aws.logging_config import configure_logging
3334
from mcp_proxy_for_aws.middleware.initialize_middleware import InitializeMiddleware
@@ -89,6 +90,7 @@ async def run_proxy(args) -> None:
8990
proxy = AWSMCPProxy(
9091
client_factory=client_factory,
9192
name='MCP Proxy for AWS',
93+
version=__version__,
9294
instructions=(
9395
'MCP Proxy for AWS provides access to SigV4 protected MCP servers through a single interface. '
9496
'This proxy handles authentication and request routing to the appropriate backend services.'

mcp_proxy_for_aws/sigv4_helper.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from botocore.awsrequest import AWSRequest
2323
from botocore.credentials import Credentials
2424
from functools import partial
25+
from httpx import __version__ as httpx_version
26+
from mcp_proxy_for_aws import __version__
2527
from typing import Any, Dict, Generator, Optional
2628

2729

@@ -154,8 +156,13 @@ def create_sigv4_client(
154156
**kwargs,
155157
}
156158

159+
user_agent = f'python-httpx/{httpx_version} mcp-proxy-for-aws/{__version__}'
160+
157161
# Add headers if provided
158-
default_headers = {'Accept': 'application/json, text/event-stream'}
162+
default_headers = {
163+
'Accept': 'application/json, text/event-stream',
164+
'User-Agent': user_agent,
165+
}
159166
if headers is not None:
160167
default_headers.update(headers)
161168
client_kwargs['headers'] = default_headers

tests/unit/test_sigv4_helper.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import httpx
1818
import pytest
19+
from httpx import __version__ as httpx_version
20+
from mcp_proxy_for_aws import __version__
1921
from mcp_proxy_for_aws.sigv4_helper import (
2022
SENSITIVE_HEADERS,
2123
SigV4HTTPXAuth,
@@ -142,6 +144,8 @@ def test_create_sigv4_client_default(self, mock_client_class, mock_create_sessio
142144
assert len(call_args[1]['event_hooks']['response']) == 1
143145
assert len(call_args[1]['event_hooks']['request']) == 2 # metadata + sign hooks
144146
assert call_args[1]['headers']['Accept'] == 'application/json, text/event-stream'
147+
expected_user_agent = f'python-httpx/{httpx_version} mcp-proxy-for-aws/{__version__}'
148+
assert call_args[1]['headers']['User-Agent'] == expected_user_agent
145149
assert result == mock_client
146150

147151
@patch('mcp_proxy_for_aws.sigv4_helper.create_aws_session')
@@ -163,6 +167,7 @@ def test_create_sigv4_client_with_custom_headers(self, mock_client_class, mock_c
163167
call_args = mock_client_class.call_args
164168
expected_headers = {
165169
'Accept': 'application/json, text/event-stream',
170+
'User-Agent': f'python-httpx/{httpx_version} mcp-proxy-for-aws/{__version__}',
166171
'Custom-Header': 'custom-value',
167172
}
168173
assert call_args[1]['headers'] == expected_headers
@@ -245,6 +250,7 @@ def test_create_sigv4_client_with_prompt_context(self, mock_client_class, mock_c
245250
# Verify headers include both default and prompt-context headers
246251
expected_headers = {
247252
'Accept': 'application/json, text/event-stream',
253+
'User-Agent': f'python-httpx/{httpx_version} mcp-proxy-for-aws/{__version__}',
248254
'X-MCP-Prompt-Context': 'enabled',
249255
'Content-Type': 'application/json',
250256
}

uv.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)