mcp-mongo-server 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +276 -118
- package/build/index.js +42 -1022
- package/build/mongo.js +33 -0
- package/build/schemas/call.js +507 -0
- package/build/schemas/completion.js +112 -0
- package/build/schemas/ping.js +20 -0
- package/build/schemas/prompts.js +71 -0
- package/build/schemas/resource.js +62 -0
- package/build/schemas/templates.js +33 -0
- package/build/schemas/tools.js +278 -0
- package/build/server.js +65 -0
- package/package.json +1 -1
- package/build/types.js +0 -169
package/build/types.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { CallToolRequestSchema, ToolSchema, ResourceSchema, TextResourceContentsSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
-
// MongoDB Collection Schema
|
|
4
|
-
export const MongoCollectionSchema = ResourceSchema.extend({
|
|
5
|
-
collectionName: z.string(),
|
|
6
|
-
databaseName: z.string(),
|
|
7
|
-
indexes: z
|
|
8
|
-
.array(z.object({
|
|
9
|
-
name: z.string(),
|
|
10
|
-
keys: z.record(z.union([z.number(), z.string()])),
|
|
11
|
-
unique: z.optional(z.boolean()),
|
|
12
|
-
}))
|
|
13
|
-
.optional(),
|
|
14
|
-
});
|
|
15
|
-
// MongoDB Document Schema
|
|
16
|
-
export const MongoDocumentSchema = TextResourceContentsSchema.extend({
|
|
17
|
-
document: z.record(z.unknown()),
|
|
18
|
-
});
|
|
19
|
-
// MongoDB Query Operators
|
|
20
|
-
export const MongoQueryOperatorSchema = z.object({
|
|
21
|
-
$eq: z.unknown().optional(),
|
|
22
|
-
$gt: z.unknown().optional(),
|
|
23
|
-
$gte: z.unknown().optional(),
|
|
24
|
-
$in: z.array(z.unknown()).optional(),
|
|
25
|
-
$lt: z.unknown().optional(),
|
|
26
|
-
$lte: z.unknown().optional(),
|
|
27
|
-
$ne: z.unknown().optional(),
|
|
28
|
-
$nin: z.array(z.unknown()).optional(),
|
|
29
|
-
$and: z.array(z.unknown()).optional(),
|
|
30
|
-
$not: z.unknown().optional(),
|
|
31
|
-
$nor: z.array(z.unknown()).optional(),
|
|
32
|
-
$or: z.array(z.unknown()).optional(),
|
|
33
|
-
$exists: z.boolean().optional(),
|
|
34
|
-
$type: z.union([z.string(), z.number()]).optional(),
|
|
35
|
-
$expr: z.unknown().optional(),
|
|
36
|
-
$regex: z.string().optional(),
|
|
37
|
-
$options: z.string().optional(),
|
|
38
|
-
});
|
|
39
|
-
// MongoDB Sort Options
|
|
40
|
-
export const MongoSortSchema = z.record(z.union([z.literal(1), z.literal(-1)]));
|
|
41
|
-
// MongoDB Query Tool Schema
|
|
42
|
-
export const MongoQueryToolSchema = ToolSchema.extend({
|
|
43
|
-
inputSchema: z.object({
|
|
44
|
-
type: z.literal("object"),
|
|
45
|
-
properties: z
|
|
46
|
-
.object({
|
|
47
|
-
collection: z.string(),
|
|
48
|
-
filter: z.record(z.union([z.unknown(), MongoQueryOperatorSchema])),
|
|
49
|
-
projection: z.record(z.union([z.literal(0), z.literal(1)])).optional(),
|
|
50
|
-
sort: MongoSortSchema.optional(),
|
|
51
|
-
limit: z.number().int().positive().optional(),
|
|
52
|
-
skip: z.number().int().nonnegative().optional(),
|
|
53
|
-
})
|
|
54
|
-
.passthrough(),
|
|
55
|
-
required: z.array(z.literal("collection")),
|
|
56
|
-
}),
|
|
57
|
-
});
|
|
58
|
-
// MongoDB Aggregate Tool Schema
|
|
59
|
-
export const MongoAggregateToolSchema = ToolSchema.extend({
|
|
60
|
-
inputSchema: z.object({
|
|
61
|
-
type: z.literal("object"),
|
|
62
|
-
properties: z
|
|
63
|
-
.object({
|
|
64
|
-
collection: z.string(),
|
|
65
|
-
pipeline: z.array(z.record(z.unknown())),
|
|
66
|
-
})
|
|
67
|
-
.passthrough(),
|
|
68
|
-
required: z.array(z.literal("collection")),
|
|
69
|
-
}),
|
|
70
|
-
});
|
|
71
|
-
// MongoDB Count Tool Schema
|
|
72
|
-
export const MongoCountToolSchema = ToolSchema.extend({
|
|
73
|
-
inputSchema: z.object({
|
|
74
|
-
type: z.literal("object"),
|
|
75
|
-
properties: z
|
|
76
|
-
.object({
|
|
77
|
-
collection: z.string(),
|
|
78
|
-
filter: z
|
|
79
|
-
.record(z.union([z.unknown(), MongoQueryOperatorSchema]))
|
|
80
|
-
.optional(),
|
|
81
|
-
})
|
|
82
|
-
.passthrough(),
|
|
83
|
-
required: z.array(z.literal("collection")),
|
|
84
|
-
}),
|
|
85
|
-
});
|
|
86
|
-
// MongoDB Distinct Tool Schema
|
|
87
|
-
export const MongoDistinctToolSchema = ToolSchema.extend({
|
|
88
|
-
inputSchema: z.object({
|
|
89
|
-
type: z.literal("object"),
|
|
90
|
-
properties: z
|
|
91
|
-
.object({
|
|
92
|
-
collection: z.string(),
|
|
93
|
-
field: z.string(),
|
|
94
|
-
filter: z
|
|
95
|
-
.record(z.union([z.unknown(), MongoQueryOperatorSchema]))
|
|
96
|
-
.optional(),
|
|
97
|
-
})
|
|
98
|
-
.passthrough(),
|
|
99
|
-
required: z.array(z.literal("collection")),
|
|
100
|
-
}),
|
|
101
|
-
});
|
|
102
|
-
// MongoDB Call Tool Request Schema
|
|
103
|
-
export const MongoCallToolRequestSchema = CallToolRequestSchema.extend({
|
|
104
|
-
params: z.object({
|
|
105
|
-
name: z.enum([
|
|
106
|
-
"query",
|
|
107
|
-
"aggregate",
|
|
108
|
-
"update",
|
|
109
|
-
"serverInfo",
|
|
110
|
-
"insert",
|
|
111
|
-
"createIndex",
|
|
112
|
-
"count",
|
|
113
|
-
"distinct",
|
|
114
|
-
"listCollections",
|
|
115
|
-
]),
|
|
116
|
-
arguments: z.union([
|
|
117
|
-
MongoQueryToolSchema.shape.inputSchema,
|
|
118
|
-
MongoAggregateToolSchema.shape.inputSchema,
|
|
119
|
-
MongoCountToolSchema.shape.inputSchema,
|
|
120
|
-
MongoDistinctToolSchema.shape.inputSchema,
|
|
121
|
-
]),
|
|
122
|
-
}),
|
|
123
|
-
});
|
|
124
|
-
// MongoDB Error Types
|
|
125
|
-
export const MongoErrorCodeSchema = z.enum([
|
|
126
|
-
"INVALID_QUERY",
|
|
127
|
-
"COLLECTION_NOT_FOUND",
|
|
128
|
-
"DATABASE_NOT_FOUND",
|
|
129
|
-
"INVALID_PIPELINE",
|
|
130
|
-
"INVALID_PROJECTION",
|
|
131
|
-
"INVALID_SORT",
|
|
132
|
-
"CONNECTION_ERROR",
|
|
133
|
-
"TIMEOUT",
|
|
134
|
-
"UNAUTHORIZED",
|
|
135
|
-
]);
|
|
136
|
-
export const MongoErrorSchema = z.object({
|
|
137
|
-
code: MongoErrorCodeSchema,
|
|
138
|
-
message: z.string(),
|
|
139
|
-
details: z.unknown().optional(),
|
|
140
|
-
});
|
|
141
|
-
// MongoDB Schema Inference Types
|
|
142
|
-
export const MongoFieldSchemaSchema = z.object({
|
|
143
|
-
type: z.union([
|
|
144
|
-
z.literal("string"),
|
|
145
|
-
z.literal("number"),
|
|
146
|
-
z.literal("boolean"),
|
|
147
|
-
z.literal("date"),
|
|
148
|
-
z.literal("objectId"),
|
|
149
|
-
z.literal("array"),
|
|
150
|
-
z.literal("object"),
|
|
151
|
-
z.literal("null"),
|
|
152
|
-
z.literal("mixed"),
|
|
153
|
-
]),
|
|
154
|
-
required: z.boolean().optional(),
|
|
155
|
-
unique: z.boolean().optional(),
|
|
156
|
-
indexed: z.boolean().optional(),
|
|
157
|
-
items: z.lazy(() => MongoFieldSchemaSchema).optional(),
|
|
158
|
-
properties: z.record(z.lazy(() => MongoFieldSchemaSchema)).optional(),
|
|
159
|
-
});
|
|
160
|
-
export const MongoCollectionSchemaSchema = z.object({
|
|
161
|
-
name: z.string(),
|
|
162
|
-
fields: z.record(MongoFieldSchemaSchema),
|
|
163
|
-
options: z
|
|
164
|
-
.object({
|
|
165
|
-
timestamps: z.boolean().optional(),
|
|
166
|
-
strict: z.boolean().optional(),
|
|
167
|
-
})
|
|
168
|
-
.optional(),
|
|
169
|
-
});
|