Compare commits
11 Commits
e2fb8d3826
...
77190ff363
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77190ff363 | ||
|
|
e448f5b0da | ||
|
|
e46d122ca0 | ||
|
|
9670a3b55e | ||
|
|
8f1be581c6 | ||
|
|
1ba8f00a56 | ||
|
|
29da78c562 | ||
|
|
95d7216752 | ||
|
|
91ca3b4b11 | ||
|
|
210497f517 | ||
|
|
10690674b6 |
@@ -81,6 +81,8 @@ async function build() {
|
||||
console.log("🎉 Build complete!");
|
||||
}
|
||||
|
||||
execSync("npm version patch", { stdio: 'inherit' })
|
||||
execSync("git add -A", { stdio: 'inherit' })
|
||||
execSync("git commit -m 'build'", { stdio: 'inherit' })
|
||||
execSync("cd src && npm version patch", { stdio: 'inherit' })
|
||||
build()
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { execSync } from "child_process";
|
||||
|
||||
execSync("npm publish", { stdio: 'inherit' })
|
||||
execSync("cd dist && bun publish", { stdio: 'inherit' })
|
||||
17
icon.svg
17
icon.svg
@@ -1,17 +0,0 @@
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128" aria-label="Icon AB square">
|
||||
<defs>
|
||||
<style>
|
||||
.bg { fill: #111827; rx: 20; }
|
||||
.letters { fill: #f9fafb; font-family: "Inter", "Segoe UI", Roboto, sans-serif; font-weight: 800; font-size: 56px; }
|
||||
</style>
|
||||
</defs>
|
||||
|
||||
<!-- rounded square background -->
|
||||
<rect class="bg" width="128" height="128" rx="20" ry="20"/>
|
||||
|
||||
<!-- letters -->
|
||||
<text class="letters" x="64" y="78" text-anchor="middle" dominant-baseline="middle">mcp</text>
|
||||
</svg>
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 550 B |
@@ -1,30 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OpenapiMcpServerCredentials = void 0;
|
||||
class OpenapiMcpServerCredentials {
|
||||
constructor() {
|
||||
this.name = "openapiMcpServerCredentials";
|
||||
this.displayName = "OpenAPI MCP Server Credentials";
|
||||
this.properties = [
|
||||
{
|
||||
displayName: "Base URL",
|
||||
name: "baseUrl",
|
||||
type: "string",
|
||||
default: "",
|
||||
placeholder: "https://api.example.com",
|
||||
description: "Masukkan URL dasar API tanpa garis miring di akhir",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: "Bearer Token",
|
||||
name: "token",
|
||||
type: "string",
|
||||
default: "",
|
||||
typeOptions: { password: true },
|
||||
description: "Masukkan token autentikasi Bearer (tanpa 'Bearer ' di depannya)",
|
||||
required: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
exports.OpenapiMcpServerCredentials = OpenapiMcpServerCredentials;
|
||||
@@ -1,325 +0,0 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.convertOpenApiToMcpTools = convertOpenApiToMcpTools;
|
||||
exports.getMcpTools = getMcpTools;
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
/**
|
||||
* Convert OpenAPI 3.x JSON spec into MCP-compatible tool definitions.
|
||||
*/
|
||||
function convertOpenApiToMcpTools(openApiJson, filterTag) {
|
||||
const tools = [];
|
||||
if (!openApiJson || typeof openApiJson !== "object") {
|
||||
console.warn("Invalid OpenAPI JSON");
|
||||
return tools;
|
||||
}
|
||||
const paths = openApiJson.paths || {};
|
||||
if (Object.keys(paths).length === 0) {
|
||||
console.warn("No paths found in OpenAPI spec");
|
||||
return tools;
|
||||
}
|
||||
for (const [path, methods] of Object.entries(paths)) {
|
||||
if (!path || typeof path !== "string")
|
||||
continue;
|
||||
if (path.startsWith("/mcp"))
|
||||
continue;
|
||||
if (!methods || typeof methods !== "object")
|
||||
continue;
|
||||
for (const [method, operation] of Object.entries(methods)) {
|
||||
const validMethods = ["get", "post", "put", "delete", "patch", "head", "options"];
|
||||
if (!validMethods.includes(method.toLowerCase()))
|
||||
continue;
|
||||
if (!operation || typeof operation !== "object")
|
||||
continue;
|
||||
const tags = Array.isArray(operation.tags) ? operation.tags : [];
|
||||
if (!tags.length || !tags.some(t => typeof t === "string" && t.toLowerCase().includes(filterTag)))
|
||||
continue;
|
||||
try {
|
||||
const tool = createToolFromOperation(path, method, operation, tags);
|
||||
if (tool) {
|
||||
tools.push(tool);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`Error creating tool for ${method.toUpperCase()} ${path}:`, error);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return tools;
|
||||
}
|
||||
/**
|
||||
* Buat MCP tool dari operation OpenAPI
|
||||
*/
|
||||
function createToolFromOperation(path, method, operation, tags) {
|
||||
try {
|
||||
const rawName = lodash_1.default.snakeCase(operation.operationId || `${method}_${path}`) || "unnamed_tool";
|
||||
const name = cleanToolName(rawName);
|
||||
if (!name || name === "unnamed_tool") {
|
||||
console.warn(`Invalid tool name for ${method} ${path}`);
|
||||
return null;
|
||||
}
|
||||
const description = operation.description ||
|
||||
operation.summary ||
|
||||
`Execute ${method.toUpperCase()} ${path}`;
|
||||
// ✅ Extract schema berdasarkan method
|
||||
let schema;
|
||||
if (method.toLowerCase() === "get") {
|
||||
// ✅ Untuk GET, ambil dari parameters (query/path)
|
||||
schema = extractParametersSchema(operation.parameters || []);
|
||||
}
|
||||
else {
|
||||
// ✅ Untuk POST/PUT/etc, ambil dari requestBody
|
||||
schema = extractRequestBodySchema(operation);
|
||||
}
|
||||
const inputSchema = createInputSchema(schema);
|
||||
return {
|
||||
name,
|
||||
description,
|
||||
"x-props": {
|
||||
method: method.toUpperCase(),
|
||||
path,
|
||||
operationId: operation.operationId,
|
||||
tag: tags[0],
|
||||
deprecated: operation.deprecated || false,
|
||||
summary: operation.summary,
|
||||
},
|
||||
inputSchema,
|
||||
};
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`Failed to create tool from operation:`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Extract schema dari parameters (untuk GET requests)
|
||||
*/
|
||||
function extractParametersSchema(parameters) {
|
||||
var _a;
|
||||
if (!Array.isArray(parameters) || parameters.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const properties = {};
|
||||
const required = [];
|
||||
for (const param of parameters) {
|
||||
if (!param || typeof param !== "object")
|
||||
continue;
|
||||
// ✅ Support path, query, dan header parameters
|
||||
if (["path", "query", "header"].includes(param.in)) {
|
||||
const paramName = param.name;
|
||||
if (!paramName || typeof paramName !== "string")
|
||||
continue;
|
||||
properties[paramName] = {
|
||||
type: ((_a = param.schema) === null || _a === void 0 ? void 0 : _a.type) || "string",
|
||||
description: param.description || `${param.in} parameter: ${paramName}`,
|
||||
};
|
||||
// ✅ Copy field tambahan dari schema
|
||||
if (param.schema) {
|
||||
const allowedFields = ["examples", "example", "default", "enum", "pattern", "minLength", "maxLength", "minimum", "maximum", "format"];
|
||||
for (const field of allowedFields) {
|
||||
if (param.schema[field] !== undefined) {
|
||||
properties[paramName][field] = param.schema[field];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (param.required === true) {
|
||||
required.push(paramName);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Object.keys(properties).length === 0) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
type: "object",
|
||||
properties,
|
||||
required,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Extract schema dari requestBody (untuk POST/PUT/etc requests)
|
||||
*/
|
||||
function extractRequestBodySchema(operation) {
|
||||
var _a, _b;
|
||||
if (!((_a = operation.requestBody) === null || _a === void 0 ? void 0 : _a.content)) {
|
||||
return null;
|
||||
}
|
||||
const content = operation.requestBody.content;
|
||||
const contentTypes = [
|
||||
"application/json",
|
||||
"multipart/form-data",
|
||||
"application/x-www-form-urlencoded",
|
||||
"text/plain",
|
||||
];
|
||||
for (const contentType of contentTypes) {
|
||||
if ((_b = content[contentType]) === null || _b === void 0 ? void 0 : _b.schema) {
|
||||
return content[contentType].schema;
|
||||
}
|
||||
}
|
||||
for (const [_, value] of Object.entries(content)) {
|
||||
if (value === null || value === void 0 ? void 0 : value.schema) {
|
||||
return value.schema;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Buat input schema yang valid untuk MCP
|
||||
*/
|
||||
function createInputSchema(schema) {
|
||||
const defaultSchema = {
|
||||
type: "object",
|
||||
properties: {},
|
||||
additionalProperties: false,
|
||||
};
|
||||
if (!schema || typeof schema !== "object") {
|
||||
return defaultSchema;
|
||||
}
|
||||
try {
|
||||
const properties = {};
|
||||
const required = [];
|
||||
const originalRequired = Array.isArray(schema.required) ? schema.required : [];
|
||||
if (schema.properties && typeof schema.properties === "object") {
|
||||
for (const [key, prop] of Object.entries(schema.properties)) {
|
||||
if (!key || typeof key !== "string")
|
||||
continue;
|
||||
try {
|
||||
const cleanProp = cleanProperty(prop);
|
||||
if (cleanProp) {
|
||||
properties[key] = cleanProp;
|
||||
// ✅ PERBAIKAN: Check optional flag dengan benar
|
||||
const isOptional = (prop === null || prop === void 0 ? void 0 : prop.optional) === true || (prop === null || prop === void 0 ? void 0 : prop.optional) === "true";
|
||||
const isInRequired = originalRequired.includes(key);
|
||||
// ✅ Hanya masukkan ke required jika memang required DAN bukan optional
|
||||
if (isInRequired && !isOptional) {
|
||||
required.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error(`Error cleaning property ${key}:`, error);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
type: "object",
|
||||
properties,
|
||||
required,
|
||||
additionalProperties: false,
|
||||
};
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Error creating input schema:", error);
|
||||
return defaultSchema;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Bersihkan property dari field custom
|
||||
*/
|
||||
function cleanProperty(prop) {
|
||||
if (!prop || typeof prop !== "object") {
|
||||
return { type: "string" };
|
||||
}
|
||||
try {
|
||||
const cleaned = {
|
||||
type: prop.type || "string",
|
||||
};
|
||||
const allowedFields = [
|
||||
"description",
|
||||
"examples",
|
||||
"example",
|
||||
"default",
|
||||
"enum",
|
||||
"pattern",
|
||||
"minLength",
|
||||
"maxLength",
|
||||
"minimum",
|
||||
"maximum",
|
||||
"format",
|
||||
"multipleOf",
|
||||
"exclusiveMinimum",
|
||||
"exclusiveMaximum",
|
||||
];
|
||||
for (const field of allowedFields) {
|
||||
if (prop[field] !== undefined && prop[field] !== null) {
|
||||
cleaned[field] = prop[field];
|
||||
}
|
||||
}
|
||||
if (prop.properties && typeof prop.properties === "object") {
|
||||
cleaned.properties = {};
|
||||
for (const [key, value] of Object.entries(prop.properties)) {
|
||||
const cleanedNested = cleanProperty(value);
|
||||
if (cleanedNested) {
|
||||
cleaned.properties[key] = cleanedNested;
|
||||
}
|
||||
}
|
||||
if (Array.isArray(prop.required)) {
|
||||
cleaned.required = prop.required.filter((r) => typeof r === "string");
|
||||
}
|
||||
}
|
||||
if (prop.items) {
|
||||
cleaned.items = cleanProperty(prop.items);
|
||||
}
|
||||
if (Array.isArray(prop.oneOf)) {
|
||||
cleaned.oneOf = prop.oneOf.map(cleanProperty).filter(Boolean);
|
||||
}
|
||||
if (Array.isArray(prop.anyOf)) {
|
||||
cleaned.anyOf = prop.anyOf.map(cleanProperty).filter(Boolean);
|
||||
}
|
||||
if (Array.isArray(prop.allOf)) {
|
||||
cleaned.allOf = prop.allOf.map(cleanProperty).filter(Boolean);
|
||||
}
|
||||
return cleaned;
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Error cleaning property:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Bersihkan nama tool
|
||||
*/
|
||||
function cleanToolName(name) {
|
||||
if (!name || typeof name !== "string") {
|
||||
return "unnamed_tool";
|
||||
}
|
||||
try {
|
||||
return name
|
||||
.replace(/[{}]/g, "")
|
||||
.replace(/[^a-zA-Z0-9_]/g, "_")
|
||||
.replace(/_+/g, "_")
|
||||
.replace(/^_|_$/g, "")
|
||||
.replace(/^(get|post|put|delete|patch|api)_/i, "")
|
||||
.replace(/^(get_|post_|put_|delete_|patch_|api_)+/gi, "")
|
||||
.replace(/(^_|_$)/g, "")
|
||||
|| "unnamed_tool";
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Error cleaning tool name:", error);
|
||||
return "unnamed_tool";
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Ambil OpenAPI JSON dari endpoint dan konversi ke tools MCP
|
||||
*/
|
||||
async function getMcpTools(url, filterTag) {
|
||||
try {
|
||||
console.log(`Fetching OpenAPI spec from: ${url}`);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const openApiJson = await response.json();
|
||||
const tools = convertOpenApiToMcpTools(openApiJson, filterTag);
|
||||
console.log(`✅ Successfully generated ${tools.length} MCP tools`);
|
||||
return tools;
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Error fetching MCP tools:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.OpenapiMcpServer = void 0;
|
||||
const mcp_tool_convert_1 = require("../lib/mcp_tool_convert");
|
||||
// ======================================================
|
||||
// Cache tools per URL
|
||||
// ======================================================
|
||||
const toolsCache = new Map();
|
||||
// ======================================================
|
||||
// Load OpenAPI → MCP Tools
|
||||
// ======================================================
|
||||
async function loadTools(openapiUrl, filterTag, forceRefresh = false) {
|
||||
const cacheKey = `${openapiUrl}::${filterTag}`;
|
||||
// Jika tidak forceRefresh, gunakan cache
|
||||
if (!forceRefresh && toolsCache.has(cacheKey)) {
|
||||
return toolsCache.get(cacheKey);
|
||||
}
|
||||
console.log(`[MCP] 🔄 Refreshing tools from ${openapiUrl} ...`);
|
||||
const fetched = await (0, mcp_tool_convert_1.getMcpTools)(openapiUrl, filterTag);
|
||||
// 🟢 Log jumlah & daftar tools
|
||||
console.log(`[MCP] ✅ Loaded ${fetched.length} tools`);
|
||||
if (fetched.length > 0) {
|
||||
console.log(`[MCP] Tools: ${fetched.map((t) => t.name).join(", ")}`);
|
||||
}
|
||||
toolsCache.set(cacheKey, fetched);
|
||||
return fetched;
|
||||
}
|
||||
// ======================================================
|
||||
// Eksekusi Tool HTTP
|
||||
// ======================================================
|
||||
async function executeTool(tool, args = {}, baseUrl, token) {
|
||||
const x = tool["x-props"] || {};
|
||||
const method = (x.method || "GET").toUpperCase();
|
||||
const path = x.path || `/${tool.name}`;
|
||||
const url = `${baseUrl}${path}`;
|
||||
const opts = {
|
||||
method,
|
||||
headers: Object.assign({ "Content-Type": "application/json" }, (token ? { Authorization: `Bearer ${token}` } : {})),
|
||||
};
|
||||
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
||||
opts.body = JSON.stringify(args || {});
|
||||
}
|
||||
const res = await fetch(url, opts);
|
||||
const contentType = res.headers.get("content-type") || "";
|
||||
const data = contentType.includes("application/json")
|
||||
? await res.json()
|
||||
: await res.text();
|
||||
return {
|
||||
success: res.ok,
|
||||
status: res.status,
|
||||
method,
|
||||
path,
|
||||
data,
|
||||
};
|
||||
}
|
||||
// ======================================================
|
||||
// JSON-RPC Handler (per node, per request)
|
||||
// ======================================================
|
||||
async function handleMCPRequest(request, tools) {
|
||||
const { id, method, params, credentials } = request;
|
||||
switch (method) {
|
||||
case "initialize":
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
result: {
|
||||
protocolVersion: "2024-11-05",
|
||||
capabilities: { tools: {} },
|
||||
serverInfo: { name: "n8n-mcp-server", version: "1.0.0" },
|
||||
},
|
||||
};
|
||||
case "tools/list":
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
result: {
|
||||
tools: tools.map((t) => {
|
||||
var _a;
|
||||
const inputSchema = typeof t.inputSchema === "object" && ((_a = t.inputSchema) === null || _a === void 0 ? void 0 : _a.type) === "object"
|
||||
? t.inputSchema
|
||||
: {
|
||||
type: "object",
|
||||
properties: {},
|
||||
required: [],
|
||||
};
|
||||
return {
|
||||
name: t.name,
|
||||
description: t.description || "No description provided",
|
||||
inputSchema,
|
||||
"x-props": t["x-props"],
|
||||
};
|
||||
}),
|
||||
},
|
||||
};
|
||||
case "tools/call": {
|
||||
const toolName = params === null || params === void 0 ? void 0 : params.name;
|
||||
const tool = tools.find((t) => t.name === toolName);
|
||||
if (!tool) {
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
error: { code: -32601, message: `Tool '${toolName}' not found` },
|
||||
};
|
||||
}
|
||||
try {
|
||||
const baseUrl = credentials === null || credentials === void 0 ? void 0 : credentials.baseUrl;
|
||||
const token = credentials === null || credentials === void 0 ? void 0 : credentials.token;
|
||||
const result = await executeTool(tool, (params === null || params === void 0 ? void 0 : params.arguments) || {}, baseUrl, token);
|
||||
const data = result.data.data;
|
||||
const isObject = typeof data === "object" && data !== null;
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
result: {
|
||||
content: [
|
||||
isObject
|
||||
? { type: "json", data: data }
|
||||
: { type: "text", text: JSON.stringify(data || result.data || result) },
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
catch (err) {
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
error: { code: -32603, message: err.message },
|
||||
};
|
||||
}
|
||||
}
|
||||
case "ping":
|
||||
return { jsonrpc: "2.0", id, result: {} };
|
||||
default:
|
||||
return {
|
||||
jsonrpc: "2.0",
|
||||
id,
|
||||
error: { code: -32601, message: `Method '${method}' not found` },
|
||||
};
|
||||
}
|
||||
}
|
||||
// ======================================================
|
||||
// NODE MCP TRIGGER
|
||||
// ======================================================
|
||||
class OpenapiMcpServer {
|
||||
constructor() {
|
||||
this.description = {
|
||||
displayName: 'OpenAPI MCP Server',
|
||||
name: 'openapiMcpServer',
|
||||
group: ['trigger'],
|
||||
version: 1,
|
||||
description: 'Runs an MCP Server inside n8n',
|
||||
icon: 'file:icon.svg',
|
||||
defaults: {
|
||||
name: 'OpenAPI MCP Server'
|
||||
},
|
||||
credentials: [
|
||||
{ name: "openapiMcpServerCredentials", required: true },
|
||||
],
|
||||
inputs: [],
|
||||
outputs: ['main'],
|
||||
webhooks: [
|
||||
{
|
||||
name: 'default',
|
||||
httpMethod: 'POST',
|
||||
responseMode: 'onReceived',
|
||||
path: '={{$parameter["path"]}}',
|
||||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: "Path",
|
||||
name: "path",
|
||||
type: "string",
|
||||
default: "mcp",
|
||||
},
|
||||
{
|
||||
displayName: "OpenAPI URL",
|
||||
name: "openapiUrl",
|
||||
type: "string",
|
||||
default: "",
|
||||
placeholder: "https://example.com/openapi.json",
|
||||
},
|
||||
{
|
||||
displayName: "Default Filter",
|
||||
name: "defaultFilter",
|
||||
type: "string",
|
||||
default: "",
|
||||
placeholder: "mcp | tag",
|
||||
},
|
||||
// 🟢 Tambahan agar terlihat jumlah tools di UI
|
||||
{
|
||||
displayName: 'Available Tools (auto-refresh)',
|
||||
name: 'toolList',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'refreshToolList',
|
||||
refreshOnOpen: true, // setiap node dibuka auto refresh
|
||||
},
|
||||
default: '',
|
||||
description: 'Daftar tools yang berhasil dimuat dari OpenAPI',
|
||||
},
|
||||
],
|
||||
};
|
||||
// ==================================================
|
||||
// LoadOptions untuk tampil di dropdown
|
||||
// ==================================================
|
||||
this.methods = {
|
||||
loadOptions: {
|
||||
// 🟢 otomatis refetch setiap kali node dibuka
|
||||
async refreshToolList() {
|
||||
const openapiUrl = this.getNodeParameter("openapiUrl", 0);
|
||||
const filterTag = this.getNodeParameter("defaultFilter", 0);
|
||||
if (!openapiUrl) {
|
||||
return [{ name: "❌ No OpenAPI URL provided", value: "" }];
|
||||
}
|
||||
const tools = await loadTools(openapiUrl, filterTag, true); // force refresh
|
||||
return tools.map((t) => ({
|
||||
name: t.name,
|
||||
value: t.name,
|
||||
description: t.description,
|
||||
}));
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
// ==================================================
|
||||
// WEBHOOK HANDLER
|
||||
// ==================================================
|
||||
async webhook() {
|
||||
const openapiUrl = this.getNodeParameter("openapiUrl", 0);
|
||||
const filterTag = this.getNodeParameter("defaultFilter", 0);
|
||||
// 🟢 selalu refresh (agar node terbaru)
|
||||
const tools = await loadTools(openapiUrl, filterTag, true);
|
||||
const creds = await this.getCredentials("openapiMcpServerCredentials");
|
||||
const body = this.getBodyData();
|
||||
if (Array.isArray(body)) {
|
||||
const responses = body.map((r) => handleMCPRequest(Object.assign(Object.assign({}, r), { credentials: creds }), tools));
|
||||
return {
|
||||
webhookResponse: await Promise.all(responses),
|
||||
};
|
||||
}
|
||||
const single = await handleMCPRequest(Object.assign(Object.assign({}, body), { credentials: creds }), tools);
|
||||
return {
|
||||
webhookResponse: single,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.OpenapiMcpServer = OpenapiMcpServer;
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128" aria-label="Icon AB square">
|
||||
<defs>
|
||||
<style>
|
||||
.bg { fill: #111827; rx: 20; }
|
||||
.letters { fill: #f9fafb; font-family: "Inter", "Segoe UI", Roboto, sans-serif; font-weight: 800; font-size: 56px; }
|
||||
</style>
|
||||
</defs>
|
||||
|
||||
<!-- rounded square background -->
|
||||
<rect class="bg" width="128" height="128" rx="20" ry="20"/>
|
||||
|
||||
<!-- letters -->
|
||||
<text class="letters" x="64" y="78" text-anchor="middle" dominant-baseline="middle">mcp</text>
|
||||
</svg>
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 550 B |
15
package.json
15
package.json
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "n8n-nodes-openapi-mcp-server",
|
||||
"name": "n8n-mcp-server",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.6",
|
||||
"scripts": {
|
||||
"build": "bun bin/build.ts",
|
||||
"publish": "bun bin/publish.ts"
|
||||
@@ -24,14 +24,5 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5"
|
||||
},
|
||||
"n8n": {
|
||||
"nodes": [
|
||||
"dist/nodes/OpenapiMcpServer.js"
|
||||
],
|
||||
"n8nNodesApiVersion": 1,
|
||||
"credentials": [
|
||||
"dist/credentials/OpenapiMcpServerCredentials.credentials.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
74
src/README.md
Normal file
74
src/README.md
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
# n8n-nodes-openapi-mcp-server
|
||||
|
||||
[](https://www.npmjs.com/package/n8n-nodes-openapi-mcp-server)
|
||||
[](https://www.npmjs.com/package/n8n-nodes-openapi-mcp-server)
|
||||
|
||||
This is an n8n node that acts as a trigger, running an MCP (Machine-readable Capability Protocol) server inside n8n. It dynamically generates tools from an OpenAPI specification URL and makes them available via a webhook.
|
||||
|
||||
## Installation
|
||||
|
||||
To install this node, follow these steps:
|
||||
|
||||
1. Go to your n8n instance.
|
||||
2. Go to **Settings > Community Nodes**.
|
||||
3. Click **Install** and enter `n8n-nodes-openapi-mcp-server`.
|
||||
4. Click **Install** again.
|
||||
|
||||
Alternatively, you can use npm in your n8n's custom nodes directory:
|
||||
|
||||
```bash
|
||||
npm install n8n-nodes-openapi-mcp-server
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
The node has the following properties:
|
||||
|
||||
- **Path**: The path for the webhook URL. Defaults to `mcp`.
|
||||
- **OpenAPI URL**: The URL of the `openapi.json` file to generate tools from.
|
||||
- **Default Filter**: An optional tag to filter the tools from the OpenAPI specification.
|
||||
- **Available Tools**: A read-only list of the tools that have been successfully loaded from the OpenAPI URL. This list refreshes automatically when you open the node.
|
||||
|
||||
### Credentials
|
||||
|
||||
This node requires credentials to authenticate with the target API.
|
||||
|
||||
- **Base URL**: The base URL of the API (e.g., `https://api.example.com`).
|
||||
- **Bearer Token**: The Bearer token for authentication.
|
||||
|
||||
## Usage
|
||||
|
||||
This node functions as a webhook trigger. Once activated, it will provide a webhook URL. You can send MCP requests to this URL to interact with the tools generated from the OpenAPI specification.
|
||||
|
||||
The node handles the following MCP methods:
|
||||
|
||||
- `initialize`: Initializes the connection.
|
||||
- `tools/list`: Lists all the available tools.
|
||||
- `tools/call`: Executes a specific tool with the given arguments.
|
||||
- `ping`: A simple ping to check the connection.
|
||||
|
||||
When a `tools/call` request is received, the node will make an HTTP request to the corresponding API endpoint defined in the OpenAPI specification, using the provided credentials.
|
||||
|
||||
## Example
|
||||
|
||||
Here is an example of how to call the `tools/list` method using `curl`. Replace `YOUR_N8N_WEBHOOK_URL` with the actual webhook URL provided by the node.
|
||||
|
||||
```bash
|
||||
curl -X POST YOUR_N8N_WEBHOOK_URL \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"jsonrpc": "2.0",
|
||||
"id": "123",
|
||||
"method": "tools/list",
|
||||
"params": {}
|
||||
}'
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
Contributions are welcome. Please open an issue or a pull request on the project's repository.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the ISC License.
|
||||
@@ -20,4 +20,4 @@
|
||||
"credentials/OpenapiMcpServerCredentials.credentials.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user