@modootoday/pmcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +93 -0
- package/NOTICE +49 -0
- package/README.md +69 -0
- package/SECURITY.md +27 -0
- package/dist/chunk-UTABV2C4.js +33 -0
- package/dist/chunk-WIVQKKE4.js +363 -0
- package/dist/chunk-X3KWFZBP.js +134 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1885 -0
- package/dist/index.d.ts +263 -0
- package/dist/index.js +43 -0
- package/dist/stdio.d.ts +14 -0
- package/dist/stdio.js +13 -0
- package/package.json +96 -0
- package/skills/package-skill-catalog/SKILL.md +237 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Elastic License 2.0
|
|
2
|
+
|
|
3
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
+
the limitations and conditions below.
|
|
15
|
+
|
|
16
|
+
## Limitations
|
|
17
|
+
|
|
18
|
+
You may not provide the software to third parties as a hosted or managed
|
|
19
|
+
service, where the service provides users with access to any substantial set of
|
|
20
|
+
the features or functionality of the software.
|
|
21
|
+
|
|
22
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
+
software that is protected by the license key.
|
|
25
|
+
|
|
26
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
+
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
28
|
+
to applicable law.
|
|
29
|
+
|
|
30
|
+
## Patents
|
|
31
|
+
|
|
32
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
+
sale, import and have imported the software, in each case subject to the
|
|
35
|
+
limitations and conditions in this license. This license does not cover any
|
|
36
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
+
the software. If you or your company make any written claim that the software
|
|
38
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
+
the software granted under these terms ends immediately. If your company makes
|
|
40
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
+
company.
|
|
42
|
+
|
|
43
|
+
## Notices
|
|
44
|
+
|
|
45
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
+
also gets a copy of these terms.
|
|
47
|
+
|
|
48
|
+
If you modify the software, you must include in any modified copies of the
|
|
49
|
+
software prominent notices stating that you have modified the software.
|
|
50
|
+
|
|
51
|
+
## No Other Rights
|
|
52
|
+
|
|
53
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
+
these terms.
|
|
55
|
+
|
|
56
|
+
## Termination
|
|
57
|
+
|
|
58
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
+
to terminate automatically and permanently.
|
|
65
|
+
|
|
66
|
+
## No Liability
|
|
67
|
+
|
|
68
|
+
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
+
legal claim.*
|
|
72
|
+
|
|
73
|
+
## Definitions
|
|
74
|
+
|
|
75
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
+
software the licensor makes available under these terms, including any portion
|
|
77
|
+
of it.
|
|
78
|
+
|
|
79
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
+
|
|
81
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
+
organization that you work for, plus all organizations that have control over,
|
|
83
|
+
are under the control of, or are under common control with that
|
|
84
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
+
otherwise. Control can be direct or indirect.
|
|
87
|
+
|
|
88
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
+
these terms.
|
|
90
|
+
|
|
91
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
+
|
|
93
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
pmcp
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 modootoday. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Licensor: modootoday
|
|
6
|
+
Licensed under the Elastic License 2.0; see LICENSE.
|
|
7
|
+
|
|
8
|
+
The licensor is modootoday, the company, not any individual contributor. This
|
|
9
|
+
file names the licensor because the Elastic License 2.0 defines that term rather
|
|
10
|
+
than carrying a copyright line of its own; LICENSE is kept unmodified.
|
|
11
|
+
|
|
12
|
+
What the licence permits, in short, without replacing the terms in LICENSE:
|
|
13
|
+
|
|
14
|
+
- Using this software inside your own company, on any scale.
|
|
15
|
+
- Embedding it in a product you sell, and modifying or forking it.
|
|
16
|
+
- Redistributing it, with these notices intact.
|
|
17
|
+
- Running it locally as an MCP server, which is what it is for. A host
|
|
18
|
+
process spawning it on your own machine is use, not a hosted service.
|
|
19
|
+
|
|
20
|
+
What it does not permit:
|
|
21
|
+
|
|
22
|
+
- Offering this software to third parties as a hosted or managed service.
|
|
23
|
+
A remotely hosted MCP endpoint serving other people is the case this
|
|
24
|
+
forbids.
|
|
25
|
+
- Circumventing licence key functionality.
|
|
26
|
+
- Removing or obscuring these notices.
|
|
27
|
+
|
|
28
|
+
The Elastic License 2.0 is source-available, not an OSI-approved open source
|
|
29
|
+
licence. It grants a patent licence and ends that licence if you assert a patent
|
|
30
|
+
claim against the software; see the Patents section of LICENSE.
|
|
31
|
+
|
|
32
|
+
LICENSE governs. Where this summary and LICENSE differ, LICENSE is what applies.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
This software depends on the following packages, which are distributed under
|
|
37
|
+
their own terms and are not covered by the licence above.
|
|
38
|
+
|
|
39
|
+
@modelcontextprotocol/server MIT Copyright (c) Anthropic, PBC
|
|
40
|
+
@modelcontextprotocol/core MIT Copyright (c) Anthropic, PBC
|
|
41
|
+
zod MIT Copyright (c) Colin McDonnell
|
|
42
|
+
semver ISC See the dependency's LICENSE file.
|
|
43
|
+
|
|
44
|
+
The MIT License permits this distribution provided the above notices are
|
|
45
|
+
retained. Full licence texts ship with those packages.
|
|
46
|
+
|
|
47
|
+
@huggingface/transformers is an optional peer dependency. It is never
|
|
48
|
+
distributed with this package; a user who wants semantic ranking installs it
|
|
49
|
+
themselves, under its own Apache-2.0 terms.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# pmcp
|
|
2
|
+
|
|
3
|
+
Find and use package skills without loading every document into your agent's context.
|
|
4
|
+
`pmcp` reads installed `SKILL.md` files and exposes three MCP tools: `skill_catalog`,
|
|
5
|
+
`skill_find`, and `skill_call`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-dev pmcp
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Register it with an MCP host:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"mcpServers": {
|
|
18
|
+
"pmcp": { "command": "npx", "args": ["-y", "@modootoday/pmcp"] }
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
For Claude Code:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
claude mcp add pmcp -- npx -y @modootoday/pmcp
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Commands
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
pmcp list
|
|
33
|
+
pmcp available
|
|
34
|
+
pmcp install --all --dry-run
|
|
35
|
+
pmcp install <skill-package> --yes
|
|
36
|
+
pmcp sync --dry-run
|
|
37
|
+
pmcp login
|
|
38
|
+
pmcp whoami
|
|
39
|
+
pmcp logout
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`available` matches the provided catalog against actual installed dependency
|
|
43
|
+
versions locally. `install` and `sync` use npm or Bun, pin exact versions, and
|
|
44
|
+
require confirmation before changing the project's manifest and lockfile.
|
|
45
|
+
`--dry-run` does not install packages. `--catalog <file>` uses a saved catalog
|
|
46
|
+
response instead of fetching one. Registry access is handled by your package
|
|
47
|
+
manager; an OAuth login is not an npm registry token.
|
|
48
|
+
|
|
49
|
+
Run `pmcp --help` or `pmcp <command> --help` for options. With no command,
|
|
50
|
+
`pmcp` serves MCP on stdio. Use `--root <node_modules>` to select a local tree
|
|
51
|
+
and repeat `--scope <prefix>` to restrict local package discovery.
|
|
52
|
+
|
|
53
|
+
## Package skills
|
|
54
|
+
|
|
55
|
+
Skills are discovered by filename, including `skills/`, `.agent/skills/`,
|
|
56
|
+
`.claude/skills/`, `.gemini/skills/`, `.codex/skills/`, and `lib/skill/` layouts
|
|
57
|
+
within the discovery depth. A skill needs a frontmatter `description` for search.
|
|
58
|
+
|
|
59
|
+
`skill_find` accepts a problem description and returns matching skills.
|
|
60
|
+
`skill_call` opens the selected document. Local MCP reading requires no login.
|
|
61
|
+
|
|
62
|
+
## Runtime and licence
|
|
63
|
+
|
|
64
|
+
Node.js 22 or later, or Bun 1.3 or later. Default ranking is lexical. The optional
|
|
65
|
+
`index` command requires a separately installed encoder; it is not part of the
|
|
66
|
+
default installation.
|
|
67
|
+
|
|
68
|
+
Elastic License 2.0. See `LICENSE` and `NOTICE` for terms and dependency notices.
|
|
69
|
+
Documentation: <https://pmcp.build>.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Security
|
|
2
|
+
|
|
3
|
+
Please report a vulnerability privately through GitHub's security advisory form:
|
|
4
|
+
|
|
5
|
+
<https://github.com/modootoday/pmcp/security/advisories/new>
|
|
6
|
+
|
|
7
|
+
Do not open a public issue for a vulnerability or include credentials, private
|
|
8
|
+
package names, dependency inventories, OAuth tokens, registry tokens, or private
|
|
9
|
+
repository details in a report that other people can read.
|
|
10
|
+
|
|
11
|
+
## Boundaries
|
|
12
|
+
|
|
13
|
+
The MCP server reads installed package manifests and `SKILL.md` files locally.
|
|
14
|
+
It must not send dependency inventories or search queries over the network.
|
|
15
|
+
Network access belongs to explicit CLI commands such as catalog retrieval,
|
|
16
|
+
authentication, installation, and synchronization.
|
|
17
|
+
|
|
18
|
+
Package installation changes a project manifest and lockfile through npm or Bun.
|
|
19
|
+
Inspect the plan with `--dry-run`; non-interactive application requires `--yes`.
|
|
20
|
+
The CLI disables dependency install scripts for skill-package installation and
|
|
21
|
+
checks catalog integrity against registry metadata before applying a plan.
|
|
22
|
+
|
|
23
|
+
## Supported versions
|
|
24
|
+
|
|
25
|
+
Security fixes are released on the latest published version. Include the pmcp
|
|
26
|
+
version, runtime version, package manager, operating system, and a minimal
|
|
27
|
+
reproduction that contains no private project data.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSkillServer
|
|
3
|
+
} from "./chunk-WIVQKKE4.js";
|
|
4
|
+
|
|
5
|
+
// src/stdio.ts
|
|
6
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
7
|
+
function resolveRoots(argv, cwd) {
|
|
8
|
+
const given = argv.filter((arg) => !arg.startsWith("-"));
|
|
9
|
+
return given.length > 0 ? given : [`${cwd}/node_modules`];
|
|
10
|
+
}
|
|
11
|
+
function serve(roots, scopes = []) {
|
|
12
|
+
const options = scopes.length > 0 ? { roots, scopes } : { roots };
|
|
13
|
+
serveStdio(() => createSkillServer(options), {
|
|
14
|
+
// stdout is the protocol. A diagnostic written there corrupts the stream,
|
|
15
|
+
// so out-of-band errors go to stderr and nowhere else.
|
|
16
|
+
onerror: (error) => process.stderr.write(`pmcp: ${error.message}
|
|
17
|
+
`)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function main(argv = process.argv.slice(2)) {
|
|
21
|
+
const scopeArg = argv.find((arg) => arg.startsWith("--scope="));
|
|
22
|
+
serve(
|
|
23
|
+
resolveRoots(argv, process.cwd()),
|
|
24
|
+
scopeArg ? scopeArg.slice("--scope=".length).split(",") : []
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
resolveRoots,
|
|
30
|
+
serve,
|
|
31
|
+
main
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=chunk-UTABV2C4.js.map
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
// src/intent.ts
|
|
2
|
+
function normaliseIntent(intent) {
|
|
3
|
+
return intent.toLowerCase().replaceAll(/[^\p{L}\p{N}\s]/gu, " ").split(/\s+/u).filter(Boolean).join(" ");
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/catalog.ts
|
|
7
|
+
import { existsSync, readFileSync, readdirSync } from "fs";
|
|
8
|
+
import { basename, dirname, join, relative } from "path";
|
|
9
|
+
var SKIPPED_DIRS = /* @__PURE__ */ new Set([
|
|
10
|
+
"node_modules",
|
|
11
|
+
".git",
|
|
12
|
+
".cache",
|
|
13
|
+
".turbo",
|
|
14
|
+
"coverage",
|
|
15
|
+
"__tests__",
|
|
16
|
+
"__fixtures__"
|
|
17
|
+
]);
|
|
18
|
+
var MAX_SKILL_DEPTH = 3;
|
|
19
|
+
function readFrontmatter(source) {
|
|
20
|
+
if (!source.startsWith("---")) return {};
|
|
21
|
+
const end = source.indexOf("\n---", 3);
|
|
22
|
+
if (end === -1) return {};
|
|
23
|
+
const fields = {};
|
|
24
|
+
for (const line of source.slice(3, end).split("\n")) {
|
|
25
|
+
const match = /^([A-Za-z][A-Za-z0-9_-]*):\s*(.*)$/u.exec(line);
|
|
26
|
+
if (!match) continue;
|
|
27
|
+
const value = (match[2] ?? "").trim();
|
|
28
|
+
if (value === "" || value.startsWith("#")) continue;
|
|
29
|
+
fields[match[1]] = value.replace(/^["'](.*)["']$/u, "$1");
|
|
30
|
+
}
|
|
31
|
+
return fields;
|
|
32
|
+
}
|
|
33
|
+
function readBody(source) {
|
|
34
|
+
if (!source.startsWith("---")) return source;
|
|
35
|
+
const end = source.indexOf("\n---", 3);
|
|
36
|
+
if (end === -1) return source;
|
|
37
|
+
return source.slice(end + 4).replace(/^(?:\r?\n)+/u, "");
|
|
38
|
+
}
|
|
39
|
+
function skillFiles(packageDir) {
|
|
40
|
+
const found = [];
|
|
41
|
+
const stack = [[packageDir, 0]];
|
|
42
|
+
while (stack.length > 0) {
|
|
43
|
+
const next = stack.pop();
|
|
44
|
+
if (next === void 0) break;
|
|
45
|
+
const [dir, depth] = next;
|
|
46
|
+
let entries;
|
|
47
|
+
try {
|
|
48
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
49
|
+
} catch {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
if (entry.isFile()) {
|
|
54
|
+
if (entry.name === "SKILL.md") found.push(join(dir, entry.name));
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (!entry.isDirectory()) continue;
|
|
58
|
+
if (SKIPPED_DIRS.has(entry.name)) continue;
|
|
59
|
+
if (depth + 1 <= MAX_SKILL_DEPTH)
|
|
60
|
+
stack.push([join(dir, entry.name), depth + 1]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return found.sort();
|
|
64
|
+
}
|
|
65
|
+
function packageDirs(root) {
|
|
66
|
+
if (!existsSync(root)) return [];
|
|
67
|
+
const found = [];
|
|
68
|
+
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
69
|
+
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
70
|
+
if (entry.name === ".bin" || entry.name === ".cache") continue;
|
|
71
|
+
const path = join(root, entry.name);
|
|
72
|
+
if (entry.name.startsWith("@")) {
|
|
73
|
+
if (!existsSync(path)) continue;
|
|
74
|
+
for (const scoped of readdirSync(path, { withFileTypes: true })) {
|
|
75
|
+
if (scoped.isDirectory() || scoped.isSymbolicLink()) {
|
|
76
|
+
found.push(join(path, scoped.name));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
found.push(path);
|
|
82
|
+
}
|
|
83
|
+
return found;
|
|
84
|
+
}
|
|
85
|
+
function readCatalog(options) {
|
|
86
|
+
const scopes = options.scopes ?? [];
|
|
87
|
+
const found = [];
|
|
88
|
+
const seen = /* @__PURE__ */ new Set();
|
|
89
|
+
for (const root of options.roots) {
|
|
90
|
+
for (const packageDir of packageDirs(root)) {
|
|
91
|
+
const manifestPath = join(packageDir, "package.json");
|
|
92
|
+
if (!existsSync(manifestPath)) continue;
|
|
93
|
+
let packageName;
|
|
94
|
+
try {
|
|
95
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
96
|
+
if (!manifest.name) continue;
|
|
97
|
+
packageName = manifest.name;
|
|
98
|
+
} catch {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (scopes.length > 0 && !scopes.some((s) => packageName.startsWith(s))) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
for (const path of skillFiles(packageDir)) {
|
|
105
|
+
let source;
|
|
106
|
+
try {
|
|
107
|
+
source = readFileSync(path, "utf8");
|
|
108
|
+
} catch {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const front = readFrontmatter(source);
|
|
112
|
+
const description = front["description"] ?? "";
|
|
113
|
+
if (description === "") continue;
|
|
114
|
+
const dirName = basename(dirname(path));
|
|
115
|
+
const slug = front["name"] ?? (dirName === basename(packageDir) ? packageName : dirName);
|
|
116
|
+
const name = `${packageName}/${slug}`;
|
|
117
|
+
if (seen.has(name)) continue;
|
|
118
|
+
seen.add(name);
|
|
119
|
+
found.push({
|
|
120
|
+
name,
|
|
121
|
+
package: packageName,
|
|
122
|
+
slug,
|
|
123
|
+
description,
|
|
124
|
+
path
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return found.sort((a, b) => a.name.localeCompare(b.name));
|
|
130
|
+
}
|
|
131
|
+
function withoutBody({
|
|
132
|
+
path,
|
|
133
|
+
...rest
|
|
134
|
+
}) {
|
|
135
|
+
void path;
|
|
136
|
+
return rest;
|
|
137
|
+
}
|
|
138
|
+
function displayPath(root, entry) {
|
|
139
|
+
return relative(root, entry.path).replaceAll("\\", "/");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/find.ts
|
|
143
|
+
var DEFAULT_FIND_LIMIT = 5;
|
|
144
|
+
function tokens(text) {
|
|
145
|
+
return normaliseIntent(text).split(" ").filter(Boolean);
|
|
146
|
+
}
|
|
147
|
+
function bigrams(text) {
|
|
148
|
+
const flat = normaliseIntent(text).replaceAll(" ", "");
|
|
149
|
+
const out = /* @__PURE__ */ new Set();
|
|
150
|
+
for (let i = 0; i + 1 < flat.length; i += 1) out.add(flat.slice(i, i + 2));
|
|
151
|
+
return out;
|
|
152
|
+
}
|
|
153
|
+
function lexicalScore(intent, description) {
|
|
154
|
+
const wanted = tokens(intent);
|
|
155
|
+
if (wanted.length === 0) return 0;
|
|
156
|
+
const have = new Set(tokens(description));
|
|
157
|
+
const overlap = wanted.filter((token) => have.has(token)).length / wanted.length;
|
|
158
|
+
const a = bigrams(intent);
|
|
159
|
+
const b = bigrams(description);
|
|
160
|
+
if (a.size === 0 || b.size === 0) return overlap / 2;
|
|
161
|
+
let shared = 0;
|
|
162
|
+
for (const gram of a) if (b.has(gram)) shared += 1;
|
|
163
|
+
const dice = 2 * shared / (a.size + b.size);
|
|
164
|
+
return (overlap + dice) / 2;
|
|
165
|
+
}
|
|
166
|
+
function cosine(a, b) {
|
|
167
|
+
if (a.length !== b.length) return 0;
|
|
168
|
+
let dot = 0;
|
|
169
|
+
let na = 0;
|
|
170
|
+
let nb = 0;
|
|
171
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
172
|
+
dot += a[i] * b[i];
|
|
173
|
+
na += a[i] * a[i];
|
|
174
|
+
nb += b[i] * b[i];
|
|
175
|
+
}
|
|
176
|
+
if (na === 0 || nb === 0) return 0;
|
|
177
|
+
return dot / (Math.sqrt(na) * Math.sqrt(nb));
|
|
178
|
+
}
|
|
179
|
+
async function find(options) {
|
|
180
|
+
const limit = options.limit ?? DEFAULT_FIND_LIMIT;
|
|
181
|
+
const semantic = options.embedder !== void 0 && options.vectors !== void 0 && options.vectors.size > 0;
|
|
182
|
+
if (semantic) {
|
|
183
|
+
const embedder = options.embedder;
|
|
184
|
+
const vectors = options.vectors;
|
|
185
|
+
let query = options.cache?.get(options.intent) ?? null;
|
|
186
|
+
if (!query) {
|
|
187
|
+
query = await embedder.embed(options.intent);
|
|
188
|
+
options.cache?.put(options.intent, query);
|
|
189
|
+
}
|
|
190
|
+
const scored = [];
|
|
191
|
+
for (const entry of options.entries) {
|
|
192
|
+
const vector = vectors.get(entry.name);
|
|
193
|
+
if (!vector) continue;
|
|
194
|
+
scored.push({
|
|
195
|
+
name: entry.name,
|
|
196
|
+
package: entry.package,
|
|
197
|
+
description: entry.description,
|
|
198
|
+
score: cosine(query, vector)
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
if (scored.length === options.entries.length) {
|
|
202
|
+
return {
|
|
203
|
+
ranking: "semantic",
|
|
204
|
+
matches: rank(scored, limit)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
ranking: "lexical",
|
|
210
|
+
matches: rank(
|
|
211
|
+
options.entries.map((entry) => ({
|
|
212
|
+
name: entry.name,
|
|
213
|
+
package: entry.package,
|
|
214
|
+
description: entry.description,
|
|
215
|
+
score: lexicalScore(options.intent, entry.description)
|
|
216
|
+
})),
|
|
217
|
+
limit
|
|
218
|
+
)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function rank(matches, limit) {
|
|
222
|
+
return matches.filter((match) => match.score > 0).sort((a, b) => b.score - a.score || a.name.localeCompare(b.name)).slice(0, limit);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/server.ts
|
|
226
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
227
|
+
function createSkillTools(options) {
|
|
228
|
+
const load = options.loadCatalog ?? readCatalog;
|
|
229
|
+
let entries = null;
|
|
230
|
+
const catalog = () => {
|
|
231
|
+
entries ??= load({ roots: options.roots, scopes: options.scopes });
|
|
232
|
+
return entries;
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
/** Grouped, and without bodies. The cheap overview and the search's miss path. */
|
|
236
|
+
catalog() {
|
|
237
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
238
|
+
for (const entry of catalog()) {
|
|
239
|
+
const list = byPackage.get(entry.package) ?? [];
|
|
240
|
+
list.push({ name: entry.name, description: entry.description });
|
|
241
|
+
byPackage.set(entry.package, list);
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
count: catalog().length,
|
|
245
|
+
packages: [...byPackage.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([pkg, skills]) => ({ package: pkg, skills }))
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
/** Ranked names. Returns; never loads a body. */
|
|
249
|
+
find(intent, limit) {
|
|
250
|
+
return find({
|
|
251
|
+
entries: catalog(),
|
|
252
|
+
intent,
|
|
253
|
+
limit,
|
|
254
|
+
embedder: options.embedder,
|
|
255
|
+
cache: options.cache,
|
|
256
|
+
vectors: options.vectors
|
|
257
|
+
});
|
|
258
|
+
},
|
|
259
|
+
/** One body, at the moment it is needed. */
|
|
260
|
+
call(name) {
|
|
261
|
+
const entry = catalog().find((candidate) => candidate.name === name);
|
|
262
|
+
if (!entry) return null;
|
|
263
|
+
return {
|
|
264
|
+
name: entry.name,
|
|
265
|
+
body: readBody(readFileSync2(entry.path, "utf8"))
|
|
266
|
+
};
|
|
267
|
+
},
|
|
268
|
+
/** Drops the memoised catalog, so the next call re-reads the tree. */
|
|
269
|
+
refresh() {
|
|
270
|
+
entries = null;
|
|
271
|
+
},
|
|
272
|
+
entries: () => catalog().map(withoutBody)
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// src/mcp.ts
|
|
277
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
278
|
+
import { z } from "zod";
|
|
279
|
+
var SERVER_NAME = "pmcp";
|
|
280
|
+
var readOnly = {
|
|
281
|
+
readOnlyHint: true,
|
|
282
|
+
destructiveHint: false,
|
|
283
|
+
idempotentHint: true,
|
|
284
|
+
openWorldHint: false
|
|
285
|
+
};
|
|
286
|
+
var asText = (value) => ({
|
|
287
|
+
content: [{ type: "text", text: JSON.stringify(value, null, 2) }]
|
|
288
|
+
});
|
|
289
|
+
function registerSkillTools(server, tools) {
|
|
290
|
+
server.registerTool(
|
|
291
|
+
"skill_catalog",
|
|
292
|
+
{
|
|
293
|
+
title: "List installed skills without their bodies",
|
|
294
|
+
description: "Every skill the installed packages ship, grouped by package, with names and one-line descriptions and no bodies. Use it to see what exists, or when skill_find returns nothing.",
|
|
295
|
+
inputSchema: z.object({}),
|
|
296
|
+
annotations: readOnly
|
|
297
|
+
},
|
|
298
|
+
async () => asText(tools.catalog())
|
|
299
|
+
);
|
|
300
|
+
server.registerTool(
|
|
301
|
+
"skill_find",
|
|
302
|
+
{
|
|
303
|
+
title: "Find skills by describing the problem",
|
|
304
|
+
description: "Ranked skill names for an intent. Describe the problem in a full sentence in English rather than a keyword: a single word matches far worse, and the ranking is over descriptions. Returns names only -- read one with skill_call.",
|
|
305
|
+
inputSchema: z.object({
|
|
306
|
+
intent: z.string().min(1).max(256).describe("What you are trying to do, as an English sentence."),
|
|
307
|
+
limit: z.number().int().min(1).max(25).optional()
|
|
308
|
+
}),
|
|
309
|
+
annotations: readOnly
|
|
310
|
+
},
|
|
311
|
+
async ({ intent, limit }) => asText(await tools.find(intent, limit))
|
|
312
|
+
);
|
|
313
|
+
server.registerTool(
|
|
314
|
+
"skill_call",
|
|
315
|
+
{
|
|
316
|
+
title: "Read one skill",
|
|
317
|
+
description: "The body of a single skill, by the name skill_find or skill_catalog returned. This is the only call that costs a document.",
|
|
318
|
+
inputSchema: z.object({
|
|
319
|
+
name: z.string().min(1).describe("The skill name, as <package>/<slug>.")
|
|
320
|
+
}),
|
|
321
|
+
annotations: readOnly
|
|
322
|
+
},
|
|
323
|
+
async ({ name }) => {
|
|
324
|
+
const found = tools.call(name);
|
|
325
|
+
if (!found) {
|
|
326
|
+
return {
|
|
327
|
+
...asText({
|
|
328
|
+
error: "unknown_skill",
|
|
329
|
+
name,
|
|
330
|
+
hint: "Call skill_catalog for the names that exist."
|
|
331
|
+
}),
|
|
332
|
+
isError: true
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return { content: [{ type: "text", text: found.body }] };
|
|
336
|
+
}
|
|
337
|
+
);
|
|
338
|
+
return server;
|
|
339
|
+
}
|
|
340
|
+
function createSkillServer(options) {
|
|
341
|
+
const server = new McpServer({ name: SERVER_NAME, version: "0.1.0" });
|
|
342
|
+
return registerSkillTools(server, createSkillTools(options));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export {
|
|
346
|
+
normaliseIntent,
|
|
347
|
+
SKIPPED_DIRS,
|
|
348
|
+
MAX_SKILL_DEPTH,
|
|
349
|
+
readFrontmatter,
|
|
350
|
+
readBody,
|
|
351
|
+
readCatalog,
|
|
352
|
+
withoutBody,
|
|
353
|
+
displayPath,
|
|
354
|
+
DEFAULT_FIND_LIMIT,
|
|
355
|
+
lexicalScore,
|
|
356
|
+
cosine,
|
|
357
|
+
find,
|
|
358
|
+
createSkillTools,
|
|
359
|
+
SERVER_NAME,
|
|
360
|
+
registerSkillTools,
|
|
361
|
+
createSkillServer
|
|
362
|
+
};
|
|
363
|
+
//# sourceMappingURL=chunk-WIVQKKE4.js.map
|