lookup-tin.tsโข1.75 kB
/**
* MCP Tool: Lookup Company Name from TIN
*
* Allows Claude to lookup company names by TIN
*/
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';
/**
* Input schema for lookup_tin tool
*/
export const LookupTinInputSchema = z.object({
tin: z.string()
.min(9)
.max(11)
.describe('Tax identification number (TIN) to lookup'),
});
export type LookupTinInput = z.infer<typeof LookupTinInputSchema>;
/**
* Tool definition for MCP server
*/
export const lookupTinTool = {
name: 'lookup_tin',
description:
'Look up a company or person name from their TIN (Tax Identification Number) ' +
'in the RS.ge system.',
inputSchema: {
type: 'object' as const,
properties: {
tin: {
type: 'string',
description: 'Tax identification number (TIN) - 9 to 11 digits',
minLength: 9,
maxLength: 11,
},
},
required: ['tin'],
},
};
/**
* Execute lookup_tin tool
*/
export async function executeLookupTin(
client: RsWaybillSoapClient,
input: unknown
): Promise<string> {
const logger = getLogger();
try {
// Validate input
const validated = LookupTinInputSchema.parse(input);
logger.info('Looking up TIN', { tin: validated.tin });
// Call SOAP API
const name = await client.getNameFromTin(validated.tin);
if (!name || name.trim() === '') {
return `No company or person found for TIN: ${validated.tin}`;
}
return `TIN ${validated.tin}: ${name}`;
} catch (error) {
logger.error('Error in lookup_tin tool', { error });
return formatErrorForUser(error);
}
}