Title: mcpx: embedding mcpx -- a public Go API, the C ABI, WASM, and mcpx as its own upstream · Issue #1877 · developing-today/code · GitHub
Open Graph Title: mcpx: embedding mcpx -- a public Go API, the C ABI, WASM, and mcpx as its own upstream · Issue #1877 · developing-today/code
X Title: mcpx: embedding mcpx -- a public Go API, the C ABI, WASM, and mcpx as its own upstream · Issue #1877 · developing-today/code
Description: Relocated from dezren39/darwin-nix#84 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/nix...
Open Graph Description: Relocated from dezren39/darwin-nix#84 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue reference...
X Description: Relocated from dezren39/darwin-nix#84 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue refer...
Opengraph URL: https://github.com/developing-today/code/issues/1877
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mcpx: embedding mcpx -- a public Go API, the C ABI, WASM, and mcpx as its own upstream","articleBody":"Relocated from dezren39/nix#84 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/nix numbering).\n\nParent: #173\n\n## Summary\n\nTwo related questions from the notes. First: can a Go module be made accessible to C — and what would that mean for mcpx, whose entire implementation currently lives under `internal/` and is therefore not importable even from Go. Second: `support embedding/config/dynamic-add mcp endpoints, connect to self over sockets?` — the daemon serving itself, or another mcpx, as an upstream MCP server.\n\nThe short answers: Go-to-C works, in two build modes, with real constraints, and it is the *third* thing to build, not the first — the ordering is public Go package → C ABI → WASM, and each step is only worth taking if the one before it has a caller. Self-composition works today in principle and needs a loop guard and an identity before it is safe to recommend.\n\n## Original notes\n\n> - can i make a go module accessible c\n> - support embedding/config/dynamic-add mcp endpoints, connect to self over sockets?\n\n## Current state (what mcpx does today, with file refs)\n\n**There is no public Go API at all.** `cmd/mcpx/main.go` is 204 lines that import `internal/cli` and `internal/daemon`; every other package is under `internal/`, which the Go toolchain forbids any other module from importing. So today \"embed mcpx in a Go program\" means \"exec the binary\" or \"speak `/v1` over the socket\". Any C-ABI, WASM or embedding work is blocked on a decision that has nothing to do with C: **which packages become public, and what compatibility promise attaches to them.** That decision is the bulk of the work; `-buildmode=c-shared` on top of it is close to free.\n\nToolchain, verified on this machine: `go version go1.26.7 darwin/arm64`, matching `go.mod:3` (`go 1.26.7`).\n\n**What `go help buildmode` says here, verbatim, for the two relevant modes:**\n\n- `c-archive`: \"Build the listed main package, plus all packages it imports, into a C archive file. The only callable symbols will be those functions exported using a cgo //export comment. Requires exactly one main package to be listed.\"\n- `c-shared`: \"Build the listed main package, plus all packages it imports, into a C shared library. The only callable symbols will be those functions exported using a cgo //export comment. **On wasip1, this mode builds it to a WASI reactor/library, of which the callable symbols are those functions exported using a //go:wasmexport directive.** Requires exactly one main package to be listed.\"\n\nThat last sentence is the useful surprise: the same build mode covers the native C library *and* the WASM library, with a different export directive. One decision about \"what is the exported surface\" serves both.\n\n**Embedded tool sources already exist.** The daemon already serves tools that are not an upstream process: every `/v1` operation is proxied as an MCP tool (`internal/cli/serve.go:344`), adapters and OpenAPI operations are attached as `mcpserver.Extra` (`internal/cli/serve.go:328-346`). So \"embedding\" in the sense of \"mcpx hosts a tool surface in-process\" is shipped; it is the *external* embedding that does not exist.\n\n**Self-connection is not prevented.** A `servers` entry with `url: \"http://127.0.0.1:PORT/mcp\"` pointing at the daemon's own MCP endpoint (`defaults.ProtoMCPPath`) is an ordinary remote server entry and would be accepted by `POST /v1/servers` (`internal/api/ops_settings.go:82`). Nothing in `internal/pool` or `internal/mcpclient` checks for it. What happens then — `tools/list` returning a namespace containing a proxy of itself, growing on each reload — is untested. There is no unix-socket MCP transport today (`transport` is `stdio|http|sse`), so \"connect to self over sockets\" specifically would need one, which is the same `unix://` addition the plugin-model issue wants for socket plugins.\n\n## Approaches\n\nThese are ordered as stages, and each is separately shippable. A/B/C is genuinely \"how far to go\", so the recommendation is the whole ladder with a stopping rule.\n\n### Approach A — least recommended: go straight to `-buildmode=c-shared` over the current code\n\nAdd a `//export` shim package and ship `libmcpx.dylib`. It fails for a stack of reasons worth writing down once:\n\n- **There is nothing to export.** Everything useful is `internal/`. The shim would have to live inside the module and re-export internals, which silently makes them public with none of the thought that implies.\n- **cgo constraints are not cosmetic.** Exported functions must be in `package main` with an empty `func main() {}`; parameters and returns must be C-compatible types, so every rich Go value crosses as a JSON string or an opaque handle plus a free function; the cgo pointer rules forbid C code retaining a Go pointer, so *every* returned string is a `C.CString` the caller must free, and a leak is the caller's default behaviour.\n- **It forces `CGO_ENABLED=1` and a C toolchain** for that artifact, complicates the nix build and makes cross-compilation a per-target problem. (This is about `-buildmode=c-shared`/`c-archive` only. mcpx's normal build does not need cgo: a `CGO_ENABLED=0` build is fully static and works — #182 verified one — and the nix package and Containerfile use cgo today by choice, which #136 owns. A C-ABI build must not change that default.)\n- **The Go runtime comes with it.** Loading the library starts a scheduler, a GC and signal handlers inside the host process; two Go shared libraries in one process means two runtimes; `dlclose` is not safe.\n- **Statefulness has nowhere to live.** mcpx's useful operations are against a *daemon* with a config chain, a pool and a socket. A C function call is not a session, so the API degenerates into `mcpx_open(config) → handle` and `mcpx_call(handle, json) → json` — which is `/v1` over a socket, minus the socket, plus a runtime in the caller's address space.\n\nOnce the API is \"pass JSON, get JSON\", the honest comparison is against the thing that already exists: a unix socket and 60 declared operations with an OpenAPI document. The socket wins on every axis except raw call latency, and mcpx has no call-latency-bound caller.\n\n### Approach B — middle: a public Go package API, and nothing else yet\n\nPromote a small, deliberately chosen surface out of `internal/`:\n\n- a **client** package — a typed Go client for `/v1`, generated from the ops table the same way the MCP tools and the OpenAPI document already are (`internal/api/ops.go`). Cheap, obviously useful, and the Go twin of the harness-free TS core in #48. This alone answers most of what people mean by \"embed mcpx\".\n- an **embeddable daemon** package — construct a daemon with options, serve on a caller-supplied listener, shut down cleanly. `internal/daemon` is close to this already (`daemon.NewServer(Options)`, options struct, injected logger and settings schema at `internal/daemon/server.go:112-176`). The work is the promise, not the plumbing.\n- possibly the **declarative types** — `adapter.Spec`, `recipes.Recipe`, the settings registry — so a Go program can generate mcpx configuration without string-templating JSON.\n\nCost is the compatibility promise. Anything out of `internal/` is a thing that cannot be renamed for the life of a major version, and mcpx is pre-1.0 and refactoring fast. Mitigate with a `pkg/`-level split: the generated client (stable, because the ops table is the contract) versus an explicitly unstable package for the rest.\n\nB is a complete answer for Go callers and no answer at all for C, Python, Rust or a host that wants to sandbox mcpx.\n\n### Approach C — recommended: B first, then `c-shared`/`c-archive` over the *public* surface only if a caller exists, and treat WASM as the better sandbox story\n\nThe ladder, with the stopping rule stated at each rung:\n\n1. **Public Go client + embeddable daemon (B).** Do this. It has callers today: tests, `plugin/` tooling, anything in this repository, and anyone writing a Go plugin. Stop here unless a non-Go in-process caller appears.\n2. **`-buildmode=c-archive` before `c-shared`.** If a C caller does appear, the archive is the better default: static linking, no `.so` to ship or find at runtime, no `dlopen`/`dlclose` questions, no version skew between library and host. `c-shared` only when the host must load mcpx at runtime or several hosts must share one copy.\n3. **The exported surface is `mcpx_open`/`mcpx_call`/`mcpx_free`-shaped, generated from the ops table.** Same source of truth as `/v1`, MCP tools and OpenAPI, so the C header cannot drift — that generation discipline is the single most valuable property to preserve, and it is the reason to build this from the ops table rather than by hand.\n4. **WASM is the more interesting target and shares the build mode.** `GOOS=wasip1 GOARCH=wasm` with `-buildmode=c-shared` produces a WASI reactor whose exports are `//go:wasmexport` functions, per `go help buildmode` above. A host embeds it with wazero — a pure-Go, cgo-free WASM runtime, so a Go host embedding a WASM mcpx needs no C toolchain at all, which is strictly better than the C path for the Go-in-Go case. It is also the only option on this list that is *sandboxed*: the guest gets exactly the filesystem and capabilities the host grants. The hard limit is that wasip1 has no sockets, so a WASM mcpx cannot dial a daemon or spawn a server subprocess. That confines the WASM build to the pure parts — config parsing and merging, schema→TypeScript codegen, the preflight scanner (`internal/diagnose`), recipe and placeholder parsing, catalog ranking — which is a real and useful product (\"mcpx's analysis in a browser or a sandboxed host\") and is not the daemon.\n5. **Mark the trap explicitly:** none of this is `plugin.Open`. Extending mcpx is the plugin issue and is out-of-process; this issue is the opposite direction, mcpx inside somebody else.\n\n**And the self-connection half of the notes.** `connect to self over sockets?` — the daemon adding itself, or another mcpx, as an upstream MCP server. This is a genuinely good primitive and needs three things before it is safe:\n\n- **A `unix://` MCP transport**, so a local mcpx can be an upstream without a TCP port. The same addition the plugin-model issue needs; do it once.\n- **Identity and a loop guard.** Every mcpx instance already has a daemon key (`FingerprintConfig`) and writes `daemon-\u003ckey>.json`; the MCP `initialize` result should carry that identity, and the client should refuse an upstream whose identity is already in the current call's ancestry. Without it, self-connection is an infinite namespace expansion and a call that recurses until something runs out. Carry the ancestry in `_meta` on outbound calls — the mechanism already exists, opencode v2 uses it for session ids (#47).\n- **A reason.** The legitimate ones are real: a remote mcpx aggregating several machines' servers; a per-project daemon composed into a user-level one; a restricted view of a daemon exposed to a less-trusted agent. Self-connection as *self* — the same daemon, no filtering — has no use case and should be a hard error with a clear message rather than a documented capability.\n\nRecommended because it spends effort in the order the value arrives, does not commit to a C ABI before a C caller exists, and gets the composition primitive (which is cheap and immediately useful) without shipping a recursion bomb.\n\n## Open questions\n\n- Which packages go public first, and under what stability promise? Pre-1.0, \"public but unstable, documented as such\" is defensible and is what most Go projects do badly.\n- Is the generated Go `/v1` client actually wanted, or is `net/http` plus the OpenAPI document enough for every real Go caller?\n- Does anyone actually want the C ABI? The bullet is a question (\"can i\"), and the answer may simply be \"yes, here is what it costs, and no we are not doing it yet\". Answering it in the issue may be the whole deliverable.\n- For WASM: is the pure-analysis subset worth packaging on its own, and does the codegen path have any filesystem or network dependency that would have to be lifted out first?\n- `c-archive` on wasip1 — does it behave like `c-shared` there, or is the reactor mode `c-shared`-only? The help text only documents the wasip1 behaviour for `c-shared`.\n- Self-connection: does a composed upstream mcpx's namespaces get re-prefixed, and how deep may composition go before `mcpx catalog` is unusable?\n- Is a remote mcpx-as-upstream just the existing `url` + `transport: http` server entry with a nicer name, or does it want its own kind so that mcpx can use the richer `/v1` surface rather than only MCP? The latter is more capable and is a second protocol between mcpx instances.\n\n## Ease · Impact · Related\n\n**Ease:** M for the public Go client and embeddable daemon; M for the `unix://` transport plus identity and loop guard; L for the C ABI; L for a useful WASM subset. **Impact:** med — high for the Go package API and self-composition, low for the C ABI until a caller names itself.\n\n**Depends on / related:** #48 (the harness-free TS core is the same idea in the other language; the Go client is its twin), #80 (shares the `unix://` transport and the \"not `plugin.Open`\" conclusion), #83 (self-composition is one more tool source; a composed upstream's namespaces follow #83's collision rules, collision 4), #82 (a detached plugin becomes a `unix://` server), #49 (CI for every package — a public surface needs one), #87 (composition makes daemon lifetime harder; #87 owns the lifetime rule, collision 9), #88 (daemon identity lives in the info file this issue's loop guard would reuse), #136 (static-build policy), #5, #78. (#52, leaked daemons, is closed — fixed in #182.)\n\nSecurity/auth deferred; see tracker.\n\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-28T22:13:36Z","url":"https://github.com/developing-today/code/issues/1877"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a33e8903-cfa9-a3af-d6a0-bb7e5ed12ad2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D45A:2FDEEB:317BBD:408D81:6B0616BF |
| html-safe-nonce | bd7b494c390766aefbc3c0697ad5cbdaf336b154c33b3ad4513887a7efd06c48 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDVBOjJGREVFQjozMTdCQkQ6NDA4RDgxOjZCMDYxNkJGIiwidmlzaXRvcl9pZCI6IjI0ODkzMDk1NTI3Mzk0ODk0NzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8c58a8751bd13ad26d56610ff8c3fd7572233087dd474f2170860c91370463b9 |
| hovercard-subject-tag | issue:6088461148 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/1877/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f50ba7b69c9e9f461be76843af612e806c163945c00a8c183d5eb4268feb1332/developing-today/code/issues/1877 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f50ba7b69c9e9f461be76843af612e806c163945c00a8c183d5eb4268feb1332/developing-today/code/issues/1877 |
| og:image:alt | Relocated from dezren39/darwin-nix#84 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue reference... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 97d4714e567728e1f85f88b0cf68c89f0f8a3dc41e8869af7aeb8195ad990374 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 866f202ebf7ac5aff8f633417d9fd8a53818a977 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width