Feature/MCP (Model Context Protocol) (#4134)

add mcp tools
This commit is contained in:
Henry Heng
2025-03-06 13:57:18 +00:00
committed by GitHub
parent 9c22bee991
commit 713ed26971
21 changed files with 1321 additions and 105 deletions
@@ -0,0 +1,74 @@
import { z } from 'zod'
import { INode } from '../../../src/Interface'
import { DynamicStructuredTool } from '../CustomTool/core'
const code = `
const now = new Date();
// Format date as YYYY-MM-DD
const date = now.toISOString().split('T')[0];
// Get time in HH:MM:SS format
const time = now.toTimeString().split(' ')[0];
// Get day of week
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const day = days[now.getDay()];
// Get timezone information
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const timezoneOffset = now.getTimezoneOffset();
const timezoneOffsetHours = Math.abs(Math.floor(timezoneOffset / 60));
const timezoneOffsetMinutes = Math.abs(timezoneOffset % 60);
const timezoneOffsetFormatted =
(timezoneOffset <= 0 ? '+' : '-') +
timezoneOffsetHours.toString().padStart(2, '0') + ':' +
timezoneOffsetMinutes.toString().padStart(2, '0');
return {
date,
time,
day,
timezone,
timezoneOffset: timezoneOffsetFormatted,
iso8601: now.toISOString(),
unix_timestamp: Math.floor(now.getTime() / 1000)
};
`
class CurrentDateTime_Tools implements INode {
label: string
name: string
version: number
description: string
type: string
icon: string
category: string
baseClasses: string[]
constructor() {
this.label = 'CurrentDateTime'
this.name = 'currentDateTime'
this.version = 1.0
this.type = 'CurrentDateTime'
this.icon = 'currentDateTime.svg'
this.category = 'Tools'
this.description = 'Get todays day, date and time.'
this.baseClasses = [this.type, 'Tool']
}
async init(): Promise<any> {
const obj = {
name: 'current_date_time',
description: 'Useful to get current day, date and time.',
schema: z.object({}),
code: code
}
let dynamicStructuredTool = new DynamicStructuredTool(obj)
return dynamicStructuredTool
}
}
module.exports = { nodeClass: CurrentDateTime_Tools }
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-timezone"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M20.884 10.554a9 9 0 1 0 -10.337 10.328" /><path d="M3.6 9h16.8" /><path d="M3.6 15h6.9" /><path d="M11.5 3a17 17 0 0 0 -1.502 14.954" /><path d="M12.5 3a17 17 0 0 1 2.52 7.603" /><path d="M18 18m-4 0a4 4 0 1 0 8 0a4 4 0 1 0 -8 0" /><path d="M18 16.5v1.5l.5 .5" /></svg>

After

Width:  |  Height:  |  Size: 588 B