vat-validator-mcp 2.0.3 → 2.0.4

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vat-validator-mcp",
3
3
  "mcpName": "io.github.OjasKord/vat-validator-mcp",
4
- "version": "2.0.3",
4
+ "version": "2.0.4",
5
5
  "description": "VAT number validator for AI agents. EU VIES, UK HMRC, AU ABR — auto-detects jurisdiction. Fraud risk scoring and invoice name cross-check in one call.",
6
6
  "main": "src/server.js",
7
7
  "scripts": {
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "io.github.OjasKord/vat-validator-mcp",
4
4
  "title": "VAT Validator MCP",
5
5
  "description": "Validate EU, UK, AU VAT numbers for AI agents. EU ViDA e-invoicing compliance.",
6
- "version": "2.0.2",
6
+ "version": "2.0.4",
7
7
  "websiteUrl": "https://kordagencies.com",
8
8
  "repository": {
9
9
  "url": "https://github.com/OjasKord/vat-validator-mcp",
@@ -13,7 +13,7 @@
13
13
  {
14
14
  "registryType": "npm",
15
15
  "identifier": "vat-validator-mcp",
16
- "version": "2.0.2",
16
+ "version": "2.0.4",
17
17
  "transport": { "type": "stdio" },
18
18
  "environmentVariables": [
19
19
  { "name": "ANTHROPIC_API_KEY", "description": "Anthropic API key for AI-powered fraud risk analysis", "isRequired": true, "isSecret": true },
package/src/server.js CHANGED
@@ -7,7 +7,7 @@ const Stripe = require('stripe');
7
7
  const stripe = Stripe(process.env.STRIPE_SECRET_KEY);
8
8
 
9
9
  const PERSIST_FILE = '/tmp/vat_stats.json';
10
- const VERSION = '2.0.3';
10
+ const VERSION = '2.0.4';
11
11
 
12
12
  // Persistent device ID for HMRC fraud prevention headers (BATCH_PROCESS_DIRECT)
13
13
  const DEVICE_ID_FILE = path.join(__dirname, '..', 'device-id.txt');
@@ -100,6 +100,25 @@ async function redisSet(key, value) {
100
100
  } catch(e) {}
101
101
  }
102
102
 
103
+ async function redisExpire(key, seconds) {
104
+ try {
105
+ await fetch(
106
+ `${UPSTASH_URL}/expire/${encodeURIComponent(key)}/${seconds}`,
107
+ { method: 'POST', headers: { Authorization: `Bearer ${UPSTASH_TOKEN}` } }
108
+ );
109
+ } catch(e) {}
110
+ }
111
+
112
+ async function appendSessionLog(ip, tool) {
113
+ const ipSafe = ip.replace(/:/g, '_').replace(/\s/g, '');
114
+ const dayKey = new Date().toISOString().slice(0, 10);
115
+ const key = `${REDIS_PREFIX}:session:${ipSafe}:${dayKey}`;
116
+ const existing = await redisGet(key) || [];
117
+ existing.push({ tool, timestamp: new Date().toISOString() });
118
+ await redisSet(key, existing);
119
+ await redisExpire(key, 86400);
120
+ }
121
+
103
122
  async function redisKeys(pattern) {
104
123
  try {
105
124
  const res = await fetch(
@@ -754,6 +773,27 @@ const server = http.createServer(async (req, res) => {
754
773
  return;
755
774
  }
756
775
 
776
+ if (req.url === '/session-log' && req.method === 'GET') {
777
+ if (req.headers['x-stats-key'] !== STATS_KEY) { res.writeHead(401, cors); res.end(JSON.stringify({ error: 'Unauthorized' })); return; }
778
+ (async () => {
779
+ const keys = await redisKeys(`${REDIS_PREFIX}:session:*`);
780
+ const sessions = [];
781
+ for (const key of keys) {
782
+ const calls = await redisGet(key) || [];
783
+ if (!calls.length) continue;
784
+ const withoutPrefix = key.slice(`${REDIS_PREFIX}:session:`.length);
785
+ const dateIdx = withoutPrefix.lastIndexOf(':');
786
+ const ipPart = withoutPrefix.slice(0, dateIdx);
787
+ const date = withoutPrefix.slice(dateIdx + 1);
788
+ sessions.push({ ip: ipPart.slice(0, 8), date, calls, first_call: calls[0]?.timestamp || '', last_call: calls[calls.length - 1]?.timestamp || '' });
789
+ }
790
+ sessions.sort((a, b) => new Date(b.first_call) - new Date(a.first_call));
791
+ res.writeHead(200, { ...cors, 'Content-Type': 'application/json' });
792
+ res.end(JSON.stringify(sessions));
793
+ })();
794
+ return;
795
+ }
796
+
757
797
  if (req.url === '/trial-extension' && req.method === 'POST') {
758
798
  let body = ''; req.on('data', c => body += c);
759
799
  req.on('end', async () => {
@@ -845,6 +885,7 @@ const server = http.createServer(async (req, res) => {
845
885
  if (usageLog.length > 1000) usageLog.shift();
846
886
  toolUsageCounts[name] = (toolUsageCounts[name] || 0) + 1;
847
887
  saveStats();
888
+ appendSessionLog(ip, name).catch(() => {});
848
889
  const result = await executeTool(name, args || {});
849
890
  if (access.plan === 'metered' && access.stripeCustomerId) {
850
891
  reportMeteredUsage(access.stripeCustomerId, 'vat_query').catch(() => {});
@@ -893,6 +934,7 @@ const server = http.createServer(async (req, res) => {
893
934
  if (usageLog.length > 1000) usageLog.shift();
894
935
  toolUsageCounts[name] = (toolUsageCounts[name] || 0) + 1;
895
936
  saveStats();
937
+ appendSessionLog(ip, name).catch(() => {});
896
938
  const result = await executeTool(name, toolArgs || {});
897
939
  if (req._accessWarning) result._notice = req._accessWarning;
898
940