Skip to content

Commit f784e1f

Browse files
author
Bryan Thompson
committed
feat: add MCP tool annotations for readOnlyHint and destructiveHint
Add tool annotations to all 13 MCP tools to improve client behavior hints: Read-only tools (readOnlyHint: true): - chroma_list_collections - chroma_peek_collection - chroma_get_collection_info - chroma_get_collection_count - chroma_query_documents - chroma_get_documents Write tools (readOnlyHint: false, destructiveHint: false): - chroma_create_collection - chroma_modify_collection - chroma_fork_collection - chroma_add_documents - chroma_update_documents Destructive tools (destructiveHint: true): - chroma_delete_collection - chroma_delete_documents These annotations help MCP clients make informed decisions about tool execution, enabling features like confirmation prompts for destructive operations.
1 parent 98ff675 commit f784e1f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/chroma_mcp/server.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def get_chroma_client(args=None):
142142

143143
##### Collection Tools #####
144144

145-
@mcp.tool()
145+
@mcp.tool(annotations={"readOnlyHint": True, "destructiveHint": False})
146146
async def chroma_list_collections(
147147
limit: int | None = None,
148148
offset: int | None = None
@@ -176,7 +176,7 @@ async def chroma_list_collections(
176176
"voyageai": VoyageAIEmbeddingFunction,
177177
"roboflow": RoboflowEmbeddingFunction,
178178
}
179-
@mcp.tool()
179+
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": False})
180180
async def chroma_create_collection(
181181
collection_name: str,
182182
embedding_function_name: str = "default",
@@ -208,7 +208,7 @@ async def chroma_create_collection(
208208
except Exception as e:
209209
raise Exception(f"Failed to create collection '{collection_name}': {str(e)}") from e
210210

211-
@mcp.tool()
211+
@mcp.tool(annotations={"readOnlyHint": True, "destructiveHint": False})
212212
async def chroma_peek_collection(
213213
collection_name: str,
214214
limit: int = 5
@@ -227,7 +227,7 @@ async def chroma_peek_collection(
227227
except Exception as e:
228228
raise Exception(f"Failed to peek collection '{collection_name}': {str(e)}") from e
229229

230-
@mcp.tool()
230+
@mcp.tool(annotations={"readOnlyHint": True, "destructiveHint": False})
231231
async def chroma_get_collection_info(collection_name: str) -> Dict:
232232
"""Get information about a Chroma collection.
233233
@@ -252,7 +252,7 @@ async def chroma_get_collection_info(collection_name: str) -> Dict:
252252
except Exception as e:
253253
raise Exception(f"Failed to get collection info for '{collection_name}': {str(e)}") from e
254254

255-
@mcp.tool()
255+
@mcp.tool(annotations={"readOnlyHint": True, "destructiveHint": False})
256256
async def chroma_get_collection_count(collection_name: str) -> int:
257257
"""Get the number of documents in a Chroma collection.
258258
@@ -266,7 +266,7 @@ async def chroma_get_collection_count(collection_name: str) -> int:
266266
except Exception as e:
267267
raise Exception(f"Failed to get collection count for '{collection_name}': {str(e)}") from e
268268

269-
@mcp.tool()
269+
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": False})
270270
async def chroma_modify_collection(
271271
collection_name: str,
272272
new_name: str | None = None,
@@ -294,7 +294,7 @@ async def chroma_modify_collection(
294294
except Exception as e:
295295
raise Exception(f"Failed to modify collection '{collection_name}': {str(e)}") from e
296296

297-
@mcp.tool()
297+
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": False})
298298
async def chroma_fork_collection(
299299
collection_name: str,
300300
new_collection_name: str,
@@ -314,7 +314,7 @@ async def chroma_fork_collection(
314314
except Exception as e:
315315
raise Exception(f"Failed to fork collection '{collection_name}': {str(e)}") from e
316316

317-
@mcp.tool()
317+
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": True})
318318
async def chroma_delete_collection(collection_name: str) -> str:
319319
"""Delete a Chroma collection.
320320
@@ -329,7 +329,7 @@ async def chroma_delete_collection(collection_name: str) -> str:
329329
raise Exception(f"Failed to delete collection '{collection_name}': {str(e)}") from e
330330

331331
##### Document Tools #####
332-
@mcp.tool()
332+
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": False})
333333
async def chroma_add_documents(
334334
collection_name: str,
335335
documents: List[str],
@@ -392,7 +392,7 @@ async def chroma_add_documents(
392392
except Exception as e:
393393
raise Exception(f"Failed to add documents to collection '{collection_name}': {str(e)}") from e
394394

395-
@mcp.tool()
395+
@mcp.tool(annotations={"readOnlyHint": True, "destructiveHint": False})
396396
async def chroma_query_documents(
397397
collection_name: str,
398398
query_texts: List[str],
@@ -439,7 +439,7 @@ async def chroma_query_documents(
439439
except Exception as e:
440440
raise Exception(f"Failed to query documents from collection '{collection_name}': {str(e)}") from e
441441

442-
@mcp.tool()
442+
@mcp.tool(annotations={"readOnlyHint": True, "destructiveHint": False})
443443
async def chroma_get_documents(
444444
collection_name: str,
445445
ids: List[str] | None = None,
@@ -489,7 +489,7 @@ async def chroma_get_documents(
489489
except Exception as e:
490490
raise Exception(f"Failed to get documents from collection '{collection_name}': {str(e)}") from e
491491

492-
@mcp.tool()
492+
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": False})
493493
async def chroma_update_documents(
494494
collection_name: str,
495495
ids: List[str],
@@ -564,7 +564,7 @@ async def chroma_update_documents(
564564
f"Failed to update documents in collection '{collection_name}': {str(e)}"
565565
) from e
566566

567-
@mcp.tool()
567+
@mcp.tool(annotations={"readOnlyHint": False, "destructiveHint": True})
568568
async def chroma_delete_documents(
569569
collection_name: str,
570570
ids: List[str]

0 commit comments

Comments
 (0)