Files
Benjamin Taylor 9c07a74ee2 feat(examples): add a managed Channel host to the mcp-apps starter
The agent is runtime-hosted rather than behind a URL, and its MCP middlewares are
part of its definition, so both move into app/agent.ts together.
2026-08-02 00:37:58 -05:00

36 lines
916 B
TypeScript

import { BuiltInAgent } from "@copilotkit/runtime/v2";
import { MCPAppsMiddleware } from "@ag-ui/mcp-apps-middleware";
/**
* Builds this starter's agent.
*
* The agent is hosted by the runtime itself — there is no agent server behind a
* URL. The MCP middlewares are part of the agent's definition, so they are
* applied here rather than at the mount: a Channel driving an agent without them
* would silently lose its MCP tools.
*/
export function createDefaultAgent(): BuiltInAgent {
const middlewares = [
new MCPAppsMiddleware({
mcpServers: [
{
type: "http",
url: "http://localhost:3108/mcp",
serverId: "threejs",
},
],
}),
];
const agent = new BuiltInAgent({
model: "openai/gpt-4o",
prompt: "You are a helpful assistant.",
});
for (const middleware of middlewares) {
agent.use(middleware);
}
return agent;
}