diff --git a/packages/components/credentials/XpozApi.credential.ts b/packages/components/credentials/XpozApi.credential.ts new file mode 100644 index 00000000000..aff0adb497b --- /dev/null +++ b/packages/components/credentials/XpozApi.credential.ts @@ -0,0 +1,27 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class XpozApi implements INodeCredential { + label: string + name: string + version: number + description: string + inputs: INodeParams[] + + constructor() { + this.label = 'Xpoz API' + this.name = 'xpozApi' + this.version = 1.0 + this.description = + 'Get a free access key (no credit card) at xpoz.ai/get-token' + this.inputs = [ + { + label: 'Access Key', + name: 'xpozApiKey', + type: 'password', + placeholder: '' + } + ] + } +} + +module.exports = { credClass: XpozApi } diff --git a/packages/components/nodes/tools/MCP/Xpoz/XpozMCP.ts b/packages/components/nodes/tools/MCP/Xpoz/XpozMCP.ts new file mode 100644 index 00000000000..4bec2e44a30 --- /dev/null +++ b/packages/components/nodes/tools/MCP/Xpoz/XpozMCP.ts @@ -0,0 +1,111 @@ +import { Tool } from '@langchain/core/tools' +import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../../src/Interface' +import { getCredentialData, getCredentialParam } from '../../../../src/utils' +import { MCPToolkit } from '../core' + +class XpozMCP implements INode { + label: string + name: string + version: number + description: string + type: string + icon: string + category: string + baseClasses: string[] + documentation: string + credential: INodeParams + inputs: INodeParams[] + + constructor() { + this.label = 'Xpoz MCP' + this.name = 'xpozMCP' + this.version = 1.0 + this.type = 'Xpoz MCP Tool' + this.icon = 'xpoz.svg' + this.category = 'Tools (MCP)' + this.description = + 'MCP Server for Xpoz - search and analyze Twitter/X, Instagram, Reddit, and TikTok posts, profiles, and engagement data' + this.documentation = 'https://xpoz.ai/docs' + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['xpozApi'] + } + this.inputs = [ + { + label: 'Available Actions', + name: 'mcpActions', + type: 'asyncMultiOptions', + loadMethod: 'listActions', + refresh: true + } + ] + this.baseClasses = ['Tool'] + } + + loadMethods = { + listActions: async (nodeData: INodeData, options?: ICommonObject): Promise => { + try { + const toolset = await this.getTools(nodeData, options ?? {}) + toolset.sort((a: any, b: any) => a.name.localeCompare(b.name)) + + return toolset.map(({ name, ...rest }) => ({ + label: name.toUpperCase(), + name: name, + description: rest.description || name + })) + } catch (error) { + console.error('Error listing actions:', error) + return [ + { + label: 'No Available Actions', + name: 'error', + description: 'No available actions, please check your access key and refresh' + } + ] + } + } + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const tools = await this.getTools(nodeData, options) + + const _mcpActions = nodeData.inputs?.mcpActions + let mcpActions = [] + if (_mcpActions) { + try { + mcpActions = typeof _mcpActions === 'string' ? JSON.parse(_mcpActions) : _mcpActions + } catch (error) { + console.error('Error parsing mcp actions:', error) + } + } + + return tools.filter((tool: any) => mcpActions.includes(tool.name)) + } + + async getTools(nodeData: INodeData, options: ICommonObject): Promise { + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const accessKey = getCredentialParam('xpozApiKey', credentialData, nodeData) + + if (!accessKey) { + throw new Error('Missing Xpoz Access Key') + } + + const serverParams = { + url: 'https://mcp.xpoz.ai/mcp', + headers: { + Authorization: `Bearer ${accessKey}` + } + } + + const toolkit = new MCPToolkit(serverParams, 'http') + await toolkit.initialize() + + const tools = toolkit.tools ?? [] + + return tools + } +} + +module.exports = { nodeClass: XpozMCP } diff --git a/packages/components/nodes/tools/MCP/Xpoz/xpoz.svg b/packages/components/nodes/tools/MCP/Xpoz/xpoz.svg new file mode 100644 index 00000000000..9e6b82b415e --- /dev/null +++ b/packages/components/nodes/tools/MCP/Xpoz/xpoz.svg @@ -0,0 +1,5 @@ + + + + +