const tool = {
name: "echo_context",
description: "Echo a short prompt with source context for smoke testing.",
inputSchema: {
type: "object",
properties: {
prompt: { type: "string" },
source: { type: "string" }
},
required: ["prompt"]
}
};
function json(body: unknown, status = 200) {
return new Response(JSON.stringify(body), {
status,
headers: {
"content-type": "application/json",
"access-control-allow-origin": "*"
}
});
}
function metadata(origin: string) {
return {
name: "Tiny Context Agent",
description:
"MCP-compatible context echo agent for The Spawn first-run testing. It exposes one safe echo_context tool, returns deterministic text, and is meant to verify metadata, endpoint liveness, and tool-call behavior before building a production agent.",
image: `${origin}/icon.svg`,
x402Support: false,
services: [
{
name: "MCP",
endpoint: `${origin}/mcp`,
version: "2025-06-18",
description: "JSON-RPC MCP endpoint with initialize, tools/list, and tools/call support.",
mcpTools: ["echo_context"]
},
{
name: "web",
endpoint: origin,
description: "Human-readable status endpoint."
}
]
};
}
async function handleMcp(request: Request) {
const message = (await request.json()) as any;
const id = message.id ?? null;
if (message.method === "initialize") {
return json({
jsonrpc: "2.0",
id,
result: {
protocolVersion: "2025-06-18",
capabilities: { tools: {} },
serverInfo: { name: "tiny-context-agent", version: "0.1.0" }
}
});
}
if (message.method === "tools/list") {
return json({
jsonrpc: "2.0",
id,
result: { tools: [tool] }
});
}
if (message.method === "tools/call") {
const args = message.params?.arguments ?? {};
if (message.params?.name !== "echo_context") {
return json({
jsonrpc: "2.0",
id,
error: { code: -32602, message: "Unknown tool" }
}, 400);
}
return json({
jsonrpc: "2.0",
id,
result: {
content: [
{
type: "text",
text: `prompt=${args.prompt}; source=${args.source ?? "not-provided"}`
}
]
}
});
}
return json({
jsonrpc: "2.0",
id,
error: { code: -32601, message: "Method not found" }
}, 404);
}
export default {
async fetch(request: Request): Promise<Response> {
const url = new URL(request.url);
const origin = url.origin;
if (request.method === "OPTIONS") {
return new Response(null, {
headers: {
"access-control-allow-origin": "*",
"access-control-allow-methods": "GET,POST,OPTIONS",
"access-control-allow-headers": "content-type,accept"
}
});
}
if (request.method === "GET" && url.pathname === "/") {
return new Response("Tiny Context Agent is online.\n", {
headers: { "content-type": "text/plain; charset=utf-8" }
});
}
if (request.method === "GET" && url.pathname === "/.well-known/agent.json") {
return json(metadata(origin));
}
if (request.method === "GET" && url.pathname === "/icon.svg") {
return new Response(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><rect width="128" height="128" rx="24" fill="#0f172a"/><path d="M32 70h64M40 46h48M48 94h32" stroke="#31d0aa" stroke-width="10" stroke-linecap="round"/></svg>',
{ headers: { "content-type": "image/svg+xml" } }
);
}
if (request.method === "POST" && url.pathname === "/mcp") {
return handleMcp(request);
}
return new Response("Not found\n", { status: 404 });
}
};