Skip to content

Commit 645aede

Browse files
committed
Fix lint
1 parent 7f68fab commit 645aede

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

examples/mcp/caching/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111

1212
async def run(mcp_server: MCPServerStreamableHttp):
13-
print(f"Cached tools before invoking tool_list")
13+
print("Cached tools before invoking tool_list")
1414
print(mcp_server._tools_list)
1515

16-
print(f"Cached tools names after invoking list_tools")
16+
print("Cached tools names after invoking list_tools")
1717
await mcp_server.list_tools()
1818
cached_tools_list = mcp_server._tools_list
1919
for tool in cached_tools_list:
2020
print(f"name: {tool.name}")
2121

22-
print(f"Cached prompts before invoking list_prompts")
22+
print("Cached prompts before invoking list_prompts")
2323
print(mcp_server._prompts_list)
2424

25-
print(f"\nCached prompts after invoking list_prompts")
25+
print("\nCached prompts after invoking list_prompts")
2626
await mcp_server.list_prompts()
2727
cached_prompts_list = mcp_server._prompts_list
2828
for prompt in cached_prompts_list.prompts:

src/agents/mcp/server.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,19 @@ def __init__(
9191
"""
9292
Args:
9393
cache_tools_list: Whether to cache the tools list. If `True`, the tools list will be
94-
cached and only fetched from the server once. If `False`, the tools list will be
95-
fetched from the server on each call to `list_tools()`. The cache can be invalidated
96-
by calling `invalidate_tools_cache()`. You should set this to `True` if you know the
97-
server will not change its tools list, because it can drastically improve latency
98-
(by avoiding a round-trip to the server every time).
99-
100-
cache_prompts_list: Whether to cache the prompts list. If `True`, the prompts list will be
101-
cached and only fetched from the server once. If `False`, the prompts list will be
102-
fetched from the server on each call to `list_prompts()`. The cache can be invalidated
103-
by calling `invalidate_prompts_cache()`. You should set this to `True` if you know the
104-
server will not change its prompts list, because it can drastically improve latency
105-
(by avoiding a round-trip to the server every time).
94+
cached and only fetched from the server once. If `False`, the tools list will be
95+
fetched from the server on each call to `list_tools()`. The cache can be invalidated
96+
by calling `invalidate_tools_cache()`. You should set this to `True` if you know the
97+
server will not change its tools list, because it can drastically improve latency
98+
(by avoiding a round-trip to the server every time).
99+
100+
cache_prompts_list: Whether to cache the prompts list. If `True`, the prompts list
101+
will be cached and only fetched from the server once. If `False`, the prompts
102+
list will be fetched from the server on each call to `list_prompts()`.
103+
The cache can be invalidated by calling `invalidate_prompts_cache()`.
104+
You should set this to `True` if you know the server will not change
105+
its prompts list, because it can drastically improve latency
106+
(by avoiding a round-trip to the server every time).
106107
107108
client_session_timeout_seconds: the read timeout passed to the MCP ClientSession.
108109
tool_filter: The tool filter to use for filtering tools.
@@ -387,11 +388,12 @@ def __init__(
387388
if you know the server will not change its tools list, because it can drastically
388389
improve latency (by avoiding a round-trip to the server every time).
389390
390-
cache_prompts_list: Whether to cache the prompts list. If `True`, the prompts list will be
391-
cached and only fetched from the server once. If `False`, the prompts list will be
392-
fetched from the server on each call to `list_prompts()`. The cache can be invalidated
393-
by calling `invalidate_prompts_cache()`. You should set this to `True` if you know the
394-
server will not change its prompts list, because it can drastically improve latency
391+
cache_prompts_list: Whether to cache the prompts list. If `True`, the prompts list
392+
will be cached and only fetched from the server once. If `False`, the prompts
393+
list will be fetched from the server on each call to `list_prompts()`.
394+
The cache can be invalidated by calling `invalidate_prompts_cache()`.
395+
You should set this to `True` if you know the server will not change
396+
its prompts list, because it can drastically improve latency
395397
(by avoiding a round-trip to the server every time).
396398
397399
name: A readable name for the server. If not provided, we'll create one from the
@@ -480,11 +482,12 @@ def __init__(
480482
if you know the server will not change its tools list, because it can drastically
481483
improve latency (by avoiding a round-trip to the server every time).
482484
483-
cache_prompts_list: Whether to cache the prompts list. If `True`, the prompts list will be
484-
cached and only fetched from the server once. If `False`, the prompts list will be
485-
fetched from the server on each call to `list_prompts()`. The cache can be invalidated
486-
by calling `invalidate_prompts_cache()`. You should set this to `True` if you know the
487-
server will not change its prompts list, because it can drastically improve latency
485+
cache_prompts_list: Whether to cache the prompts list. If `True`, the prompts list
486+
will be cached and only fetched from the server once. If `False`, the prompts
487+
list will be fetched from the server on each call to `list_prompts()`.
488+
The cache can be invalidated by calling `invalidate_prompts_cache()`.
489+
You should set this to `True` if you know the server will not change
490+
its prompts list, because it can drastically improve latency
488491
(by avoiding a round-trip to the server every time).
489492
490493
name: A readable name for the server. If not provided, we'll create one from the
@@ -575,11 +578,12 @@ def __init__(
575578
if you know the server will not change its tools list, because it can drastically
576579
improve latency (by avoiding a round-trip to the server every time).
577580
578-
cache_prompts_list: Whether to cache the prompts list. If `True`, the prompts list will be
579-
cached and only fetched from the server once. If `False`, the prompts list will be
580-
fetched from the server on each call to `list_prompts()`. The cache can be invalidated
581-
by calling `invalidate_prompts_cache()`. You should set this to `True` if you know the
582-
server will not change its prompts list, because it can drastically improve latency
581+
cache_prompts_list: Whether to cache the prompts list. If `True`, the prompts list
582+
will be cached and only fetched from the server once. If `False`, the prompts
583+
list will be fetched from the server on each call to `list_prompts()`.
584+
The cache can be invalidated by calling `invalidate_prompts_cache()`.
585+
You should set this to `True` if you know the server will not change
586+
its prompts list, because it can drastically improve latency
583587
(by avoiding a round-trip to the server every time).
584588
585589
name: A readable name for the server. If not provided, we'll create one from the

tests/mcp/test_caching.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ async def test_server_caching_tools_works(
6969
async def test_server_caching_prompts_works(
7070
mock_list_prompts: AsyncMock, mock_initialize: AsyncMock, mock_stdio_client
7171
):
72-
"""Test that if we turn caching on, the list of prompts is cached and not fetched from the server
73-
on each call to `list_prompts()`.
72+
"""Test that if we turn caching on, the list of prompts is cached and not fetched
73+
from the server on each call to `list_prompts()`.
7474
"""
7575
server = MCPServerStdio(
7676
params={
@@ -98,15 +98,18 @@ async def test_server_caching_prompts_works(
9898
result_prompts = await server.list_prompts()
9999
assert result_prompts == prompts
100100

101-
assert mock_list_prompts.call_count == 1, "list_prompts() should not have been called again"
101+
assert mock_list_prompts.call_count == 1, ("list_prompts() "
102+
"should not have been called again")
102103

103104
# Invalidate the cache and call list_prompts() again
104105
server.invalidate_prompts_cache()
105106
result_prompts = await server.list_prompts()
106107
assert result_prompts == prompts
107108

108-
assert mock_list_prompts.call_count == 2, "list_prompts() should be called again"
109+
assert mock_list_prompts.call_count == 2, ("list_prompts() "
110+
"should be called again")
109111

110-
# Without invalidating the cache, calling list_prompts() again should return the cached value
112+
# Without invalidating the cache, calling list_prompts()
113+
# again should return the cached value
111114
result_prompts = await server.list_prompts()
112115
assert result_prompts == prompts

0 commit comments

Comments
 (0)