Add project tagging to store tool and metadata.project index
Some checks failed
pre-commit / main (push) Has been cancelled
Run Tests / Python 3.10 (push) Has been cancelled
Run Tests / Python 3.11 (push) Has been cancelled
Run Tests / Python 3.12 (push) Has been cancelled
Run Tests / Python 3.13 (push) Has been cancelled

- Add explicit `project` parameter to qdrant-store tool (default: "global")
- Auto-inject project name into metadata for every stored record
- Create keyword payload index on metadata.project for efficient filtering

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Mr. Kutin
2026-04-03 10:43:05 +03:00
parent e9f0a1fa4a
commit e13a8981e7
2 changed files with 20 additions and 2 deletions

View File

@@ -98,6 +98,13 @@ class QdrantMCPServer(FastMCP):
collection_name: Annotated[ collection_name: Annotated[
str, Field(description="The collection to store the information in") str, Field(description="The collection to store the information in")
], ],
project: Annotated[
str,
Field(
description="Project name, e.g. devops, stereo-hysteria, voice-assistant. "
"Use 'global' for cross-project knowledge (servers, network, user preferences)."
),
] = "global",
# 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.
@@ -112,12 +119,17 @@ class QdrantMCPServer(FastMCP):
Store some information in Qdrant. Store some information in Qdrant.
:param ctx: The context for the request. :param ctx: The context for the request.
:param information: The information to store. :param information: The information to store.
:param project: The project name to tag this memory with.
:param metadata: JSON metadata to store with the information, optional. :param metadata: JSON metadata to store with the information, optional.
:param collection_name: The name of the collection to store the information in, optional. If not provided, :param collection_name: The name of the collection to store the information in, optional. If not provided,
the default collection is used. the default collection is used.
:return: A message indicating that the information was stored. :return: A message indicating that the information was stored.
""" """
await ctx.debug(f"Storing information {information} in Qdrant") await ctx.debug(f"Storing information {information} in Qdrant (project={project})")
if metadata is None:
metadata = {}
metadata["project"] = project
entry = Entry(content=information, metadata=metadata) entry = Entry(content=information, metadata=metadata)

View File

@@ -211,8 +211,14 @@ class QdrantConnector:
sparse_vectors_config=sparse_config, sparse_vectors_config=sparse_config,
) )
# Create payload indexes if configured # Always index metadata.project for efficient filtering
await self._client.create_payload_index(
collection_name=collection_name,
field_name="metadata.project",
field_schema=models.PayloadSchemaType.KEYWORD,
)
# Create payload indexes if configured
if self._field_indexes: if self._field_indexes:
for field_name, field_type in self._field_indexes.items(): for field_name, field_type in self._field_indexes.items():
await self._client.create_payload_index( await self._client.create_payload_index(