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
Expose Server4Agent's MCP tools to your model, then run a normal tool-calling loop. The agent provisions a server, writes files, runs commands, and deploys, all by emitting tool calls. This example is framework-agnostic Python; the same pattern works in any agent runtime that speaks MCP.
import asyncio
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
MCP_URL = "https://mcp.server4agent.com"
HEADERS = {"Authorization": f"Bearer {AGENTSERVER_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:
# A typical trace the model produces on its own:
→ create_server() # gets srv_2k9 + a public URL
→ 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.
# Don't block your agent waiting for long builds, subscribe to events.
curl -X POST https://api.server4agent.com/webhooks \
-H "Authorization: Bearer $AGENTSERVER_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.