
N8n Code Tool
Write JavaScript or Python for the n8n Custom Code Tool...
Install
npx skills add czlonkowski/n8n-mcp --skill n8n-code-tool -g -a claude-code -y- Repository
- czlonkowski/n8n-mcp23.2k
- Category
- AI and agents
- Updated
- 8d ago
- License
- MIT
- Context cost
- Mediumabout 3,000 tokens
- Runs scripts
- No, instructions only
What it does
Write JavaScript or Python for the n8n Custom Code Tool (@n8n/n8n-nodes-langchain.toolCode), the AI-agent-callable tool, NOT the workflow Code node. Use when building a Code Tool attached to an AI Agent, writing code that an LLM will invoke, parsing the `query` input, returning a string result, defining an input schema for structured arguments (specifyInputSchema, jsonSchemaExample, DynamicStructuredTool), or troubleshooting errors like \"Wrong output type returned\", \"No execution data available\", \"The response property should be a string, but it is an object\", \"Cannot assign to read only property 'name'\", or an AI agent that refuses to call the tool. Covers the critical differences between Code node and Code Tool: return format (string vs `[{json:{...}}]`), unavailability of `$fromAI`/`$input`/`$helpers` in the Code Tool sandbox, naming rules for AI invocation, and when to use `toolWorkflow`/HTTP Request Tool instead.
n8n Custom Code Tool
Expert guidance for writing code inside @n8n/n8n-nodes-langchain.toolCode, the tool an AI Agent can invoke, not the regular workflow Code node.
⚠️ This is NOT the Code node
The Custom Code Tool looks like a Code node in the editor, same JavaScript editor, similar layout, but it is a completely different node from a different package with a different runtime contract.
| Code node | Custom Code Tool | |
|---|---|---|
| Node type | n8n-nodes-base.code | @n8n/n8n-nodes-langchain.toolCode |
| Package | n8n-nodes-base | @n8n/n8n-nodes-langchain |
| Invoked by | Previous node (workflow flow) | AI Agent (LangChain) |
| Input | $input.all(), item stream | query, string or object from LLM |
| Return | [{json: {...}}] (items array) | A string |
$fromAI() | N/A | Not available (see Errors) |
| HTTP helper | this.helpers.httpRequest (auth helpers blocked) | Not exposed to the tool sandbox |
| State | Per-run execution data | No getContext, no $getWorkflowStaticData |
If you treat it like a Code node, it fails. The rest of this skill covers the Code Tool's actual contract.
Quick Start
Minimal JavaScript Code Tool
// `query` is whatever the AI sent (a string by default)
return `You asked: ${query}`;
Minimal Python Code Tool
# `_query` is whatever the AI sent (a string by default)
return f"You asked: {_query}"

