midnight-mcp 0.0.9 → 0.1.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.
@@ -230,6 +230,111 @@ function getPrivacyConsiderations(circuit) {
230
230
  }
231
231
  return considerations;
232
232
  }
233
+ // Output schemas for analysis tools
234
+ const analyzeContractOutputSchema = {
235
+ type: "object",
236
+ properties: {
237
+ name: { type: "string", description: "Contract name" },
238
+ summary: { type: "string", description: "Brief contract summary" },
239
+ ledgerState: {
240
+ type: "array",
241
+ description: "Ledger state fields",
242
+ items: {
243
+ type: "object",
244
+ properties: {
245
+ name: { type: "string" },
246
+ type: { type: "string" },
247
+ isPrivate: { type: "boolean" },
248
+ },
249
+ },
250
+ },
251
+ circuits: {
252
+ type: "array",
253
+ description: "Circuit definitions",
254
+ items: {
255
+ type: "object",
256
+ properties: {
257
+ name: { type: "string" },
258
+ isPublic: { type: "boolean" },
259
+ parameters: { type: "array", items: { type: "object" } },
260
+ purpose: { type: "string" },
261
+ },
262
+ },
263
+ },
264
+ witnesses: {
265
+ type: "array",
266
+ description: "Witness functions",
267
+ items: {
268
+ type: "object",
269
+ properties: {
270
+ name: { type: "string" },
271
+ returnType: { type: "string" },
272
+ purpose: { type: "string" },
273
+ },
274
+ },
275
+ },
276
+ securityFindings: {
277
+ type: "array",
278
+ description: "Security analysis findings",
279
+ items: {
280
+ type: "object",
281
+ properties: {
282
+ severity: {
283
+ type: "string",
284
+ enum: ["info", "warning", "error"],
285
+ },
286
+ message: { type: "string" },
287
+ suggestion: { type: "string" },
288
+ },
289
+ },
290
+ },
291
+ recommendations: {
292
+ type: "array",
293
+ items: { type: "string" },
294
+ description: "Recommendations for improvement",
295
+ },
296
+ },
297
+ required: ["summary", "circuits"],
298
+ description: "Detailed contract analysis with security findings",
299
+ };
300
+ const explainCircuitOutputSchema = {
301
+ type: "object",
302
+ properties: {
303
+ name: { type: "string", description: "Circuit name" },
304
+ type: {
305
+ type: "string",
306
+ description: "Type: circuit or witness",
307
+ },
308
+ isPublic: { type: "boolean", description: "Whether it's exported" },
309
+ plainEnglishExplanation: {
310
+ type: "string",
311
+ description: "Plain language explanation",
312
+ },
313
+ zkProofImplications: {
314
+ type: "string",
315
+ description: "Zero-knowledge proof implications",
316
+ },
317
+ privacyConsiderations: {
318
+ type: "array",
319
+ items: { type: "string" },
320
+ description: "Privacy-related considerations",
321
+ },
322
+ parameters: {
323
+ type: "array",
324
+ items: {
325
+ type: "object",
326
+ properties: {
327
+ name: { type: "string" },
328
+ type: { type: "string" },
329
+ description: { type: "string" },
330
+ },
331
+ },
332
+ },
333
+ returnType: { type: "string" },
334
+ },
335
+ required: ["name", "plainEnglishExplanation"],
336
+ description: "Detailed circuit explanation with privacy analysis",
337
+ };
233
338
  // Tool definitions for MCP
234
339
  export const analyzeTools = [
235
340
  {
@@ -249,6 +354,12 @@ export const analyzeTools = [
249
354
  },
250
355
  required: ["code"],
251
356
  },
357
+ outputSchema: analyzeContractOutputSchema,
358
+ annotations: {
359
+ readOnlyHint: true,
360
+ idempotentHint: true,
361
+ title: "Analyze Compact Contract",
362
+ },
252
363
  handler: analyzeContract,
253
364
  },
254
365
  {
@@ -264,6 +375,12 @@ export const analyzeTools = [
264
375
  },
265
376
  required: ["circuitCode"],
266
377
  },
378
+ outputSchema: explainCircuitOutputSchema,
379
+ annotations: {
380
+ readOnlyHint: true,
381
+ idempotentHint: true,
382
+ title: "Explain Circuit",
383
+ },
267
384
  handler: explainCircuit,
268
385
  },
269
386
  ];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Contract generation tool using sampling capability
3
+ *
4
+ * Enables AI-assisted generation and review of Compact smart contracts
5
+ */
6
+ import type { ExtendedToolDefinition } from "../types/index.js";
7
+ export declare const generationTools: ExtendedToolDefinition[];
8
+ export declare const generationHandlers: Record<string, (args: any) => Promise<any>>;
9
+ //# sourceMappingURL=generation.d.ts.map
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Contract generation tool using sampling capability
3
+ *
4
+ * Enables AI-assisted generation and review of Compact smart contracts
5
+ */
6
+ import { z } from "zod";
7
+ import { generateContract, reviewContract, generateDocumentation, isSamplingAvailable, } from "../services/index.js";
8
+ // Input schemas
9
+ const generateContractSchema = z.object({
10
+ requirements: z
11
+ .string()
12
+ .describe("Natural language description of the contract requirements"),
13
+ contractType: z
14
+ .enum(["counter", "token", "voting", "custom"])
15
+ .optional()
16
+ .describe("Type of contract to generate"),
17
+ baseExample: z
18
+ .string()
19
+ .optional()
20
+ .describe("Example contract code to use as a base"),
21
+ });
22
+ const reviewContractSchema = z.object({
23
+ code: z.string().describe("Compact contract code to review"),
24
+ });
25
+ const documentContractSchema = z.object({
26
+ code: z.string().describe("Compact contract code to document"),
27
+ format: z
28
+ .enum(["markdown", "jsdoc"])
29
+ .optional()
30
+ .describe("Documentation format (default: markdown)"),
31
+ });
32
+ // Output schemas for structured responses
33
+ const generateContractOutputSchema = {
34
+ type: "object",
35
+ properties: {
36
+ code: {
37
+ type: "string",
38
+ description: "Generated Compact contract code",
39
+ },
40
+ explanation: {
41
+ type: "string",
42
+ description: "Brief explanation of what the contract does",
43
+ },
44
+ warnings: {
45
+ type: "array",
46
+ items: { type: "string" },
47
+ description: "Any warnings or notes about the generated code",
48
+ },
49
+ samplingAvailable: {
50
+ type: "boolean",
51
+ description: "Whether sampling capability was available",
52
+ },
53
+ },
54
+ required: ["code", "explanation", "warnings", "samplingAvailable"],
55
+ };
56
+ const reviewContractOutputSchema = {
57
+ type: "object",
58
+ properties: {
59
+ summary: {
60
+ type: "string",
61
+ description: "Summary of the contract review",
62
+ },
63
+ issues: {
64
+ type: "array",
65
+ items: {
66
+ type: "object",
67
+ properties: {
68
+ severity: {
69
+ type: "string",
70
+ enum: ["error", "warning", "info"],
71
+ },
72
+ line: { type: "number" },
73
+ message: { type: "string" },
74
+ suggestion: { type: "string" },
75
+ },
76
+ },
77
+ description: "List of issues found",
78
+ },
79
+ improvedCode: {
80
+ type: "string",
81
+ description: "Improved version of the contract if applicable",
82
+ },
83
+ samplingAvailable: {
84
+ type: "boolean",
85
+ description: "Whether sampling capability was available",
86
+ },
87
+ },
88
+ required: ["summary", "issues", "samplingAvailable"],
89
+ };
90
+ const documentContractOutputSchema = {
91
+ type: "object",
92
+ properties: {
93
+ documentation: {
94
+ type: "string",
95
+ description: "Generated documentation",
96
+ },
97
+ format: {
98
+ type: "string",
99
+ description: "Format of the documentation",
100
+ },
101
+ samplingAvailable: {
102
+ type: "boolean",
103
+ description: "Whether sampling capability was available",
104
+ },
105
+ },
106
+ required: ["documentation", "format", "samplingAvailable"],
107
+ };
108
+ // Handler functions
109
+ async function handleGenerateContract(args) {
110
+ const result = await generateContract(args.requirements, {
111
+ contractType: args.contractType,
112
+ baseExample: args.baseExample,
113
+ });
114
+ return {
115
+ ...result,
116
+ samplingAvailable: isSamplingAvailable(),
117
+ };
118
+ }
119
+ async function handleReviewContract(args) {
120
+ const result = await reviewContract(args.code);
121
+ return {
122
+ ...result,
123
+ samplingAvailable: isSamplingAvailable(),
124
+ };
125
+ }
126
+ async function handleDocumentContract(args) {
127
+ const documentation = await generateDocumentation(args.code, args.format || "markdown");
128
+ return {
129
+ documentation,
130
+ format: args.format || "markdown",
131
+ samplingAvailable: isSamplingAvailable(),
132
+ };
133
+ }
134
+ // Tool definitions
135
+ export const generationTools = [
136
+ {
137
+ name: "midnight-generate-contract",
138
+ description: `🔮 AI-POWERED CONTRACT GENERATION
139
+
140
+ Generates Compact smart contracts from natural language requirements.
141
+ Uses the client's LLM through MCP sampling to create contracts.
142
+
143
+ REQUIREMENTS FORMAT:
144
+ - Describe what the contract should do
145
+ - Specify state variables needed
146
+ - Define access control requirements
147
+ - List the operations/circuits needed
148
+
149
+ CONTRACT TYPES:
150
+ • counter - Simple counter with increment/decrement
151
+ • token - Token with transfers and balances
152
+ • voting - Voting/governance mechanisms
153
+ • custom - Free-form custom contract
154
+
155
+ EXAMPLE USAGE:
156
+ "Create a token contract with private balances, mint/burn capabilities for admin, and transfer functionality between users"
157
+
158
+ ⚠️ REQUIRES: Client with sampling capability (e.g., Claude Desktop)`,
159
+ inputSchema: {
160
+ type: "object",
161
+ properties: {
162
+ requirements: {
163
+ type: "string",
164
+ description: "Natural language description of the contract requirements",
165
+ },
166
+ contractType: {
167
+ type: "string",
168
+ enum: ["counter", "token", "voting", "custom"],
169
+ description: "Type of contract to generate",
170
+ },
171
+ baseExample: {
172
+ type: "string",
173
+ description: "Example contract code to use as a base",
174
+ },
175
+ },
176
+ required: ["requirements"],
177
+ },
178
+ outputSchema: generateContractOutputSchema,
179
+ annotations: {
180
+ title: "Generate Compact Contract",
181
+ readOnlyHint: false,
182
+ idempotentHint: false,
183
+ openWorldHint: true,
184
+ longRunningHint: true,
185
+ },
186
+ handler: handleGenerateContract,
187
+ },
188
+ {
189
+ name: "midnight-review-contract",
190
+ description: `🔍 AI-POWERED CONTRACT REVIEW
191
+
192
+ Performs security review and analysis of Compact smart contracts.
193
+ Uses the client's LLM to identify issues and suggest improvements.
194
+
195
+ CHECKS PERFORMED:
196
+ • Security vulnerabilities
197
+ • Privacy concerns (shielded state handling)
198
+ • Logic errors
199
+ • Best practice violations
200
+ • Performance issues
201
+
202
+ OUTPUT INCLUDES:
203
+ • Summary of contract quality
204
+ • List of issues with severity levels
205
+ • Suggested fixes for each issue
206
+ • Improved code version if applicable
207
+
208
+ ⚠️ REQUIRES: Client with sampling capability (e.g., Claude Desktop)`,
209
+ inputSchema: {
210
+ type: "object",
211
+ properties: {
212
+ code: {
213
+ type: "string",
214
+ description: "Compact contract code to review",
215
+ },
216
+ },
217
+ required: ["code"],
218
+ },
219
+ outputSchema: reviewContractOutputSchema,
220
+ annotations: {
221
+ title: "Review Compact Contract",
222
+ readOnlyHint: true,
223
+ idempotentHint: true,
224
+ openWorldHint: true,
225
+ longRunningHint: true,
226
+ },
227
+ handler: handleReviewContract,
228
+ },
229
+ {
230
+ name: "midnight-document-contract",
231
+ description: `📝 AI-POWERED DOCUMENTATION GENERATION
232
+
233
+ Generates comprehensive documentation for Compact smart contracts.
234
+ Uses the client's LLM to create detailed, human-readable docs.
235
+
236
+ FORMATS:
237
+ • markdown - Full Markdown documentation with examples
238
+ • jsdoc - JSDoc-style inline comments
239
+
240
+ MARKDOWN INCLUDES:
241
+ • Contract overview and purpose
242
+ • State variables with privacy annotations
243
+ • Circuit function documentation
244
+ • Witness function documentation
245
+ • Usage examples
246
+ • Security considerations
247
+
248
+ ⚠️ REQUIRES: Client with sampling capability (e.g., Claude Desktop)`,
249
+ inputSchema: {
250
+ type: "object",
251
+ properties: {
252
+ code: {
253
+ type: "string",
254
+ description: "Compact contract code to document",
255
+ },
256
+ format: {
257
+ type: "string",
258
+ enum: ["markdown", "jsdoc"],
259
+ description: "Documentation format (default: markdown)",
260
+ },
261
+ },
262
+ required: ["code"],
263
+ },
264
+ outputSchema: documentContractOutputSchema,
265
+ annotations: {
266
+ title: "Generate Contract Documentation",
267
+ readOnlyHint: true,
268
+ idempotentHint: true,
269
+ openWorldHint: true,
270
+ longRunningHint: true,
271
+ },
272
+ handler: handleDocumentContract,
273
+ },
274
+ ];
275
+ // Export handler map
276
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
277
+ export const generationHandlers = {
278
+ "midnight-generate-contract": handleGenerateContract,
279
+ "midnight-review-contract": handleReviewContract,
280
+ "midnight-document-contract": handleDocumentContract,
281
+ };
282
+ //# sourceMappingURL=generation.js.map
@@ -2,6 +2,7 @@
2
2
  * Health check and diagnostic tools for MCP server
3
3
  */
4
4
  import { z } from "zod";
5
+ import type { ExtendedToolDefinition } from "../types/index.js";
5
6
  export declare const HealthCheckInputSchema: z.ZodObject<{
6
7
  detailed: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
7
8
  }, "strip", z.ZodTypeAny, {
@@ -63,29 +64,5 @@ export declare function getStatus(_input: GetStatusInput): Promise<{
63
64
  metadata: import("../utils/cache.js").CacheStats;
64
65
  };
65
66
  }>;
66
- export declare const healthTools: ({
67
- name: string;
68
- description: string;
69
- inputSchema: {
70
- type: "object";
71
- properties: {
72
- detailed: {
73
- type: string;
74
- description: string;
75
- default: boolean;
76
- };
77
- };
78
- };
79
- handler: typeof healthCheck;
80
- } | {
81
- name: string;
82
- description: string;
83
- inputSchema: {
84
- type: "object";
85
- properties: {
86
- detailed?: undefined;
87
- };
88
- };
89
- handler: typeof getStatus;
90
- })[];
67
+ export declare const healthTools: ExtendedToolDefinition[];
91
68
  //# sourceMappingURL=health.d.ts.map
@@ -61,6 +61,65 @@ export async function getStatus(_input) {
61
61
  },
62
62
  };
63
63
  }
64
+ // Output schemas for health tools
65
+ const healthCheckOutputSchema = {
66
+ type: "object",
67
+ properties: {
68
+ status: {
69
+ type: "string",
70
+ enum: ["healthy", "degraded", "unhealthy"],
71
+ description: "Overall health status",
72
+ },
73
+ version: { type: "string", description: "Server version" },
74
+ rateLimit: {
75
+ type: "object",
76
+ properties: {
77
+ remaining: { type: "number" },
78
+ limit: { type: "number" },
79
+ percentUsed: { type: "number" },
80
+ status: { type: "string" },
81
+ },
82
+ },
83
+ cacheStats: {
84
+ type: "object",
85
+ properties: {
86
+ search: { type: "object" },
87
+ file: { type: "object" },
88
+ metadata: { type: "object" },
89
+ },
90
+ },
91
+ },
92
+ required: ["status"],
93
+ description: "Server health status with optional detailed diagnostics",
94
+ };
95
+ const getStatusOutputSchema = {
96
+ type: "object",
97
+ properties: {
98
+ server: { type: "string", description: "Server name" },
99
+ status: { type: "string", description: "Running status" },
100
+ timestamp: { type: "string", description: "ISO timestamp" },
101
+ rateLimit: {
102
+ type: "object",
103
+ properties: {
104
+ remaining: { type: "number" },
105
+ limit: { type: "number" },
106
+ percentUsed: { type: "number" },
107
+ status: { type: "string" },
108
+ message: { type: "string" },
109
+ },
110
+ },
111
+ cache: {
112
+ type: "object",
113
+ properties: {
114
+ search: { type: "object" },
115
+ file: { type: "object" },
116
+ metadata: { type: "object" },
117
+ },
118
+ },
119
+ },
120
+ required: ["server", "status", "timestamp"],
121
+ description: "Current server status and statistics",
122
+ };
64
123
  // Tool definitions for MCP server
65
124
  export const healthTools = [
66
125
  {
@@ -76,6 +135,12 @@ export const healthTools = [
76
135
  },
77
136
  },
78
137
  },
138
+ outputSchema: healthCheckOutputSchema,
139
+ annotations: {
140
+ readOnlyHint: true,
141
+ idempotentHint: true,
142
+ title: "Health Check",
143
+ },
79
144
  handler: healthCheck,
80
145
  },
81
146
  {
@@ -85,6 +150,12 @@ export const healthTools = [
85
150
  type: "object",
86
151
  properties: {},
87
152
  },
153
+ outputSchema: getStatusOutputSchema,
154
+ annotations: {
155
+ readOnlyHint: true,
156
+ idempotentHint: true,
157
+ title: "Get Server Status",
158
+ },
88
159
  handler: getStatus,
89
160
  },
90
161
  ];