feat(build): install stdio MCP tool packages when the image is built

Aperta
#54 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, go, node.js, python, yaml

Direzione di ricerca

Start with pkg/agentkit/config/tool.go and validate.go, then read pkg/agentkit2llb/agent/convert.go and image.go to trace validation and image construction. Run the Go tests in pkg/agentkit/config and pkg/agentkit2llb/agent; add coverage for the specified validation and install behavior, then build the packaged-tools fixture and verify it starts with --network none. Done means both tools start offline, invalid package values fail clearly, and the docs are updated.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/build enhancement security

Problem

Most stdio MCP tools are started with uvx or npx:

tools:
  - name: fetch
    command: ["uvx", "mcp-server-fetch"]

The built image doesn't contain mcp-server-fetch. Each time a container starts, uvx downloads it and its dependencies from PyPI. npx does the same from npm. This causes four problems:

  1. Slow start. The first boot waits for downloads. The README even tells people to raise AGENTKIT_MCP_TIMEOUT to 180 seconds.
  2. No internet means no tools. Containers on locked-down clusters or offline networks can't start their tools.
  3. The code can change between starts. Without a pinned version, each start can pick up a newer release. Two containers from the same image can run different tool code. A bad or compromised release reaches running agents without anyone rebuilding.
  4. Image scanners and signatures miss it. They only cover what's inside the image, and the tool code isn't.

What

Add an optional package field to stdio tools. When it's set, AgentKit installs that exact version into the image at build time. The container then runs the installed program without downloading anything.

tools:
  - name: fetch
    package:
      pypi: mcp-server-fetch==<version>
    command: ["mcp-server-fetch"]

  - name: everything
    package:
      npm: "@modelcontextprotocol/server-everything@<version>"
    command: ["mcp-server-everything"]
  • pypi and npm are the two sources. They match the uvx and npx launchers the runtime images already include.
  • The version must be exact: ==1.2.3 for PyPI, @1.2.3 for npm. Version ranges and tags such as latest fail the build.
  • Tools without package keep working exactly as they do today.
  • /agent/agent.yaml doesn't change. The runtime runs command the same way as now; the program is simply already installed.
Out of scope
  • Downloading plain binaries with checksums. #43 (kind: Toolbox) covers that, and the download code could be shared later.
  • Lock files or hashes for dependencies. The tool's own version is pinned. Its dependencies are picked at build time and then fixed inside the image. Pinning them too can come later.
  • Private package indexes that need credentials. This would need BuildKit build secrets, so it's left for later.
  • Rejecting uvx or npx tools that have no package. They keep working, and the docs recommend package.

Why

  • Agents start in seconds and work without internet access.
  • Every container from the same image runs the same tool code.
  • Image scanners and signatures cover the tools too.
  • This is the point of AgentKit: one image that holds everything the agent needs except secrets.

How

Where things are
File What it does
pkg/agentkit/config/tool.go The Tool struct. Add the new field here.
pkg/agentkit/config/validate.go Tool checks: validateToolTransport, validateToolEnv and others.
pkg/agentkit/effective/agent.go Copies the config into the build-ready agent. Check that the new field is copied too.
pkg/agentkit2llb/agent/convert.go Builds the image. Today it starts from the runtime image and writes /agent/agent.yaml. Add the install steps here.
pkg/agentkit2llb/agent/image.go Image settings such as PATH. Tests are in image_test.go.
pkg/agentkit/abi/render.go Writes /agent/agent.yaml. Don't add package there.
runtimes/*/Dockerfile All three runtime images already include uv, node and npm.
Steps
  1. Schema. Add Package *ToolPackage to Tool, where ToolPackage has two fields: PyPI string (yaml:"pypi,omitempty") and NPM string (yaml:"npm,omitempty").
  2. Validation. Each of these rules fails the build with a clear message:
    • package is allowed only on stdio tools, meaning command is set. Remote tools can't use it.
    • Set exactly one of pypi or npm.
    • The version must be exact:
      • PyPI: name==version. Extras such as name[extra]==version are fine.
      • npm: name@version or @scope/name@version, where the version is a plain number such as 1.2.3.
      • Reject ranges, tags, URLs, git sources and file paths.
      • Use a strict pattern, because this text ends up in a build command.
    • When package is set, command[0] can't be uvx, uv, npx or npm. Example message: this tool is installed when the image is built; run its program directly, e.g. command: ["mcp-server-fetch"].
  3. Build. In convert.go, add one install step per packaged tool on top of the runtime image, before agent.yaml is written:
    • PyPI: uv tool install <spec>, with these environment variables:
      • UV_TOOL_DIR=/opt/agentkit-tools/uv
      • UV_TOOL_BIN_DIR=/opt/agentkit-tools/bin
      • UV_PYTHON_DOWNLOADS=never, so uv uses the image's Python 3.12 instead of downloading another one.
    • npm: npm install --global --prefix /opt/agentkit-tools <spec>. The programs end up in /opt/agentkit-tools/bin.
    • Pass the command as a list with llb.Args(...), never as one shell string.
    • Run the install as root. The agent runs as user 1000, so it can run the tools but can't change them.
    • In a multi-platform build, the step runs once per platform, so each platform gets its own native files.
    • If uv or npm is missing from the base image, fail with a clear message. That could happen once #52 lets people bring their own base image.
  4. PATH. In image.go, add /opt/agentkit-tools/bin to the end of PATH.
    • Tool processes already get PATH from the server. That's how uvx and npx are found today. So command: ["mcp-server-fetch"] should work without other changes.
    • Add a test that confirms this.
  5. No runtime change. Don't write package into /agent/agent.yaml, so the Python side doesn't need to change. If you decide it should be written there, note that the Python reader (runtimes/common/agentkit_serve_common/config.py) rejects unknown fields and would need updating.
Tests
  • Go unit tests in pkg/agentkit/config for each validation rule.
  • A Go test in pkg/agentkit2llb/agent that checks:
    • each packaged tool gets an install step with the exact arguments;
    • tools without package get no install step;
    • PATH includes /opt/agentkit-tools/bin.
  • A container test:
    • Add a fixture test/agentkitfile-packaged-tools.yaml with one PyPI tool and one npm tool.
    • Build it and run it with docker run --network none.
    • Check that /healthz returns 200 from inside the container, for example with python -c and urllib. Tools start before the server accepts requests, so a 200 shows both tools started with no network.
    • Add this check to the Docker job in .github/workflows/ci.yml, next to the existing fixture smoke tests. Run actionlint after editing workflows (see AGENTS.md).

Run:

go test ./...
make lint
Docs
  • docs/agentkitfile.md: document package with the examples and rules above.
  • README.md, in "Add MCP tools": show package as the recommended option and keep plain uvx as the quick one. Update the slow-first-boot note.

Done when

  • An agent with one PyPI tool and one npm tool builds, and its container starts with --network none with both tools ready.
  • Each invalid package value fails the build with a clear message.
  • A second build of the same file reuses the cached install step.
  • Tools without package work exactly as before.
  • The docs explain package and recommend it.
Lingua principale
Python
Stelle
7
Fork
5
Merge medio
3h 39m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di orka-agents/agentkit

Tutte le issue di orka-agents/agentkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.