@nekzus/mcp-server 1.0.25 → 1.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
3
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
4
5
  import 'dotenv/config';
5
- import { z } from 'zod';
6
6
  import availableTools from './tools/index.js';
7
- import { schemaConverter } from './utils/schema.js';
8
7
  export class McpUtilityServer {
9
8
  constructor() {
10
9
  this.server = new Server({
@@ -19,60 +18,55 @@ export class McpUtilityServer {
19
18
  });
20
19
  this.transport = new StdioServerTransport();
21
20
  this.tools = availableTools;
22
- // Registrar el método tools/list
23
- this.server.setRequestHandler(z.object({
24
- method: z.literal('tools/list'),
25
- params: z.object({}).optional(),
26
- }), async () => {
27
- return {
28
- tools: this.tools.map((tool) => ({
29
- name: tool.name,
30
- description: tool.description,
31
- schema: tool.inputSchema,
32
- })),
33
- };
34
- });
21
+ // Configurar los manejadores de solicitudes
22
+ this.setupRequestHandlers();
35
23
  }
36
- registerTool(tool) {
37
- try {
38
- console.log(`[Tool Registration] Registering tool: ${tool.name}`);
39
- const zodSchema = schemaConverter.toZod(tool.inputSchema);
40
- const handler = tool.handler;
41
- // Registrar el método de la herramienta
42
- this.server.setRequestHandler(z.object({
43
- method: z.literal('tool'),
44
- params: z.object({
45
- name: z.literal(tool.name),
46
- arguments: zodSchema,
47
- }),
48
- }), async (request) => {
49
- const result = await handler(request.params.arguments, {});
24
+ setupRequestHandlers() {
25
+ // Listar herramientas disponibles
26
+ this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
27
+ tools: this.tools,
28
+ }));
29
+ // Manejar llamadas a herramientas
30
+ this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
31
+ const { name, arguments: args = {} } = request.params;
32
+ try {
33
+ const tool = this.tools.find((t) => t.name === name);
34
+ if (!tool) {
35
+ throw new Error(`Tool not found: ${name}`);
36
+ }
37
+ const handler = tool.handler;
38
+ const result = await handler(args);
39
+ return {
40
+ content: result.content.map((content) => {
41
+ const mappedContent = {
42
+ type: content.type,
43
+ text: typeof content.text === 'string'
44
+ ? content.text
45
+ : JSON.stringify(content.text, null, 2),
46
+ };
47
+ if (content.data !== undefined) {
48
+ return { ...mappedContent, data: content.data };
49
+ }
50
+ return mappedContent;
51
+ }),
52
+ isError: result.isError,
53
+ };
54
+ }
55
+ catch (error) {
50
56
  return {
51
57
  content: [
52
58
  {
53
59
  type: 'text',
54
- text: JSON.stringify(result),
60
+ text: error instanceof Error ? error.message : String(error),
55
61
  },
56
62
  ],
63
+ isError: true,
57
64
  };
58
- });
59
- console.log(`[Tool Registration] Successfully registered: ${tool.name}`);
60
- }
61
- catch (error) {
62
- console.error(`[Tool Registration] Failed to register tool ${tool.name}:`, error);
63
- throw error;
64
- }
65
- }
66
- initializeTools() {
67
- console.log(`[Server] Initializing ${this.tools.length} tools...`);
68
- for (const tool of this.tools) {
69
- this.registerTool(tool);
70
- }
71
- console.log('[Server] Tool initialization completed successfully');
65
+ }
66
+ });
72
67
  }
73
68
  async start() {
74
69
  try {
75
- this.initializeTools();
76
70
  await this.server.connect(this.transport);
77
71
  console.log('[Server] MCP Utility Server is running');
78
72
  console.log('[Server] Available tools:', this.tools.map((t) => t.name).join(', '));
@@ -10,7 +10,7 @@ export const greetingTool = {
10
10
  },
11
11
  required: ['name'],
12
12
  },
13
- handler: async (args, _extra) => {
13
+ handler: async (args) => {
14
14
  try {
15
15
  return {
16
16
  content: [
@@ -42,7 +42,7 @@ export const cardTool = {
42
42
  properties: {},
43
43
  required: [],
44
44
  },
45
- handler: async (_args, _extra) => {
45
+ handler: async () => {
46
46
  try {
47
47
  const card = getRandomCard();
48
48
  return {
@@ -69,28 +69,28 @@ export const cardTool = {
69
69
  };
70
70
  export const dateTimeTool = {
71
71
  name: 'datetime',
72
- description: 'Get current date and time for a specific timezone and locale',
72
+ description: 'Get the current date and time for a specific timezone',
73
73
  inputSchema: {
74
74
  type: 'object',
75
75
  properties: {
76
76
  timeZone: {
77
77
  type: 'string',
78
- description: 'Timezone identifier (e.g., America/New_York, Europe/London, Asia/Tokyo)',
78
+ description: 'Timezone identifier (e.g., "America/New_York")',
79
79
  },
80
80
  locale: {
81
81
  type: 'string',
82
- description: 'Locale identifier (e.g., en-US, es-ES, fr-FR)',
82
+ description: 'Locale identifier (e.g., "en-US")',
83
83
  },
84
84
  },
85
85
  },
86
- handler: async (args, _extra) => {
86
+ handler: async (args) => {
87
87
  try {
88
- const { date, time, timeZone } = getCurrentDateTime(args);
88
+ const { date, time, timezone } = getCurrentDateTime(args.timeZone, args.locale);
89
89
  return {
90
90
  content: [
91
91
  {
92
92
  type: 'text',
93
- text: `🗓️ Date: ${date}\n⏰ Time: ${time}\n🌍 Timezone: ${timeZone}`,
93
+ text: `🗓️ Date: ${date}\n⏰ Time: ${time}\n🌍 Timezone: ${timezone}`,
94
94
  },
95
95
  ],
96
96
  };
@@ -100,7 +100,7 @@ export const dateTimeTool = {
100
100
  content: [
101
101
  {
102
102
  type: 'text',
103
- text: 'Error retrieving date and time information',
103
+ text: 'Error getting date and time',
104
104
  },
105
105
  ],
106
106
  isError: true,
@@ -108,6 +108,4 @@ export const dateTimeTool = {
108
108
  }
109
109
  },
110
110
  };
111
- // Export all available tools
112
- const availableTools = [greetingTool, cardTool, dateTimeTool];
113
- export default availableTools;
111
+ export default [greetingTool, cardTool, dateTimeTool];
@@ -1,22 +1,28 @@
1
- export function getCurrentDateTime(options = {}) {
2
- const { timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone, locale = 'en-US' } = options;
3
- const now = new Date();
4
- const dateFormatter = new Intl.DateTimeFormat(locale, {
5
- timeZone,
6
- year: 'numeric',
7
- month: 'long',
8
- day: 'numeric',
9
- });
10
- const timeFormatter = new Intl.DateTimeFormat(locale, {
11
- timeZone,
12
- hour: '2-digit',
13
- minute: '2-digit',
14
- second: '2-digit',
15
- hour12: true,
16
- });
17
- return {
18
- date: dateFormatter.format(now),
19
- time: timeFormatter.format(now),
20
- timeZone,
21
- };
1
+ export function getCurrentDateTime(timeZone, locale) {
2
+ try {
3
+ const now = new Date();
4
+ const defaultTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
5
+ const options = {
6
+ timeZone: timeZone || defaultTimeZone,
7
+ dateStyle: 'full',
8
+ timeStyle: 'medium',
9
+ };
10
+ const formatter = new Intl.DateTimeFormat(locale || 'en-US', options);
11
+ const [datePart, timePart] = formatter.format(now).split(' at ');
12
+ return {
13
+ date: datePart,
14
+ time: timePart,
15
+ timezone: timeZone || defaultTimeZone,
16
+ };
17
+ }
18
+ catch (error) {
19
+ console.error('[DateTime] Error formatting date and time:', error);
20
+ const now = new Date();
21
+ const defaultTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
22
+ return {
23
+ date: now.toLocaleDateString(),
24
+ time: now.toLocaleTimeString(),
25
+ timezone: defaultTimeZone,
26
+ };
27
+ }
22
28
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nekzus/mcp-server",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
4
4
  "description": "Personal MCP Server implementation providing extensible utility functions and tools for development and testing purposes",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "bin": {
9
- "@nekzus/mcp-server": "dist/index.js"
9
+ "mcp-server": "dist/index.js"
10
10
  },
11
11
  "files": [
12
12
  "dist"