-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhanced ResourceTemplate URI matching and type handling logic. #1439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
beaterblank
wants to merge
28
commits into
modelcontextprotocol:main
Choose a base branch
from
beaterblank:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
79bc4b8
Added RFC 6570 complaint form style query expansion as optional param…
33fd246
uv lock fix
01025ea
fix
397569a
fix mismatch
543e86c
added type validation for optional params
bfcbf6f
resolve conflicts
b076a13
fix format
7af828a
resolved conflicts
2ed668c
resolved conflicts
5d43128
Feature Added:
beaterblank 8fb7988
linting and formatting
beaterblank 8742101
Enhancement: compile and store the pattern once instead of recompilin…
beaterblank 15d6426
formatting
beaterblank d1de7f4
Merge branch 'main' into main
beaterblank 8e000d4
Merge branch 'main' into main
beaterblank 2be0e2a
Merge branch 'main' into main
beaterblank 4c10e65
Merge branch 'main' into main
beaterblank 20b4d28
merge #427
beaterblank bc7df53
handle validation in templates
beaterblank d7c21c1
bug fix
beaterblank 010c5f7
linting
beaterblank 7d60f21
Merge branch 'main' into main
beaterblank 6ab862b
added Path and Query Annotations
beaterblank 7e3b415
Merge branch 'main' of https://github.com/beaterblank/python-sdk
beaterblank 4027141
linting
beaterblank 5873bdd
examples
beaterblank 6c7819a
Path and Query bug fixes and tests and example.
beaterblank 0953fcb
Merge branch 'main' into main
beaterblank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import math | ||
| import uuid | ||
| from typing import ( | ||
| Any, | ||
| ClassVar, | ||
| Generic, | ||
| TypeVar, | ||
| ) | ||
|
|
||
| T = TypeVar("T") | ||
|
|
||
|
|
||
| class Convertor(Generic[T]): | ||
| regex: ClassVar[str] = "" | ||
|
|
||
| def convert(self, value: str) -> T: | ||
| raise NotImplementedError() | ||
|
|
||
| def to_string(self, value: T) -> str: | ||
| raise NotImplementedError() | ||
|
|
||
|
|
||
| class StringConvertor(Convertor[str]): | ||
| regex = r"[^/]+" | ||
|
|
||
| def convert(self, value: str) -> str: | ||
| return value | ||
|
|
||
| def to_string(self, value: str) -> str: | ||
| value = str(value) | ||
| assert "/" not in value, "May not contain path separators" | ||
| assert value, "Must not be empty" | ||
| return value | ||
|
|
||
|
|
||
| class PathConvertor(Convertor[str]): | ||
| regex = r".*" | ||
|
|
||
| def convert(self, value: str) -> str: | ||
| return str(value) | ||
|
|
||
| def to_string(self, value: str) -> str: | ||
| return str(value) | ||
|
|
||
|
|
||
| class IntegerConvertor(Convertor[int]): | ||
| regex = r"[0-9]+" | ||
|
|
||
| def convert(self, value: str) -> int: | ||
| try: | ||
| return int(value) | ||
| except ValueError: | ||
| raise ValueError(f"Value '{value}' is not a valid integer") | ||
|
|
||
| def to_string(self, value: int) -> str: | ||
| value = int(value) | ||
| assert value >= 0, "Negative integers are not supported" | ||
| return str(value) | ||
|
|
||
|
|
||
| class FloatConvertor(Convertor[float]): | ||
| regex = r"[0-9]+(?:\.[0-9]+)?" | ||
|
|
||
| def convert(self, value: str) -> float: | ||
| try: | ||
| return float(value) | ||
| except ValueError: | ||
| raise ValueError(f"Value '{value}' is not a valid float") | ||
|
|
||
| def to_string(self, value: float) -> str: | ||
| value = float(value) | ||
| assert value >= 0.0, "Negative floats are not supported" | ||
| assert not math.isnan(value), "NaN values are not supported" | ||
| assert not math.isinf(value), "Infinite values are not supported" | ||
| return f"{value:.20f}".rstrip("0").rstrip(".") | ||
|
|
||
|
|
||
| class UUIDConvertor(Convertor[uuid.UUID]): | ||
| regex = r"[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12}" | ||
|
|
||
| def convert(self, value: str) -> uuid.UUID: | ||
| try: | ||
| return uuid.UUID(value) | ||
| except ValueError: | ||
| raise ValueError(f"Value '{value}' is not a valid UUID") | ||
|
|
||
| def to_string(self, value: uuid.UUID) -> str: | ||
| return str(value) | ||
|
|
||
|
|
||
| CONVERTOR_TYPES: dict[str, Convertor[Any]] = { | ||
| "str": StringConvertor(), | ||
| "path": PathConvertor(), | ||
| "int": IntegerConvertor(), | ||
| "float": FloatConvertor(), | ||
| "uuid": UUIDConvertor(), | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should This be a
ValueError? Since it only happens when the converter has a bad implementation of converting.Should we go for
RuntimeError?