Why: external tool ecosystems speak MCP; the kernel had no way to mount them, so every external capability needed a bespoke builtin. Evidence: go vet ./... clean; go test ./... 11 packages ok. Tests run against a REAL stdio server (test binary re-exec via mcp.RunFakeServer) and httptest HTTP servers: initialize handshake, tools/list with pagination cap, tools/call success / tool-level isError / unknown-tool rpc error, JSON and SSE response modes, Mcp-Session-Id capture, manager registration as mcp__<server>__<tool>, namespace wildcard allowlist (mcp__fake__* keeps only that namespace, unknown wildcard fails closed), unreachable server failing the step, hung server bounded by per-request timeout, config validation (duplicate names, dual/missing transport, bad name chars), and an adapter end-to-end execution calling an MCP tool. Impact: new runtime/mcp package; native.Options gains MCP *mcp.Manager and Close() for process cleanup; tools.Registry.Restrict gains prefix/* namespace entries; server-provided metadata is capped (64 tools/server, 1 KiB descriptions, 64 KiB text results) and treated as untrusted input. Refs: plan B5; agent-execution standard (tool providers get authorized capability only).
18 lines
286 B
Go
18 lines
286 B
Go
package native
|
||
|
||
import (
|
||
"os"
|
||
"testing"
|
||
|
||
"agent-native/runtime/mcp"
|
||
)
|
||
|
||
// TestMain:MCP fake server 的 re-exec 分支(详见 mcp.RunFakeServer)。
|
||
func TestMain(m *testing.M) {
|
||
if os.Getenv(mcp.FakeServerEnv) == "1" {
|
||
mcp.RunFakeServer()
|
||
os.Exit(0)
|
||
}
|
||
os.Exit(m.Run())
|
||
}
|