Skip to content

Commit 69a2722

Browse files
authored
Add Sequential Thinking MCP tool for structured problem-solving (#4143)
1 parent a369f0c commit 69a2722

File tree

4 files changed

+316
-151
lines changed

4 files changed

+316
-151
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { Tool } from '@langchain/core/tools'
2+
import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../../src/Interface'
3+
import { getNodeModulesPackagePath } from '../../../../src/utils'
4+
import { MCPToolkit } from '../core'
5+
6+
class SequentialThinking_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+
inputs: INodeParams[]
17+
18+
constructor() {
19+
this.label = 'Sequential Thinking MCP'
20+
this.name = 'sequentialThinkingMCP'
21+
this.version = 1.0
22+
this.type = 'Sequential Thinking MCP Tool'
23+
this.icon = 'sequentialthinking.svg'
24+
this.category = 'Tools (MCP)'
25+
this.description =
26+
'MCP server that provides a tool for dynamic and reflective problem-solving through a structured thinking process'
27+
this.documentation = 'https://github.com/modelcontextprotocol/servers/tree/main/src/sequentialthinking'
28+
this.inputs = [
29+
{
30+
label: 'Available Actions',
31+
name: 'mcpActions',
32+
type: 'asyncMultiOptions',
33+
loadMethod: 'listActions',
34+
refresh: true
35+
}
36+
]
37+
this.baseClasses = ['Tool']
38+
}
39+
40+
//@ts-ignore
41+
loadMethods = {
42+
listActions: async (nodeData: INodeData, options: ICommonObject): Promise<INodeOptionsValue[]> => {
43+
try {
44+
const toolset = await this.getTools(nodeData, options)
45+
toolset.sort((a: any, b: any) => a.name.localeCompare(b.name))
46+
47+
return toolset.map(({ name, ...rest }) => ({
48+
label: name.toUpperCase(),
49+
name: name,
50+
description: rest.description || name
51+
}))
52+
} catch (error) {
53+
console.error('Error listing actions:', error)
54+
return [
55+
{
56+
label: 'No Available Actions',
57+
name: 'error',
58+
description: 'No available actions, please refresh'
59+
}
60+
]
61+
}
62+
}
63+
}
64+
65+
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
66+
const tools = await this.getTools(nodeData, options)
67+
68+
const _mcpActions = nodeData.inputs?.mcpActions
69+
let mcpActions = []
70+
if (_mcpActions) {
71+
try {
72+
mcpActions = typeof _mcpActions === 'string' ? JSON.parse(_mcpActions) : _mcpActions
73+
} catch (error) {
74+
console.error('Error parsing mcp actions:', error)
75+
}
76+
}
77+
78+
return tools.filter((tool: any) => mcpActions.includes(tool.name))
79+
}
80+
81+
async getTools(_nodeData: INodeData, _options: ICommonObject): Promise<Tool[]> {
82+
const packagePath = getNodeModulesPackagePath('@modelcontextprotocol/server-sequential-thinking/dist/index.js')
83+
84+
const serverParams = {
85+
command: 'node',
86+
args: [packagePath]
87+
}
88+
89+
const toolkit = new MCPToolkit(serverParams, 'stdio')
90+
await toolkit.initialize()
91+
92+
const tools = toolkit.tools ?? []
93+
94+
return tools as Tool[]
95+
}
96+
}
97+
98+
module.exports = { nodeClass: SequentialThinking_MCP }
Lines changed: 36 additions & 0 deletions
Loading

packages/components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"@modelcontextprotocol/server-brave-search": "^0.6.2",
6464
"@modelcontextprotocol/server-github": "^2025.1.23",
6565
"@modelcontextprotocol/server-postgres": "^0.6.2",
66+
"@modelcontextprotocol/server-sequential-thinking": "^0.6.2",
6667
"@modelcontextprotocol/server-slack": "^2025.1.17",
6768
"@notionhq/client": "^2.2.8",
6869
"@opensearch-project/opensearch": "^1.2.0",

0 commit comments

Comments
 (0)