Skip to content

Commit 52cfd6f

Browse files
committed
feat: user agent should identify deepset mcp requests
1 parent 28a38e8 commit 52cfd6f

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/deepset_mcp/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# SPDX-FileCopyrightText: 2025-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
import importlib.metadata
45

6+
try:
7+
__version__ = importlib.metadata.version(__name__)
8+
except importlib.metadata.PackageNotFoundError:
9+
__version__ = "0.0.0" # Fallback for development mode

src/deepset_mcp/config.py

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

55
"""This module contains static configuration for the deepset MCP server."""
66

7+
from deepset_mcp import __version__
8+
79
# We need this mapping to which environment variables integrations are mapped to
810
# The mapping is maintained in the pipeline operator:
911
# https://github.com/deepset-ai/dc-pipeline-operator/blob/main/dc_operators/config.py#L279
@@ -27,3 +29,5 @@
2729
}
2830

2931
DEEPSET_DOCS_DEFAULT_SHARE_URL = "https://cloud.deepset.ai/shared_prototypes?share_token=prototype_eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3ODM0MjE0OTguNTk5LCJhdWQiOiJleHRlcm5hbCB1c2VyIiwiaXNzIjoiZEMiLCJ3b3Jrc3BhY2VfaWQiOiI4YzI0ZjExMi1iMjljLTQ5MWMtOTkzOS1hZTkxMDRhNTQyMWMiLCJ3b3Jrc3BhY2VfbmFtZSI6ImRjLWRvY3MtY29udGVudCIsIm9yZ2FuaXphdGlvbl9pZCI6ImNhOWYxNGQ0LWMyYzktNDYwZC04ZDI2LWY4Y2IwYWNhMDI0ZiIsInNoYXJlX2lkIjoiY2Y3MTA3ODAtOThmNi00MzlmLThiNzYtMmMwNDkyODNiMDZhIiwibG9naW5fcmVxdWlyZWQiOmZhbHNlfQ.5j6DCNRQ1_KB8lhIJqHyw2hBIleEW1_Y_UBuH6MTYY0"
32+
33+
DEFAULT_CLIENT_HEADER = {"headers": {"User-Agent": f"deepset-mcp/{__version__}"}}

src/deepset_mcp/tool_factory.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from mcp.server.fastmcp import FastMCP
1717

1818
from deepset_mcp.api.client import AsyncDeepsetClient
19+
from deepset_mcp.config import DEFAULT_CLIENT_HEADER
1920
from deepset_mcp.initialize_embedding_model import get_initialized_model
2021
from deepset_mcp.store import STORE
2122
from deepset_mcp.tools.custom_components import (
@@ -121,7 +122,9 @@ async def search_docs(query: str) -> str:
121122
:param query: The search query to execute against the documentation.
122123
:returns: The formatted search results from the documentation.
123124
"""
124-
async with AsyncDeepsetClient(api_key=os.environ["DEEPSET_DOCS_API_KEY"]) as client:
125+
async with AsyncDeepsetClient(
126+
api_key=os.environ["DEEPSET_DOCS_API_KEY"], transport_config=DEFAULT_CLIENT_HEADER
127+
) as client:
125128
response = await search_docs_tool(
126129
client=client,
127130
workspace=os.environ["DEEPSET_DOCS_WORKSPACE"],
@@ -377,22 +380,22 @@ async def func_with_custom_args(*args: Any, **kwargs: Any) -> Any:
377380

378381
async def workspace_environment_wrapper(**kwargs: Any) -> Any:
379382
ws = workspace or get_workspace_from_env()
380-
async with AsyncDeepsetClient() as client:
383+
async with AsyncDeepsetClient(transport_config=DEFAULT_CLIENT_HEADER) as client:
381384
return await decorated_func(client=client, workspace=ws, **kwargs)
382385

383386
wrapper = workspace_environment_wrapper
384387
else: # DYNAMIC mode
385388

386389
async def workspace_explicit_wrapper(**kwargs: Any) -> Any:
387-
async with AsyncDeepsetClient() as client:
390+
async with AsyncDeepsetClient(transport_config=DEFAULT_CLIENT_HEADER) as client:
388391
# The first argument is the workspace, which must be passed by keyword.
389392
return await decorated_func(client=client, **kwargs)
390393

391394
wrapper = workspace_explicit_wrapper
392395
else: # Client-only tools
393396

394397
async def client_only_wrapper(**kwargs: Any) -> Any:
395-
async with AsyncDeepsetClient() as client:
398+
async with AsyncDeepsetClient(transport_config=DEFAULT_CLIENT_HEADER) as client:
396399
return await decorated_func(client=client, **kwargs)
397400

398401
wrapper = client_only_wrapper

0 commit comments

Comments
 (0)