tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

Runtime error "Server error: Netdev not set" in wasip2

Open Mossaka opened this issue 8 months ago • 8 comments

I could compile a MCP server using mcp-go to wasip2 target, with the wasi-http-go interface and disabling the stdio transport due to #4865. However, when I run this component on wasmtime with wasi-http capability, I got a runtime error saying "server error: netdev not set". Would love some help on figuring out why is a netdev even being used in the first place.

wasmtime run -Shttp main.wasm
2025/05/01 19:25:03 SSE server listening on :8080
2025/05/01 19:25:03 Server error: Netdev not set

https://github.com/tinygo-org/net/blob/main/netdev.go#L147

Mossaka avatar May 01 '25 19:05 Mossaka

What did you do to get the example building?

(I've fixed the os/signal issues but adding wasi-http-go I get

~/go/src/github.com/mark3labs/mcp-go/examples/everything $ tinygo build -target=wasip2
error: failed to encode a component from module

Caused by:
    0: failed to decode world from module
    1: module was not valid
    2: module requires an import interface named `wasi:http/[email protected]`
`wasm-tools component new` failed: exit status 1
~/go/src/github.com/mark3labs/mcp-go/examples/everything $ git diff .
diff --git a/examples/everything/main.go b/examples/everything/main.go
index fa1c304..90f69ec 100644
--- a/examples/everything/main.go
+++ b/examples/everything/main.go
@@ -9,6 +9,8 @@ import (

        "github.com/mark3labs/mcp-go/mcp"
        "github.com/mark3labs/mcp-go/server"
+
+       _ "github.com/ydnar/wasi-http-go/wasihttp"
 )

 type ToolName string

dgryski avatar May 02 '25 21:05 dgryski

Sorry, you need a WIT file for wasi-http. I've pushed my changes to a forked branch and you may see the diff here. To run it, run the following command

cd examples/everything
tinygo build -target=wasip2.json main.go
wasmtime run -Shttp main.wasm

where wasip2.json is

{
        "inherits": ["wasip2"],
        "wit-package": "./wit/proxy.wit",
        "wit-world": "go:http/proxy",
        "emulator": "wasmtime serve -Scli --dir={tmpDir}::/tmp {}"
}

Mossaka avatar May 03 '25 00:05 Mossaka

That is not working for me:

~/go/src/github.com/mark3labs/mcp-go/examples/everything $ git show |head -1
commit 78fa3977d55f5f3cc2e3a6e6225833af122c0915
~/go/src/github.com/mark3labs/mcp-go/examples/everything $ tinygo build -target=wasip2.json main.go
error: expected `world`, `interface` or `use`, found keyword `package`
     --> ./wit/proxy.wit:38:1
      |
   38 | package wasi:[email protected] {
      | ^------
`wasm-tools component embed` failed: exit status 1

dgryski avatar May 08 '25 23:05 dgryski

Do you have the same exact WIT file as this one? Could you please check your wasm-tools version?

Mossaka avatar May 12 '25 16:05 Mossaka

I think my wasip2 build stuff is broken at the moment. I'll fix it and come back to this.

dgryski avatar May 12 '25 17:05 dgryski

Ok, I'm able to reproduce this now.

dgryski avatar May 12 '25 17:05 dgryski

From diving into the source code, it appears we need a driver in https://github.com/tinygo-org/drivers (or elsewhere) that calls https://pkg.go.dev/tinygo.org/x/drivers/netdev#UseNetdev . Without that, the network device is left as https://github.com/tinygo-org/net/blob/main/netdev.go#L149 which always returns errors.

dgryski avatar May 12 '25 17:05 dgryski

I guess we could add sockets to wasip2

ydnar avatar May 12 '25 21:05 ydnar