midnight-mcp 0.1.16 → 0.1.18
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/dist/db/vectorStore.d.ts +3 -0
- package/dist/pipeline/indexer.d.ts +3 -0
- package/dist/pipeline/indexer.js +36 -4
- package/dist/tools/meta.js +9 -0
- package/dist/tools/repository/handlers.d.ts +4 -8
- package/dist/tools/repository/handlers.js +28 -0
- package/dist/tools/repository/index.d.ts +2 -2
- package/dist/tools/repository/index.js +2 -2
- package/dist/tools/repository/schemas.d.ts +39 -0
- package/dist/tools/repository/schemas.js +35 -0
- package/dist/tools/repository/tools.js +190 -1
- package/dist/tools/repository/validation.d.ts +628 -0
- package/dist/tools/repository/validation.js +1208 -0
- package/dist/types/mcp.d.ts +1 -1
- package/package.json +1 -1
package/dist/db/vectorStore.d.ts
CHANGED
package/dist/pipeline/indexer.js
CHANGED
|
@@ -3,12 +3,26 @@ import { parseFile } from "./parser.js";
|
|
|
3
3
|
import { embeddingGenerator } from "./embeddings.js";
|
|
4
4
|
import { vectorStore } from "../db/vectorStore.js";
|
|
5
5
|
import { logger, DEFAULT_REPOSITORIES, } from "../utils/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Extract pragma language_version from Compact file content
|
|
8
|
+
* Returns the version string or undefined if not found
|
|
9
|
+
*/
|
|
10
|
+
function extractPragmaVersion(content) {
|
|
11
|
+
// Match patterns like: pragma language_version >= 0.14.0;
|
|
12
|
+
const pragmaMatch = content.match(/pragma\s+language_version\s*[><=]*\s*([\d.]+)/);
|
|
13
|
+
return pragmaMatch?.[1];
|
|
14
|
+
}
|
|
6
15
|
/**
|
|
7
16
|
* Create chunks from a parsed file
|
|
8
17
|
* Uses intelligent chunking based on code structure
|
|
9
18
|
*/
|
|
10
|
-
function createChunks(file, repository) {
|
|
19
|
+
function createChunks(file, repository, repoVersion) {
|
|
11
20
|
const chunks = [];
|
|
21
|
+
const indexedAt = new Date().toISOString();
|
|
22
|
+
// Extract pragma version for Compact files
|
|
23
|
+
const pragmaVersion = file.language === "compact"
|
|
24
|
+
? extractPragmaVersion(file.content)
|
|
25
|
+
: undefined;
|
|
12
26
|
// Add code units as individual chunks
|
|
13
27
|
for (const unit of file.codeUnits) {
|
|
14
28
|
chunks.push({
|
|
@@ -23,6 +37,9 @@ function createChunks(file, repository) {
|
|
|
23
37
|
startLine: unit.startLine,
|
|
24
38
|
endLine: unit.endLine,
|
|
25
39
|
isPublic: unit.isPublic,
|
|
40
|
+
repoVersion,
|
|
41
|
+
pragmaVersion,
|
|
42
|
+
indexedAt,
|
|
26
43
|
},
|
|
27
44
|
});
|
|
28
45
|
}
|
|
@@ -47,6 +64,9 @@ function createChunks(file, repository) {
|
|
|
47
64
|
startLine,
|
|
48
65
|
endLine: currentLine - 1,
|
|
49
66
|
isPublic: true,
|
|
67
|
+
repoVersion,
|
|
68
|
+
pragmaVersion,
|
|
69
|
+
indexedAt,
|
|
50
70
|
},
|
|
51
71
|
});
|
|
52
72
|
// Start new chunk with overlap
|
|
@@ -69,6 +89,9 @@ function createChunks(file, repository) {
|
|
|
69
89
|
startLine,
|
|
70
90
|
endLine: currentLine - 1,
|
|
71
91
|
isPublic: true,
|
|
92
|
+
repoVersion,
|
|
93
|
+
pragmaVersion,
|
|
94
|
+
indexedAt,
|
|
72
95
|
},
|
|
73
96
|
});
|
|
74
97
|
}
|
|
@@ -81,6 +104,8 @@ function createChunks(file, repository) {
|
|
|
81
104
|
export async function indexRepository(repoConfig) {
|
|
82
105
|
const repoName = `${repoConfig.owner}/${repoConfig.repo}`;
|
|
83
106
|
logger.info(`Starting index for ${repoName}...`);
|
|
107
|
+
// Get repo version (branch name or tag)
|
|
108
|
+
const repoVersion = repoConfig.branch || "main";
|
|
84
109
|
try {
|
|
85
110
|
// Fetch all files from the repository
|
|
86
111
|
const files = await githubClient.fetchRepositoryFiles(repoConfig);
|
|
@@ -90,8 +115,8 @@ export async function indexRepository(repoConfig) {
|
|
|
90
115
|
for (const file of files) {
|
|
91
116
|
// Parse the file
|
|
92
117
|
const parsed = parseFile(file.path, file.content);
|
|
93
|
-
// Create chunks
|
|
94
|
-
const chunks = createChunks(parsed, repoName);
|
|
118
|
+
// Create chunks with version info
|
|
119
|
+
const chunks = createChunks(parsed, repoName, repoVersion);
|
|
95
120
|
for (const chunk of chunks) {
|
|
96
121
|
documents.push({
|
|
97
122
|
id: `${repoName}:${file.path}:${chunk.metadata.startLine}`,
|
|
@@ -105,6 +130,9 @@ export async function indexRepository(repoConfig) {
|
|
|
105
130
|
codeType: chunk.metadata.codeUnitType || "unknown",
|
|
106
131
|
codeName: chunk.metadata.codeUnitName || "",
|
|
107
132
|
isPublic: chunk.metadata.isPublic,
|
|
133
|
+
repoVersion: chunk.metadata.repoVersion,
|
|
134
|
+
pragmaVersion: chunk.metadata.pragmaVersion,
|
|
135
|
+
indexedAt: chunk.metadata.indexedAt,
|
|
108
136
|
},
|
|
109
137
|
});
|
|
110
138
|
chunkCount++;
|
|
@@ -181,7 +209,8 @@ export async function incrementalUpdate(repoConfig, since) {
|
|
|
181
209
|
const file = await githubClient.getFileContent(repoConfig.owner, repoConfig.repo, filePath, repoConfig.branch);
|
|
182
210
|
if (file) {
|
|
183
211
|
const parsed = parseFile(file.path, file.content);
|
|
184
|
-
const
|
|
212
|
+
const repoVersion = repoConfig.branch || "main";
|
|
213
|
+
const chunks = createChunks(parsed, repoName, repoVersion);
|
|
185
214
|
for (const chunk of chunks) {
|
|
186
215
|
documents.push({
|
|
187
216
|
id: `${repoName}:${filePath}:${chunk.metadata.startLine}`,
|
|
@@ -195,6 +224,9 @@ export async function incrementalUpdate(repoConfig, since) {
|
|
|
195
224
|
codeType: chunk.metadata.codeUnitType || "unknown",
|
|
196
225
|
codeName: chunk.metadata.codeUnitName || "",
|
|
197
226
|
isPublic: chunk.metadata.isPublic,
|
|
227
|
+
repoVersion: chunk.metadata.repoVersion,
|
|
228
|
+
pragmaVersion: chunk.metadata.pragmaVersion,
|
|
229
|
+
indexedAt: chunk.metadata.indexedAt,
|
|
198
230
|
},
|
|
199
231
|
});
|
|
200
232
|
chunkCount++;
|
package/dist/tools/meta.js
CHANGED
|
@@ -61,6 +61,14 @@ const CATEGORY_INFO = {
|
|
|
61
61
|
"One-shot operations",
|
|
62
62
|
],
|
|
63
63
|
},
|
|
64
|
+
validation: {
|
|
65
|
+
description: "Pre-compilation contract validation using the Compact compiler",
|
|
66
|
+
useCases: [
|
|
67
|
+
"Validate contract syntax",
|
|
68
|
+
"Catch errors before deployment",
|
|
69
|
+
"Get detailed error diagnostics",
|
|
70
|
+
],
|
|
71
|
+
},
|
|
64
72
|
};
|
|
65
73
|
const listCategoriesOutputSchema = {
|
|
66
74
|
type: "object",
|
|
@@ -258,6 +266,7 @@ export const metaTools = [
|
|
|
258
266
|
"generation",
|
|
259
267
|
"health",
|
|
260
268
|
"compound",
|
|
269
|
+
"validation",
|
|
261
270
|
],
|
|
262
271
|
description: "Category to list tools for",
|
|
263
272
|
},
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Business logic for repository-related MCP tools
|
|
4
4
|
*/
|
|
5
5
|
import type { GetFileInput, ListExamplesInput, GetLatestUpdatesInput, GetVersionInfoInput, CheckBreakingChangesInput, GetMigrationGuideInput, GetFileAtVersionInput, CompareSyntaxInput, GetLatestSyntaxInput, UpgradeCheckInput, FullRepoContextInput } from "./schemas.js";
|
|
6
|
+
export { validateContract, extractContractStructure } from "./validation.js";
|
|
6
7
|
/**
|
|
7
8
|
* Resolve repository name alias to owner/repo
|
|
8
9
|
*/
|
|
@@ -157,12 +158,13 @@ export declare function compareSyntax(input: CompareSyntaxInput): Promise<{
|
|
|
157
158
|
* This is the source of truth for writing valid, compilable contracts
|
|
158
159
|
*/
|
|
159
160
|
export declare function getLatestSyntax(input: GetLatestSyntaxInput): Promise<{
|
|
160
|
-
repository: string;
|
|
161
|
-
version: string;
|
|
162
161
|
syntaxReference: string;
|
|
163
162
|
sections: string[];
|
|
164
163
|
pitfalls: string[];
|
|
165
164
|
note: string;
|
|
165
|
+
versionWarning?: string | undefined;
|
|
166
|
+
repository: string;
|
|
167
|
+
version: string;
|
|
166
168
|
warning?: undefined;
|
|
167
169
|
syntaxFiles?: undefined;
|
|
168
170
|
examplePaths?: undefined;
|
|
@@ -172,9 +174,6 @@ export declare function getLatestSyntax(input: GetLatestSyntaxInput): Promise<{
|
|
|
172
174
|
warning: string;
|
|
173
175
|
syntaxFiles: never[];
|
|
174
176
|
examplePaths: string[];
|
|
175
|
-
syntaxReference?: undefined;
|
|
176
|
-
sections?: undefined;
|
|
177
|
-
pitfalls?: undefined;
|
|
178
177
|
note?: undefined;
|
|
179
178
|
} | {
|
|
180
179
|
repository: string;
|
|
@@ -184,9 +183,6 @@ export declare function getLatestSyntax(input: GetLatestSyntaxInput): Promise<{
|
|
|
184
183
|
content: string;
|
|
185
184
|
}[];
|
|
186
185
|
note: string;
|
|
187
|
-
syntaxReference?: undefined;
|
|
188
|
-
sections?: undefined;
|
|
189
|
-
pitfalls?: undefined;
|
|
190
186
|
warning?: undefined;
|
|
191
187
|
examplePaths?: undefined;
|
|
192
188
|
}>;
|
|
@@ -7,6 +7,8 @@ import { releaseTracker } from "../../pipeline/releases.js";
|
|
|
7
7
|
import { logger, DEFAULT_REPOSITORIES, SelfCorrectionHints, } from "../../utils/index.js";
|
|
8
8
|
import { REPO_ALIASES, EXAMPLES } from "./constants.js";
|
|
9
9
|
import { EMBEDDED_DOCS } from "../../resources/content/docs-content.js";
|
|
10
|
+
// Re-export validation handlers from validation.ts
|
|
11
|
+
export { validateContract, extractContractStructure } from "./validation.js";
|
|
10
12
|
/**
|
|
11
13
|
* Resolve repository name alias to owner/repo
|
|
12
14
|
*/
|
|
@@ -306,10 +308,36 @@ export async function getLatestSyntax(input) {
|
|
|
306
308
|
// This is more reliable than fetching from GitHub and includes pitfalls/patterns
|
|
307
309
|
if (repoName === "compact" || repoName === "midnight-compact") {
|
|
308
310
|
const compactReference = EMBEDDED_DOCS["midnight://docs/compact-reference"];
|
|
311
|
+
// Check if there's a newer release we might not have documented
|
|
312
|
+
const EMBEDDED_DOCS_VERSION = "0.16"; // Version our docs are based on
|
|
313
|
+
let versionWarning;
|
|
314
|
+
try {
|
|
315
|
+
const versionInfo = await releaseTracker.getVersionInfo("midnightntwrk", "compact");
|
|
316
|
+
const latestTag = versionInfo.latestStableRelease?.tag || versionInfo.latestRelease?.tag;
|
|
317
|
+
if (latestTag) {
|
|
318
|
+
// Extract version number from tag (e.g., "v0.18.0" -> "0.18")
|
|
319
|
+
const latestVersion = latestTag
|
|
320
|
+
.replace(/^v/, "")
|
|
321
|
+
.split(".")
|
|
322
|
+
.slice(0, 2)
|
|
323
|
+
.join(".");
|
|
324
|
+
const embeddedMajorMinor = EMBEDDED_DOCS_VERSION.split(".")
|
|
325
|
+
.slice(0, 2)
|
|
326
|
+
.join(".");
|
|
327
|
+
if (latestVersion !== embeddedMajorMinor &&
|
|
328
|
+
parseFloat(latestVersion) > parseFloat(embeddedMajorMinor)) {
|
|
329
|
+
versionWarning = `⚠️ Compact ${latestTag} is available. This reference is based on ${EMBEDDED_DOCS_VERSION}. Some syntax may have changed - check release notes for breaking changes.`;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
// Ignore version check errors, still return cached docs
|
|
335
|
+
}
|
|
309
336
|
if (compactReference) {
|
|
310
337
|
return {
|
|
311
338
|
repository: "midnightntwrk/compact",
|
|
312
339
|
version: "0.16+ (current)",
|
|
340
|
+
...(versionWarning && { versionWarning }),
|
|
313
341
|
syntaxReference: compactReference,
|
|
314
342
|
sections: [
|
|
315
343
|
"Basic Structure",
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Repository module exports
|
|
3
3
|
* Barrel file for repository-related tools
|
|
4
4
|
*/
|
|
5
|
-
export { GetFileInputSchema, ListExamplesInputSchema, GetLatestUpdatesInputSchema, GetVersionInfoInputSchema, CheckBreakingChangesInputSchema, GetMigrationGuideInputSchema, GetFileAtVersionInputSchema, CompareSyntaxInputSchema, GetLatestSyntaxInputSchema, type GetFileInput, type ListExamplesInput, type GetLatestUpdatesInput, type GetVersionInfoInput, type CheckBreakingChangesInput, type GetMigrationGuideInput, type GetFileAtVersionInput, type CompareSyntaxInput, type GetLatestSyntaxInput, } from "./schemas.js";
|
|
5
|
+
export { GetFileInputSchema, ListExamplesInputSchema, GetLatestUpdatesInputSchema, GetVersionInfoInputSchema, CheckBreakingChangesInputSchema, GetMigrationGuideInputSchema, GetFileAtVersionInputSchema, CompareSyntaxInputSchema, GetLatestSyntaxInputSchema, ValidateContractInputSchema, ExtractContractStructureInputSchema, type GetFileInput, type ListExamplesInput, type GetLatestUpdatesInput, type GetVersionInfoInput, type CheckBreakingChangesInput, type GetMigrationGuideInput, type GetFileAtVersionInput, type CompareSyntaxInput, type GetLatestSyntaxInput, type ValidateContractInput, type ExtractContractStructureInput, } from "./schemas.js";
|
|
6
6
|
export { REPO_ALIASES, EXAMPLES, type ExampleDefinition } from "./constants.js";
|
|
7
|
-
export { resolveRepo, getFile, listExamples, getLatestUpdates, getVersionInfo, checkBreakingChanges, getMigrationGuide, getFileAtVersion, compareSyntax, getLatestSyntax, } from "./handlers.js";
|
|
7
|
+
export { resolveRepo, getFile, listExamples, getLatestUpdates, getVersionInfo, checkBreakingChanges, getMigrationGuide, getFileAtVersion, compareSyntax, getLatestSyntax, validateContract, extractContractStructure, } from "./handlers.js";
|
|
8
8
|
export { repositoryTools } from "./tools.js";
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* Barrel file for repository-related tools
|
|
4
4
|
*/
|
|
5
5
|
// Schemas and types
|
|
6
|
-
export { GetFileInputSchema, ListExamplesInputSchema, GetLatestUpdatesInputSchema, GetVersionInfoInputSchema, CheckBreakingChangesInputSchema, GetMigrationGuideInputSchema, GetFileAtVersionInputSchema, CompareSyntaxInputSchema, GetLatestSyntaxInputSchema, } from "./schemas.js";
|
|
6
|
+
export { GetFileInputSchema, ListExamplesInputSchema, GetLatestUpdatesInputSchema, GetVersionInfoInputSchema, CheckBreakingChangesInputSchema, GetMigrationGuideInputSchema, GetFileAtVersionInputSchema, CompareSyntaxInputSchema, GetLatestSyntaxInputSchema, ValidateContractInputSchema, ExtractContractStructureInputSchema, } from "./schemas.js";
|
|
7
7
|
// Constants
|
|
8
8
|
export { REPO_ALIASES, EXAMPLES } from "./constants.js";
|
|
9
9
|
// Handlers
|
|
10
|
-
export { resolveRepo, getFile, listExamples, getLatestUpdates, getVersionInfo, checkBreakingChanges, getMigrationGuide, getFileAtVersion, compareSyntax, getLatestSyntax, } from "./handlers.js";
|
|
10
|
+
export { resolveRepo, getFile, listExamples, getLatestUpdates, getVersionInfo, checkBreakingChanges, getMigrationGuide, getFileAtVersion, compareSyntax, getLatestSyntax, validateContract, extractContractStructure, } from "./handlers.js";
|
|
11
11
|
// Tools
|
|
12
12
|
export { repositoryTools } from "./tools.js";
|
|
13
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -122,6 +122,43 @@ export declare const FullRepoContextInputSchema: z.ZodObject<{
|
|
|
122
122
|
includeExamples?: boolean | undefined;
|
|
123
123
|
includeSyntax?: boolean | undefined;
|
|
124
124
|
}>;
|
|
125
|
+
export declare const ValidateContractInputSchema: z.ZodEffects<z.ZodObject<{
|
|
126
|
+
code: z.ZodOptional<z.ZodString>;
|
|
127
|
+
filePath: z.ZodOptional<z.ZodString>;
|
|
128
|
+
filename: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
129
|
+
}, "strip", z.ZodTypeAny, {
|
|
130
|
+
filename: string;
|
|
131
|
+
code?: string | undefined;
|
|
132
|
+
filePath?: string | undefined;
|
|
133
|
+
}, {
|
|
134
|
+
code?: string | undefined;
|
|
135
|
+
filePath?: string | undefined;
|
|
136
|
+
filename?: string | undefined;
|
|
137
|
+
}>, {
|
|
138
|
+
filename: string;
|
|
139
|
+
code?: string | undefined;
|
|
140
|
+
filePath?: string | undefined;
|
|
141
|
+
}, {
|
|
142
|
+
code?: string | undefined;
|
|
143
|
+
filePath?: string | undefined;
|
|
144
|
+
filename?: string | undefined;
|
|
145
|
+
}>;
|
|
146
|
+
export declare const ExtractContractStructureInputSchema: z.ZodEffects<z.ZodObject<{
|
|
147
|
+
code: z.ZodOptional<z.ZodString>;
|
|
148
|
+
filePath: z.ZodOptional<z.ZodString>;
|
|
149
|
+
}, "strip", z.ZodTypeAny, {
|
|
150
|
+
code?: string | undefined;
|
|
151
|
+
filePath?: string | undefined;
|
|
152
|
+
}, {
|
|
153
|
+
code?: string | undefined;
|
|
154
|
+
filePath?: string | undefined;
|
|
155
|
+
}>, {
|
|
156
|
+
code?: string | undefined;
|
|
157
|
+
filePath?: string | undefined;
|
|
158
|
+
}, {
|
|
159
|
+
code?: string | undefined;
|
|
160
|
+
filePath?: string | undefined;
|
|
161
|
+
}>;
|
|
125
162
|
export type GetFileInput = z.infer<typeof GetFileInputSchema>;
|
|
126
163
|
export type ListExamplesInput = z.infer<typeof ListExamplesInputSchema>;
|
|
127
164
|
export type GetLatestUpdatesInput = z.infer<typeof GetLatestUpdatesInputSchema>;
|
|
@@ -133,4 +170,6 @@ export type CompareSyntaxInput = z.infer<typeof CompareSyntaxInputSchema>;
|
|
|
133
170
|
export type GetLatestSyntaxInput = z.infer<typeof GetLatestSyntaxInputSchema>;
|
|
134
171
|
export type UpgradeCheckInput = z.infer<typeof UpgradeCheckInputSchema>;
|
|
135
172
|
export type FullRepoContextInput = z.infer<typeof FullRepoContextInputSchema>;
|
|
173
|
+
export type ValidateContractInput = z.infer<typeof ValidateContractInputSchema>;
|
|
174
|
+
export type ExtractContractStructureInput = z.infer<typeof ExtractContractStructureInputSchema>;
|
|
136
175
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -88,4 +88,39 @@ export const FullRepoContextInputSchema = z.object({
|
|
|
88
88
|
.describe("Include example code snippets"),
|
|
89
89
|
includeSyntax: z.boolean().default(true).describe("Include syntax reference"),
|
|
90
90
|
});
|
|
91
|
+
export const ValidateContractInputSchema = z
|
|
92
|
+
.object({
|
|
93
|
+
code: z
|
|
94
|
+
.string()
|
|
95
|
+
.optional()
|
|
96
|
+
.describe("The Compact contract source code to validate (provide this OR filePath)"),
|
|
97
|
+
filePath: z
|
|
98
|
+
.string()
|
|
99
|
+
.optional()
|
|
100
|
+
.describe("Path to a .compact file to validate (alternative to providing code directly)"),
|
|
101
|
+
filename: z
|
|
102
|
+
.string()
|
|
103
|
+
.optional()
|
|
104
|
+
.default("contract.compact")
|
|
105
|
+
.describe("Optional filename for the contract (default: contract.compact)"),
|
|
106
|
+
})
|
|
107
|
+
.refine((data) => (data.code !== undefined && data.code.trim() !== "") ||
|
|
108
|
+
data.filePath !== undefined, {
|
|
109
|
+
message: "Either 'code' or 'filePath' must be provided",
|
|
110
|
+
});
|
|
111
|
+
export const ExtractContractStructureInputSchema = z
|
|
112
|
+
.object({
|
|
113
|
+
code: z
|
|
114
|
+
.string()
|
|
115
|
+
.optional()
|
|
116
|
+
.describe("The Compact contract source code to analyze (provide this OR filePath)"),
|
|
117
|
+
filePath: z
|
|
118
|
+
.string()
|
|
119
|
+
.optional()
|
|
120
|
+
.describe("Path to a .compact file to analyze (alternative to providing code directly)"),
|
|
121
|
+
})
|
|
122
|
+
.refine((data) => (data.code !== undefined && data.code.trim() !== "") ||
|
|
123
|
+
data.filePath !== undefined, {
|
|
124
|
+
message: "Either 'code' or 'filePath' must be provided",
|
|
125
|
+
});
|
|
91
126
|
//# sourceMappingURL=schemas.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Repository tool definitions
|
|
3
3
|
* MCP tool registration for repository-related operations
|
|
4
4
|
*/
|
|
5
|
-
import { getFile, listExamples, getLatestUpdates, getVersionInfo, checkBreakingChanges, getMigrationGuide, getFileAtVersion, compareSyntax, getLatestSyntax, upgradeCheck, getFullRepoContext, } from "./handlers.js";
|
|
5
|
+
import { getFile, listExamples, getLatestUpdates, getVersionInfo, checkBreakingChanges, getMigrationGuide, getFileAtVersion, compareSyntax, getLatestSyntax, upgradeCheck, getFullRepoContext, validateContract, extractContractStructure, } from "./handlers.js";
|
|
6
6
|
// Tool definitions for MCP
|
|
7
7
|
export const repositoryTools = [
|
|
8
8
|
{
|
|
@@ -353,5 +353,194 @@ export const repositoryTools = [
|
|
|
353
353
|
},
|
|
354
354
|
handler: getFullRepoContext,
|
|
355
355
|
},
|
|
356
|
+
// ============================================================================
|
|
357
|
+
// VALIDATION TOOLS - Pre-compilation contract validation
|
|
358
|
+
// ============================================================================
|
|
359
|
+
{
|
|
360
|
+
name: "midnight-validate-contract",
|
|
361
|
+
description: "🔍 VALIDATION TOOL: Compile and validate a Compact contract BEFORE deployment. This runs the actual Compact compiler to check for syntax errors, type errors, and other issues. Use this after writing or modifying contract code to catch errors early. Requires the Compact CLI to be installed locally. Accepts either source code directly OR a file path to a .compact file.",
|
|
362
|
+
inputSchema: {
|
|
363
|
+
type: "object",
|
|
364
|
+
properties: {
|
|
365
|
+
code: {
|
|
366
|
+
type: "string",
|
|
367
|
+
description: "The Compact contract source code to validate (provide this OR filePath)",
|
|
368
|
+
},
|
|
369
|
+
filePath: {
|
|
370
|
+
type: "string",
|
|
371
|
+
description: "Path to a .compact file to validate (alternative to providing code directly)",
|
|
372
|
+
},
|
|
373
|
+
filename: {
|
|
374
|
+
type: "string",
|
|
375
|
+
description: "Optional filename for the contract when using code (default: contract.compact)",
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
required: [],
|
|
379
|
+
},
|
|
380
|
+
outputSchema: {
|
|
381
|
+
type: "object",
|
|
382
|
+
properties: {
|
|
383
|
+
success: {
|
|
384
|
+
type: "boolean",
|
|
385
|
+
description: "Whether the contract compiled successfully",
|
|
386
|
+
},
|
|
387
|
+
errorType: {
|
|
388
|
+
type: "string",
|
|
389
|
+
description: "Category of error: user_error, environment_error, system_error, compilation_error",
|
|
390
|
+
},
|
|
391
|
+
compilerInstalled: {
|
|
392
|
+
type: "boolean",
|
|
393
|
+
description: "Whether the Compact compiler is available",
|
|
394
|
+
},
|
|
395
|
+
compilerVersion: {
|
|
396
|
+
type: "string",
|
|
397
|
+
description: "Version of the Compact compiler",
|
|
398
|
+
},
|
|
399
|
+
message: { type: "string", description: "Summary message" },
|
|
400
|
+
errors: {
|
|
401
|
+
type: "array",
|
|
402
|
+
description: "List of compilation errors with line numbers",
|
|
403
|
+
items: {
|
|
404
|
+
type: "object",
|
|
405
|
+
properties: {
|
|
406
|
+
line: { type: "number" },
|
|
407
|
+
column: { type: "number" },
|
|
408
|
+
message: { type: "string" },
|
|
409
|
+
severity: { type: "string" },
|
|
410
|
+
context: { type: "string" },
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
userAction: {
|
|
415
|
+
type: "object",
|
|
416
|
+
description: "What the user needs to do to fix the problem",
|
|
417
|
+
properties: {
|
|
418
|
+
problem: { type: "string" },
|
|
419
|
+
solution: { type: "string" },
|
|
420
|
+
isUserFault: { type: "boolean" },
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
suggestions: {
|
|
424
|
+
type: "array",
|
|
425
|
+
description: "Suggestions for fixing errors",
|
|
426
|
+
items: { type: "string" },
|
|
427
|
+
},
|
|
428
|
+
commonFixes: {
|
|
429
|
+
type: "array",
|
|
430
|
+
description: "Common fix patterns",
|
|
431
|
+
items: {
|
|
432
|
+
type: "object",
|
|
433
|
+
properties: {
|
|
434
|
+
pattern: { type: "string" },
|
|
435
|
+
fix: { type: "string" },
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
installation: {
|
|
440
|
+
type: "object",
|
|
441
|
+
description: "Installation instructions if compiler not found",
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
annotations: {
|
|
446
|
+
readOnlyHint: false, // Creates temp files
|
|
447
|
+
idempotentHint: true, // Same input = same output
|
|
448
|
+
openWorldHint: true,
|
|
449
|
+
longRunningHint: true, // Compilation can take time
|
|
450
|
+
title: "🔍 Validate Contract",
|
|
451
|
+
category: "validation",
|
|
452
|
+
},
|
|
453
|
+
handler: validateContract,
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
name: "midnight-extract-contract-structure",
|
|
457
|
+
description: "📋 ANALYSIS TOOL: Extract the structure of a Compact contract - circuits, witnesses, ledger items, types, structs, and enums. Use this to understand what a contract does without reading all the code. Returns exported and internal definitions with line numbers. Accepts either source code directly OR a file path.",
|
|
458
|
+
inputSchema: {
|
|
459
|
+
type: "object",
|
|
460
|
+
properties: {
|
|
461
|
+
code: {
|
|
462
|
+
type: "string",
|
|
463
|
+
description: "The Compact contract source code to analyze (provide this OR filePath)",
|
|
464
|
+
},
|
|
465
|
+
filePath: {
|
|
466
|
+
type: "string",
|
|
467
|
+
description: "Path to a .compact file to analyze (alternative to providing code directly)",
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
required: [],
|
|
471
|
+
},
|
|
472
|
+
outputSchema: {
|
|
473
|
+
type: "object",
|
|
474
|
+
properties: {
|
|
475
|
+
success: { type: "boolean" },
|
|
476
|
+
filename: { type: "string" },
|
|
477
|
+
languageVersion: { type: "string" },
|
|
478
|
+
imports: { type: "array", items: { type: "string" } },
|
|
479
|
+
structure: {
|
|
480
|
+
type: "object",
|
|
481
|
+
properties: {
|
|
482
|
+
circuits: {
|
|
483
|
+
type: "array",
|
|
484
|
+
items: {
|
|
485
|
+
type: "object",
|
|
486
|
+
properties: {
|
|
487
|
+
name: { type: "string" },
|
|
488
|
+
params: { type: "array", items: { type: "string" } },
|
|
489
|
+
returnType: { type: "string" },
|
|
490
|
+
isExport: { type: "boolean" },
|
|
491
|
+
line: { type: "number" },
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
witnesses: {
|
|
496
|
+
type: "array",
|
|
497
|
+
items: {
|
|
498
|
+
type: "object",
|
|
499
|
+
properties: {
|
|
500
|
+
name: { type: "string" },
|
|
501
|
+
type: { type: "string" },
|
|
502
|
+
isExport: { type: "boolean" },
|
|
503
|
+
line: { type: "number" },
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
ledgerItems: {
|
|
508
|
+
type: "array",
|
|
509
|
+
items: {
|
|
510
|
+
type: "object",
|
|
511
|
+
properties: {
|
|
512
|
+
name: { type: "string" },
|
|
513
|
+
type: { type: "string" },
|
|
514
|
+
isExport: { type: "boolean" },
|
|
515
|
+
line: { type: "number" },
|
|
516
|
+
},
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
types: { type: "array" },
|
|
520
|
+
structs: { type: "array" },
|
|
521
|
+
enums: { type: "array" },
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
exports: {
|
|
525
|
+
type: "object",
|
|
526
|
+
description: "Names of all exported items",
|
|
527
|
+
},
|
|
528
|
+
stats: {
|
|
529
|
+
type: "object",
|
|
530
|
+
description: "Counts of each type of definition",
|
|
531
|
+
},
|
|
532
|
+
summary: { type: "string" },
|
|
533
|
+
message: { type: "string" },
|
|
534
|
+
},
|
|
535
|
+
},
|
|
536
|
+
annotations: {
|
|
537
|
+
readOnlyHint: true,
|
|
538
|
+
idempotentHint: true,
|
|
539
|
+
openWorldHint: false,
|
|
540
|
+
title: "📋 Extract Contract Structure",
|
|
541
|
+
category: "validation",
|
|
542
|
+
},
|
|
543
|
+
handler: extractContractStructure,
|
|
544
|
+
},
|
|
356
545
|
];
|
|
357
546
|
//# sourceMappingURL=tools.js.map
|