Server4Agent

Guides

A full agent loop

Connect Server4Agent to your agent over MCP and it can build and ship software on its own. The model sees Server4Agent's tools and decides when to use them.

The loop

This page shows the lower-level path. Your agent drives the primitives itself. If you just want a build done, call prompt and let the build agent handle it (see Examples). The loop below is for cases where your agent wants direct control over each step.

Expose Server4Agent's MCP tools to your agent, then run a normal tool-calling loop. Your agent provisions a server, writes files, runs commands, and deploys, all by emitting tool calls. Framework-agnostic Python; the same pattern works in any runtime that speaks MCP.

agent.py
import asyncio
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

MCP_URL = "https://mcp.server4agent.com"
HEADERS = {"Authorization": f"Bearer {SERVER4AGENT_API_KEY}"}

async def run(goal: str):
    async with streamablehttp_client(MCP_URL, headers=HEADERS) as (r, w, _):
        async with ClientSession(r, w) as mcp:
            await mcp.initialize()

            # Server4Agent's tools become callable functions for your model.
            tools = (await mcp.list_tools()).tools

            messages = [{"role": "user", "content": goal}]
            while True:
                # your LLM of choice, it sees the Server4Agent tools
                reply = llm.chat(messages, tools=tools)

                if not reply.tool_calls:
                    print(reply.content)        # agent is done
                    return

                for call in reply.tool_calls:
                    # the model decided to create_server / write_file / deploy / ...
                    result = await mcp.call_tool(call.name, call.arguments)
                    messages.append({
                        "role": "tool",
                        "tool_call_id": call.id,
                        "content": result.content[0].text,
                    })

asyncio.run(run("Build a landing page with a waitlist form and deploy it."))

What the agent does

You give it a goal; it figures out the steps. A common trace looks like this:

trace
# A typical trace the model produces on its own:
→ create_server()                                  # gets srv_2k9, a persistent box
→ write_file(srv_2k9, "app/page.tsx", "...")       # authors the app
→ write_file(srv_2k9, "package.json", "...")
→ exec(srv_2k9, "npm install && npm run build")    # builds it
→ deploy(srv_2k9)                                  # → https://srv_2k9.apps.server4agent.com
"Done, your waitlist page is live at https://srv_2k9.apps.server4agent.com"

Long-running work

Builds and deploys can take a while. Rather than poll, subscribe to webhooks and let your agent react when the deployment goes live.

webhook.sh
# Don't block your agent waiting for long builds, subscribe to events.
curl -X POST https://api.server4agent.com/webhooks \
  -H "Authorization: Bearer $SERVER4AGENT_API_KEY" \
  -d '{ "url": "https://example.com/hooks", "events": ["deployment.live"] }'

That's the whole model: your agent brings the intelligence, Server4Agent gives it hands, a real server, a workspace, and a public URL.

Connect an agent

Create a key, paste the MCP config, and give your agent a persistent server it can build on.

MCP setup