Skip to content

Commit 53c8b26

Browse files
authored
Let Harnesses own function and MCP URL limits (#770)
* Let Harnesses own function and MCP URL limits * Admit MCP query URLs in the official-client check
1 parent 38df315 commit 53c8b26

26 files changed

Lines changed: 85 additions & 48 deletions

‎apps/daemon/internal/agent/claudesdk/mcp.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func validateMCPServers(servers []proto.MCPHTTPServer) error {
3434
endpoint, err := url.Parse(server.ServerURL)
3535
if !mcpLabel.MatchString(server.ServerLabel) || server.ServerLabel == "functions" || labels[server.ServerLabel] ||
3636
err != nil || (endpoint.Scheme != "http" && endpoint.Scheme != "https") || endpoint.Hostname() == "" || endpoint.User != nil ||
37-
strings.ContainsAny(server.ServerURL, "?#") || endpoint.Opaque != "" {
37+
strings.Contains(server.ServerURL, "#") || endpoint.Opaque != "" {
3838
return fmt.Errorf("claudesdk: unsupported HTTP MCP declaration")
3939
}
4040
if server.BearerToken != nil && (endpoint.Scheme != "https" || !agent.ValidMCPHTTPBearerToken(*server.BearerToken)) {

‎apps/daemon/internal/agent/claudesdk/mcp_bearer_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestMCPBearerRejectsInvalidCredentialBeforeStateCreation(t *testing.T) {
7575
t.Fatal("invalid credential wrote execution state", err)
7676
}
7777
}
78-
for _, url := range []string{"http://example.invalid/mcp", "https://example.invalid/mcp#", "https://example.invalid/mcp?", "https://user:secret@example.invalid/mcp"} {
78+
for _, url := range []string{"http://example.invalid/mcp", "https://example.invalid/mcp#", "https://user:secret@example.invalid/mcp"} {
7979
token := "synthetic-token"
8080
servers := []proto.MCPHTTPServer{{ConnectionOrigin: "service", ServerLabel: "fixture", ServerURL: url, BearerToken: &token}}
8181
if err := validateMCP(proto.PromptRequestPayload{DisableExecutionEnvironment: true, MCPHTTPServers: &servers}); err == nil {

‎apps/daemon/internal/agent/claudesdk/mcp_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestHTTPMCPDeclaration(t *testing.T) {
3535
case "url-auth":
3636
servers[0].ServerURL = "https://user:secret@example.invalid/mcp"
3737
case "query":
38-
servers[0].ServerURL += "?"
38+
servers[0].ServerURL += "?tenant=a"
3939
case "wildcard":
4040
tools = []string{"*"}
4141
servers[0].AllowedTools = &tools
@@ -47,7 +47,7 @@ func TestHTTPMCPDeclaration(t *testing.T) {
4747
req.DisableExecutionEnvironment = false
4848
}
4949
start, _, err := prepare(config, req)
50-
valid := mode == "unrestricted" || mode == "selected" || mode == "empty" || mode == "nil-slice" || mode == "auth" || mode == "required"
50+
valid := mode == "unrestricted" || mode == "selected" || mode == "empty" || mode == "nil-slice" || mode == "auth" || mode == "required" || mode == "query"
5151
if (err == nil) != valid {
5252
t.Fatalf("unexpected admission: %v", err)
5353
}

‎apps/daemon/internal/agent/codex/functions.go‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ type functionCalls struct {
2828

2929
func prepareFunctionTools(tools []proto.FunctionTool) (*functionCalls, error) {
3030
state := &functionCalls{names: map[string]bool{}, pending: map[string]*pendingFunction{}}
31-
if len(tools) > 64 {
32-
return nil, errors.New("at most 64 function tools are supported")
33-
}
3431
for _, tool := range tools {
3532
var schema map[string]any
3633
if strings.TrimSpace(tool.Name) == "" || state.names[tool.Name] || json.Unmarshal(tool.Parameters, &schema) != nil || schema == nil {

‎apps/daemon/internal/agent/codex/mcp_http_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func TestPublicMCPHTTPRejectsInvalidProfileAndStoredCredentials(t *testing.T) {
8181
for _, server := range []proto.MCPHTTPServer{
8282
{ConnectionOrigin: "service", ServerLabel: "codex_apps", ServerURL: "https://docs.example/mcp"},
8383
{ConnectionOrigin: "service", ServerLabel: "docs", ServerURL: "https://user:synthetic-secret@docs.example/mcp"},
84-
{ConnectionOrigin: "service", ServerLabel: "docs", ServerURL: "https://docs.example/mcp?token=synthetic-secret"},
8584
{ConnectionOrigin: "service", ServerLabel: "docs", ServerURL: "file:///tmp/mcp"},
8685
} {
8786
servers := []proto.MCPHTTPServer{server}

‎apps/daemon/internal/agent/mcode/environment_mcp.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func runtimeMCP(req proto.PromptRequestPayload) ([]map[string]any, error) {
3939
// pinned native HTTP client can forward them across redirect origins.
4040
func environmentHTTPMCP(item agent.MCPBinding) (map[string]any, error) {
4141
endpoint, err := url.Parse(item.ServerURL)
42-
if err != nil || (endpoint.Scheme != "http" && endpoint.Scheme != "https") || endpoint.Hostname() == "" || endpoint.User != nil || endpoint.Fragment != "" || endpoint.RawQuery != "" || endpoint.ForceQuery || endpoint.Opaque != "" || len(item.HTTPHeaders) != 0 {
42+
if err != nil || (endpoint.Scheme != "http" && endpoint.Scheme != "https") || endpoint.Hostname() == "" || endpoint.User != nil || endpoint.Fragment != "" || endpoint.Opaque != "" || len(item.HTTPHeaders) != 0 {
4343
return nil, fmt.Errorf("mcode: unsupported environment HTTP MCP declaration")
4444
}
4545
headers := []map[string]string{}

‎apps/daemon/internal/agent/mcp_binding.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func ResolveMCPBindings(req proto.PromptRequestPayload) ([]MCPBinding, error) {
8989
}
9090
case "http":
9191
endpoint, err := url.Parse(item.ServerURL)
92-
if err != nil || endpoint.Hostname() == "" || (endpoint.Scheme != "https" && endpoint.Scheme != "http") || endpoint.User != nil || endpoint.Fragment != "" || endpoint.Opaque != "" || (item.ConnectionOrigin == "service" && (endpoint.RawQuery != "" || endpoint.ForceQuery)) {
92+
if err != nil || endpoint.Hostname() == "" || (endpoint.Scheme != "https" && endpoint.Scheme != "http") || endpoint.User != nil || endpoint.Fragment != "" || endpoint.Opaque != "" {
9393
return nil, errors.New("invalid MCP endpoint")
9494
}
9595
if item.BearerToken != nil && (endpoint.Scheme != "https" || !ValidMCPHTTPBearerToken(*item.BearerToken)) {

‎contracts/agents-api/execution-tools.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ An Agent declares application functions, controls and MCP servers in `tools`, an
1313

1414
## Functions
1515

16-
A function declaration requires `name`, `description` and a JSON Schema in `parameters`; `defer_loading` defaults to false and cannot be null. Names are nonblank, unique and at most 512 bytes; a Session holds at most 64 function definitions. Saved references resolve into the Session snapshot, and the definitions stay fixed through native preparation and continuation.
16+
A function declaration requires `name`, `description` and a JSON Schema in `parameters`; `defer_loading` defaults to false and cannot be null. Names are nonblank and unique. Saved references resolve into the Session snapshot, and the definitions stay fixed through native preparation and continuation.
1717

1818
**Results.** A caller submits `agent.session.input.tool_result` events with `turn_id`, `call_id` and `success`, and optional nullable `error` and `output`. Output is a string or ordered text and image parts, subject to the Harness. Batches are atomic and keep field presence, original content and retry identity; public result Items and events always carry `output` and `error`, null when not submitted.
1919

@@ -85,7 +85,7 @@ Execution carries the resolved values to the Harness and validates them against
8585
}
8686
```
8787

88-
- `server_label` is nonempty and unique within the Session. Only the `http` transport is accepted; `server_url` is an absolute HTTP or HTTPS URL without credentials, query or fragment. Nonempty `headers` and `request_metadata` and an inline `authorization` are rejected.
88+
- `server_label` is nonempty and unique within the Session. Only the `http` transport is accepted; `server_url` is an absolute HTTP or HTTPS URL without credentials or fragment. Nonempty `headers` and `request_metadata` and an inline `authorization` are rejected.
8989
- [Public MCP connection origin](./environments.md#public-mcp-connection-origin) owns origin defaults, placement and credential authority; [Harness capabilities](./harness-capabilities.md#tools) owns per-Harness support.
9090
- Omitted or null `allowed_tools` permits every server tool; `[]` permits none.
9191
- `required: true` makes native thread creation and cold resume wait for the server to initialize; a failure stops execution without replacing retained history. It needs the Runtime's `mcp_http_required` capability. Public work can be accepted or queued during the wait.

‎contracts/agents-api/wire-semantics.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ A Session's effective configuration must also pass execution admission, which ap
186186
| Configuration | Message |
187187
| --- | --- |
188188
| A `reasoning.effort`, `reasoning.summary`, `service_tier`, `web_search` mode or setting, `programmatic_tool_calling` value or `text.verbosity` the Harness does not declare | A message naming the field, such as `reasoning.effort "max" is not supported by this Harness.`; see [tool policy](./execution-tools.md#web-search-and-programmatic-tool-calling) and [Harness capabilities](./harness-capabilities.md#execution-and-input) |
189-
| More than 64 functions, or a function name that is blank or longer than 512 bytes | "This service supports at most 64 function tools." or "Function names must be nonempty, unique and at most 512 bytes." |
189+
| A function name that is blank or repeated | "Function names must be nonempty and unique." |
190190
| Two MCP servers with one label | "Execution requires distinct MCP server labels." |
191191

192192
A per-Session `tools` replacement admits a Session whose saved tools would be rejected. Support for each tool and Harness is in [execution and tools](./execution-tools.md).

‎contracts/agents-api/zh/execution-tools.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "执行工具"
33
source: contracts/agents-api/execution-tools.md
4-
source_hash: 7608c08f707c1970f1365d9b5d5f0979a71af35c4b9ca82d64ec6d2d95344a2a
4+
source_hash: db52d727ddf370a8047089457227584e89faf2132546a164b170e6b475b28abb
55
---
66

77
Agent 在 `tools` 中声明应用函数、控制项和 MCP 服务器,并可在 `text.format` 中声明输出 schema。本契约说明 Core 如何验证声明、哪些内容跨越 Runtime 边界,以及调用方如何恢复待执行操作。[Harness 能力](harness-capabilities.md)列出各 Harness 在不同部署位置支持的操作。原生工作区工具和 Environment Plugin MCP 属于 [Environment](environments.md#skills-plugins-and-environment-mcp)。
@@ -15,7 +15,7 @@ Agent 在 `tools` 中声明应用函数、控制项和 MCP 服务器,并可在
1515

1616
## 函数 {#functions}
1717

18-
函数声明要求 `name`、`description` 和 `parameters` 中的 JSON Schema;`defer_loading` 默认为 false,不能为 null。名称必须非空白、唯一且最多 512 字节;每个 Session 最多有 64 个函数定义。保存的引用解析到 Session 快照,定义在原生准备和继续执行期间保持固定。
18+
函数声明要求 `name`、`description` 和 `parameters` 中的 JSON Schema;`defer_loading` 默认为 false,不能为 null。名称必须非空白且唯一。保存的引用解析到 Session 快照,定义在原生准备和继续执行期间保持固定。
1919

2020
**结果。** 调用方提交 `agent.session.input.tool_result` 事件,包含 `turn_id`、`call_id`、`success`,以及可选且可空的 `error` 和 `output`。输出为字符串或有序文本与图像部分,受 Harness 支持范围约束。批次原子处理并保留字段存在性、原始内容和重试身份;公开结果 Item 与事件始终包含 `output` 和 `error`,未提交时为 null。
2121

@@ -87,7 +87,7 @@ Core 发送 `PromptRequestPayload.ToolSearch` 和每个 `FunctionTool.DeferLoadi
8787
}
8888
```
8989

90-
- `server_label` 非空且在 Session 中唯一。仅接受 `http` 传输;`server_url` 为不带凭据、查询或片段的绝对 HTTP 或 HTTPS URL。非空 `headers`、`request_metadata` 和内联 `authorization` 被拒绝。
90+
- `server_label` 非空且在 Session 中唯一。仅接受 `http` 传输;`server_url` 为不带凭据或片段的绝对 HTTP 或 HTTPS URL。非空 `headers`、`request_metadata` 和内联 `authorization` 被拒绝。
9191
- [公开 MCP 连接来源](environments.md#public-mcp-connection-origin)定义来源默认值、部署位置和凭据权限;[Harness 能力](harness-capabilities.md#tools)定义各 Harness 支持范围。
9292
- 省略或 null 的 `allowed_tools` 允许所有服务器工具;`[]` 不允许任何工具。
9393
- `required: true` 使原生线程创建和冷恢复等待服务器初始化;失败会停止执行,不替换保留历史。它要求 Runtime 的 `mcp_http_required` 能力。等待期间公开工作可被接受或排队。

0 commit comments

Comments
 (0)