-
-
Notifications
You must be signed in to change notification settings - Fork 24.7k
feat(unstructured-mcp): adding unstructured.io transform mcp #6626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattbarrio
wants to merge
3
commits into
FlowiseAI:main
Choose a base branch
from
mattbarrio:feature/unstructured-mcp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/components/credentials/UnstructuredTransformApi.credential.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { INodeParams, INodeCredential } from '../src/Interface' | ||
|
|
||
| class UnstructuredTransformApi implements INodeCredential { | ||
| label: string | ||
| name: string | ||
| version: number | ||
| description: string | ||
| inputs: INodeParams[] | ||
|
|
||
| constructor() { | ||
| this.label = 'Unstructured Transform API' | ||
| this.name = 'unstructuredTransformApi' | ||
| this.version = 1.0 | ||
| this.description = | ||
| 'Sign in at <a target="_blank" href="https://transform.unstructured.io/get-started">Unstructured Transform</a> to get your API key. See the <a target="_blank" href="https://docs.unstructured.io/transform/quickstart">quickstart</a> for details.' | ||
| this.inputs = [ | ||
| { | ||
| label: 'API Key', | ||
| name: 'unstructuredTransformAPIKey', | ||
| type: 'password' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| module.exports = { credClass: UnstructuredTransformApi } |
114 changes: 114 additions & 0 deletions
114
packages/components/nodes/tools/MCP/UnstructuredMCP/UnstructuredMCP.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| 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 UnstructuredMCP 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 = 'Unstructured MCP' | ||
| this.name = 'unstructuredMCP' | ||
| this.version = 1.0 | ||
| this.type = 'Unstructured MCP Tool' | ||
| this.icon = 'unstructured.png' | ||
| this.category = 'Tools (MCP)' | ||
| this.description = | ||
| 'MCP Server for Unstructured.io — parse PDFs, DOCX, PPTX, images and 60+ other file types into clean markdown or structured JSON' | ||
| this.documentation = 'https://docs.unstructured.io/transform/overview' | ||
| this.credential = { | ||
| label: 'Connect Credential', | ||
| name: 'credential', | ||
| type: 'credential', | ||
| credentialNames: ['unstructuredTransformApi'] | ||
| } | ||
| this.inputs = [ | ||
| { | ||
| label: 'Available Actions', | ||
| name: 'mcpActions', | ||
| type: 'asyncMultiOptions', | ||
| loadMethod: 'listActions', | ||
| refresh: true | ||
| } | ||
| ] | ||
| this.baseClasses = ['Tool'] | ||
| } | ||
|
|
||
| loadMethods = { | ||
| listActions: async (nodeData: INodeData, options: ICommonObject = {}): Promise<INodeOptionsValue[]> => { | ||
| 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 Unstructured.io Transform API Key and refresh' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async init(nodeData: INodeData, _: string, options: ICommonObject = {}): Promise<any> { | ||
| const tools = await this.getTools(nodeData, options) | ||
|
|
||
| const _mcpActions = nodeData.inputs?.mcpActions | ||
| let mcpActions: string[] = [] | ||
| if (_mcpActions) { | ||
| const parsed = typeof _mcpActions === 'string' ? JSON.parse(_mcpActions) : _mcpActions | ||
| if (!Array.isArray(parsed)) { | ||
| throw new Error('mcpActions must be an array') | ||
| } | ||
| mcpActions = parsed | ||
| } | ||
|
|
||
| return tools.filter((tool: any) => mcpActions.includes(tool.name)) | ||
| } | ||
|
|
||
| async getTools(nodeData: INodeData, options: ICommonObject = {}): Promise<Tool[]> { | ||
| const credentialData = await getCredentialData(nodeData.credential ?? '', options) | ||
| const apiKey = getCredentialParam('unstructuredTransformAPIKey', credentialData, nodeData) | ||
|
|
||
| const url = 'https://mcp.transform.unstructured.io/' | ||
|
|
||
| if (!apiKey) { | ||
| throw new Error('Missing Unstructured.io Transform API Key') | ||
| } | ||
|
|
||
| const serverParams = { | ||
| type: 'http', | ||
| url, | ||
| headers: { | ||
| Authorization: `Bearer ${apiKey}` | ||
| } | ||
| } | ||
|
|
||
| const toolkit = new MCPToolkit(serverParams, 'http') | ||
| await toolkit.initialize() | ||
|
|
||
| const tools = toolkit.tools ?? [] | ||
|
|
||
| return tools as Tool[] | ||
| } | ||
| } | ||
|
|
||
| module.exports = { nodeClass: UnstructuredMCP } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.