Skip to content

Commit 73a240f

Browse files
committed
simplify code
1 parent e79b7b3 commit 73a240f

7 files changed

Lines changed: 203 additions & 692 deletions

File tree

pkg/vmcp/client/client.go

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ package client
99

1010
import (
1111
"context"
12-
"encoding/json"
1312
"errors"
1413
"fmt"
1514
"io"
1615
"net"
1716
"net/http"
18-
"strings"
1917
"time"
2018

2119
"github.com/mark3labs/mcp-go/client"
@@ -386,13 +384,6 @@ func queryPrompts(ctx context.Context, c *client.Client, supported bool, backend
386384
return &mcp.ListPromptsResult{Prompts: []mcp.Prompt{}}, nil
387385
}
388386

389-
// convertContent converts a single mcp.Content item to vmcp.Content.
390-
// Delegates to the shared conversion package; kept here for backward compatibility
391-
// with tests that call it directly.
392-
func convertContent(content mcp.Content) vmcp.Content {
393-
return conversion.ConvertMCPContent(content)
394-
}
395-
396387
// ListCapabilities queries a backend for its MCP capabilities.
397388
// Returns tools, resources, and prompts exposed by the backend.
398389
// Only queries capabilities that the server advertises during initialization.
@@ -445,25 +436,10 @@ func (h *httpBackendClient) ListCapabilities(ctx context.Context, target *vmcp.B
445436

446437
// Convert tools
447438
for i, tool := range toolsResp.Tools {
448-
// Use a JSON round-trip to capture all schema fields (type, properties,
449-
// required, $defs, additionalProperties, etc.) rather than enumerating
450-
// them manually. This is forward-safe: any fields the SDK adds in future
451-
// versions are preserved automatically.
452-
inputSchema := make(map[string]any)
453-
if b, err := json.Marshal(tool.InputSchema); err == nil {
454-
if jsonErr := json.Unmarshal(b, &inputSchema); jsonErr != nil {
455-
logger.Debugf("Failed to decode tool input schema for %s; using type-only fallback: %v", tool.Name, jsonErr)
456-
inputSchema = map[string]any{"type": tool.InputSchema.Type}
457-
}
458-
} else {
459-
logger.Debugf("Failed to encode tool input schema for %s; using type-only fallback: %v", tool.Name, err)
460-
inputSchema = map[string]any{"type": tool.InputSchema.Type}
461-
}
462-
463439
capabilities.Tools[i] = vmcp.Tool{
464440
Name: tool.Name,
465441
Description: tool.Description,
466-
InputSchema: inputSchema,
442+
InputSchema: conversion.ConvertToolInputSchema(tool.InputSchema),
467443
BackendID: target.WorkloadID,
468444
}
469445
}
@@ -702,11 +678,7 @@ func (h *httpBackendClient) GetPrompt(
702678
logger.Debugf("Translating prompt name: %s (client-facing) → %s (backend)", name, backendPromptName)
703679
}
704680

705-
// Convert map[string]any to map[string]string
706-
stringArgs := make(map[string]string)
707-
for k, v := range arguments {
708-
stringArgs[k] = fmt.Sprintf("%v", v)
709-
}
681+
stringArgs := conversion.ConvertPromptArguments(arguments)
710682

711683
result, err := c.GetPrompt(ctx, mcp.GetPromptRequest{
712684
Params: mcp.GetPromptParams{
@@ -718,27 +690,9 @@ func (h *httpBackendClient) GetPrompt(
718690
return nil, fmt.Errorf("prompt get failed on backend %s: %w", target.WorkloadID, err)
719691
}
720692

721-
// Concatenate all prompt messages into a single string.
722-
// MCP prompts return messages with role and multi-modal content; only text
723-
// chunks are captured (non-text content is silently discarded — Phase 1 limitation).
724-
var sb strings.Builder
725-
for _, msg := range result.Messages {
726-
if msg.Role != "" {
727-
fmt.Fprintf(&sb, "[%s] ", msg.Role)
728-
}
729-
if textContent, ok := mcp.AsTextContent(msg.Content); ok {
730-
sb.WriteString(textContent.Text)
731-
sb.WriteByte('\n')
732-
}
733-
}
734-
prompt := sb.String()
735-
736-
// Extract _meta field from backend response
737-
meta := conversion.FromMCPMeta(result.Meta)
738-
739693
return &vmcp.PromptGetResult{
740-
Messages: prompt,
694+
Messages: conversion.ConvertPromptMessages(result.Messages),
741695
Description: result.Description,
742-
Meta: meta,
696+
Meta: conversion.FromMCPMeta(result.Meta),
743697
}, nil
744698
}

0 commit comments

Comments
 (0)