Skip to content

Commit 9109577

Browse files
committed
add a no op validator, add logging and ensure cache is refreshed properly
1 parent 4d327cd commit 9109577

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/mcp/client/session.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import logging
12
from collections.abc import Awaitable, Callable
23
from datetime import timedelta
3-
import logging
44
from typing import Any, Protocol, TypeAlias
55

66
import anyio.lowlevel
@@ -14,11 +14,11 @@
1414
from mcp.shared.session import BaseSession, ProgressFnT, RequestResponder
1515
from mcp.shared.version import SUPPORTED_PROTOCOL_VERSIONS
1616

17-
1817
logger = logging.getLogger(__name__)
1918

2019
DEFAULT_CLIENT_INFO = types.Implementation(name="mcp", version="0.1.0")
2120

21+
2222
class SamplingFnT(Protocol):
2323
async def __call__(
2424
self,
@@ -451,6 +451,13 @@ async def _received_notification(
451451
pass
452452

453453

454+
class NoOpToolOutputValidator(ToolOutputValidationFnT):
455+
async def __call__(
456+
self, request: types.CallToolRequest, result: types.CallToolResult
457+
) -> bool:
458+
return True
459+
460+
454461
class SimpleCachingToolOutputValidator(ToolOutputValidationFnT):
455462
_schema_cache: dict[str, dict[str, Any] | bool]
456463

@@ -475,7 +482,7 @@ async def __call__(
475482
raise RuntimeError(f"Unknown tool {request.params.name}")
476483
elif schema is False:
477484
# no schema
478-
logging.debug('No schema found checking structuredContent is empty')
485+
logging.debug("No schema found checking structuredContent is empty")
479486
return result.structuredContent is None
480487
else:
481488
try:
@@ -490,6 +497,7 @@ async def __call__(
490497
async def _refresh_schema_cache(self):
491498
cursor = None
492499
first = True
500+
self._schema_cache = {}
493501
while first or cursor is not None:
494502
first = False
495503
tools_result = await self._session.list_tools(cursor)

0 commit comments

Comments
 (0)