@agentvalet/mcp-server 0.3.3 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.js +48 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -325,6 +325,40 @@ async function fetchWithAuth(url, init) {
325
325
  function errorContent(message) {
326
326
  return { content: [{ type: "text", text: message }], isError: true };
327
327
  }
328
+ // Return helper that gives an MCP-aware host the structured content directly
329
+ // (no parse step), while still emitting the text-content envelope every MCP
330
+ // client understands. Avoids the "list of length 1 with empty fields → let me
331
+ // parse the wrapper" round-trip Claude does on tool results that are raw
332
+ // JSON strings — every read-heavy use_platform call pays that cost otherwise.
333
+ //
334
+ // If `body` isn't valid JSON, we just return the text envelope unchanged —
335
+ // callers that emit prose (summaries, error strings) get the old behaviour.
336
+ function jsonContent(body) {
337
+ const parsed = tryParseJson(body);
338
+ if (parsed === undefined) {
339
+ return { content: [{ type: "text", text: body }] };
340
+ }
341
+ return {
342
+ content: [{ type: "text", text: body }],
343
+ structuredContent: parsed,
344
+ };
345
+ }
346
+ function tryParseJson(text) {
347
+ const trimmed = text.trim();
348
+ // Only attempt parse if it looks structured. Avoids parsing a stray "true"
349
+ // / number / etc. into structuredContent and confusing the host.
350
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("["))
351
+ return undefined;
352
+ try {
353
+ const v = JSON.parse(trimmed);
354
+ if (v && typeof v === "object")
355
+ return v;
356
+ return undefined;
357
+ }
358
+ catch {
359
+ return undefined;
360
+ }
361
+ }
328
362
  // ---------------------------------------------------------------------------
329
363
  // Tool handlers
330
364
  // ---------------------------------------------------------------------------
@@ -343,7 +377,7 @@ async function handleListPlatforms() {
343
377
  const body = await response.text();
344
378
  if (!response.ok)
345
379
  return errorContent(`Proxy error ${response.status}: ${body}`);
346
- return { content: [{ type: "text", text: body }] };
380
+ return jsonContent(body);
347
381
  }
348
382
  // Translates a fetch() failure into something an end-user can actually act on.
349
383
  // The default "Network error: fetch failed" message tells a non-developer
@@ -409,7 +443,7 @@ async function handleUsePlatform(params, progressToken) {
409
443
  }
410
444
  if (!response.ok)
411
445
  return errorContent(`Proxy error ${response.status}: ${body}`);
412
- return { content: [{ type: "text", text: body }] };
446
+ return jsonContent(body);
413
447
  }
414
448
  async function waitForApproval(approvalId, originalCall, progressToken) {
415
449
  const startedAt = Date.now();
@@ -465,18 +499,13 @@ async function waitForApproval(approvalId, originalCall, progressToken) {
465
499
  // Timed out — fall through to async-recap path. The action is still
466
500
  // queued and will run when the owner approves; the user is notified via
467
501
  // push/email at that point. Layer 4's list_my_pending_actions surfaces it.
468
- return {
469
- content: [{
470
- type: "text",
471
- text: JSON.stringify({
472
- status: "pending_approval",
473
- approval_id: approvalId,
474
- message: `Owner hasn't approved within ${APPROVAL_POLL_BUDGET_MS / 1000}s. ` +
475
- `The action is queued — your owner will be notified, and you'll see it ` +
476
- `complete next time we chat (or you can ask me to check pending actions).`,
477
- }),
478
- }],
479
- };
502
+ return jsonContent(JSON.stringify({
503
+ status: "pending_approval",
504
+ approval_id: approvalId,
505
+ message: `Owner hasn't approved within ${APPROVAL_POLL_BUDGET_MS / 1000}s. ` +
506
+ `The action is queued — your owner will be notified, and you'll see it ` +
507
+ `complete next time we chat (or you can ask me to check pending actions).`,
508
+ }));
480
509
  }
481
510
  function safeJsonParse(text) {
482
511
  try {
@@ -517,7 +546,7 @@ async function handleAgentRegister(args) {
517
546
  const body = await response.text();
518
547
  if (!response.ok)
519
548
  return errorContent(`Proxy error ${response.status}: ${body}`);
520
- return { content: [{ type: "text", text: body }] };
549
+ return jsonContent(body);
521
550
  }
522
551
  async function handleAgentStatus(token) {
523
552
  let response;
@@ -533,7 +562,7 @@ async function handleAgentStatus(token) {
533
562
  const body = await response.text();
534
563
  if (!response.ok)
535
564
  return errorContent(`Proxy error ${response.status}: ${body}`);
536
- return { content: [{ type: "text", text: body }] };
565
+ return jsonContent(body);
537
566
  }
538
567
  async function handleAuthzenEvaluate(platformId, scope) {
539
568
  const authzenBody = {
@@ -554,7 +583,7 @@ async function handleAuthzenEvaluate(platformId, scope) {
554
583
  const body = await response.text();
555
584
  if (!response.ok)
556
585
  return errorContent(`Proxy error ${response.status}: ${body}`);
557
- return { content: [{ type: "text", text: body }] };
586
+ return jsonContent(body);
558
587
  }
559
588
  async function handleListMyPendingActions() {
560
589
  if (AGENT_PRIVATE_KEY_RAW === null) {
@@ -571,7 +600,7 @@ async function handleListMyPendingActions() {
571
600
  const text = await response.text();
572
601
  if (!response.ok)
573
602
  return errorContent(`Proxy error ${response.status}: ${text}`);
574
- return { content: [{ type: "text", text }] };
603
+ return jsonContent(text);
575
604
  }
576
605
  async function handleReportSelfDiagnostic(args) {
577
606
  if (AGENT_PRIVATE_KEY_RAW === null) {
@@ -600,7 +629,7 @@ async function handleReportSelfDiagnostic(args) {
600
629
  const text = await response.text();
601
630
  if (!response.ok)
602
631
  return errorContent(`Proxy error ${response.status}: ${text}`);
603
- return { content: [{ type: "text", text }] };
632
+ return jsonContent(text);
604
633
  }
605
634
  // ---------------------------------------------------------------------------
606
635
  // Connect transport
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvalet/mcp-server",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "AgentValet MCP server — lets AI agents call approved platforms via the AgentValet proxy",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",