omp-codemode 0.0.0-stage → 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.
Files changed (3) hide show
  1. package/README.md +39 -2
  2. package/mcp-find.js +89 -0
  3. package/package.json +16 -4
package/README.md CHANGED
@@ -1,3 +1,40 @@
1
- # Temporary Holding Version
1
+ # OMP MCP Find
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A local OMP extension with one read-only tool: `mcp_find`. It returns one matching enabled MCP method and its argument schema by default (`limit` allows up to three). It never invokes the method.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ omp plugin install omp-codemode
9
+ ```
10
+
11
+ Or install directly from GitHub:
12
+
13
+ ```sh
14
+ omp plugin install github:juhas96/omp-codemode
15
+ ```
16
+
17
+ Start a fresh OMP session. Tested with OMP 19.1.1. If you previously installed the extension by symlink, remove that symlink before installing the plugin so OMP loads only one copy.
18
+
19
+ Ask an MCP question normally. For an unknown method or signature, the tool description tells the model to try one focused lookup, then fall back to `help://eval/<namespace>` if needed. If it already knows the signature, it can call the method directly. A returned name works in native Eval as `await tool[name](args)` under OMP's normal approvals.
20
+
21
+ ## Native MCP namespaces
22
+
23
+ This separate OMP setting keeps MCP method schemas out of the upfront tool list. The extension does not change it or replace native Eval. See the [namespace verification](https://github.com/juhas96/omp-codemode/blob/main/docs/pdd/mcp-namespaces.md) and the [finder measurements](https://github.com/juhas96/omp-codemode/blob/main/docs/pdd/mcp-find.md).
24
+
25
+ ```sh
26
+ omp config get mcp.evalNamespaces
27
+ omp config set mcp.evalNamespaces true # enable for new sessions
28
+ omp config reset mcp.evalNamespaces # restore the default (false)
29
+ ```
30
+
31
+ ## Local install and checks
32
+
33
+ For local development, link the entry point instead of installing the package, then start a new OMP process:
34
+
35
+ ```sh
36
+ mkdir -p "$HOME/.omp/agent/extensions"
37
+ ln -s "$PWD/mcp-find.js" "$HOME/.omp/agent/extensions/mcp-find.js"
38
+ ```
39
+
40
+ To uninstall, remove the `mcp-find.js` symlink. Run `node --test test/mcp-find.test.mjs` for the OMP integration checks.
package/mcp-find.js ADDED
@@ -0,0 +1,89 @@
1
+ import { toolWireSchema } from '@oh-my-pi/pi-ai';
2
+
3
+ const maxDescription = 240;
4
+ const maxSchema = 4096;
5
+
6
+ function words(text) {
7
+ return new Set(text.replace(/([a-z\d])([A-Z])/g, '$1 $2').toLowerCase().match(/[\p{L}\p{N}]+/gu));
8
+ }
9
+
10
+ const normalizeServer = name => name.replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '');
11
+
12
+ function resolveServer(methods, server) {
13
+ const name = server.toLowerCase();
14
+ const alias = normalizeServer(name);
15
+ const candidates = new Set();
16
+ for (const method of methods) {
17
+ const original = method.mcpServerName.toLowerCase();
18
+ if (original === name) return original;
19
+ if (alias && normalizeServer(original) === alias) candidates.add(original);
20
+ }
21
+ return candidates.size === 1 ? candidates.values().next().value : undefined;
22
+ }
23
+
24
+ function findMethods(omp, { query, server, limit = 1 }) {
25
+ const enabled = new Set(omp.getActiveTools());
26
+ const methods = omp.getAllTools().filter(tool => tool.mcpServerName && tool.mcpToolName && enabled.has(tool.name));
27
+ const serverName = server && resolveServer(methods, server);
28
+ if (server && !serverName) return [];
29
+ const needle = query.toLowerCase();
30
+ const exact = needle.startsWith('mcp__');
31
+ const terms = exact ? undefined : words(query);
32
+ const hits = [];
33
+
34
+ for (const tool of methods) {
35
+ if (serverName && tool.mcpServerName.toLowerCase() !== serverName) continue;
36
+ if (exact) {
37
+ if (tool.name.toLowerCase() !== needle) continue;
38
+ return [tool];
39
+ }
40
+
41
+ const nameWords = words(tool.mcpToolName);
42
+ const descriptionWords = words(tool.description);
43
+ let nameHits = 0;
44
+ let descriptionHits = 0;
45
+ for (const term of terms) {
46
+ if (nameWords.has(term)) nameHits++;
47
+ if (descriptionWords.has(term)) descriptionHits++;
48
+ }
49
+ if (nameHits || descriptionHits) hits.push({ tool, nameHits, descriptionHits });
50
+ }
51
+
52
+ hits.sort((a, b) => b.nameHits - a.nameHits || b.descriptionHits - a.descriptionHits
53
+ || (a.tool.name < b.tool.name ? -1 : a.tool.name > b.tool.name ? 1 : 0));
54
+ return hits.slice(0, limit).map(hit => hit.tool);
55
+ }
56
+
57
+ function describeMethod(tool) {
58
+ const description = tool.description.replace(/\s+/g, ' ').trim();
59
+ const hit = {
60
+ name: tool.name,
61
+ server: tool.mcpServerName,
62
+ method: tool.mcpToolName,
63
+ description: description.length <= maxDescription ? description : description.slice(0, maxDescription - 1) + '…',
64
+ };
65
+ const schema = toolWireSchema(tool);
66
+ return JSON.stringify(schema).length <= maxSchema
67
+ ? { ...hit, arguments: schema }
68
+ : { ...hit, schemaOmitted: 'Argument schema too large. Use native help://eval/<namespace> for the full signature.' };
69
+ }
70
+
71
+ export default function mcpFind(omp) {
72
+ const z = omp.zod;
73
+ omp.registerTool({
74
+ name: 'mcp_find',
75
+ label: 'MCP Find',
76
+ description: 'Find enabled MCP methods and their argument schemas. If the method or arguments are unknown, try one focused lookup with task keywords and the server if known. If the result is unusable, read help://eval/<namespace> instead of searching again. Skip lookup when the signature is known. In native Eval, call the returned name with await tool[name](args).',
77
+ loadMode: 'essential',
78
+ approval: 'read',
79
+ parameters: z.object({
80
+ query: z.string().trim().min(1).max(240).describe('Keywords or exact registered MCP tool name'),
81
+ server: z.string().trim().min(1).max(160).optional().describe('MCP server name or its namespace spelling, if known'),
82
+ limit: z.number().int().min(1).max(3).optional().describe('Maximum matches; defaults to one'),
83
+ }),
84
+ async execute(_id, params) {
85
+ const matches = findMethods(omp, params).map(describeMethod);
86
+ return { content: [{ type: 'text', text: JSON.stringify({ matches }) }] };
87
+ },
88
+ });
89
+ }
package/package.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "name": "omp-codemode",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Find the argument schema for one enabled MCP method in oh-my-pi.",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/juhas96/omp-codemode.git"
9
+ },
10
+ "files": ["mcp-find.js"],
11
+ "omp": {
12
+ "extensions": ["./mcp-find.js"]
13
+ },
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "registry": "https://registry.npmjs.org/"
17
+ }
18
+ }