get-dictionaries.tsโข4.07 kB
/**
* MCP Tools: Get Dictionaries (Waybill Types, Error Codes, Akciz Codes)
*
* Allows Claude to query reference data from RS.ge
*/
import { z } from 'zod';
import type { RsWaybillSoapClient } from '../services/soap-client.js';
import { getLogger } from '../utils/logger.js';
import { formatErrorForUser } from '../utils/error-handler.js';
/**
* Tool: Get Waybill Types
*/
export const getWaybillTypesTool = {
name: 'get_waybill_types',
description: 'Get all available waybill types from RS.ge system',
inputSchema: {
type: 'object' as const,
properties: {},
required: [],
},
};
export async function executeGetWaybillTypes(
client: RsWaybillSoapClient
): Promise<string> {
const logger = getLogger();
try {
logger.info('Getting waybill types');
const types = await client.getWaybillTypes();
if (types.length === 0) {
return 'No waybill types found';
}
let response = `Available Waybill Types (${types.length}):\n\n`;
types.forEach((type: any) => {
response += `- Type ${type.TYPE_ID}: ${type.TYPE_NAME}\n`;
});
return response;
} catch (error) {
logger.error('Error in get_waybill_types tool', { error });
return formatErrorForUser(error);
}
}
/**
* Tool: Get Error Codes
*/
export const getErrorCodesTool = {
name: 'get_error_codes',
description: 'Get all error codes and their descriptions from RS.ge system',
inputSchema: {
type: 'object' as const,
properties: {},
required: [],
},
};
export async function executeGetErrorCodes(
client: RsWaybillSoapClient
): Promise<string> {
const logger = getLogger();
try {
logger.info('Getting error codes');
const codes = await client.getErrorCodes();
if (codes.length === 0) {
return 'No error codes found';
}
let response = `RS.ge Error Codes (${codes.length}):\n\n`;
codes.slice(0, 20).forEach((code: any) => {
response += `- ${code.CODE}: ${code.NAME}`;
if (code.DESCRIPTION) {
response += ` - ${code.DESCRIPTION}`;
}
response += '\n';
});
if (codes.length > 20) {
response += `\n... and ${codes.length - 20} more error codes`;
}
return response;
} catch (error) {
logger.error('Error in get_error_codes tool', { error });
return formatErrorForUser(error);
}
}
/**
* Tool: Get Akciz Codes (with optional search)
*/
export const getAkcizCodesInputSchema = z.object({
search: z.string()
.optional()
.describe('Optional search text to filter akciz codes'),
});
export const getAkcizCodesTool = {
name: 'get_akciz_codes',
description:
'Get akciz (excise) codes from RS.ge system. Optionally filter by search text.',
inputSchema: {
type: 'object' as const,
properties: {
search: {
type: 'string',
description: 'Optional search text to filter results',
},
},
required: [],
},
};
export async function executeGetAkcizCodes(
client: RsWaybillSoapClient,
input: unknown
): Promise<string> {
const logger = getLogger();
try {
const validated = getAkcizCodesInputSchema.parse(input || {});
logger.info('Getting akciz codes', { search: validated.search });
const codes = await client.getAkcizCodes(validated.search);
if (codes.length === 0) {
return validated.search
? `No akciz codes found matching "${validated.search}"`
: 'No akciz codes found';
}
let response = `Akciz Codes (${codes.length})`;
if (validated.search) {
response += ` matching "${validated.search}"`;
}
response += ':\n\n';
codes.slice(0, 20).forEach((code: any) => {
response += `- ${code.CODE}: ${code.NAME}`;
if (code.DESCRIPTION) {
response += ` - ${code.DESCRIPTION}`;
}
response += '\n';
});
if (codes.length > 20) {
response += `\n... and ${codes.length - 20} more codes`;
}
return response;
} catch (error) {
logger.error('Error in get_akciz_codes tool', { error });
return formatErrorForUser(error);
}
}