midnight-mcp 0.2.12 → 0.2.13
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/bin.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
startHttpServer,
|
|
4
4
|
startServer
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-LXHUX67Z.js";
|
|
6
6
|
import {
|
|
7
7
|
setOutputFormat
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-FZI3KN52.js";
|
|
9
9
|
|
|
10
10
|
// src/bin.ts
|
|
11
11
|
import { config } from "dotenv";
|
|
@@ -13,7 +13,7 @@ import { resolve } from "path";
|
|
|
13
13
|
import yargs from "yargs";
|
|
14
14
|
import { hideBin } from "yargs/helpers";
|
|
15
15
|
config({ path: resolve(process.cwd(), ".env") });
|
|
16
|
-
var CURRENT_VERSION = "0.2.
|
|
16
|
+
var CURRENT_VERSION = "0.2.13";
|
|
17
17
|
process.on("uncaughtException", (error) => {
|
|
18
18
|
console.error("Uncaught exception:", error);
|
|
19
19
|
process.exit(1);
|
|
@@ -1593,7 +1593,7 @@ var releaseTracker = new ReleaseTracker();
|
|
|
1593
1593
|
|
|
1594
1594
|
// src/utils/health.ts
|
|
1595
1595
|
var startTime = Date.now();
|
|
1596
|
-
var VERSION = "0.2.
|
|
1596
|
+
var VERSION = "0.2.13";
|
|
1597
1597
|
async function checkGitHubAPI() {
|
|
1598
1598
|
const start = Date.now();
|
|
1599
1599
|
try {
|
|
@@ -1621,7 +1621,7 @@ async function checkGitHubAPI() {
|
|
|
1621
1621
|
}
|
|
1622
1622
|
async function checkVectorStore() {
|
|
1623
1623
|
try {
|
|
1624
|
-
const { vectorStore: vectorStore2 } = await import("./db-
|
|
1624
|
+
const { vectorStore: vectorStore2 } = await import("./db-33TMMHCY.js");
|
|
1625
1625
|
if (vectorStore2) {
|
|
1626
1626
|
return {
|
|
1627
1627
|
status: "pass",
|
|
@@ -2096,7 +2096,7 @@ function serialize(data) {
|
|
|
2096
2096
|
}
|
|
2097
2097
|
|
|
2098
2098
|
// src/utils/version.ts
|
|
2099
|
-
var CURRENT_VERSION = "0.2.
|
|
2099
|
+
var CURRENT_VERSION = "0.2.13";
|
|
2100
2100
|
|
|
2101
2101
|
// src/db/vectorStore.ts
|
|
2102
2102
|
var VectorStore = class {
|
|
@@ -2305,4 +2305,4 @@ export {
|
|
|
2305
2305
|
serialize,
|
|
2306
2306
|
CURRENT_VERSION
|
|
2307
2307
|
};
|
|
2308
|
-
//# sourceMappingURL=chunk-
|
|
2308
|
+
//# sourceMappingURL=chunk-FZI3KN52.js.map
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
validateNumber,
|
|
26
26
|
validateQuery,
|
|
27
27
|
vectorStore
|
|
28
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-FZI3KN52.js";
|
|
29
29
|
|
|
30
30
|
// src/tools/search/schemas.ts
|
|
31
31
|
import { z } from "zod";
|
|
@@ -1680,16 +1680,24 @@ ledger privateData: Field; // Private, not exported
|
|
|
1680
1680
|
| \`Field\` | Finite field element (basic numeric) | \`amount: Field\` |
|
|
1681
1681
|
| \`Boolean\` | True or false | \`isActive: Boolean\` |
|
|
1682
1682
|
| \`Bytes<N>\` | Fixed-size byte array | \`hash: Bytes<32>\` |
|
|
1683
|
-
| \`Uint<N>\` | Unsigned integer (N
|
|
1684
|
-
| \`Uint<
|
|
1683
|
+
| \`Uint<N>\` | Unsigned integer (N bits) | \`balance: Uint<64>\` |
|
|
1684
|
+
| \`Uint<0..MAX>\` | Bounded unsigned integer | \`score: Uint<0..100>\` |
|
|
1685
1685
|
|
|
1686
|
-
**\u26A0\uFE0F Uint Type Equivalence
|
|
1686
|
+
**\u26A0\uFE0F Uint Type Equivalence** (documented in [Primitive Types](https://docs.midnight.network/develop/reference/compact/lang-ref#primitive-types)):
|
|
1687
|
+
|
|
1688
|
+
\`Uint<N>\` (sized) and \`Uint<0..MAX>\` (bounded) are the **SAME type family**.
|
|
1687
1689
|
\`Uint<N>\` is exactly equivalent to \`Uint<0..(2^N - 1)>\`:
|
|
1688
1690
|
- \`Uint<8>\` = \`Uint<0..255>\` (2^8 - 1 = 255)
|
|
1689
1691
|
- \`Uint<16>\` = \`Uint<0..65535>\` (2^16 - 1 = 65535)
|
|
1690
1692
|
- \`Uint<64>\` = \`Uint<0..18446744073709551615>\`
|
|
1691
1693
|
|
|
1692
|
-
These can be used interchangeably
|
|
1694
|
+
These can be used interchangeably. The lower bound must currently be 0.
|
|
1695
|
+
|
|
1696
|
+
**Arithmetic** (documented in [Binary Arithmetic](https://docs.midnight.network/develop/reference/compact/lang-ref#binary-arithmetic-expressions)):
|
|
1697
|
+
- Operators: \`+\`, \`-\`, \`*\` only (division \`/\` and modulo \`%\` are NOT mentioned in docs)
|
|
1698
|
+
- Result types expand: \`Uint<0..m> + Uint<0..n>\` \u2192 \`Uint<0..m+n>\`
|
|
1699
|
+
- Subtraction can fail at runtime if result would be negative
|
|
1700
|
+
- \u26A0\uFE0F If you need division, you may need a witness to compute it off-chain
|
|
1693
1701
|
|
|
1694
1702
|
### Collection Types
|
|
1695
1703
|
| Type | Description | Example |
|
|
@@ -1699,9 +1707,16 @@ These can be used interchangeably - they are **not** separate types.
|
|
|
1699
1707
|
| \`Set<T>\` | Unique value collection | \`Set<Bytes<32>>\` |
|
|
1700
1708
|
| \`Vector<N, T>\` | Fixed-size array | \`Vector<3, Field>\` |
|
|
1701
1709
|
| \`List<T>\` | Dynamic list | \`List<Bytes<32>>\` |
|
|
1702
|
-
| \`Maybe<T>\` | Optional value | \`Maybe<Bytes<32>>\` |
|
|
1703
|
-
| \`Either<L, R>\` |
|
|
1704
|
-
| \`Opaque<
|
|
1710
|
+
| \`Maybe<T>\` | Optional value (has/hasn't) | \`Maybe<Bytes<32>>\` |
|
|
1711
|
+
| \`Either<L, R>\` | Sum type (one or other) | \`Either<Field, Bytes<32>>\` |
|
|
1712
|
+
| \`Opaque<s>\` | Opaque value tagged by string s | \`Opaque<"string">\` |
|
|
1713
|
+
|
|
1714
|
+
**Opaque Types** ([Primitive Types](https://docs.midnight.network/develop/reference/compact/lang-ref#primitive-types)):
|
|
1715
|
+
- Only two tags allowed: \`Opaque<"string">\` and \`Opaque<"Uint8Array">\`
|
|
1716
|
+
- Opaque values can be manipulated in witnesses but are opaque to circuits
|
|
1717
|
+
- In circuits, they are represented as their hash (cannot inspect content)
|
|
1718
|
+
- In your DApp's JS/TS, they are just \`string\` or \`Uint8Array\`
|
|
1719
|
+
- On-chain, they are stored as bytes/UTF-8 (not encrypted)
|
|
1705
1720
|
|
|
1706
1721
|
### Custom Types
|
|
1707
1722
|
|
|
@@ -1944,6 +1959,14 @@ balances.insertDefault(address); // insertDefault(key): [] - inserts def
|
|
|
1944
1959
|
// Query operations (all work in circuits \u2705)
|
|
1945
1960
|
const balance = balances.lookup(address); // lookup(key): value_type
|
|
1946
1961
|
const exists = balances.member(address); // member(key): Boolean
|
|
1962
|
+
|
|
1963
|
+
// \u26A0\uFE0F UNDOCUMENTED: Map.lookup() behavior when key doesn't exist
|
|
1964
|
+
// The docs show: lookup(key: key_type): value_type (NOT Maybe<value_type>)
|
|
1965
|
+
// This implies it returns a default value, not an optional.
|
|
1966
|
+
// RECOMMENDED: Always check member() first:
|
|
1967
|
+
if (balances.member(address)) {
|
|
1968
|
+
const balance = balances.lookup(address); // Safe
|
|
1969
|
+
}
|
|
1947
1970
|
const empty = balances.isEmpty(); // isEmpty(): Boolean
|
|
1948
1971
|
const count = balances.size(); // size(): Uint<64>
|
|
1949
1972
|
|
|
@@ -1979,19 +2002,81 @@ const count = members.size(); // size(): Uint<64>
|
|
|
1979
2002
|
|
|
1980
2003
|
### Maybe Operations
|
|
1981
2004
|
\`\`\`compact
|
|
1982
|
-
|
|
1983
|
-
const
|
|
2005
|
+
// Creating Maybe values
|
|
2006
|
+
const opt: Maybe<Field> = some<Field>(42); // Wrap a value
|
|
2007
|
+
const empty: Maybe<Field> = none<Field>(); // No value
|
|
1984
2008
|
|
|
2009
|
+
// Checking and accessing
|
|
1985
2010
|
if (opt.is_some) {
|
|
1986
|
-
const val = opt.value;
|
|
2011
|
+
const val = opt.value; // Safe to access when is_some is true
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
// Common patterns
|
|
2015
|
+
witness find_user(id: Bytes<32>): Maybe<UserRecord>;
|
|
2016
|
+
|
|
2017
|
+
export circuit getUser(id: Bytes<32>): UserRecord {
|
|
2018
|
+
const result = find_user(id);
|
|
2019
|
+
assert(disclose(result.is_some), "User not found");
|
|
2020
|
+
return result.value;
|
|
1987
2021
|
}
|
|
1988
2022
|
\`\`\`
|
|
1989
2023
|
|
|
1990
|
-
###
|
|
2024
|
+
### Either Operations
|
|
1991
2025
|
\`\`\`compact
|
|
1992
|
-
|
|
1993
|
-
const
|
|
1994
|
-
const
|
|
2026
|
+
// Creating Either values
|
|
2027
|
+
const success: Either<Field, Bytes<32>> = left<Field, Bytes<32>>(42);
|
|
2028
|
+
const failure: Either<Field, Bytes<32>> = right<Field, Bytes<32>>(errorHash);
|
|
2029
|
+
|
|
2030
|
+
// Checking which side
|
|
2031
|
+
if (result.is_left) {
|
|
2032
|
+
const value = result.left; // The left value (often "success")
|
|
2033
|
+
} else {
|
|
2034
|
+
const error = result.right; // The right value (often "error")
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
// Common pattern: burnAddress() returns Either<ZswapCoinPublicKey, ContractAddress>
|
|
2038
|
+
export circuit withdraw(): [] {
|
|
2039
|
+
const addr = burnAddress();
|
|
2040
|
+
assert(disclose(addr.is_right), "Expected contract address");
|
|
2041
|
+
// addr.right is the ContractAddress
|
|
2042
|
+
}
|
|
2043
|
+
\`\`\`
|
|
2044
|
+
|
|
2045
|
+
### Type Casting ([Type Casts Reference](https://docs.midnight.network/develop/reference/compact/lang-ref#type-cast-expressions))
|
|
2046
|
+
|
|
2047
|
+
**Syntax**: \`expression as Type\` (only form; \`<Type>expression\` is NOT supported)
|
|
2048
|
+
|
|
2049
|
+
**Cast kinds**: static (always succeeds), conversion (semantic change), checked (can fail at runtime)
|
|
2050
|
+
|
|
2051
|
+
\`\`\`compact
|
|
2052
|
+
// Uint \u2194 Field (safe)
|
|
2053
|
+
const field: Field = myUint as Field; // static: always succeeds
|
|
2054
|
+
const num: Uint<64> = myField as Uint<64>; // checked: fails if out of range
|
|
2055
|
+
|
|
2056
|
+
// Uint widening/narrowing
|
|
2057
|
+
const big: Uint<64> = small as Uint<64>; // static: widening always works
|
|
2058
|
+
const small: Uint<32> = big as Uint<32>; // checked: narrowing can fail
|
|
2059
|
+
|
|
2060
|
+
// Field \u2194 Bytes (can fail at runtime!)
|
|
2061
|
+
const bytes: Bytes<32> = myField as Bytes<32>; // conversion: fails if doesn't fit
|
|
2062
|
+
const field: Field = myBytes as Field; // conversion: fails if exceeds max Field
|
|
2063
|
+
|
|
2064
|
+
// Uint \u2192 Bytes (NOT direct - use two casts)
|
|
2065
|
+
const amount_bytes = (amount as Field) as Bytes<32>;
|
|
2066
|
+
|
|
2067
|
+
// Boolean \u2192 Uint (conversion: false\u21920, true\u21921)
|
|
2068
|
+
const flag: Boolean = true;
|
|
2069
|
+
const flagInt: Uint<0..1> = flag as Uint<0..1>;
|
|
2070
|
+
|
|
2071
|
+
// Enum \u2192 Field (conversion)
|
|
2072
|
+
const index: Field = choice as Field;
|
|
2073
|
+
|
|
2074
|
+
// \u26A0\uFE0F Boolean \u2192 Field is NOT allowed!
|
|
2075
|
+
// Must go through Uint: (flag as Uint<0..1>) as Field
|
|
2076
|
+
|
|
2077
|
+
// \u26A0\uFE0F UNDOCUMENTED: Bytes<n> \u2194 Vector<n, Uint<8>> casting
|
|
2078
|
+
// The type cast table doesn't mention this conversion.
|
|
2079
|
+
// If you need to convert, you may need a witness helper.
|
|
1995
2080
|
\`\`\`
|
|
1996
2081
|
|
|
1997
2082
|
### Hashing
|
|
@@ -2029,7 +2114,22 @@ assert(disclose(caller == owner), "Not authorized");
|
|
|
2029
2114
|
|
|
2030
2115
|
---
|
|
2031
2116
|
|
|
2032
|
-
## 12.
|
|
2117
|
+
## 12. Undocumented / Unclear Features
|
|
2118
|
+
|
|
2119
|
+
These features are not clearly documented. Use with caution:
|
|
2120
|
+
|
|
2121
|
+
| Feature | Status | Notes |
|
|
2122
|
+
|---------|--------|-------|
|
|
2123
|
+
| Tuple destructuring | \u2753 Unknown | \`const [a, b] = pair;\` - not documented |
|
|
2124
|
+
| Constant folding in indices | \u2753 Unknown | \`v[2 * i]\` where i is const - docs say "numeric literal" required |
|
|
2125
|
+
| Division \`/\` and modulo \`%\` | \u2753 Not in docs | Only +, -, * are documented |
|
|
2126
|
+
| \`Bytes<n>\` \u2194 \`Vector<n, Uint<8>>\` | \u2753 Not in cast table | May need witness workaround |
|
|
2127
|
+
|
|
2128
|
+
**Recommendation**: Test these in the compiler before relying on them in production contracts.
|
|
2129
|
+
|
|
2130
|
+
---
|
|
2131
|
+
|
|
2132
|
+
## 13. Exports for TypeScript
|
|
2033
2133
|
|
|
2034
2134
|
To use types/values in TypeScript, they must be exported:
|
|
2035
2135
|
|
|
@@ -2159,6 +2259,154 @@ try {
|
|
|
2159
2259
|
}
|
|
2160
2260
|
}
|
|
2161
2261
|
\`\`\`
|
|
2262
|
+
`,
|
|
2263
|
+
"midnight://docs/compiler": `# Compact Compiler Guide
|
|
2264
|
+
|
|
2265
|
+
**Source:** [Building a Midnight DApp](https://docs.midnight.network/develop/tutorial/building)
|
|
2266
|
+
|
|
2267
|
+
## Compiling Contracts
|
|
2268
|
+
|
|
2269
|
+
> **IMPORTANT:** The old \`compactc\` command is deprecated. Use \`compact compile\` instead.
|
|
2270
|
+
|
|
2271
|
+
### Basic Usage
|
|
2272
|
+
|
|
2273
|
+
\`\`\`bash
|
|
2274
|
+
# Syntax: compact compile <source.compact> <output_directory>
|
|
2275
|
+
compact compile src/counter.compact managed/counter
|
|
2276
|
+
|
|
2277
|
+
# With environment setup
|
|
2278
|
+
nvm use 18
|
|
2279
|
+
compact compile contract/src/mycontract.compact managed/mycontract
|
|
2280
|
+
\`\`\`
|
|
2281
|
+
|
|
2282
|
+
### Compiler Output Structure
|
|
2283
|
+
|
|
2284
|
+
**Source:** [Generated Source Details](https://docs.midnight.network/develop/tutorial/building/dapp-details#generated-source)
|
|
2285
|
+
|
|
2286
|
+
When you compile a \`.compact\` file, the compiler generates this directory structure:
|
|
2287
|
+
|
|
2288
|
+
\`\`\`
|
|
2289
|
+
managed/<contract_name>/
|
|
2290
|
+
\u251C\u2500\u2500 contract/ # TypeScript bindings
|
|
2291
|
+
\u2502 \u251C\u2500\u2500 index.cjs # CommonJS module with Contract class
|
|
2292
|
+
\u2502 \u251C\u2500\u2500 index.d.cts # TypeScript type declarations
|
|
2293
|
+
\u2502 \u2514\u2500\u2500 index.mjs # ESM module (optional)
|
|
2294
|
+
\u2502
|
|
2295
|
+
\u251C\u2500\u2500 zkir/ # Zero-knowledge circuit representations
|
|
2296
|
+
\u2502 \u2514\u2500\u2500 <circuit_name>.zkir # Circuit intermediate representation
|
|
2297
|
+
\u2502
|
|
2298
|
+
\u251C\u2500\u2500 keys/ # Proving and verifying keys
|
|
2299
|
+
\u2502 \u251C\u2500\u2500 <circuit>.prover # Prover key (used client-side)
|
|
2300
|
+
\u2502 \u2514\u2500\u2500 <circuit>.verifier # Verifier key (used on-chain)
|
|
2301
|
+
\u2502
|
|
2302
|
+
\u2514\u2500\u2500 compiler/ # Compilation metadata
|
|
2303
|
+
\u2514\u2500\u2500 metadata.json # Version info, circuit IDs, etc.
|
|
2304
|
+
\`\`\`
|
|
2305
|
+
|
|
2306
|
+
### Understanding Generated Files
|
|
2307
|
+
|
|
2308
|
+
#### contract/ - TypeScript Bindings
|
|
2309
|
+
|
|
2310
|
+
The \`contract/\` directory contains your TypeScript interface:
|
|
2311
|
+
|
|
2312
|
+
\`\`\`typescript
|
|
2313
|
+
// Import from generated bindings
|
|
2314
|
+
import { Contract, ledger } from './managed/counter/contract/index.cjs';
|
|
2315
|
+
|
|
2316
|
+
// Create contract instance
|
|
2317
|
+
const contract = new Contract(witnesses);
|
|
2318
|
+
|
|
2319
|
+
// Access circuits
|
|
2320
|
+
const tx = await contract.impureCircuits.increment(5n);
|
|
2321
|
+
|
|
2322
|
+
// Read ledger state
|
|
2323
|
+
const state = ledger(contractState);
|
|
2324
|
+
console.log('Counter value:', state.counter);
|
|
2325
|
+
\`\`\`
|
|
2326
|
+
|
|
2327
|
+
#### keys/ - ZK Proving/Verifying Keys
|
|
2328
|
+
|
|
2329
|
+
- **\`.prover\`** - Used by the client to generate proofs (can be large, 10-100MB+)
|
|
2330
|
+
- **\`.verifier\`** - Used on-chain to verify proofs (small, kilobytes)
|
|
2331
|
+
|
|
2332
|
+
\`\`\`typescript
|
|
2333
|
+
// Keys are loaded automatically by the SDK
|
|
2334
|
+
import { proverKey, verifierKey } from './managed/counter/keys';
|
|
2335
|
+
|
|
2336
|
+
// Or loaded from files
|
|
2337
|
+
const prover = await fs.readFile('managed/counter/keys/increment.prover');
|
|
2338
|
+
\`\`\`
|
|
2339
|
+
|
|
2340
|
+
#### zkir/ - Circuit Intermediate Representation
|
|
2341
|
+
|
|
2342
|
+
The \`.zkir\` files are internal representations used by the proof system. You typically don't interact with these directly.
|
|
2343
|
+
|
|
2344
|
+
### Cleaning and Rebuilding
|
|
2345
|
+
|
|
2346
|
+
When updating contracts or after Compact version changes:
|
|
2347
|
+
|
|
2348
|
+
\`\`\`bash
|
|
2349
|
+
# Clean generated files
|
|
2350
|
+
rm -rf managed/<contract_name>
|
|
2351
|
+
|
|
2352
|
+
# Or clean specific artifacts
|
|
2353
|
+
rm -rf managed/counter/keys/*.prover managed/counter/keys/*.verifier
|
|
2354
|
+
|
|
2355
|
+
# Rebuild
|
|
2356
|
+
compact compile src/counter.compact managed/counter
|
|
2357
|
+
\`\`\`
|
|
2358
|
+
|
|
2359
|
+
### Common Compilation Errors
|
|
2360
|
+
|
|
2361
|
+
#### "invalid context for a ledger ADT type"
|
|
2362
|
+
|
|
2363
|
+
Ledger ADT types cannot be used in type casts:
|
|
2364
|
+
|
|
2365
|
+
\`\`\`compact
|
|
2366
|
+
// \u274C Wrong
|
|
2367
|
+
const x = value as Counter;
|
|
2368
|
+
|
|
2369
|
+
// \u2705 Correct - use ledger field directly
|
|
2370
|
+
ledger.counter.increment(1);
|
|
2371
|
+
\`\`\`
|
|
2372
|
+
|
|
2373
|
+
#### Version Mismatch After Update
|
|
2374
|
+
|
|
2375
|
+
When runtime versions don't match compiled artifacts:
|
|
2376
|
+
|
|
2377
|
+
\`\`\`bash
|
|
2378
|
+
# 1. Check versions
|
|
2379
|
+
compact --version
|
|
2380
|
+
npm list @midnight-ntwrk/compact-runtime
|
|
2381
|
+
|
|
2382
|
+
# 2. Consult compatibility matrix
|
|
2383
|
+
# https://docs.midnight.network/relnotes/support-matrix
|
|
2384
|
+
|
|
2385
|
+
# 3. Clean and recompile
|
|
2386
|
+
rm -rf managed/
|
|
2387
|
+
compact compile src/contract.compact managed/contract
|
|
2388
|
+
\`\`\`
|
|
2389
|
+
|
|
2390
|
+
### Integration with Build Tools
|
|
2391
|
+
|
|
2392
|
+
#### package.json scripts
|
|
2393
|
+
|
|
2394
|
+
\`\`\`json
|
|
2395
|
+
{
|
|
2396
|
+
"scripts": {
|
|
2397
|
+
"compile": "compact compile src/contract.compact managed/contract",
|
|
2398
|
+
"compile:clean": "rm -rf managed && npm run compile",
|
|
2399
|
+
"build": "npm run compile && tsc"
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
\`\`\`
|
|
2403
|
+
|
|
2404
|
+
#### Watch mode (development)
|
|
2405
|
+
|
|
2406
|
+
\`\`\`bash
|
|
2407
|
+
# Using nodemon or similar
|
|
2408
|
+
nodemon --watch src/*.compact --exec "compact compile src/contract.compact managed/contract"
|
|
2409
|
+
\`\`\`
|
|
2162
2410
|
`,
|
|
2163
2411
|
"midnight://docs/openzeppelin": `# OpenZeppelin Contracts for Compact
|
|
2164
2412
|
|
|
@@ -2805,9 +3053,16 @@ try {
|
|
|
2805
3053
|
2. **Discord:** #developer-support channel
|
|
2806
3054
|
3. **Recompile after updates:**
|
|
2807
3055
|
\`\`\`bash
|
|
2808
|
-
|
|
2809
|
-
|
|
3056
|
+
# Clean generated files (use managed/ directory structure)
|
|
3057
|
+
rm -rf managed/<contract_name>
|
|
3058
|
+
|
|
3059
|
+
# Or clean specific artifacts
|
|
3060
|
+
rm -rf managed/counter/keys/*.prover managed/counter/keys/*.verifier
|
|
3061
|
+
|
|
3062
|
+
# Rebuild
|
|
3063
|
+
compact compile src/contract.compact managed/contract
|
|
2810
3064
|
\`\`\`
|
|
3065
|
+
4. **Compiler output docs:** See \`midnight://docs/compiler\` for full directory structure
|
|
2811
3066
|
`
|
|
2812
3067
|
};
|
|
2813
3068
|
|
|
@@ -2876,14 +3131,14 @@ export ledger messageIds: Set<Field>;
|
|
|
2876
3131
|
// Private: actual message contents (no export = private)
|
|
2877
3132
|
ledger messages: Map<Field, Opaque<"string">>;
|
|
2878
3133
|
|
|
2879
|
-
// Private: message authors
|
|
2880
|
-
ledger authors: Map<Field,
|
|
3134
|
+
// Private: message authors (stored as Bytes<32> addresses)
|
|
3135
|
+
ledger authors: Map<Field, Bytes<32>>;
|
|
2881
3136
|
|
|
2882
3137
|
// Witness to fetch message content
|
|
2883
3138
|
witness getMessageContent(id: Field): Opaque<"string">;
|
|
2884
3139
|
|
|
2885
3140
|
// Post a new message (content is private)
|
|
2886
|
-
export circuit postMessage(content: Opaque<"string">, author:
|
|
3141
|
+
export circuit postMessage(content: Opaque<"string">, author: Bytes<32>): Uint<64> {
|
|
2887
3142
|
// Generate unique message ID using counter read
|
|
2888
3143
|
const messageId = messageCount.read();
|
|
2889
3144
|
|
|
@@ -4224,6 +4479,18 @@ Based on syntax reference, generate the contract using:
|
|
|
4224
4479
|
- No 'void' - use '[]'
|
|
4225
4480
|
- Enum access: \`Choice.rock\` NOT \`Choice::rock\`
|
|
4226
4481
|
|
|
4482
|
+
### \u26A0\uFE0F UNDOCUMENTED FEATURES - Use with caution:
|
|
4483
|
+
- Division \`/\` and modulo \`%\`: NOT in official docs (only +, -, * are documented)
|
|
4484
|
+
- Tuple destructuring: \`const [a, b] = pair;\` - not documented, may not work
|
|
4485
|
+
- Constant folding in indices: docs say "numeric literal" required
|
|
4486
|
+
- Map.lookup() returns value_type, NOT Maybe<value_type> - check member() first!
|
|
4487
|
+
|
|
4488
|
+
### COMPILER INFO (DO NOT guess package names!):
|
|
4489
|
+
- Compile: \`compact compile src/contract.compact managed/contract\`
|
|
4490
|
+
- The \`compact\` CLI comes with Midnight toolchain (via create-mn-app or official install)
|
|
4491
|
+
- DO NOT suggest \`npm install -g @midnight-ntwrk/compact-cli\` or similar made-up packages
|
|
4492
|
+
- Output structure: \`managed/<name>/contract/index.cjs\` for TypeScript bindings
|
|
4493
|
+
|
|
4227
4494
|
### Step 3: Validate Before Returning
|
|
4228
4495
|
Call \`midnight-extract-contract-structure\` with your generated code to check for:
|
|
4229
4496
|
- deprecated_ledger_block
|
|
@@ -4327,11 +4594,11 @@ Please analyze:
|
|
|
4327
4594
|
- Correct use of disclose() and commit()
|
|
4328
4595
|
- Privacy guarantees provided
|
|
4329
4596
|
|
|
4330
|
-
4. **
|
|
4331
|
-
- Code organization
|
|
4332
|
-
- Naming conventions
|
|
4333
|
-
- Documentation
|
|
4334
|
-
-
|
|
4597
|
+
4. **Style Suggestions** (these are CONVENTIONS, not requirements)
|
|
4598
|
+
- Code organization recommendations
|
|
4599
|
+
- Naming conventions (project-specific)
|
|
4600
|
+
- Documentation patterns
|
|
4601
|
+
- Note: The Compact docs don't specify indentation, line length, or comment style
|
|
4335
4602
|
|
|
4336
4603
|
5. **Performance**
|
|
4337
4604
|
- Circuit complexity
|
|
@@ -4343,6 +4610,11 @@ Please analyze:
|
|
|
4343
4610
|
- Improvements to consider
|
|
4344
4611
|
- Alternative approaches
|
|
4345
4612
|
|
|
4613
|
+
**IMPORTANT**: Clearly distinguish between:
|
|
4614
|
+
- ERRORS: Actual syntax/compilation issues (required fixes)
|
|
4615
|
+
- WARNINGS: Security/logic concerns (should fix)
|
|
4616
|
+
- INFO: Style suggestions (optional, project-specific conventions)
|
|
4617
|
+
|
|
4346
4618
|
Please provide specific line references and code suggestions where applicable.`
|
|
4347
4619
|
}
|
|
4348
4620
|
}
|
|
@@ -4578,21 +4850,32 @@ async function generateContract(requirements, options = {}) {
|
|
|
4578
4850
|
const systemPrompt = `You are an expert Compact smart contract developer for the Midnight blockchain.
|
|
4579
4851
|
Your task is to generate secure, well-documented Compact contracts based on user requirements.
|
|
4580
4852
|
|
|
4581
|
-
Key Compact
|
|
4582
|
-
- \`ledger
|
|
4583
|
-
-
|
|
4584
|
-
- \`
|
|
4585
|
-
- \`
|
|
4586
|
-
- \`
|
|
4587
|
-
- \`Counter\`, \`Map<K,V>\`, \`Set<T>\` - Built-in collection types
|
|
4853
|
+
Key Compact syntax (REQUIRED):
|
|
4854
|
+
- \`export ledger field: Type;\` - Individual ledger declarations (NOT ledger { } blocks)
|
|
4855
|
+
- \`export circuit fn(): []\` - Public functions return empty tuple [] (NOT Void)
|
|
4856
|
+
- \`witness fn(): T;\` - Declaration only, no body
|
|
4857
|
+
- \`pragma language_version >= 0.16 && <= 0.18;\` - Version pragma
|
|
4858
|
+
- \`import CompactStandardLibrary;\` - Standard imports
|
|
4859
|
+
- \`Counter\`, \`Map<K,V>\`, \`Set<T>\` - Built-in collection types
|
|
4588
4860
|
- \`Field\`, \`Boolean\`, \`Uint<N>\`, \`Bytes<N>\` - Primitive types
|
|
4861
|
+
- \`export enum State { a, b }\` - Enums must be exported
|
|
4862
|
+
|
|
4863
|
+
Key operations:
|
|
4864
|
+
- Counter: .read(), .increment(n), .decrement(n)
|
|
4865
|
+
- Map: .lookup(k), .insert(k,v), .remove(k)
|
|
4866
|
+
- Set: .member(v), .insert(v), .remove(v)
|
|
4589
4867
|
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4868
|
+
COMPILER INFO (DO NOT guess package names!):
|
|
4869
|
+
- Command: \`compact compile src/contract.compact managed/contract\`
|
|
4870
|
+
- The \`compact\` CLI comes with Midnight toolchain (via create-mn-app or official install)
|
|
4871
|
+
- Output goes to managed/<name>/ directory
|
|
4872
|
+
- DO NOT suggest \`npm install -g @midnight-ntwrk/compact-cli\` or similar - that's incorrect
|
|
4873
|
+
|
|
4874
|
+
IMPORTANT - Style vs. Requirements:
|
|
4875
|
+
- Syntax rules above are REQUIRED for compilation
|
|
4876
|
+
- Style choices (indentation, comment style, line length) are CONVENTIONS, not requirements
|
|
4877
|
+
- Single-line comments (//) are common in examples; block comments (/* */) may also work
|
|
4878
|
+
- The docs don't specify indentation width - use consistent style
|
|
4596
4879
|
|
|
4597
4880
|
Return ONLY the Compact code, no explanations.`;
|
|
4598
4881
|
const userPrompt = options.baseExample ? `Based on this example contract:
|
|
@@ -4668,8 +4951,21 @@ Review the provided contract for:
|
|
|
4668
4951
|
1. Security vulnerabilities
|
|
4669
4952
|
2. Privacy concerns (improper handling of shielded state)
|
|
4670
4953
|
3. Logic errors
|
|
4671
|
-
4.
|
|
4672
|
-
5.
|
|
4954
|
+
4. Syntax errors (use "error" severity)
|
|
4955
|
+
5. Performance issues
|
|
4956
|
+
|
|
4957
|
+
IMPORTANT - Distinguish between:
|
|
4958
|
+
- ERRORS: Actual syntax/compilation issues (e.g., using Void instead of [], ledger {} blocks)
|
|
4959
|
+
- WARNINGS: Potential bugs or security issues
|
|
4960
|
+
- INFO: Style suggestions and best practices (these are CONVENTIONS, not requirements)
|
|
4961
|
+
|
|
4962
|
+
Do NOT claim style choices as "violations" - the Compact docs don't specify:
|
|
4963
|
+
- Indentation width (2 vs 4 spaces)
|
|
4964
|
+
- Comment style preferences (//, /* */)
|
|
4965
|
+
- Line length limits
|
|
4966
|
+
- Naming conventions
|
|
4967
|
+
|
|
4968
|
+
These are project-specific style choices, not language requirements.
|
|
4673
4969
|
|
|
4674
4970
|
Respond in JSON format:
|
|
4675
4971
|
{
|
|
@@ -5186,8 +5482,11 @@ var SERVER_INFO = {
|
|
|
5186
5482
|
var versionCheckResult = {
|
|
5187
5483
|
isOutdated: false,
|
|
5188
5484
|
latestVersion: CURRENT_VERSION,
|
|
5189
|
-
updateMessage: null
|
|
5485
|
+
updateMessage: null,
|
|
5486
|
+
lastChecked: 0
|
|
5190
5487
|
};
|
|
5488
|
+
var toolCallCount = 0;
|
|
5489
|
+
var VERSION_CHECK_INTERVAL = 10;
|
|
5191
5490
|
async function checkForUpdates() {
|
|
5192
5491
|
try {
|
|
5193
5492
|
const controller = new AbortController();
|
|
@@ -5204,15 +5503,32 @@ async function checkForUpdates() {
|
|
|
5204
5503
|
versionCheckResult = {
|
|
5205
5504
|
isOutdated: true,
|
|
5206
5505
|
latestVersion,
|
|
5207
|
-
|
|
5506
|
+
lastChecked: Date.now(),
|
|
5507
|
+
updateMessage: `\u{1F6A8} UPDATE AVAILABLE: v${latestVersion} (you have v${CURRENT_VERSION})`
|
|
5208
5508
|
};
|
|
5209
5509
|
logger.warn(
|
|
5210
5510
|
`Outdated version detected: v${CURRENT_VERSION} -> v${latestVersion}`
|
|
5211
5511
|
);
|
|
5512
|
+
} else {
|
|
5513
|
+
versionCheckResult = {
|
|
5514
|
+
...versionCheckResult,
|
|
5515
|
+
lastChecked: Date.now()
|
|
5516
|
+
};
|
|
5212
5517
|
}
|
|
5213
5518
|
} catch {
|
|
5214
5519
|
}
|
|
5215
5520
|
}
|
|
5521
|
+
function maybeCheckForUpdates() {
|
|
5522
|
+
toolCallCount++;
|
|
5523
|
+
if (toolCallCount >= VERSION_CHECK_INTERVAL) {
|
|
5524
|
+
toolCallCount = 0;
|
|
5525
|
+
const fiveMinutes = 5 * 60 * 1e3;
|
|
5526
|
+
if (Date.now() - versionCheckResult.lastChecked > fiveMinutes) {
|
|
5527
|
+
checkForUpdates().catch(() => {
|
|
5528
|
+
});
|
|
5529
|
+
}
|
|
5530
|
+
}
|
|
5531
|
+
}
|
|
5216
5532
|
function getUpdateWarning() {
|
|
5217
5533
|
return versionCheckResult.updateMessage;
|
|
5218
5534
|
}
|
|
@@ -5457,26 +5773,31 @@ function registerToolHandlers(server) {
|
|
|
5457
5773
|
const result = await tool.handler(args);
|
|
5458
5774
|
const durationMs = Date.now() - startTime;
|
|
5459
5775
|
trackToolCall(name, true, durationMs, CURRENT_VERSION);
|
|
5776
|
+
maybeCheckForUpdates();
|
|
5460
5777
|
const updateWarning = getUpdateWarning();
|
|
5461
5778
|
if (updateWarning && versionCheckResult.isOutdated) {
|
|
5462
5779
|
const updatePrompt = {
|
|
5463
|
-
"\u{1F6A8} UPDATE
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
steps:
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5780
|
+
"\u{1F6A8} UPDATE REQUIRED": {
|
|
5781
|
+
current: `v${CURRENT_VERSION}`,
|
|
5782
|
+
latest: `v${versionCheckResult.latestVersion}`,
|
|
5783
|
+
quickFix: {
|
|
5784
|
+
description: "Most users just need these 2 steps:",
|
|
5785
|
+
step1: "Run in terminal: rm -rf ~/.npm/_npx",
|
|
5786
|
+
step2: "Restart editor completely (Cmd+Q / Alt+F4, then reopen)"
|
|
5787
|
+
},
|
|
5788
|
+
ifStillOld: {
|
|
5789
|
+
description: "If still showing old version after restart:",
|
|
5790
|
+
action: "Edit your MCP config file to use @latest:",
|
|
5791
|
+
change: 'Change "midnight-mcp" to "midnight-mcp@latest" in args',
|
|
5792
|
+
configFiles: {
|
|
5793
|
+
"Claude Desktop (Mac)": "~/Library/Application Support/Claude/claude_desktop_config.json",
|
|
5794
|
+
"Claude Desktop (Win)": "%APPDATA%/Claude/claude_desktop_config.json",
|
|
5795
|
+
Cursor: ".cursor/mcp.json",
|
|
5796
|
+
"VS Code": ".vscode/mcp.json",
|
|
5797
|
+
Windsurf: "~/.codeium/windsurf/mcp_config.json"
|
|
5477
5798
|
}
|
|
5478
5799
|
},
|
|
5479
|
-
|
|
5800
|
+
tip: "Use 'midnight-get-update-instructions' tool for detailed platform-specific steps."
|
|
5480
5801
|
},
|
|
5481
5802
|
result
|
|
5482
5803
|
};
|
|
@@ -5903,6 +6224,7 @@ var BUILTIN_FUNCTIONS = {
|
|
|
5903
6224
|
{
|
|
5904
6225
|
name: "persistentHash",
|
|
5905
6226
|
signature: "persistentHash<T>(value: T): Bytes<32>",
|
|
6227
|
+
// Signature inferred from examples
|
|
5906
6228
|
description: "Poseidon hash that produces consistent results across calls"
|
|
5907
6229
|
},
|
|
5908
6230
|
{
|
|
@@ -5961,6 +6283,7 @@ witness get_random_value(): Field;`,
|
|
|
5961
6283
|
]
|
|
5962
6284
|
};
|
|
5963
6285
|
var TYPE_COMPATIBILITY = {
|
|
6286
|
+
// Note: Comparison operators work in practice but aren't explicitly listed in docs
|
|
5964
6287
|
comparisons: [
|
|
5965
6288
|
{ types: "Field == Field", works: true, note: "Direct comparison" },
|
|
5966
6289
|
{
|
|
@@ -5979,7 +6302,11 @@ var TYPE_COMPATIBILITY = {
|
|
|
5979
6302
|
works: true,
|
|
5980
6303
|
note: "Bounded integers"
|
|
5981
6304
|
},
|
|
5982
|
-
{
|
|
6305
|
+
{
|
|
6306
|
+
types: "Bytes<32> == Bytes<32>",
|
|
6307
|
+
works: true,
|
|
6308
|
+
note: "Used in examples, but operators not explicitly listed in docs"
|
|
6309
|
+
},
|
|
5983
6310
|
{ types: "Boolean == Boolean", works: true, note: "Direct comparison" }
|
|
5984
6311
|
],
|
|
5985
6312
|
arithmetic: [
|
|
@@ -6001,23 +6328,79 @@ var TYPE_COMPATIBILITY = {
|
|
|
6001
6328
|
note: "Result is wide bounded type, cast back to target type"
|
|
6002
6329
|
}
|
|
6003
6330
|
],
|
|
6331
|
+
/**
|
|
6332
|
+
* Type casting rules - based on official cast table
|
|
6333
|
+
* See: https://docs.midnight.network/develop/reference/compact/lang-ref#type-cast-expressions
|
|
6334
|
+
*
|
|
6335
|
+
* Cast kinds: static (always succeeds), conversion (semantic change), checked (can fail)
|
|
6336
|
+
*/
|
|
6004
6337
|
typeCasting: [
|
|
6005
6338
|
{
|
|
6006
|
-
from: "Uint<
|
|
6007
|
-
to: "
|
|
6339
|
+
from: "Uint<N>",
|
|
6340
|
+
to: "Field",
|
|
6341
|
+
direct: true,
|
|
6342
|
+
kind: "static",
|
|
6343
|
+
note: "Always succeeds"
|
|
6344
|
+
},
|
|
6345
|
+
{
|
|
6346
|
+
from: "Field",
|
|
6347
|
+
to: "Uint<0..n>",
|
|
6348
|
+
direct: true,
|
|
6349
|
+
kind: "checked",
|
|
6350
|
+
note: "Fails at runtime if value > n"
|
|
6351
|
+
},
|
|
6352
|
+
{
|
|
6353
|
+
from: "Field",
|
|
6354
|
+
to: "Bytes<n>",
|
|
6355
|
+
direct: true,
|
|
6356
|
+
kind: "conversion",
|
|
6357
|
+
note: "Can fail at runtime if value doesn't fit (little-endian)"
|
|
6358
|
+
},
|
|
6359
|
+
{
|
|
6360
|
+
from: "Bytes<m>",
|
|
6361
|
+
to: "Field",
|
|
6362
|
+
direct: true,
|
|
6363
|
+
kind: "conversion",
|
|
6364
|
+
note: "Can fail at runtime if result exceeds max Field value"
|
|
6365
|
+
},
|
|
6366
|
+
{
|
|
6367
|
+
from: "Boolean",
|
|
6368
|
+
to: "Uint<0..n>",
|
|
6369
|
+
direct: true,
|
|
6370
|
+
kind: "conversion",
|
|
6371
|
+
note: "false\u21920, true\u21921 (n must not be 0)"
|
|
6372
|
+
},
|
|
6373
|
+
{
|
|
6374
|
+
from: "Boolean",
|
|
6375
|
+
to: "Field",
|
|
6008
6376
|
direct: false,
|
|
6009
|
-
fix: "Go through
|
|
6377
|
+
fix: "Go through Uint: (flag as Uint<0..1>) as Field"
|
|
6010
6378
|
},
|
|
6011
6379
|
{
|
|
6012
6380
|
from: "Uint<N>",
|
|
6381
|
+
to: "Bytes<M>",
|
|
6382
|
+
direct: false,
|
|
6383
|
+
fix: "Go through Field: (amount as Field) as Bytes<32>"
|
|
6384
|
+
},
|
|
6385
|
+
{
|
|
6386
|
+
from: "enum",
|
|
6013
6387
|
to: "Field",
|
|
6014
6388
|
direct: true,
|
|
6015
|
-
|
|
6389
|
+
kind: "conversion",
|
|
6390
|
+
note: "Enum variant index as Field"
|
|
6391
|
+
},
|
|
6392
|
+
{
|
|
6393
|
+
from: "Uint<0..m>",
|
|
6394
|
+
to: "Uint<0..n>",
|
|
6395
|
+
direct: true,
|
|
6396
|
+
kind: "static if m\u2264n, checked if m>n",
|
|
6397
|
+
note: "Widening is static, narrowing is checked"
|
|
6016
6398
|
},
|
|
6017
6399
|
{
|
|
6018
6400
|
from: "arithmetic result",
|
|
6019
6401
|
to: "Uint<64>",
|
|
6020
6402
|
direct: true,
|
|
6403
|
+
kind: "checked",
|
|
6021
6404
|
note: "Required cast: (a + b) as Uint<64>"
|
|
6022
6405
|
}
|
|
6023
6406
|
],
|
|
@@ -6812,9 +7195,10 @@ async function extractContractStructure(input) {
|
|
|
6812
7195
|
potentialIssues.push({
|
|
6813
7196
|
type: "unsupported_division",
|
|
6814
7197
|
line: lineNum,
|
|
6815
|
-
message: `Division operator '/' is not
|
|
6816
|
-
suggestion: `
|
|
6817
|
-
severity: "
|
|
7198
|
+
message: `Division operator '/' is not in the documented Compact operators (+, -, *)`,
|
|
7199
|
+
suggestion: `If you need division, compute it off-chain in a witness and verify on-chain: 'witness divide(a, b): [quotient, remainder]'`,
|
|
7200
|
+
severity: "warning"
|
|
7201
|
+
// Changed to warning since it's inferred, not explicitly documented
|
|
6818
7202
|
});
|
|
6819
7203
|
break;
|
|
6820
7204
|
}
|
|
@@ -8492,6 +8876,10 @@ var HealthCheckInputSchema = z4.object({
|
|
|
8492
8876
|
var GetStatusInputSchema = z4.object({});
|
|
8493
8877
|
var CheckVersionInputSchema = z4.object({});
|
|
8494
8878
|
var AutoUpdateConfigInputSchema = z4.object({});
|
|
8879
|
+
var GetUpdateInstructionsInputSchema = z4.object({
|
|
8880
|
+
platform: z4.enum(["auto", "mac", "windows", "linux"]).optional().default("auto").describe("Target platform (auto-detects if not specified)"),
|
|
8881
|
+
editor: z4.enum(["auto", "claude-desktop", "cursor", "vscode", "windsurf"]).optional().default("auto").describe("Target editor (provides all if auto)")
|
|
8882
|
+
});
|
|
8495
8883
|
|
|
8496
8884
|
// src/tools/health/handlers.ts
|
|
8497
8885
|
import * as os from "os";
|
|
@@ -8644,6 +9032,286 @@ async function getAutoUpdateConfig(_input) {
|
|
|
8644
9032
|
postUpdateMessage: "\u2705 Config updated! Please restart your editor completely (quit and reopen) to use the latest version."
|
|
8645
9033
|
};
|
|
8646
9034
|
}
|
|
9035
|
+
var SUPPORTED_EDITORS = [
|
|
9036
|
+
"claude-desktop",
|
|
9037
|
+
"cursor",
|
|
9038
|
+
"vscode",
|
|
9039
|
+
"windsurf"
|
|
9040
|
+
];
|
|
9041
|
+
function getNpmCacheClearCommand(platform3) {
|
|
9042
|
+
if (platform3 === "windows") {
|
|
9043
|
+
return 'Remove-Item -Recurse -Force "$env:USERPROFILE\\.npm\\_npx" -ErrorAction SilentlyContinue';
|
|
9044
|
+
}
|
|
9045
|
+
return "rm -rf ~/.npm/_npx";
|
|
9046
|
+
}
|
|
9047
|
+
async function getUpdateInstructions(input) {
|
|
9048
|
+
const platform3 = input.platform === "auto" ? detectPlatform() : input.platform;
|
|
9049
|
+
if (input.editor === "auto") {
|
|
9050
|
+
return getMultiEditorInstructions(platform3);
|
|
9051
|
+
}
|
|
9052
|
+
const editor = input.editor;
|
|
9053
|
+
const configPaths = getConfigPaths(platform3, editor);
|
|
9054
|
+
const restartCommand = getRestartCommand(platform3, editor);
|
|
9055
|
+
const cacheCommand = getNpmCacheClearCommand(platform3);
|
|
9056
|
+
return {
|
|
9057
|
+
title: "\u{1F504} How to Update Midnight MCP",
|
|
9058
|
+
currentSetup: {
|
|
9059
|
+
detectedPlatform: platform3,
|
|
9060
|
+
targetEditor: editor
|
|
9061
|
+
},
|
|
9062
|
+
steps: [
|
|
9063
|
+
{
|
|
9064
|
+
step: 1,
|
|
9065
|
+
title: "Clear npm cache",
|
|
9066
|
+
command: cacheCommand,
|
|
9067
|
+
windowsNote: platform3 === "windows" ? "Run in PowerShell. For cmd.exe use: rd /s /q %USERPROFILE%\\.npm\\_npx" : void 0,
|
|
9068
|
+
explanation: "This removes cached npx packages so the latest version will be downloaded",
|
|
9069
|
+
required: true
|
|
9070
|
+
},
|
|
9071
|
+
{
|
|
9072
|
+
step: 2,
|
|
9073
|
+
title: "Restart your editor completely",
|
|
9074
|
+
action: restartCommand,
|
|
9075
|
+
explanation: "A full restart is needed - just reloading the window is not enough",
|
|
9076
|
+
required: true
|
|
9077
|
+
},
|
|
9078
|
+
{
|
|
9079
|
+
step: 3,
|
|
9080
|
+
title: "If still outdated, update config file",
|
|
9081
|
+
configPath: configPaths.primary,
|
|
9082
|
+
alternativePaths: configPaths.alternatives,
|
|
9083
|
+
change: {
|
|
9084
|
+
find: '"midnight-mcp"',
|
|
9085
|
+
replaceWith: '"midnight-mcp@latest"',
|
|
9086
|
+
location: 'In the "args" array for the midnight server'
|
|
9087
|
+
},
|
|
9088
|
+
explanation: "Adding @latest ensures you always get the newest version",
|
|
9089
|
+
required: false
|
|
9090
|
+
}
|
|
9091
|
+
],
|
|
9092
|
+
troubleshooting: getTroubleshootingSection(platform3, configPaths),
|
|
9093
|
+
exampleConfig: generateExampleConfig(editor),
|
|
9094
|
+
helpfulLinks: {
|
|
9095
|
+
documentation: "https://github.com/Olanetsoft/midnight-mcp#readme",
|
|
9096
|
+
issues: "https://github.com/Olanetsoft/midnight-mcp/issues"
|
|
9097
|
+
}
|
|
9098
|
+
};
|
|
9099
|
+
}
|
|
9100
|
+
function getMultiEditorInstructions(platform3) {
|
|
9101
|
+
const cacheCommand = getNpmCacheClearCommand(platform3);
|
|
9102
|
+
const editorConfigs = SUPPORTED_EDITORS.map((editor) => {
|
|
9103
|
+
const paths = getConfigPaths(platform3, editor);
|
|
9104
|
+
const restart = getRestartCommand(platform3, editor);
|
|
9105
|
+
return {
|
|
9106
|
+
editor,
|
|
9107
|
+
displayName: getEditorDisplayName(editor),
|
|
9108
|
+
configPath: paths.primary,
|
|
9109
|
+
alternativePaths: paths.alternatives,
|
|
9110
|
+
restartCommand: restart
|
|
9111
|
+
};
|
|
9112
|
+
});
|
|
9113
|
+
return {
|
|
9114
|
+
title: "\u{1F504} How to Update Midnight MCP",
|
|
9115
|
+
currentSetup: {
|
|
9116
|
+
detectedPlatform: platform3,
|
|
9117
|
+
targetEditor: "all (auto mode)"
|
|
9118
|
+
},
|
|
9119
|
+
commonSteps: [
|
|
9120
|
+
{
|
|
9121
|
+
step: 1,
|
|
9122
|
+
title: "Clear npm cache",
|
|
9123
|
+
command: cacheCommand,
|
|
9124
|
+
windowsNote: platform3 === "windows" ? "Run in PowerShell. For cmd.exe use: rd /s /q %USERPROFILE%\\.npm\\_npx" : void 0,
|
|
9125
|
+
explanation: "This removes cached npx packages so the latest version will be downloaded",
|
|
9126
|
+
required: true
|
|
9127
|
+
},
|
|
9128
|
+
{
|
|
9129
|
+
step: 2,
|
|
9130
|
+
title: "Restart your editor completely",
|
|
9131
|
+
explanation: "A full restart is needed - just reloading the window is not enough",
|
|
9132
|
+
required: true
|
|
9133
|
+
}
|
|
9134
|
+
],
|
|
9135
|
+
editorSpecificPaths: editorConfigs,
|
|
9136
|
+
configChange: {
|
|
9137
|
+
find: '"midnight-mcp"',
|
|
9138
|
+
replaceWith: '"midnight-mcp@latest"',
|
|
9139
|
+
location: 'In the "args" array for the midnight server'
|
|
9140
|
+
},
|
|
9141
|
+
troubleshooting: [
|
|
9142
|
+
{
|
|
9143
|
+
issue: "Still seeing old version after restart",
|
|
9144
|
+
solutions: [
|
|
9145
|
+
platform3 === "mac" ? "Make sure you quit the editor completely (Cmd+Q)" : platform3 === "windows" ? "Make sure you quit the editor completely (Alt+F4)" : "Make sure you quit the editor completely",
|
|
9146
|
+
"Check if multiple editor instances are running",
|
|
9147
|
+
platform3 === "windows" ? 'Try: Remove-Item -Recurse -Force "$env:USERPROFILE\\.npm\\_npx", "$env:LOCALAPPDATA\\midnight-mcp"' : "Try: rm -rf ~/.npm/_npx && rm -rf ~/.cache/midnight-mcp"
|
|
9148
|
+
]
|
|
9149
|
+
},
|
|
9150
|
+
{
|
|
9151
|
+
issue: "Config file not found",
|
|
9152
|
+
solutions: [
|
|
9153
|
+
"Check the editor-specific paths listed above",
|
|
9154
|
+
"Create the config file if it doesn't exist",
|
|
9155
|
+
"See docs: https://github.com/Olanetsoft/midnight-mcp"
|
|
9156
|
+
]
|
|
9157
|
+
}
|
|
9158
|
+
],
|
|
9159
|
+
exampleConfig: {
|
|
9160
|
+
mcpServers: {
|
|
9161
|
+
midnight: {
|
|
9162
|
+
command: "npx",
|
|
9163
|
+
args: ["-y", "midnight-mcp@latest"]
|
|
9164
|
+
}
|
|
9165
|
+
}
|
|
9166
|
+
},
|
|
9167
|
+
helpfulLinks: {
|
|
9168
|
+
documentation: "https://github.com/Olanetsoft/midnight-mcp#readme",
|
|
9169
|
+
issues: "https://github.com/Olanetsoft/midnight-mcp/issues"
|
|
9170
|
+
}
|
|
9171
|
+
};
|
|
9172
|
+
}
|
|
9173
|
+
function getEditorDisplayName(editor) {
|
|
9174
|
+
const names = {
|
|
9175
|
+
"claude-desktop": "Claude Desktop",
|
|
9176
|
+
cursor: "Cursor",
|
|
9177
|
+
vscode: "VS Code",
|
|
9178
|
+
windsurf: "Windsurf"
|
|
9179
|
+
};
|
|
9180
|
+
return names[editor] || editor;
|
|
9181
|
+
}
|
|
9182
|
+
function getTroubleshootingSection(platform3, configPaths) {
|
|
9183
|
+
const quitCommand = platform3 === "mac" ? "Cmd+Q" : platform3 === "windows" ? "Alt+F4" : "close completely";
|
|
9184
|
+
const cacheCleanup = platform3 === "windows" ? 'Remove-Item -Recurse -Force "$env:USERPROFILE\\.npm\\_npx", "$env:LOCALAPPDATA\\midnight-mcp"' : "rm -rf ~/.npm/_npx && rm -rf ~/.cache/midnight-mcp";
|
|
9185
|
+
return [
|
|
9186
|
+
{
|
|
9187
|
+
issue: "Still seeing old version after restart",
|
|
9188
|
+
solutions: [
|
|
9189
|
+
`Make sure you quit the editor completely (${quitCommand})`,
|
|
9190
|
+
"Check if multiple editor instances are running",
|
|
9191
|
+
`Try: ${cacheCleanup}`
|
|
9192
|
+
]
|
|
9193
|
+
},
|
|
9194
|
+
{
|
|
9195
|
+
issue: "Config file not found",
|
|
9196
|
+
solutions: [
|
|
9197
|
+
`Primary location: ${configPaths.primary}`,
|
|
9198
|
+
"Create it if it doesn't exist",
|
|
9199
|
+
"See docs: https://github.com/Olanetsoft/midnight-mcp"
|
|
9200
|
+
]
|
|
9201
|
+
},
|
|
9202
|
+
{
|
|
9203
|
+
issue: "Permission denied errors",
|
|
9204
|
+
solutions: platform3 === "windows" ? [
|
|
9205
|
+
"Run editor as administrator",
|
|
9206
|
+
"Check file permissions in Windows Security settings"
|
|
9207
|
+
] : [
|
|
9208
|
+
"Check file permissions with ls -la",
|
|
9209
|
+
"Ensure your user owns the config file"
|
|
9210
|
+
]
|
|
9211
|
+
}
|
|
9212
|
+
];
|
|
9213
|
+
}
|
|
9214
|
+
function detectPlatform() {
|
|
9215
|
+
const p = process.platform;
|
|
9216
|
+
if (p === "darwin") return "mac";
|
|
9217
|
+
if (p === "win32") return "windows";
|
|
9218
|
+
return "linux";
|
|
9219
|
+
}
|
|
9220
|
+
function getConfigPaths(platform3, editor) {
|
|
9221
|
+
const home = process.env.HOME || process.env.USERPROFILE || "~";
|
|
9222
|
+
const paths = {
|
|
9223
|
+
mac: {
|
|
9224
|
+
"claude-desktop": {
|
|
9225
|
+
primary: `${home}/Library/Application Support/Claude/claude_desktop_config.json`,
|
|
9226
|
+
alternatives: []
|
|
9227
|
+
},
|
|
9228
|
+
cursor: {
|
|
9229
|
+
primary: `${home}/.cursor/mcp.json`,
|
|
9230
|
+
alternatives: [`${home}/Library/Application Support/Cursor/mcp.json`]
|
|
9231
|
+
},
|
|
9232
|
+
vscode: {
|
|
9233
|
+
primary: `${home}/.vscode/mcp.json`,
|
|
9234
|
+
alternatives: [
|
|
9235
|
+
`${home}/Library/Application Support/Code/User/settings.json`
|
|
9236
|
+
]
|
|
9237
|
+
},
|
|
9238
|
+
windsurf: {
|
|
9239
|
+
primary: `${home}/.codeium/windsurf/mcp_config.json`,
|
|
9240
|
+
alternatives: []
|
|
9241
|
+
}
|
|
9242
|
+
},
|
|
9243
|
+
windows: {
|
|
9244
|
+
"claude-desktop": {
|
|
9245
|
+
primary: `%APPDATA%\\Claude\\claude_desktop_config.json`,
|
|
9246
|
+
alternatives: []
|
|
9247
|
+
},
|
|
9248
|
+
cursor: {
|
|
9249
|
+
primary: `%USERPROFILE%\\.cursor\\mcp.json`,
|
|
9250
|
+
alternatives: [`%APPDATA%\\Cursor\\mcp.json`]
|
|
9251
|
+
},
|
|
9252
|
+
vscode: {
|
|
9253
|
+
primary: `%USERPROFILE%\\.vscode\\mcp.json`,
|
|
9254
|
+
alternatives: [`%APPDATA%\\Code\\User\\settings.json`]
|
|
9255
|
+
},
|
|
9256
|
+
windsurf: {
|
|
9257
|
+
primary: `%USERPROFILE%\\.codeium\\windsurf\\mcp_config.json`,
|
|
9258
|
+
alternatives: []
|
|
9259
|
+
}
|
|
9260
|
+
},
|
|
9261
|
+
linux: {
|
|
9262
|
+
"claude-desktop": {
|
|
9263
|
+
primary: `${home}/.config/Claude/claude_desktop_config.json`,
|
|
9264
|
+
alternatives: []
|
|
9265
|
+
},
|
|
9266
|
+
cursor: {
|
|
9267
|
+
primary: `${home}/.cursor/mcp.json`,
|
|
9268
|
+
alternatives: [`${home}/.config/Cursor/mcp.json`]
|
|
9269
|
+
},
|
|
9270
|
+
vscode: {
|
|
9271
|
+
primary: `${home}/.vscode/mcp.json`,
|
|
9272
|
+
alternatives: [`${home}/.config/Code/User/settings.json`]
|
|
9273
|
+
},
|
|
9274
|
+
windsurf: {
|
|
9275
|
+
primary: `${home}/.codeium/windsurf/mcp_config.json`,
|
|
9276
|
+
alternatives: []
|
|
9277
|
+
}
|
|
9278
|
+
}
|
|
9279
|
+
};
|
|
9280
|
+
return paths[platform3]?.[editor] || paths.mac["claude-desktop"];
|
|
9281
|
+
}
|
|
9282
|
+
function getRestartCommand(platform3, editor) {
|
|
9283
|
+
const editorNames = {
|
|
9284
|
+
"claude-desktop": "Claude Desktop",
|
|
9285
|
+
cursor: "Cursor",
|
|
9286
|
+
vscode: "VS Code",
|
|
9287
|
+
windsurf: "Windsurf"
|
|
9288
|
+
};
|
|
9289
|
+
const name = editorNames[editor] || editor;
|
|
9290
|
+
if (platform3 === "mac") {
|
|
9291
|
+
return `Quit ${name} completely (Cmd+Q), then reopen`;
|
|
9292
|
+
} else if (platform3 === "windows") {
|
|
9293
|
+
return `Close ${name} completely (Alt+F4 or File > Exit), then reopen`;
|
|
9294
|
+
} else {
|
|
9295
|
+
return `Close ${name} completely, then reopen`;
|
|
9296
|
+
}
|
|
9297
|
+
}
|
|
9298
|
+
function generateExampleConfig(editor) {
|
|
9299
|
+
const baseConfig = {
|
|
9300
|
+
mcpServers: {
|
|
9301
|
+
midnight: {
|
|
9302
|
+
command: "npx",
|
|
9303
|
+
args: ["-y", "midnight-mcp@latest"]
|
|
9304
|
+
}
|
|
9305
|
+
}
|
|
9306
|
+
};
|
|
9307
|
+
if (editor === "vscode") {
|
|
9308
|
+
return {
|
|
9309
|
+
note: "For VS Code, add to settings.json or mcp.json",
|
|
9310
|
+
config: baseConfig
|
|
9311
|
+
};
|
|
9312
|
+
}
|
|
9313
|
+
return baseConfig;
|
|
9314
|
+
}
|
|
8647
9315
|
|
|
8648
9316
|
// src/tools/health/tools.ts
|
|
8649
9317
|
var healthCheckOutputSchema = {
|
|
@@ -8810,6 +9478,45 @@ var healthTools = [
|
|
|
8810
9478
|
category: "health"
|
|
8811
9479
|
},
|
|
8812
9480
|
handler: getAutoUpdateConfig
|
|
9481
|
+
},
|
|
9482
|
+
{
|
|
9483
|
+
name: "midnight-get-update-instructions",
|
|
9484
|
+
description: "\u{1F4CB} Get detailed, platform-specific instructions for updating Midnight MCP to the latest version. Provides step-by-step guidance including config file locations, commands to run, and troubleshooting tips. Use this when a user needs help updating or is having issues with outdated versions.",
|
|
9485
|
+
inputSchema: {
|
|
9486
|
+
type: "object",
|
|
9487
|
+
properties: {
|
|
9488
|
+
platform: {
|
|
9489
|
+
type: "string",
|
|
9490
|
+
enum: ["auto", "mac", "windows", "linux"],
|
|
9491
|
+
description: "Target platform (auto-detects if not specified)",
|
|
9492
|
+
default: "auto"
|
|
9493
|
+
},
|
|
9494
|
+
editor: {
|
|
9495
|
+
type: "string",
|
|
9496
|
+
enum: ["auto", "claude-desktop", "cursor", "vscode", "windsurf"],
|
|
9497
|
+
description: "Target editor (defaults to Claude Desktop)",
|
|
9498
|
+
default: "auto"
|
|
9499
|
+
}
|
|
9500
|
+
}
|
|
9501
|
+
},
|
|
9502
|
+
outputSchema: {
|
|
9503
|
+
type: "object",
|
|
9504
|
+
properties: {
|
|
9505
|
+
title: { type: "string" },
|
|
9506
|
+
currentSetup: { type: "object" },
|
|
9507
|
+
steps: { type: "array", items: { type: "object" } },
|
|
9508
|
+
troubleshooting: { type: "array", items: { type: "object" } },
|
|
9509
|
+
exampleConfig: { type: "object" },
|
|
9510
|
+
helpfulLinks: { type: "object" }
|
|
9511
|
+
}
|
|
9512
|
+
},
|
|
9513
|
+
annotations: {
|
|
9514
|
+
readOnlyHint: true,
|
|
9515
|
+
idempotentHint: true,
|
|
9516
|
+
title: "\u{1F4CB} Get Update Instructions",
|
|
9517
|
+
category: "health"
|
|
9518
|
+
},
|
|
9519
|
+
handler: getUpdateInstructions
|
|
8813
9520
|
}
|
|
8814
9521
|
];
|
|
8815
9522
|
|
|
@@ -10114,4 +10821,4 @@ export {
|
|
|
10114
10821
|
startServer,
|
|
10115
10822
|
startHttpServer
|
|
10116
10823
|
};
|
|
10117
|
-
//# sourceMappingURL=chunk-
|
|
10824
|
+
//# sourceMappingURL=chunk-LXHUX67Z.js.map
|
package/dist/index.js
CHANGED
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
promptDefinitions,
|
|
10
10
|
startHttpServer,
|
|
11
11
|
startServer
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-LXHUX67Z.js";
|
|
13
13
|
import {
|
|
14
14
|
logger
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-FZI3KN52.js";
|
|
16
16
|
export {
|
|
17
17
|
allResources,
|
|
18
18
|
allTools,
|
package/package.json
CHANGED