Add mypy to pre-commit (#43)

* Add mypy to pre-commit

* Enable GH action to run pytest on Python 3.13
This commit is contained in:
Kacper Łukawski
2025-04-10 15:03:48 +02:00
committed by GitHub
parent 75d605deff
commit ecba1ddce6
6 changed files with 21 additions and 14 deletions

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python-version: ['3.10', '3.11', '3.12'] python-version: ['3.10', '3.11', '3.12', '3.13']
name: Python ${{ matrix.python-version }} name: Python ${{ matrix.python-version }}

View File

@@ -27,3 +27,9 @@ repos:
- id: isort - id: isort
name: "Sort Imports" name: "Sort Imports"
args: [ "--profile", "black" ] args: [ "--profile", "black" ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies: [tokenize-rt==3.2.0]

View File

@@ -19,6 +19,7 @@ build-backend = "hatchling.build"
[tool.uv] [tool.uv]
dev-dependencies = [ dev-dependencies = [
"isort>=6.0.1", "isort>=6.0.1",
"mypy>=1.9.0",
"pre-commit>=4.1.0", "pre-commit>=4.1.0",
"pyright>=1.1.389", "pyright>=1.1.389",
"pytest>=8.3.3", "pytest>=8.3.3",

View File

@@ -56,6 +56,10 @@ class QdrantMCPServer(FastMCP):
return f"<entry><content>{entry.content}</content><metadata>{entry_metadata}</metadata></entry>" return f"<entry><content>{entry.content}</content><metadata>{entry_metadata}</metadata></entry>"
def setup_tools(self): def setup_tools(self):
"""
Register the tools in the server.
"""
async def store( async def store(
ctx: Context, ctx: Context,
information: str, information: str,
@@ -63,7 +67,7 @@ class QdrantMCPServer(FastMCP):
# The `metadata` parameter is defined as non-optional, but it can be None. # The `metadata` parameter is defined as non-optional, but it can be None.
# If we set it to be optional, some of the MCP clients, like Cursor, cannot # If we set it to be optional, some of the MCP clients, like Cursor, cannot
# handle the optional parameter correctly. # handle the optional parameter correctly.
metadata: Metadata = None, metadata: Metadata = None, # type: ignore
) -> str: ) -> str:
""" """
Store some information in Qdrant. Store some information in Qdrant.
@@ -86,8 +90,9 @@ class QdrantMCPServer(FastMCP):
async def store_with_default_collection( async def store_with_default_collection(
ctx: Context, ctx: Context,
information: str, information: str,
metadata: Metadata = None, metadata: Metadata = None, # type: ignore
) -> str: ) -> str:
assert self.qdrant_settings.collection_name is not None
return await store( return await store(
ctx, information, self.qdrant_settings.collection_name, metadata ctx, information, self.qdrant_settings.collection_name, metadata
) )
@@ -129,6 +134,7 @@ class QdrantMCPServer(FastMCP):
ctx: Context, ctx: Context,
query: str, query: str,
) -> List[str]: ) -> List[str]:
assert self.qdrant_settings.collection_name is not None
return await find(ctx, query, self.qdrant_settings.collection_name) return await find(ctx, query, self.qdrant_settings.collection_name)
# Register the tools depending on the configuration # Register the tools depending on the configuration

View File

@@ -26,7 +26,8 @@ class QdrantConnector:
Encapsulates the connection to a Qdrant server and all the methods to interact with it. Encapsulates the connection to a Qdrant server and all the methods to interact with it.
:param qdrant_url: The URL of the Qdrant server. :param qdrant_url: The URL of the Qdrant server.
:param qdrant_api_key: The API key to use for the Qdrant server. :param qdrant_api_key: The API key to use for the Qdrant server.
:param collection_name: The name of the collection to use. :param collection_name: The name of the default collection to use. If not provided, each tool will require
the collection name to be provided.
:param embedding_provider: The embedding provider to use. :param embedding_provider: The embedding provider to use.
:param qdrant_local_path: The path to the storage directory for the Qdrant client, if local mode is used. :param qdrant_local_path: The path to the storage directory for the Qdrant client, if local mode is used.
""" """
@@ -35,7 +36,7 @@ class QdrantConnector:
self, self,
qdrant_url: Optional[str], qdrant_url: Optional[str],
qdrant_api_key: Optional[str], qdrant_api_key: Optional[str],
collection_name: str, collection_name: Optional[str],
embedding_provider: EmbeddingProvider, embedding_provider: EmbeddingProvider,
qdrant_local_path: Optional[str] = None, qdrant_local_path: Optional[str] = None,
): ):
@@ -63,6 +64,7 @@ class QdrantConnector:
the default collection is used. the default collection is used.
""" """
collection_name = collection_name or self._default_collection_name collection_name = collection_name or self._default_collection_name
assert collection_name is not None
await self._ensure_collection_exists(collection_name) await self._ensure_collection_exists(collection_name)
# Embed the document # Embed the document

View File

@@ -59,13 +59,5 @@ class QdrantSettings(BaseSettings):
local_path: Optional[str] = Field( local_path: Optional[str] = Field(
default=None, validation_alias="QDRANT_LOCAL_PATH" default=None, validation_alias="QDRANT_LOCAL_PATH"
) )
search_limit: Optional[int] = Field( search_limit: int = Field(default=10, validation_alias="QDRANT_SEARCH_LIMIT")
default=None, validation_alias="QDRANT_SEARCH_LIMIT"
)
read_only: bool = Field(default=False, validation_alias="QDRANT_READ_ONLY") read_only: bool = Field(default=False, validation_alias="QDRANT_READ_ONLY")
def get_qdrant_location(self) -> str:
"""
Get the Qdrant location, either the URL or the local path.
"""
return self.location or self.local_path