claude-flow
Version:
Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration
447 lines • 19 kB
JavaScript
/**
* Transfer MCP Tools
* Pattern and plugin sharing via IPFS-based decentralized registry
*
* @module @claude-flow/cli/mcp-tools/transfer-tools
* @version 3.0.0
*/
import { validateIdentifier, validatePackageName, validateText } from './validate-input.js';
/**
* Helper to create MCP tool result
*/
function createResult(data, isError = false) {
return {
content: [
{
type: 'text',
text: typeof data === 'string' ? data : JSON.stringify(data, null, 2),
},
],
isError,
};
}
/**
* Transfer MCP tools for pattern export, import, anonymization, and sharing
*/
export const transferTools = [
// ═══════════════════════════════════════════════════════════════
// ANONYMIZATION TOOLS
// ═══════════════════════════════════════════════════════════════
{
name: 'transfer_detect-pii',
description: 'Detect PII in content without redacting Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
content: {
type: 'string',
description: 'Content to scan for PII',
},
},
required: ['content'],
},
handler: async (input) => {
{
const v = validateText(input.content, 'content');
if (!v.valid)
return createResult({ error: v.error }, true);
}
try {
const { detectPII } = await import('../transfer/anonymization/index.js');
const result = detectPII(input.content);
return createResult(result);
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
// ═══════════════════════════════════════════════════════════════
// IPFS TOOLS
// ═══════════════════════════════════════════════════════════════
{
name: 'transfer_ipfs-resolve',
description: 'Resolve IPNS name to CID Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'IPNS name to resolve',
},
},
required: ['name'],
},
handler: async (input) => {
{
const v = validateIdentifier(input.name, 'name');
if (!v.valid)
return createResult({ error: v.error }, true);
}
try {
const { resolveIPNS } = await import('../transfer/ipfs/client.js');
const result = await resolveIPNS(input.name);
return createResult({ success: true, cid: result });
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
// ═══════════════════════════════════════════════════════════════
// PATTERN STORE TOOLS
// ═══════════════════════════════════════════════════════════════
{
name: 'transfer_store-search',
description: 'Search the pattern store Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
query: {
type: 'string',
description: 'Search query',
},
category: {
type: 'string',
description: 'Filter by category',
},
minRating: {
type: 'number',
description: 'Minimum rating',
},
verified: {
type: 'boolean',
description: 'Only show verified patterns',
},
limit: {
type: 'number',
description: 'Maximum results',
},
},
},
handler: async (input) => {
if (input.query) {
const v = validateText(input.query, 'query');
if (!v.valid)
return createResult({ error: v.error }, true);
}
if (input.category) {
const v = validateIdentifier(input.category, 'category');
if (!v.valid)
return createResult({ error: v.error }, true);
}
try {
const { PatternStore } = await import('../transfer/store/index.js');
const store = new PatternStore();
await store.initialize();
const results = store.search(input);
return createResult(results);
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
{
name: 'transfer_store-info',
description: 'Get detailed info about a pattern Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'Pattern ID',
},
},
required: ['id'],
},
handler: async (input) => {
{
const v = validateIdentifier(input.id, 'id');
if (!v.valid)
return createResult({ error: v.error }, true);
}
try {
const { PatternStore } = await import('../transfer/store/index.js');
const store = new PatternStore();
await store.initialize();
const pattern = store.getPattern(input.id);
if (!pattern) {
return createResult({ error: 'Pattern not found' }, true);
}
return createResult(pattern);
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
{
name: 'transfer_store-download',
description: 'Download a pattern from the store Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'Pattern ID',
},
verify: {
type: 'boolean',
description: 'Verify pattern integrity',
},
},
required: ['id'],
},
handler: async (input) => {
{
const v = validateIdentifier(input.id, 'id');
if (!v.valid)
return createResult({ error: v.error }, true);
}
try {
const { PatternStore } = await import('../transfer/store/index.js');
const store = new PatternStore();
await store.initialize();
const result = await store.download(input.id, { verify: input.verify });
return createResult(result);
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
{
name: 'transfer_store-featured',
description: 'Get featured patterns from the store Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
limit: {
type: 'number',
description: 'Maximum results',
},
},
},
handler: async (input) => {
try {
const { PatternStore } = await import('../transfer/store/index.js');
const store = new PatternStore();
await store.initialize();
const featured = store.getFeatured();
const limit = input.limit || 10;
return createResult(featured.slice(0, limit));
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
{
name: 'transfer_store-trending',
description: 'Get trending patterns from the store Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
limit: {
type: 'number',
description: 'Maximum results',
},
},
},
handler: async (input) => {
try {
const { PatternStore } = await import('../transfer/store/index.js');
const store = new PatternStore();
await store.initialize();
const trending = store.getTrending();
const limit = input.limit || 10;
return createResult(trending.slice(0, limit));
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
// ═══════════════════════════════════════════════════════════════
// PLUGIN STORE TOOLS
// ═══════════════════════════════════════════════════════════════
{
name: 'transfer_plugin-search',
description: 'Search the plugin store Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
query: {
type: 'string',
description: 'Search query',
},
category: {
type: 'string',
description: 'Filter by category',
},
type: {
type: 'string',
description: 'Filter by plugin type',
},
verified: {
type: 'boolean',
description: 'Only show verified plugins',
},
minRating: {
type: 'number',
description: 'Minimum rating',
},
limit: {
type: 'number',
description: 'Maximum results',
},
},
},
handler: async (input) => {
if (input.query) {
const v = validateText(input.query, 'query');
if (!v.valid)
return createResult({ error: v.error }, true);
}
if (input.category) {
const v = validateIdentifier(input.category, 'category');
if (!v.valid)
return createResult({ error: v.error }, true);
}
if (input.type) {
const v = validateIdentifier(input.type, 'type');
if (!v.valid)
return createResult({ error: v.error }, true);
}
try {
const { createPluginDiscoveryService, searchPlugins } = await import('../plugins/store/index.js');
const discovery = createPluginDiscoveryService();
const result = await discovery.discoverRegistry();
if (!result.success || !result.registry) {
return createResult({ error: result.error || 'Failed to discover registry' }, true);
}
const opts = input;
const searchResult = searchPlugins(result.registry, opts);
return createResult(searchResult);
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
{
name: 'transfer_plugin-info',
description: 'Get detailed info about a plugin Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Plugin name or ID',
},
},
required: ['name'],
},
handler: async (input) => {
{
const v = validatePackageName(input.name, 'name');
if (!v.valid)
return createResult({ error: v.error }, true);
}
try {
const { createPluginDiscoveryService } = await import('../plugins/store/index.js');
const discovery = createPluginDiscoveryService();
const result = await discovery.discoverRegistry();
if (!result.success || !result.registry) {
return createResult({ error: result.error || 'Failed to discover registry' }, true);
}
const name = input.name;
const plugin = result.registry.plugins.find((p) => p.id === name || p.name === name);
if (!plugin) {
return createResult({ error: 'Plugin not found' }, true);
}
return createResult(plugin);
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
{
name: 'transfer_plugin-featured',
description: 'Get featured plugins from the store Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {
limit: {
type: 'number',
description: 'Maximum results',
},
},
},
handler: async (input) => {
try {
const { createPluginDiscoveryService, getFeaturedPlugins } = await import('../plugins/store/index.js');
const discovery = createPluginDiscoveryService();
const result = await discovery.discoverRegistry();
if (!result.success || !result.registry) {
return createResult({ error: result.error || 'Failed to discover registry' }, true);
}
const featured = getFeaturedPlugins(result.registry);
const limit = input.limit || 10;
return createResult(featured.slice(0, limit));
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
{
name: 'transfer_plugin-official',
description: 'Get official plugins from the store Use when native package install (`npm i`, `pip install`) is wrong because the artifact lives on IPFS (plugins, witness chains, learned patterns). For npm-registry deps, native npm is fine.',
category: 'transfer',
version: '1.0.0',
inputSchema: {
type: 'object',
properties: {},
},
handler: async () => {
try {
const { createPluginDiscoveryService, getOfficialPlugins } = await import('../plugins/store/index.js');
const discovery = createPluginDiscoveryService();
const result = await discovery.discoverRegistry();
if (!result.success || !result.registry) {
return createResult({ error: result.error || 'Failed to discover registry' }, true);
}
const official = getOfficialPlugins(result.registry);
return createResult(official);
}
catch (error) {
return createResult({ error: error.message }, true);
}
},
},
];
export default transferTools;
//# sourceMappingURL=transfer-tools.js.map