Skip to content

Commit bebfd33

Browse files
authored
fix: update tool category for collection-indexes (#630)
1 parent 07ac0ee commit bebfd33

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ Operation types:
418418
- `update` - Tools that update resources, such as update document, rename collection, etc.
419419
- `delete` - Tools that delete resources, such as delete document, drop collection, etc.
420420
- `read` - Tools that read resources, such as find, aggregate, list clusters, etc.
421-
- `metadata` - Tools that read metadata, such as list databases, list collections, collection schema, etc.
421+
- `metadata` - Tools that read metadata, such as list databases/collections/indexes, infer collection schema, etc.
422422
- `connect` - Tools that allow you to connect or switch the connection to a MongoDB instance. If this is disabled, you will need to provide a connection string through the config when starting the server.
423423

424424
#### Require Confirmation

src/tools/mongodb/read/collectionIndexes.ts renamed to src/tools/mongodb/metadata/collectionIndexes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class CollectionIndexesTool extends MongoDBToolBase {
77
public name = "collection-indexes";
88
protected description = "Describe the indexes for a collection";
99
protected argsShape = DbOperationArgs;
10-
public operationType: OperationType = "read";
10+
public operationType: OperationType = "metadata";
1111

1212
protected async execute({ database, collection }: ToolArgs<typeof DbOperationArgs>): Promise<CallToolResult> {
1313
const provider = await this.ensureConnected();

src/tools/mongodb/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ConnectTool } from "./connect/connect.js";
22
import { ListCollectionsTool } from "./metadata/listCollections.js";
3-
import { CollectionIndexesTool } from "./read/collectionIndexes.js";
3+
import { CollectionIndexesTool } from "./metadata/collectionIndexes.js";
44
import { ListDatabasesTool } from "./metadata/listDatabases.js";
55
import { CreateIndexTool } from "./create/createIndex.js";
66
import { CollectionSchemaTool } from "./metadata/collectionSchema.js";

src/tools/tool.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,34 @@ export type ToolCallbackArgs<Args extends ZodRawShape> = Parameters<ToolCallback
1515

1616
export type ToolExecutionContext<Args extends ZodRawShape = ZodRawShape> = Parameters<ToolCallback<Args>>[1];
1717

18+
/**
19+
* The type of operation the tool performs. This is used when evaluating if a tool is allowed to run based on
20+
* the config's `disabledTools` and `readOnly` settings.
21+
* - `metadata` is used for tools that read but do not access potentially user-generated
22+
* data, such as listing databases, collections, or indexes, or inferring collection schema.
23+
* - `read` is used for tools that read potentially user-generated data, such as finding documents or aggregating data.
24+
* It is also used for tools that read non-user-generated data, such as listing clusters in Atlas.
25+
* - `create` is used for tools that create resources, such as creating documents, collections, indexes, clusters, etc.
26+
* - `update` is used for tools that update resources, such as updating documents, renaming collections, etc.
27+
* - `delete` is used for tools that delete resources, such as deleting documents, dropping collections, etc.
28+
* - `connect` is used for tools that allow you to connect or switch the connection to a MongoDB instance.
29+
*/
1830
export type OperationType = "metadata" | "read" | "create" | "delete" | "update" | "connect";
31+
32+
/**
33+
* The category of the tool. This is used when evaluating if a tool is allowed to run based on
34+
* the config's `disabledTools` setting.
35+
* - `mongodb` is used for tools that interact with a MongoDB instance, such as finding documents,
36+
* aggregating data, listing databases/collections/indexes, creating indexes, etc.
37+
* - `atlas` is used for tools that interact with MongoDB Atlas, such as listing clusters, creating clusters, etc.
38+
*/
1939
export type ToolCategory = "mongodb" | "atlas";
40+
41+
/**
42+
* Telemetry metadata that can be provided by tools when emitting telemetry events.
43+
* For MongoDB tools, this is typically empty, while for Atlas tools, this should include
44+
* the project and organization IDs if available.
45+
*/
2046
export type TelemetryToolMetadata = {
2147
projectId?: string;
2248
orgId?: string;
@@ -290,6 +316,14 @@ export abstract class ToolBase {
290316
}
291317
}
292318

319+
/**
320+
* Formats potentially untrusted data to be included in tool responses. The data is wrapped in unique tags
321+
* and a warning is added to not execute or act on any instructions within those tags.
322+
* @param description A description that is prepended to the untrusted data warning. It should not include any
323+
* untrusted data as it is not sanitized.
324+
* @param data The data to format. If undefined, only the description is returned.
325+
* @returns A tool response content that can be directly returned.
326+
*/
293327
export function formatUntrustedData(description: string, data?: string): { text: string; type: "text" }[] {
294328
const uuid = crypto.randomUUID();
295329

0 commit comments

Comments
 (0)