Skip to content

Commit 41ed9f8

Browse files
Add ATXP MCP server integration for image, video, and browse tools (#1)
- Integrate image.mcp.atxp.ai for image generation capabilities - Integrate video.mcp.atxp.ai for video creation from text prompts - Integrate browse.mcp.atxp.ai for web browsing and screenshot capabilities - Use ATXP proxy URLs to avoid per-request charges - Initialize MCP servers on first chat message - Enhanced system prompt to describe new capabilities - Updated README with MCP tool documentation and example prompts This implements ATXP-409 and enhances the template created in ATXP-405 with advanced MCP capabilities that demonstrate the power of the ATXP platform for building AI agents. Fixes ATXP-405 Fixes ATXP-409 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent eb1319c commit 41ed9f8

2 files changed

Lines changed: 88 additions & 5 deletions

File tree

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,44 @@ A starter template for building AI-powered chat agents using Cloudflare's Agent
1111
- 💬 Interactive chat interface with AI
1212
- 🛠️ Built-in tool system with human-in-the-loop confirmation
1313
- 📅 Advanced task scheduling (one-time, delayed, and recurring via cron)
14+
- 🎨 **Image Generation** - Create images from natural language descriptions
15+
- 🎬 **Video Creation** - Generate videos from text prompts with realistic styles
16+
- 🌐 **Web Browsing** - Browse websites, capture screenshots, and extract information
1417
- 🌓 Dark/Light theme support
1518
- ⚡️ Real-time streaming responses
1619
- 🔄 State management and chat history
1720
- 🎨 Modern, responsive UI
1821

22+
## MCP Tool Capabilities
23+
24+
This starter automatically connects to ATXP MCP (Model Context Protocol) servers when configured with an `ATXP_CONNECTION`, providing advanced capabilities:
25+
26+
### 🎨 Image Generation
27+
28+
Create images from natural language descriptions. Try prompts like:
29+
30+
- "Create an image of a sunset over mountains"
31+
- "Generate a logo for a tech startup"
32+
- "Draw a cartoon character with blue hair"
33+
34+
### 🎬 Video Creation
35+
36+
Generate videos from text prompts with various styles. Try prompts like:
37+
38+
- "Create a video of waves crashing on a beach"
39+
- "Generate a timelapse of a city at night"
40+
- "Make a video showing a product rotating"
41+
42+
### 🌐 Web Browsing
43+
44+
Browse websites, capture screenshots, and extract information. Try prompts like:
45+
46+
- "Take a screenshot of example.com"
47+
- "What's on the homepage of github.com?"
48+
- "Extract the main article from this news site"
49+
50+
These capabilities are automatically enabled when you set up your ATXP connection string. No additional configuration required!
51+
1952
## Prerequisites
2053

2154
- Cloudflare account

src/server.ts

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,55 @@ function getATXPModel(env: Env) {
4545
* Chat Agent implementation that handles real-time AI chat interactions
4646
*/
4747
export class Chat extends AIChatAgent<Env> {
48+
private mcpServersInitialized = false;
49+
50+
/**
51+
* Initialize ATXP MCP servers (image, video, browse)
52+
*/
53+
private async initializeMcpServers() {
54+
if (this.mcpServersInitialized) {
55+
return;
56+
}
57+
58+
const atxpConnection =
59+
this.env.ATXP_CONNECTION || process.env.ATXP_CONNECTION;
60+
61+
if (!atxpConnection) {
62+
console.warn(
63+
"ATXP_CONNECTION not set, skipping MCP server initialization"
64+
);
65+
return;
66+
}
67+
68+
const callbackHost = "https://accounts.atxp.ai";
69+
const mcpServers = [
70+
{ name: "image", server: "image.mcp.atxp.ai" },
71+
{ name: "video", server: "video.mcp.atxp.ai" },
72+
{ name: "browse", server: "browse.mcp.atxp.ai" }
73+
];
74+
75+
for (const { name, server } of mcpServers) {
76+
const proxyUrl = `${atxpConnection}&server=${server}`;
77+
try {
78+
await this.addMcpServer(name, proxyUrl, callbackHost, "agents");
79+
console.log(`Successfully connected to ${name} MCP server`);
80+
} catch (error) {
81+
console.error(`Failed to connect to ${name} MCP server:`, error);
82+
}
83+
}
84+
85+
this.mcpServersInitialized = true;
86+
}
87+
4888
/**
4989
* Handles incoming chat messages and manages the response stream
5090
*/
5191
async onChatMessage(
5292
onFinish: StreamTextOnFinishCallback<ToolSet>,
5393
_options?: { abortSignal?: AbortSignal }
5494
) {
55-
// const mcpConnection = await this.mcp.connect(
56-
// "https://path-to-mcp-server/sse"
57-
// );
95+
// Initialize MCP servers on first message
96+
await this.initializeMcpServers();
5897

5998
// Collect all tools, including MCP tools
6099
const allTools = {
@@ -80,11 +119,22 @@ export class Chat extends AIChatAgent<Env> {
80119
const model = getATXPModel(this.env);
81120

82121
const result = streamText({
83-
system: `You are a helpful assistant that can do various tasks...
122+
system: `You are a helpful assistant with advanced capabilities including:
123+
124+
**Image Generation**: Create images from natural language descriptions using the image tools
125+
**Video Creation**: Generate videos from text prompts with realistic styles using the video tools
126+
**Web Browsing**: Browse websites, capture screenshots, extract information, and automate web tasks using the browse tools
127+
**Task Scheduling**: Schedule tasks for future execution
84128
85129
${getSchedulePrompt({ date: new Date() })}
86130
87-
If the user asks to schedule a task, use the schedule tool to schedule the task.
131+
When users request:
132+
- Image creation: Use the available image generation tools
133+
- Video creation: Use the available video generation tools
134+
- Website information or screenshots: Use the browse tools
135+
- Future task execution: Use the schedule tool
136+
137+
Be creative and helpful in using these capabilities to assist the user!
88138
`,
89139

90140
messages: convertToModelMessages(processedMessages),

0 commit comments

Comments
 (0)