2 Commits
Author SHA1 Message Date
sausheong 40fb986b3f feat: MCP adapter falls back to structured content when a tool returns no text
Servers that return their result only as structuredContent (no TextContent
block) reached the agent as an empty result. Serialize StructuredContent to
JSON in that case; when text is present it still wins, since the MCP spec
has tools send the same data as text.
2026-09-30 21:04:09 +08:00
sausheong 611198dc64 Document Harness v0.6.0 in README 2026-09-28 22:15:58 +08:00
3 changed files with 67 additions and 3 deletions

No files matched your search

+23 -3
View File
@@ -5,7 +5,7 @@ streaming agent loop, tool registry, session storage, compaction, and
token budgeting needed to run a multi-provider agent in production. BYO
concrete tools, BYO provider clients, BYO memory/knowledge-graph plugins.
> **Status: v0.4.2.** Latest tagged release. The `runtime` API
> **Status: v0.6.0.** Latest tagged release. The `runtime` API
> surface may still shift in the v0.x line — pin your version.
## Why Harness
@@ -26,6 +26,26 @@ opinions about how your agents should be deployed. There is no
`harness` binary. You import packages, compose a `Runtime`, and call
`rt.Run(ctx, msg, nil)`.
## What's in v0.6.0
[v0.6.0](https://github.com/sausheong/harness/releases/tag/v0.6.0) and
[v0.5.0](https://github.com/sausheong/harness/releases/tag/v0.5.0) add two
tools and raise the minimum Go version:
- **Go 1.26 required.** The module declares `go 1.26.0`, needed by the
Stagehand SDK. With the default `GOTOOLCHAIN=auto`, older toolchains
download 1.26 automatically; pinned CI images must be updated.
- **Natural-language browser.** `tools/stagehand` drives a browser with
instructions such as "click the Sign in button" instead of CSS selectors
(`act`, `observe`, `extract`, plus `navigate`, `get_text`, `screenshot`).
It runs on local Chrome or Browserbase, and Stagehand's inference goes
through your own `LLMProvider`.
- **Exa search.** `web.ExaSearchTool` (`exa_search`) returns ranked results
with query-relevant highlights, with category, domain and date filters.
- **Smaller changes.** PDF attachments are sent to Anthropic as document
blocks, Opus 5.5 uses adaptive low-effort thinking when reasoning is off,
and `WebFetchTool`'s output cap is raised to about 1M tokens.
## What's in v0.4.2
[v0.4.2](https://github.com/sausheong/harness/releases/tag/v0.4.2)
@@ -452,12 +472,12 @@ tests. See [`scripts/QUALIFICATION.md`](./scripts/QUALIFICATION.md).
## Status
`v0.4.2` is the latest tagged release. The v0.x line follows Go
`v0.6.0` is the latest tagged release. The v0.x line follows Go
module semver: minor bumps may break API, patch bumps are bug-fix
only. Pin your dependency:
```bash
go get github.com/sausheong/harness@v0.4.2
go get github.com/sausheong/harness@v0.6.0
```
Likely sources of v0.x churn before a v1.0.0:
+13
View File
@@ -79,6 +79,12 @@ func (a *mcpToolAdapter) Execute(ctx context.Context, input json.RawMessage) (to
// ToolResult: TextContent concatenated into Output (or Error if
// IsError), ImageContent collected into Images. Other content types
// (audio, embedded resources) are described in Output as a placeholder.
//
// StructuredContent is used only when there is no text: the MCP spec says
// a tool returning structured content SHOULD also send it serialized as a
// TextContent block, so when both are present the text already carries it.
// Servers that send structured content alone would otherwise reach the
// agent as an empty result.
func mcpResultToToolResult(res *sdk.CallToolResult) tool.ToolResult {
var text strings.Builder
var images []llm.ImageContent
@@ -103,6 +109,13 @@ func mcpResultToToolResult(res *sdk.CallToolResult) tool.ToolResult {
fmt.Fprintf(&text, "[unsupported MCP content: %T]", c)
}
}
if text.Len() == 0 && res.StructuredContent != nil {
if b, err := json.Marshal(res.StructuredContent); err == nil {
text.Write(b)
} else {
fmt.Fprintf(&text, "[unserializable MCP structured content: %v]", err)
}
}
out := tool.ToolResult{Images: images}
if res.IsError {
out.Error = text.String()
+31
View File
@@ -135,6 +135,37 @@ func TestMCPAdapter_ImageContentMapping(t *testing.T) {
var _ llm.ImageContent = res.Images[0]
}
func TestMCPAdapter_StructuredContentFallback(t *testing.T) {
cli := startInProcessServer(t, "srv", []sdkToolFixture{
stringArgTool("structured_only", "hits as structured content only", func(_ context.Context, _ *sdk.CallToolRequest) (*sdk.CallToolResult, error) {
return &sdk.CallToolResult{
Content: []sdk.Content{},
StructuredContent: map[string]any{"hits": []any{map[string]any{"text": "leave policy", "score": 0.9}}},
}, nil
}),
stringArgTool("both", "text and structured content", func(_ context.Context, _ *sdk.CallToolRequest) (*sdk.CallToolResult, error) {
return &sdk.CallToolResult{
Content: []sdk.Content{&sdk.TextContent{Text: "summary text"}},
StructuredContent: map[string]any{"hits": []any{}},
}, nil
}),
})
byName := map[string]int{}
for i, tl := range cli.Tools() {
byName[tl.Name()] = i
}
require.Len(t, byName, 2)
res, err := cli.Tools()[byName["mcp__srv__structured_only"]].Execute(context.Background(), json.RawMessage(`{}`))
require.NoError(t, err)
assert.Empty(t, res.Error)
assert.JSONEq(t, `{"hits":[{"text":"leave policy","score":0.9}]}`, res.Output)
res, err = cli.Tools()[byName["mcp__srv__both"]].Execute(context.Background(), json.RawMessage(`{}`))
require.NoError(t, err)
assert.Equal(t, "summary text", res.Output, "text wins when present; structured content is not duplicated")
}
func TestMCPClient_ConnectDiscovers(t *testing.T) {
cli := startInProcessServer(t, "srv", []sdkToolFixture{
stringArgTool("a", "first", func(_ context.Context, _ *sdk.CallToolRequest) (*sdk.CallToolResult, error) {