Skip to content

Commit c00a1e7

Browse files
author
vijay
committed
Extract parallel directory-URI validator in Skills handlers
_handle_read_directory inlined the same "validate incoming URI, convert ValueError to MCPError" pattern that _handle_get had already extracted into a helper. Add a parallel _require_directory_uri so both handlers open with a symmetric one-line precondition check, matching the _require_ui_scheme helper idiom from the Apps extension.
1 parent d31511c commit c00a1e7

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/mcp/server/skills.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ async def _handle_read_directory(
126126
self, ctx: ServerRequestContext[Any, Any], params: ReadDirectoryParams
127127
) -> HandlerResult:
128128
assert self._read_directory is not None
129-
try:
130-
parse_directory_uri(params.uri)
131-
except ValueError as exc:
132-
raise MCPError(code=INVALID_PARAMS, message=str(exc)) from exc
129+
_require_directory_uri(params.uri)
133130
result = await self._read_directory(ctx, params)
134131
try:
135132
validate_directory_result(params.uri, result)
@@ -147,6 +144,13 @@ def _require_skill_md_uri(uri: str) -> None:
147144
raise MCPError(code=INVALID_PARAMS, message=str(exc)) from exc
148145

149146

147+
def _require_directory_uri(uri: str) -> None:
148+
try:
149+
parse_directory_uri(uri)
150+
except ValueError as exc:
151+
raise MCPError(code=INVALID_PARAMS, message=str(exc)) from exc
152+
153+
150154
def _finalize_cacheable(result: ListSkillsResult, protocol_version: str) -> HandlerResult:
151155
"""Gate SEP-2549's `ttlMs`/`cacheScope` to protocol version 2026-07-28+.
152156

0 commit comments

Comments
 (0)