From 6aa21b6d999c212422840dc56149bfc92cfad02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=C5=81ukawski?= Date: Wed, 5 Mar 2025 22:54:21 +0100 Subject: [PATCH] Run pre-commit --- README.md | 6 +-- src/mcp_server_qdrant/embeddings/factory.py | 51 +------------------ src/mcp_server_qdrant/embeddings/fastembed.py | 3 +- src/mcp_server_qdrant/qdrant.py | 8 ++- src/mcp_server_qdrant/server.py | 26 ++++++---- 5 files changed, 27 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index f430e0c..28247a7 100644 --- a/README.md +++ b/README.md @@ -114,13 +114,13 @@ You cannot provide `QDRANT_URL` and `QDRANT_LOCAL_PATH` at the same time. ## Contributing -If you have suggestions for how mcp-server-qdrant could be improved, or want to report a bug, open an issue! +If you have suggestions for how mcp-server-qdrant could be improved, or want to report a bug, open an issue! We'd love all and any contributions. ### Testing `mcp-server-qdrant` locally -The [MCP inspector](https://github.com/modelcontextprotocol/inspector) is a developer tool for testing and debugging MCP -servers. It runs both a client UI (default port 5173) and an MCP proxy server (default port 3000). Open the client UI in +The [MCP inspector](https://github.com/modelcontextprotocol/inspector) is a developer tool for testing and debugging MCP +servers. It runs both a client UI (default port 5173) and an MCP proxy server (default port 3000). Open the client UI in your browser to use the inspector. ```shell diff --git a/src/mcp_server_qdrant/embeddings/factory.py b/src/mcp_server_qdrant/embeddings/factory.py index a160dcf..b8b7f4e 100644 --- a/src/mcp_server_qdrant/embeddings/factory.py +++ b/src/mcp_server_qdrant/embeddings/factory.py @@ -11,56 +11,7 @@ def create_embedding_provider(provider_type: str, **kwargs) -> EmbeddingProvider """ if provider_type.lower() == "fastembed": from .fastembed import FastEmbedProvider - model_name = kwargs.get("model_name", "sentence-transformers/all-MiniLM-L6-v2") - return FastEmbedProvider(model_name) - else: - raise ValueError(f"Unsupported embedding provider: {provider_type}") -from typing import Optional -from .fastembed import FastEmbedProvider -from .base import EmbeddingProvider - - -def create_embedding_provider(provider_type: str, model_name: Optional[str] = None) -> EmbeddingProvider: - """ - Create an embedding provider based on the provider type. - - Args: - provider_type: The type of embedding provider to create. - model_name: The name of the model to use. - - Returns: - An instance of EmbeddingProvider. - - Raises: - ValueError: If the provider type is not supported. - """ - if provider_type.lower() == "fastembed": - return FastEmbedProvider(model_name) - else: - raise ValueError(f"Unsupported embedding provider: {provider_type}") -from typing import Literal - -from .fastembed import FastEmbedProvider - - -def create_embedding_provider( - provider_type: Literal["fastembed"], - **kwargs -) -> FastEmbedProvider: - """ - Factory function to create an embedding provider. - - Args: - provider_type: The type of embedding provider to create. - **kwargs: Additional arguments to pass to the provider constructor. - - Returns: - An instance of the requested embedding provider. - - Raises: - ValueError: If the provider type is not supported. - """ - if provider_type == "fastembed": + model_name = kwargs.get("model_name", "sentence-transformers/all-MiniLM-L6-v2") return FastEmbedProvider(model_name) else: diff --git a/src/mcp_server_qdrant/embeddings/fastembed.py b/src/mcp_server_qdrant/embeddings/fastembed.py index c54bbb1..cc79b85 100644 --- a/src/mcp_server_qdrant/embeddings/fastembed.py +++ b/src/mcp_server_qdrant/embeddings/fastembed.py @@ -1,5 +1,6 @@ -from typing import List import asyncio +from typing import List + from fastembed import TextEmbedding from .base import EmbeddingProvider diff --git a/src/mcp_server_qdrant/qdrant.py b/src/mcp_server_qdrant/qdrant.py index c281aa3..f5b4cf3 100644 --- a/src/mcp_server_qdrant/qdrant.py +++ b/src/mcp_server_qdrant/qdrant.py @@ -1,5 +1,7 @@ -from typing import Optional, List +from typing import Optional + from qdrant_client import AsyncQdrantClient, models + from .embeddings.base import EmbeddingProvider @@ -25,7 +27,9 @@ class QdrantConnector: self._qdrant_api_key = qdrant_api_key self._collection_name = collection_name self._embedding_provider = embedding_provider - self._client = AsyncQdrantClient(location=qdrant_url, api_key=qdrant_api_key, path=qdrant_local_path) + self._client = AsyncQdrantClient( + location=qdrant_url, api_key=qdrant_api_key, path=qdrant_local_path + ) async def _ensure_collection_exists(self): """Ensure that the collection exists, creating it if necessary.""" diff --git a/src/mcp_server_qdrant/server.py b/src/mcp_server_qdrant/server.py index 96921fd..12a03cb 100644 --- a/src/mcp_server_qdrant/server.py +++ b/src/mcp_server_qdrant/server.py @@ -1,15 +1,14 @@ +import asyncio from typing import Optional -from mcp.server import Server, NotificationOptions +import click +import mcp +import mcp.types as types +from mcp.server import NotificationOptions, Server from mcp.server.models import InitializationOptions -import click -import mcp.types as types -import asyncio -import mcp - -from .qdrant import QdrantConnector from .embeddings.factory import create_embedding_provider +from .qdrant import QdrantConnector def serve( @@ -33,12 +32,15 @@ def serve( # Create the embedding provider embedding_provider = create_embedding_provider( - embedding_provider_type, - model_name=embedding_model_name + embedding_provider_type, model_name=embedding_model_name ) qdrant = QdrantConnector( - qdrant_url, qdrant_api_key, collection_name, embedding_provider, qdrant_local_path + qdrant_url, + qdrant_api_key, + collection_name, + embedding_provider, + qdrant_local_path, ) @server.list_tools() @@ -169,7 +171,9 @@ def main( ): # XOR of url and local path, since we accept only one of them if not (bool(qdrant_url) ^ bool(qdrant_local_path)): - raise ValueError("Exactly one of qdrant-url or qdrant-local-path must be provided") + raise ValueError( + "Exactly one of qdrant-url or qdrant-local-path must be provided" + ) async def _run(): async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):