Files
openmotion/shared/mcp-registry.ts
huihui-crypto f0e8525426 feat(mcp): define when Agents list, recommend and read library Skills (#658)
* feat(mcp): define when Agents list, recommend and read library Skills

Adds skillDiscoveryGuide to the phase-one initialize instructions and the
openmotion_list_skills description: call it for technique/recipe or
Skill-recommendation requests and recurring formats, recommend at most three
Skills with a reason and wait for the user's choice, read the choice with
openmotion_get_skill, prefer host-installed Skills, and treat listing as
side-effect free. The handbook example and docs follow the same rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(mcp): align Skill recommendations with template discovery

Recommend two or three Skills (one if only one fits, never pad), matching
template browsing, and state that suggesting Skills for a described
recurring format is deliberately more proactive than template discovery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: zhanghuihua <zhanghuihua@Mac.lan>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 17:55:18 +08:00

26 lines
2.5 KiB
TypeScript

import assert from 'node:assert/strict';
import { workflowEntryGuide, templateDiscoveryGuide, skillDiscoveryGuide } from './workflow-entry.js';
import { readFileSync } from 'node:fs';
const profiles: Record<string, { tools: string[] | null; instructions: string | null }> = JSON.parse(readFileSync(new URL('./mcp-profiles.json', import.meta.url), 'utf8'));
export const releaseProfile: string = JSON.parse(readFileSync(new URL('./mcp-release.json', import.meta.url), 'utf8')).profile;
/** The packaged profile controls discovery and dispatch, not the internal business handlers. */
export function createToolRegistry<T extends { name: string }, E extends { name: string } = never>(implementations: readonly T[], profile = releaseProfile, extensions: readonly E[] = []) {
assert(typeof profile === 'string' && Object.hasOwn(profiles, profile), `Unknown MCP release profile: ${profile}`);
const definition = profiles[profile];
const byName = new Map(implementations.map(tool => [tool.name, tool]));
assert.equal(byName.size, implementations.length, 'Duplicate MCP implementation names');
const names = definition.tools ?? implementations.map(tool => tool.name);
assert(Array.isArray(names) && names.every(name => typeof name === 'string' && /^[A-Za-z0-9_.-]{1,128}$/.test(name)), 'Invalid MCP registration list');
assert.equal(new Set(names).size, names.length, 'Duplicate MCP public names');
const missing = names.filter(name => !byName.has(name));
assert.equal(missing.length, 0, `MCP_PROFILE_INCOMPLETE (${profile}): missing registrations: ${missing.join(', ')}. Existing names are not equivalent adapters; no partial phase-one package was produced.`);
const extensionNames = extensions.map(tool => tool.name);
assert(extensions.length === 0 || profile === 'phase1', 'MCP extensions require the phase-one profile');
assert(extensionNames.every(name => ['openmotion_show_template_recommendations', 'openmotion_show_video'].includes(name)), 'Unknown MCP optional extension');
assert.equal(new Set(extensionNames).size, extensionNames.length, 'Duplicate MCP optional extensions');
assert(extensionNames.every(name => !byName.has(name)), 'MCP optional extension shadows an implementation');
return { profile, tools: [...names.map(name => byName.get(name)!), ...extensions] as (T | E)[], instructions: definition.instructions === null ? null : workflowEntryGuide + ' ' + (profile === 'phase1' ? templateDiscoveryGuide + ' ' + skillDiscoveryGuide + ' ' : '') + definition.instructions };
}