Skip to content

Commit 6426c13

Browse files
committed
feat(unstructured-mcp): adding unstructured.io transform mcp
1 parent bb773ff commit 6426c13

3 files changed

Lines changed: 141 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { INodeParams, INodeCredential } from '../src/Interface'
2+
3+
class UnstructuredTransformApi implements INodeCredential {
4+
label: string
5+
name: string
6+
version: number
7+
description: string
8+
inputs: INodeParams[]
9+
10+
constructor() {
11+
this.label = 'Unstructured Transform API'
12+
this.name = 'unstructuredTransformApi'
13+
this.version = 1.0
14+
this.description =
15+
'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.'
16+
this.inputs = [
17+
{
18+
label: 'API Key',
19+
name: 'unstructuredTransformAPIKey',
20+
type: 'password'
21+
}
22+
]
23+
}
24+
}
25+
26+
module.exports = { credClass: UnstructuredTransformApi }
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { Tool } from '@langchain/core/tools'
2+
import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../../src/Interface'
3+
import { getCredentialData, getCredentialParam } from '../../../../src/utils'
4+
import { MCPToolkit } from '../core'
5+
6+
class Unstructured_MCP implements INode {
7+
label: string
8+
name: string
9+
version: number
10+
description: string
11+
type: string
12+
icon: string
13+
category: string
14+
baseClasses: string[]
15+
documentation: string
16+
credential: INodeParams
17+
inputs: INodeParams[]
18+
19+
constructor() {
20+
this.label = 'Unstructured MCP'
21+
this.name = 'unstructuredMCP'
22+
this.version = 1.0
23+
this.type = 'Unstructured MCP Tool'
24+
this.icon = 'unstructured.png'
25+
this.category = 'Tools (MCP)'
26+
this.description =
27+
'MCP Server for Unstructured.io — parse PDFs, DOCX, PPTX, images and 60+ other file types into clean markdown or structured JSON'
28+
this.documentation = 'https://docs.unstructured.io/transform/overview'
29+
this.credential = {
30+
label: 'Connect Credential',
31+
name: 'credential',
32+
type: 'credential',
33+
credentialNames: ['unstructuredTransformApi']
34+
}
35+
this.inputs = [
36+
{
37+
label: 'Available Actions',
38+
name: 'mcpActions',
39+
type: 'asyncMultiOptions',
40+
loadMethod: 'listActions',
41+
refresh: true
42+
}
43+
]
44+
this.baseClasses = ['Tool']
45+
}
46+
47+
//@ts-ignore
48+
loadMethods = {
49+
listActions: async (nodeData: INodeData, options: ICommonObject): Promise<INodeOptionsValue[]> => {
50+
try {
51+
const toolset = await this.getTools(nodeData, options)
52+
toolset.sort((a: any, b: any) => a.name.localeCompare(b.name))
53+
54+
return toolset.map(({ name, ...rest }) => ({
55+
label: name.toUpperCase(),
56+
name: name,
57+
description: rest.description || name
58+
}))
59+
} catch (error) {
60+
console.error('Error listing actions:', error)
61+
return [
62+
{
63+
label: 'No Available Actions',
64+
name: 'error',
65+
description: 'No available actions, please check your Unstructured.io Transform API Key and refresh'
66+
}
67+
]
68+
}
69+
}
70+
}
71+
72+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
73+
const tools = await this.getTools(nodeData, options)
74+
75+
const _mcpActions = nodeData.inputs?.mcpActions
76+
let mcpActions = []
77+
if (_mcpActions) {
78+
try {
79+
mcpActions = typeof _mcpActions === 'string' ? JSON.parse(_mcpActions) : _mcpActions
80+
} catch (error) {
81+
console.error('Error parsing mcp actions:', error)
82+
}
83+
}
84+
85+
return tools.filter((tool: any) => mcpActions.includes(tool.name))
86+
}
87+
88+
async getTools(nodeData: INodeData, options: ICommonObject): Promise<Tool[]> {
89+
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
90+
const apiKey = getCredentialParam('unstructuredTransformAPIKey', credentialData, nodeData)
91+
92+
const url = 'https://mcp.transform.unstructured.io/'
93+
94+
if (!apiKey) {
95+
throw new Error('Missing Unstructured.io Transform API Key')
96+
}
97+
98+
const serverParams = {
99+
type: 'http',
100+
url,
101+
headers: {
102+
Authorization: `Bearer ${apiKey}`
103+
}
104+
}
105+
106+
const toolkit = new MCPToolkit(serverParams, 'http')
107+
await toolkit.initialize()
108+
109+
const tools = toolkit.tools ?? []
110+
111+
return tools as Tool[]
112+
}
113+
}
114+
115+
module.exports = { nodeClass: Unstructured_MCP }
4.99 KB
Loading

0 commit comments

Comments
 (0)