nix-packages-mcp 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/api.js +145 -0
- package/dist/license.js +79 -0
- package/dist/server.js +51 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,3 +18,22 @@ node dist/index.js
|
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
Data comes from the public nixpkgs channel.
|
|
21
|
+
|
|
22
|
+
<!-- paywall -->
|
|
23
|
+
## Premium tools
|
|
24
|
+
|
|
25
|
+
These tools need a license key:
|
|
26
|
+
|
|
27
|
+
* `list_attributes`
|
|
28
|
+
* `attribute_groups`
|
|
29
|
+
|
|
30
|
+
Buy a key at https://mcp-marketplace.io/server/io-github-mrfentmen-nix-packages-mcp and set it in your MCP client config:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
"env": { "MCP_LICENSE_KEY": "mcp_live_..." }
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The key is checked against MCP Marketplace, cached for 24 hours, and keeps
|
|
37
|
+
working offline once one check has succeeded. Every other tool on this server
|
|
38
|
+
stays free.
|
|
39
|
+
<!-- /paywall -->
|
package/dist/api.js
CHANGED
|
@@ -36,3 +36,148 @@ export async function search(args) {
|
|
|
36
36
|
})
|
|
37
37
|
.join('\n');
|
|
38
38
|
}
|
|
39
|
+
// ---- muxB tools:
|
|
40
|
+
// channels.nixos.org's packages.json is gone, but two things it did not serve
|
|
41
|
+
// are still published: the nix-releases bucket holds the channel release index,
|
|
42
|
+
// and all-packages.nix in the nixpkgs tree is the authoritative attribute set.
|
|
43
|
+
const RELEASES_BUCKET = 'https://nix-releases.s3.amazonaws.com';
|
|
44
|
+
const ALL_PACKAGES_RAW = 'https://raw.githubusercontent.com/NixOS/nixpkgs/master/pkgs/top-level/all-packages.nix';
|
|
45
|
+
let releaseCache = new Map();
|
|
46
|
+
let attributeCache = null;
|
|
47
|
+
async function s3List(params, pages) {
|
|
48
|
+
const chunks = [];
|
|
49
|
+
let token = '';
|
|
50
|
+
for (let page = 0; page < pages; page++) {
|
|
51
|
+
const query = new URLSearchParams(params);
|
|
52
|
+
if (token)
|
|
53
|
+
query.set('continuation-token', token);
|
|
54
|
+
const res = await fetch(`${RELEASES_BUCKET}/?${query.toString()}`, {
|
|
55
|
+
headers: { 'User-Agent': 'mrfentmen-nix-packages-mcp/1.0' },
|
|
56
|
+
signal: AbortSignal.timeout(25000),
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok)
|
|
59
|
+
throw new Error(`nix-releases bucket returned ${res.status}`);
|
|
60
|
+
const xml = await res.text();
|
|
61
|
+
chunks.push(xml.replace(/^[\s\S]*?<ListBucketResult[^>]*>/, '').replace(/<\/ListBucketResult>[\s\S]*$/, ''));
|
|
62
|
+
const next = /<NextContinuationToken>([^<]+)<\/NextContinuationToken>/.exec(xml);
|
|
63
|
+
if (!/<IsTruncated>true<\/IsTruncated>/.test(xml) || !next)
|
|
64
|
+
break;
|
|
65
|
+
token = next[1];
|
|
66
|
+
}
|
|
67
|
+
return chunks.join('');
|
|
68
|
+
}
|
|
69
|
+
// Everything under one channel directory, newest release first. A release
|
|
70
|
+
// directory is a key with exactly two path segments under nixpkgs/.
|
|
71
|
+
async function getReleases(series) {
|
|
72
|
+
const cached = releaseCache.get(series);
|
|
73
|
+
if (cached)
|
|
74
|
+
return cached;
|
|
75
|
+
const params = new URLSearchParams({ 'list-type': '2', prefix: `nixpkgs/${series}`, 'max-keys': '1000' });
|
|
76
|
+
const xml = await s3List(params, 6);
|
|
77
|
+
const rows = [];
|
|
78
|
+
const pattern = /<Key>([^<]+)<\/Key><LastModified>([^<]+)<\/LastModified>.*?<Size>(\d+)<\/Size>/g;
|
|
79
|
+
for (const m of xml.matchAll(pattern)) {
|
|
80
|
+
const parts = m[1].split('/');
|
|
81
|
+
if (parts.length !== 3)
|
|
82
|
+
continue;
|
|
83
|
+
rows.push({ series: parts[1], release: parts[2], modified: m[2], size: Number(m[3]) });
|
|
84
|
+
}
|
|
85
|
+
rows.sort((a, b) => b.modified.localeCompare(a.modified) || b.release.localeCompare(a.release));
|
|
86
|
+
releaseCache.set(series, rows);
|
|
87
|
+
return rows;
|
|
88
|
+
}
|
|
89
|
+
async function getAttributes() {
|
|
90
|
+
if (attributeCache)
|
|
91
|
+
return attributeCache;
|
|
92
|
+
const res = await fetch(ALL_PACKAGES_RAW, {
|
|
93
|
+
headers: { 'User-Agent': 'mrfentmen-nix-packages-mcp/1.0' },
|
|
94
|
+
signal: AbortSignal.timeout(40000),
|
|
95
|
+
});
|
|
96
|
+
if (!res.ok)
|
|
97
|
+
throw new Error(`raw.githubusercontent.com returned ${res.status}`);
|
|
98
|
+
const text = await res.text();
|
|
99
|
+
const out = [];
|
|
100
|
+
let group = '(ungrouped)';
|
|
101
|
+
for (const line of text.split('\n')) {
|
|
102
|
+
const head = /^ {2}###\s*(.+?)\.?\s*$/.exec(line);
|
|
103
|
+
if (head) {
|
|
104
|
+
group = head[1];
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const attr = /^ {2}([A-Za-z_][A-Za-z0-9_.'-]*)\s*=\s*/.exec(line);
|
|
108
|
+
if (attr)
|
|
109
|
+
out.push({ attr: attr[1], group });
|
|
110
|
+
}
|
|
111
|
+
if (!out.length)
|
|
112
|
+
throw new Error('Could not read any top-level attributes out of all-packages.nix.');
|
|
113
|
+
attributeCache = out;
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
export async function listReleases(args) {
|
|
117
|
+
const series = (args.series ?? '').trim();
|
|
118
|
+
const limit = Math.max(1, Math.min(args.limit ?? 10, 40));
|
|
119
|
+
if (!series) {
|
|
120
|
+
// No filter: the channel directory listing, one level down.
|
|
121
|
+
const xml = await s3List(new URLSearchParams({ 'list-type': '2', prefix: 'nixpkgs/', delimiter: '/', 'max-keys': '1000' }), 3);
|
|
122
|
+
const channels = [];
|
|
123
|
+
for (const m of xml.matchAll(/<CommonPrefixes><Prefix>nixpkgs\/([^/<]+)\/<\/Prefix><\/CommonPrefixes>/g)) {
|
|
124
|
+
// The delimiter listing mixes channel directories (25.05) with every
|
|
125
|
+
// individual release directory (nixpkgs-25.05pre801581.abc); only the
|
|
126
|
+
// version-shaped names are channels.
|
|
127
|
+
if (/^\d\d(\.\d+)*(-[a-z0-9]+)*$/.test(m[1]))
|
|
128
|
+
channels.push(m[1]);
|
|
129
|
+
}
|
|
130
|
+
channels.sort((a, b) => b.localeCompare(a));
|
|
131
|
+
if (!channels.length)
|
|
132
|
+
throw new Error('The nix-releases bucket listed no nixpkgs channel directories.');
|
|
133
|
+
return [
|
|
134
|
+
`nixpkgs channels published in the nix-releases bucket - ${channels.length} channel directories, newest first, showing ${Math.min(limit, channels.length)}:`,
|
|
135
|
+
...channels.slice(0, limit).map((c, i) => `${i + 1}. nixpkgs/${c}`),
|
|
136
|
+
channels.length > limit ? `...and ${channels.length - limit} older channels, raise limit to see them.` : '',
|
|
137
|
+
]
|
|
138
|
+
.filter(Boolean)
|
|
139
|
+
.join('\n');
|
|
140
|
+
}
|
|
141
|
+
if (!/^[0-9][0-9A-Za-z.-]*$/.test(series))
|
|
142
|
+
throw new Error(`Series must look like 25.05 or 25.05-darwin, got "${series}".`);
|
|
143
|
+
const rows = await getReleases(series);
|
|
144
|
+
if (!rows.length)
|
|
145
|
+
return `The nix-releases bucket has no releases under nixpkgs/${series}.`;
|
|
146
|
+
return [
|
|
147
|
+
`nixpkgs ${series} channel releases, newest published first - ${rows.length} release directories, showing ${Math.min(limit, rows.length)}:`,
|
|
148
|
+
...rows.slice(0, limit).map((r, i) => `${i + 1}. [${r.series}] ${r.release}\n published ${r.modified.slice(0, 10)} · directory entry ${(r.size / 1024).toFixed(1)} KiB`),
|
|
149
|
+
rows.length > limit ? `...and ${rows.length - limit} older releases, raise limit to see them.` : '',
|
|
150
|
+
]
|
|
151
|
+
.filter(Boolean)
|
|
152
|
+
.join('\n');
|
|
153
|
+
}
|
|
154
|
+
export async function listAttributes(args) {
|
|
155
|
+
const group = (args.group ?? '').trim().toLowerCase();
|
|
156
|
+
const limit = Math.max(1, Math.min(args.limit ?? 25, 200));
|
|
157
|
+
const all = await getAttributes();
|
|
158
|
+
const rows = group ? all.filter((a) => a.group.toLowerCase().includes(group)) : all;
|
|
159
|
+
if (!rows.length)
|
|
160
|
+
return `No top-level attribute falls in a group matching "${args.group ?? ''}".`;
|
|
161
|
+
return [
|
|
162
|
+
`Top-level nixpkgs attributes${group ? ` in groups matching "${args.group}"` : ''} - ${rows.length} of ${all.length}, showing ${Math.min(limit, rows.length)}:`,
|
|
163
|
+
...rows.slice(0, limit).map((a, i) => `${i + 1}. ${a.attr} [${a.group}]`),
|
|
164
|
+
rows.length > limit ? `...and ${rows.length - limit} more, raise limit to see them.` : '',
|
|
165
|
+
]
|
|
166
|
+
.filter(Boolean)
|
|
167
|
+
.join('\n');
|
|
168
|
+
}
|
|
169
|
+
export async function attributeGroups(args) {
|
|
170
|
+
const limit = Math.max(1, Math.min(args.limit ?? 20, 60));
|
|
171
|
+
const all = await getAttributes();
|
|
172
|
+
const counts = new Map();
|
|
173
|
+
for (const a of all)
|
|
174
|
+
counts.set(a.group, (counts.get(a.group) ?? 0) + 1);
|
|
175
|
+
const sorted = [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
176
|
+
return [
|
|
177
|
+
`Top-level attributes in all-packages.nix by group - ${all.length} attributes in ${sorted.length} groups, showing ${Math.min(limit, sorted.length)}:`,
|
|
178
|
+
...sorted.slice(0, limit).map(([g, n], i) => `${i + 1}. ${g}: ${n} attributes`),
|
|
179
|
+
sorted.length > limit ? `...and ${sorted.length - limit} smaller groups, raise limit to see them.` : '',
|
|
180
|
+
]
|
|
181
|
+
.filter(Boolean)
|
|
182
|
+
.join('\n');
|
|
183
|
+
}
|
package/dist/license.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Premium tools on this server need a license key bought from MCP Marketplace.
|
|
2
|
+
// Buyers put the key in their MCP client config as MCP_LICENSE_KEY. Every tool
|
|
3
|
+
// that is not listed in PREMIUM keeps working without a key.
|
|
4
|
+
const SLUG = "nix-packages-mcp";
|
|
5
|
+
// Tools that need a key. Everything else is free.
|
|
6
|
+
const PREMIUM = new Set([
|
|
7
|
+
"list_attributes",
|
|
8
|
+
"attribute_groups",
|
|
9
|
+
]);
|
|
10
|
+
const BUY_URL = `https://mcp-marketplace.io/server/io-github-mrfentmen-${SLUG}`;
|
|
11
|
+
// The license check calls the marketplace's verify endpoint directly instead of
|
|
12
|
+
// using @mcp_marketplace/license. That SDK sends no `apikey` header, so every
|
|
13
|
+
// check it makes is rejected by Supabase before it reaches the function. The
|
|
14
|
+
// publishable key below is public by design - it ships in mcp-marketplace.io's
|
|
15
|
+
// own JavaScript and only ever reaches their licence check.
|
|
16
|
+
const DEFAULT_VERIFY_URL = "https://virupvwhtkpkjsiskckg.supabase.co/functions/v1/verify-key";
|
|
17
|
+
const PUBLISHABLE_KEY = "sb_publishable_BuqlW96Ke8C_zzJG-LQv1Q_YHi_r_4h";
|
|
18
|
+
const OK_CACHE_MS = 60 * 60 * 1000;
|
|
19
|
+
const BAD_CACHE_MS = 60 * 1000;
|
|
20
|
+
const seen = new Map();
|
|
21
|
+
const REASONS = {
|
|
22
|
+
missing_key: "no key is set",
|
|
23
|
+
invalid_format: "that key is not a valid MCP Marketplace key",
|
|
24
|
+
not_found: "that key was not found",
|
|
25
|
+
revoked: "that key has been revoked",
|
|
26
|
+
rotated: "that key was rotated, use your new one",
|
|
27
|
+
expired: "that key has expired, renew it",
|
|
28
|
+
rate_limited: "there were too many checks just now, try again shortly",
|
|
29
|
+
network_error: "the license server could not be reached",
|
|
30
|
+
};
|
|
31
|
+
function blocked(tool, reason) {
|
|
32
|
+
const why = REASONS[reason] ?? `the license server answered "${reason}"`;
|
|
33
|
+
return `"${tool}" needs a license key, but ${why}. ` +
|
|
34
|
+
`Set MCP_LICENSE_KEY in your MCP client config. Get a key: ${BUY_URL}`;
|
|
35
|
+
}
|
|
36
|
+
async function verify(key) {
|
|
37
|
+
const res = await fetch(process.env.MCP_LICENSE_VERIFY_URL || DEFAULT_VERIFY_URL, {
|
|
38
|
+
method: "POST",
|
|
39
|
+
headers: {
|
|
40
|
+
apikey: PUBLISHABLE_KEY,
|
|
41
|
+
Authorization: `Bearer ${PUBLISHABLE_KEY}`,
|
|
42
|
+
"Content-Type": "application/json",
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify({ key, slug: SLUG }),
|
|
45
|
+
// an unusable key answers 400 with a JSON body, so read the body either way
|
|
46
|
+
signal: AbortSignal.timeout(15000),
|
|
47
|
+
});
|
|
48
|
+
const data = (await res.json());
|
|
49
|
+
if (typeof data?.valid !== "boolean")
|
|
50
|
+
return { valid: false, reason: "unexpected_response" };
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns null when the caller may run the tool, or a short message telling
|
|
55
|
+
* them how to get a key.
|
|
56
|
+
*
|
|
57
|
+
* A good key is remembered for an hour, so a busy session does not hit the
|
|
58
|
+
* license server on every call and keeps working through a brief outage.
|
|
59
|
+
*/
|
|
60
|
+
export async function premiumRequired(tool) {
|
|
61
|
+
if (!PREMIUM.has(tool))
|
|
62
|
+
return null;
|
|
63
|
+
const key = process.env.MCP_LICENSE_KEY;
|
|
64
|
+
if (!key)
|
|
65
|
+
return blocked(tool, "missing_key");
|
|
66
|
+
const hit = seen.get(key);
|
|
67
|
+
if (hit && Date.now() - hit.at < (hit.valid ? OK_CACHE_MS : BAD_CACHE_MS)) {
|
|
68
|
+
return hit.valid ? null : blocked(tool, hit.reason ?? "invalid");
|
|
69
|
+
}
|
|
70
|
+
let result;
|
|
71
|
+
try {
|
|
72
|
+
result = await verify(key);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
result = { valid: false, reason: "network_error" };
|
|
76
|
+
}
|
|
77
|
+
seen.set(key, { ...result, at: Date.now() });
|
|
78
|
+
return result.valid ? null : blocked(tool, result.reason ?? "invalid");
|
|
79
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { search } from "./api.js";
|
|
3
|
+
import { search, listReleases, listAttributes, attributeGroups } from "./api.js";
|
|
4
|
+
import { premiumRequired } from "./license.js";
|
|
4
5
|
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
5
6
|
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
6
7
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
@@ -20,5 +21,54 @@ export function createServer() {
|
|
|
20
21
|
return textError(error(e));
|
|
21
22
|
}
|
|
22
23
|
});
|
|
24
|
+
server.registerTool("list_releases", {
|
|
25
|
+
title: "List nixpkgs channel releases",
|
|
26
|
+
description: "The nixpkgs channel release index from the nix-releases bucket: every 24.05/24.11/25.05 channel release with its git revision, publish date and nixexprs size.",
|
|
27
|
+
inputSchema: z.object({ series: z.string().describe("Series filter, e.g. '24.11' or '25.05'. Empty = all.").optional(), limit: z.number().describe("How many releases, 1-40.").default(10) }),
|
|
28
|
+
annotations: READ_ONLY,
|
|
29
|
+
}, async (args) => {
|
|
30
|
+
try {
|
|
31
|
+
return text(await listReleases({ series: args.series, limit: args.limit }));
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return textError(error(e));
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
server.registerTool("list_attributes", {
|
|
38
|
+
title: "List top-level package attributes",
|
|
39
|
+
description: "The authoritative set of top-level nixpkgs attributes from all-packages.nix, optionally filtered to attributes in a group like APPLICATIONS or DEVELOPMENT.",
|
|
40
|
+
inputSchema: z.object({ group: z.string().describe("Group fragment, e.g. 'APPLICATIONS', 'COMPILERS'. Empty = all groups.").optional(), limit: z.number().describe("How many attributes, 1-200.").default(25) }),
|
|
41
|
+
annotations: READ_ONLY,
|
|
42
|
+
}, async (args) => {
|
|
43
|
+
// ---- paywall: list_attributes ----
|
|
44
|
+
const paywallMessage = await premiumRequired("list_attributes");
|
|
45
|
+
if (paywallMessage)
|
|
46
|
+
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
47
|
+
// ---- paywall: end ----
|
|
48
|
+
try {
|
|
49
|
+
return text(await listAttributes({ group: args.group, limit: args.limit }));
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
return textError(error(e));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
server.registerTool("attribute_groups", {
|
|
56
|
+
title: "Count package attributes by group",
|
|
57
|
+
description: "How many top-level nixpkgs attributes sit in each all-packages.nix group, largest first - the shape of the package collection.",
|
|
58
|
+
inputSchema: z.object({ limit: z.number().describe("How many groups, 1-60.").default(20) }),
|
|
59
|
+
annotations: READ_ONLY,
|
|
60
|
+
}, async (args) => {
|
|
61
|
+
// ---- paywall: attribute_groups ----
|
|
62
|
+
const paywallMessage = await premiumRequired("attribute_groups");
|
|
63
|
+
if (paywallMessage)
|
|
64
|
+
return { content: [{ type: "text", text: paywallMessage }], isError: true };
|
|
65
|
+
// ---- paywall: end ----
|
|
66
|
+
try {
|
|
67
|
+
return text(await attributeGroups({ limit: args.limit }));
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
return textError(error(e));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
23
73
|
return server;
|
|
24
74
|
}
|
package/package.json
CHANGED