|
| 1 | +import sys |
1 | 2 | import time |
2 | 3 | import uuid |
3 | 4 | import json |
| 5 | +import inspect |
4 | 6 | import threading |
5 | 7 | import traceback |
6 | | -import sys |
7 | 8 | from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer |
8 | | -from typing import Any, Callable, get_type_hints, Annotated, BinaryIO |
| 9 | +from typing import Any, Callable, Union, Annotated, BinaryIO, NotRequired, get_origin, get_args, get_type_hints |
9 | 10 | from urllib.parse import urlparse, parse_qs |
10 | 11 | from io import BufferedIOBase |
11 | 12 |
|
@@ -338,8 +339,6 @@ def _mcp_tools_call(self, name: str, arguments: dict | None = None, _meta: dict |
338 | 339 |
|
339 | 340 | def _type_to_json_schema(self, py_type: Any) -> dict: |
340 | 341 | """Convert Python type hint to JSON schema object""" |
341 | | - from typing import get_origin, get_args, Union |
342 | | - |
343 | 342 | # Handle Annotated[Type, "description"] |
344 | 343 | if get_origin(py_type) is Annotated: |
345 | 344 | args = get_args(py_type) |
@@ -391,13 +390,6 @@ def _type_to_json_schema(self, py_type: Any) -> dict: |
391 | 390 |
|
392 | 391 | def _typed_dict_to_schema(self, typed_dict_class) -> dict: |
393 | 392 | """Convert TypedDict to JSON schema""" |
394 | | - try: |
395 | | - from typing_extensions import NotRequired |
396 | | - except ImportError: |
397 | | - from typing import NotRequired |
398 | | - |
399 | | - from typing import get_origin, get_args |
400 | | - |
401 | 393 | hints = get_type_hints(typed_dict_class, include_extras=True) |
402 | 394 | properties = {} |
403 | 395 | required = [] |
@@ -432,8 +424,6 @@ def _typed_dict_to_schema(self, typed_dict_class) -> dict: |
432 | 424 |
|
433 | 425 | def _generate_tool_schema(self, func_name: str, func: Callable) -> dict: |
434 | 426 | """Generate MCP tool schema from a function""" |
435 | | - import inspect |
436 | | - |
437 | 427 | hints = get_type_hints(func, include_extras=True) |
438 | 428 | return_type = hints.pop("return", None) |
439 | 429 | sig = inspect.signature(func) |
|
0 commit comments