Skip to content

Agent Zero AI framework

#84 - Projects support in MCP, A2A, API

decid1be7f25319f
diff --git a/docs/connectivity.md b/docs/connectivity.md
index 8cfbe250e..a6f465eab 100644
--- a/docs/connectivity.md
+++ b/docs/connectivity.md
@@ -25,6 +25,7 @@ Send messages to Agent Zero and receive responses. Supports text messages, file
* `message` (string, required): The message to send
* `attachments` (array, optional): Array of `{filename, base64}` objects
* `lifetime_hours` (number, optional): Chat lifetime in hours (default: 24)
+* `project` (string, optional): Project name to activate (only on first message)
**Headers:**
* `X-API-KEY` (required)
@@ -169,6 +170,63 @@ async function sendWithAttachment() {
sendWithAttachment();
```
+#### Project Usage Example
+
+```javascript
+// Working with projects
+async function sendMessageWithProject() {
+ try {
+ // First message - activate project
+ const response = await fetch('YOUR_AGENT_ZERO_URL/api_message', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-API-KEY': 'YOUR_API_KEY'
+ },
+ body: JSON.stringify({
+ message: "Analyze the project structure",
+ project: "my-web-app" // Activates this project
+ })
+ });
+
+ const data = await response.json();
+
+ if (response.ok) {
+ console.log('✅ Project activated!');
+ console.log('Context ID:', data.context_id);
+ console.log('Response:', data.response);
+
+ // Continue conversation - project already set
+ const followUp = await fetch('YOUR_AGENT_ZERO_URL/api_message', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-API-KEY': 'YOUR_API_KEY'
+ },
+ body: JSON.stringify({
+ context_id: data.context_id,
+ message: "What files are in the project?"
+ // Do NOT include project field here - already set on first message
+ })
+ });
+
+ const followUpData = await followUp.json();
+ console.log('Follow-up response:', followUpData.response);
+ return followUpData;
+ } else {
+ console.error('❌ Error:', data.error);
+ return null;
+ }
+ } catch (error) {
+ console.error('❌ Request failed:', error);
+ return null;
+ }
+}
+
+// Call the function
+sendMessageWithProject();
+```
+
---
## `GET/POST /api_log_get`
@@ -568,6 +626,30 @@ Below is an example of a `mcp.json` configuration file that a client could use t
}
```
+### Project Support in MCP
+
+You can specify a project for MCP connections by including it in the URL path:
+
+```json
+{
+ "mcpServers": {
+ "agent-zero-with-project": {
+ "type": "sse",
+ "url": "YOUR_AGENT_ZERO_URL/mcp/t-YOUR_API_TOKEN/p-my-project-name/sse"
+ },
+ "agent-zero-http-with-project": {
+ "type": "streamable-http",
+ "url": "YOUR_AGENT_ZERO_URL/mcp/t-YOUR_API_TOKEN/p-my-project-name/http/"
+ }
+ }
+}
+```
+
+When a project is specified in the URL:
+- All new chats will be created within that project context
+- The agent will have access to project-specific instructions, knowledge, and file structure
+- Attempting to use an existing chat_id from a different project will result in an error
+
---
## A2A (Agent-to-Agent) Connectivity
@@ -583,3 +665,14 @@ To connect another agent to your Agent Zero instance, use the following URL form
```
YOUR_AGENT_ZERO_URL/a2a/t-YOUR_API_TOKEN
```
+
+To connect with a specific project active:
+
+```
+YOUR_AGENT_ZERO_URL/a2a/t-YOUR_API_TOKEN/p-PROJECT_NAME
+```
+
+When a project is specified:
+- All A2A conversations will run in the context of that project
+- The agent will have access to project-specific resources, instructions, and knowledge
+- This enables project-isolated agent-to-agent communication
diff --git a/python/api/api_message.py b/python/api/api_message.py
index 385d556dd..f955024d2 100644
--- a/python/api/api_message.py
+++ b/python/api/api_message.py
@@ -3,7 +3,7 @@ import os
from datetime import datetime, timedelta
from agent import AgentContext, UserMessage, AgentContextType
from python.helpers.api import ApiHandler, Request, Response
-from python.helpers import files
+from python.helpers import files, projects
from python.helpers.print_style import PrintStyle
from werkzeug.utils import secure_filename
from initialize import initialize_agent
@@ -33,6 +33,7 @@ class ApiMessage(ApiHandler):
message = input.get("message", "")
attachments = input.get("attachments", [])
lifetime_hours = input.get("lifetime_hours", 24) # Default 24 hours
+ project = input.get("project", None) # Optional project name
if not message:
return Response('{"error": "Message is required"}', status=400, mimetype="application/json")
@@ -71,12 +72,24 @@ class ApiMessage(ApiHandler):
context = AgentContext.use(context_id)
if not context:
return Response('{"error": "Context not found"}', status=404, mimetype="application/json")
+
+ # Validation: if project is provided but context already has different project
+ existing_project = context.get_data(projects.CONTEXT_DATA_KEY_PROJECT)
+ if project and existing_project and existing_project != project:
+ return Response('{"error": "Project can only be set on first message"}', status=400, mimetype="application/json")
else:
config = initialize_agent()
context = AgentContext(config=config, type=AgentContextType.USER)
AgentContext.use(context.id)
context_id = context.id
+ # Activate project if provided
+ if project:
+ try:
+ projects.activate_project(context_id, project)
+ except Exception as e:
+ return Response(f'{{"error": "Failed to activate project: {str(e)}"}}', status=400, mimetype="application/json")
+
# Update chat lifetime
with self._cleanup_lock:
self._chat_lifetimes[context_id] = datetime.now() + timedelta(hours=lifetime_hours)
diff --git a/python/helpers/fasta2a_server.py b/python/helpers/fasta2a_server.py
index d058d1b68..50d4a4908 100644
--- a/python/helpers/fasta2a_server.py
+++ b/python/helpers/fasta2a_server.py
@@ -5,8 +5,9 @@ import atexit
from typing import Any, List
import contextlib
import threading
+import contextvars
-from python.helpers import settings
+from python.helpers import settings, projects
from starlette.requests import Request
# Local imports
@@ -60,6 +61,9 @@ except ImportError: # pragma: no cover – library not installed
_PRINTER = PrintStyle(italic=True, font_color="purple", padding=False)
+# Context variable to store project name from URL
+_a2a_project_name: contextvars.ContextVar[str | None] = contextvars.ContextVar('a2a_project_name', default=None)
+
class AgentZeroWorker(Worker): # type: ignore[misc]
"""Agent Zero implementation of FastA2A Worker."""
@@ -84,6 +88,16 @@ class AgentZeroWorker(Worker): # type: ignore[misc]
cfg = initialize_agent()
context = AgentContext(cfg, type=AgentContextType.BACKGROUND)
+ # Activate project if specified in URL
+ project_name = _a2a_project_name.get()
+ if project_name:
+ try:
+ projects.activate_project(context.id, project_name)
+ _PRINTER.print(f"[A2A] Activated project: {project_name}")
+ except Exception as e:
+ _PRINTER.print(f"[A2A] Failed to activate project: {e}")
+ raise Exception(f"Failed to activate project: {str(e)}")
+
# Log user message so it appears instantly in UI chat window
context.log.log(
type="user", # type: ignore[arg-type]
@@ -424,6 +438,9 @@ class DynamicA2AProxy:
if path.startswith('/a2a'):
path = path[4:] # Remove '/a2a' prefix
+ # Initialize project name
+ project_name = None
+
# Check if path matches token pattern /t-{token}/
if path.startswith('/t-'):
# Extract token from path
@@ -431,6 +448,14 @@ class DynamicA2AProxy:
path_parts = path[3:].split('/', 1) # Remove '/t-' prefix
request_token = path_parts[0]
remaining_path = '/' + path_parts[1] if len(path_parts) > 1 else '/'
+
+ # Check for project pattern /p-{project}/
+ if remaining_path.startswith('/p-'):
+ project_parts = remaining_path[3:].split('/', 1)
+ if project_parts[0]:
+ project_name = project_parts[0]
+ remaining_path = '/' + project_parts[1] if len(project_parts) > 1 else '/'
+ _PRINTER.print(f"[A2A] Extracted project from URL: {project_name}")
else:
request_token = path[3:]
remaining_path = '/'
@@ -452,6 +477,9 @@ class DynamicA2AProxy:
})
return
+ # Set project name in context variable for use by worker
+ _a2a_project_name.set(project_name)
+
# Update scope with cleaned path
scope = dict(scope)
scope['path'] = remaining_path
diff --git a/python/helpers/mcp_server.py b/python/helpers/mcp_server.py
index 4c080da69..466cc2277 100644
--- a/python/helpers/mcp_server.py
+++ b/python/helpers/mcp_server.py
@@ -3,23 +3,31 @@ from typing import Annotated, Literal, Union
from urllib.parse import urlparse
from openai import BaseModel
from pydantic import Field
-from fastmcp import FastMCP
+from fastmcp import FastMCP # type: ignore
+import contextvars
from agent import AgentContext, AgentContextType, UserMessage
from python.helpers.persist_chat import remove_chat
from initialize import initialize_agent
from python.helpers.print_style import PrintStyle
-from python.helpers import settings
+from python.helpers import settings, projects
from starlette.middleware import Middleware
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.exceptions import HTTPException as StarletteHTTPException
from starlette.types import ASGIApp, Receive, Scope, Send
-from fastmcp.server.http import create_sse_app
+from fastmcp.server.http import create_sse_app # type: ignore
from starlette.requests import Request
import threading
_PRINTER = PrintStyle(italic=True, font_color="green", padding=False)
+# Context variable to store project name from URL (per-request)
+_mcp_project_name: contextvars.ContextVar[str | None] = contextvars.ContextVar('mcp_project_name', default=None)
+
+# Session storage for project names (persists across SSE tool calls)
+# Key: connection identifier, Value: project name
+_mcp_project_sessions: dict[str, str | None] = {}
+_mcp_session_lock = threading.Lock()
mcp_server: FastMCP = FastMCP(
name="Agent Zero integrated MCP Server",
@@ -127,6 +135,25 @@ async def send_message(
description="The response from the remote Agent Zero Instance", title="response"
),
]:
+ # Get project name from session storage (persists across SSE connection)
+ # First try context variable (for HTTP requests), then session storage (for SSE tool calls)
+ project_name = _mcp_project_name.get()
+
+ # If not in context variable, try session storage using current token
+ if not project_name:
+ cfg = settings.get_settings()
+ current_token = cfg.get("mcp_server_token")
+ _PRINTER.print(f"[MCP] send_message - Looking for project. Token: '{current_token}' (type: {type(current_token).__name__})")
+ if current_token:
+ with _mcp_session_lock:
+ _PRINTER.print(f"[MCP] Session storage keys: {list(_mcp_project_sessions.keys())}")
+ _PRINTER.print(f"[MCP] Session storage: {_mcp_project_sessions}")
+ project_name = _mcp_project_sessions.get(current_token)
+ if project_name:
+ _PRINTER.print(f"[MCP] Retrieved project from session: {project_name}")
+ else:
+ _PRINTER.print(f"[MCP] No project found in session for token: {current_token}")
+
context: AgentContext | None = None
if chat_id:
context = AgentContext.get(chat_id)
@@ -137,10 +164,27 @@ async def send_message(
# whether we should save the chat or delete it afterwards
# If we continue a conversation, it must be persistent
persistent_chat = True
+
+ # Validation: if project is in URL but context has different project
+ if project_name:
+ existing_project = context.get_data(projects.CONTEXT_DATA_KEY_PROJECT)
+ if existing_project and existing_project != project_name:
+ return ToolError(
+ error=f"Chat belongs to project '{existing_project}' but URL specifies '{project_name}'",
+ chat_id=chat_id
+ )
else:
config = initialize_agent()
context = AgentContext(config=config, type=AgentContextType.BACKGROUND)
+ # Activate project if specified in URL
+ if project_name:
+ try:
+ projects.activate_project(context.id, project_name)
+ _PRINTER.print(f"[MCP] Activated project: {project_name}")
+ except Exception as e:
+ return ToolError(error=f"Failed to activate project: {str(e)}", chat_id="")
+
if not message:
return ToolError(
error="Message is required", chat_id=context.id if persistent_chat else ""
@@ -325,10 +369,10 @@ class DynamicMcpProxy:
def _create_custom_http_app(self, streamable_http_path, auth_server_provider, auth_settings, debug, routes):
"""Create a custom HTTP app that manages the session manager manually."""
- from fastmcp.server.http import setup_auth_middleware_and_routes, create_base_app
- from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
+ from fastmcp.server.http import setup_auth_middleware_and_routes, create_base_app # type: ignore
+ from mcp.server.streamable_http_manager import StreamableHTTPSessionManager # type: ignore
from starlette.routing import Mount
- from mcp.server.auth.middleware.bearer_auth import RequireAuthMiddleware
+ from mcp.server.auth.middleware.bearer_auth import RequireAuthMiddleware # type: ignore
import anyio
server_routes = []
@@ -408,12 +452,47 @@ class DynamicMcpProxy:
# Route based on path
path = scope.get("path", "")
- if f"/t-{self.token}/sse" in path or f"t-{self.token}/messages" in path:
- # Route to SSE app
- await sse_app(scope, receive, send)
- elif f"/t-{self.token}/http" in path:
- # Route to HTTP app
- await http_app(scope, receive, send)
+ # Check for token in path (with or without project segment)
+ # Patterns: /t-{token}/sse, /t-{token}/p-{project}/sse, etc.
+ has_token = f"/t-{self.token}/" in path or f"t-{self.token}/" in path
+
+ # Extract project from path BEFORE cleaning (for session storage)
+ project_name = None
+ if "/p-" in path:
+ try:
+ parts = path.split("/p-")
+ if len(parts) > 1:
+ project_part = parts[1].split("/")[0]
+ if project_part:
+ project_name = project_part
+ _PRINTER.print(f"[MCP] Proxy extracted project from URL: {project_name}")
+ except Exception as e:
+ _PRINTER.print(f"[MCP] Failed to extract project in proxy: {e}")
+
+ # Store project in session (persists across SSE connection)
+ if self.token and project_name:
+ with _mcp_session_lock:
+ _mcp_project_sessions[self.token] = project_name
+ _PRINTER.print(f"[MCP] Stored project '{project_name}' for token '{self.token}' (type: {type(self.token).__name__}) in proxy")
+
+ # Strip project segment from path if present (e.g., /p-project_name/)
+ # This is needed because the underlying MCP apps were configured without project paths
+ cleaned_path = path
+ if "/p-" in path:
+ # Remove /p-{project}/ segment: /t-TOKEN/p-PROJECT/sse -> /t-TOKEN/sse
+ import re
+ cleaned_path = re.sub(r'/p-[^/]+/', '/', path)
+
+ # Update scope with cleaned path for the underlying app
+ modified_scope = dict(scope)
+ modified_scope['path'] = cleaned_path
+
+ if has_token and ("/sse" in path or "/messages" in path):
+ # Route to SSE app with cleaned path
+ await sse_app(modified_scope, receive, send)
+ elif has_token and "/http" in path:
+ # Route to HTTP app with cleaned path
+ await http_app(modified_scope, receive, send)
else:
raise StarletteHTTPException(
status_code=403, detail="MCP forbidden"
@@ -430,4 +509,40 @@ async def mcp_middleware(request: Request, call_next):
status_code=403, detail="MCP server is disabled in settings."
)
+ # Extract project from URL path if present (pattern: /mcp/t-{token}/p-{project}/...)
+ path = request.url.path
+ project_name = None
+ token = None
+
+ # Extract token from path
+ if "/t-" in path:
+ token_parts = path.split("/t-")
+ if len(token_parts) > 1:
+ token = token_parts[1].split("/")[0]
+
+ # Extract project if present
+ if "/p-" in path:
+ try:
+ parts = path.split("/p-")
+ if len(parts) > 1:
+ project_part = parts[1].split("/")[0]
+ if project_part:
+ project_name = project_part
+ _PRINTER.print(f"[MCP] Extracted project from URL: {project_name}")
+ except Exception as e:
+ _PRINTER.print(f"[MCP] Failed to extract project from URL: {e}")
+
+ # Debug logging
+ _PRINTER.print(f"[MCP] Middleware - Path: {path}, Token: {token}, Project: {project_name}")
+
+ # Store project in session dict ONLY if we found one (don't overwrite with None)
+ # The proxy already handles project extraction before path cleaning
+ if token and project_name:
+ with _mcp_session_lock:
+ _mcp_project_sessions[token] = project_name
+ _PRINTER.print(f"[MCP] Middleware stored project '{project_name}' for token session")
+
+ # Also set in context variable for backwards compatibility
+ _mcp_project_name.set(project_name)
+
return await call_next(request)
diff --git a/webui/components/settings/a2a/a2a-connection.html b/webui/components/settings/a2a/a2a-connection.html
index c71c575f2..fc640a68d 100644
--- a/webui/components/settings/a2a/a2a-connection.html
+++ b/webui/components/settings/a2a/a2a-connection.html
@@ -21,10 +21,21 @@
</div>
<h3>A2A Connection URL</h3>
+
+ <!-- Project selector -->
+ <div style="margin: 16px 0;">
+ <label for="a2a-project-select" style="display: block; margin-bottom: 8px; color: var(--color-text-primary);">
+ Select Project (optional):
+ </label>
+ <select id="a2a-project-select" style="width: 100%; padding: 8px; background-color: var(--color-bg-secondary); color: var(--color-text-primary); border: 1px solid var(--color-border); border-radius: 4px;">
+ <option value="">No project</option>
+ </select>
+ </div>
+
<div id="a2a-connection-example"></div>
<script>
- setTimeout(() => {
+ setTimeout(async () => {
const url = window.location.origin;
// Try to get a2a_token first, fallback to mcp_server_token
let tokenField = null;
@@ -33,15 +44,49 @@
tokenField = allFields.find(f => f.id === 'a2a_token') || allFields.find(f => f.id === 'mcp_server_token');
} catch (e) { }
const token = tokenField ? tokenField.value : '';
- const connectionUrl = `${url}/a2a/t-${token}`;
+ // Fetch and populate projects
+ const projectSelect = document.getElementById('a2a-project-select');
+ try {
+ const response = await fetch('/projects', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ action: 'list' })
+ });
+ const data = await response.json();
+ if (data.ok && data.data) {
+ data.data.forEach(project => {
+ const option = document.createElement('option');
+ option.value = project.name;
+ option.textContent = project.title || project.name;
+ projectSelect.appendChild(option);
+ });
+ }
+ } catch (e) {
+ console.error('Failed to load projects:', e);
+ }
+
+ // Function to update URL based on selected project
+ function updateConnectionUrl() {
+ const selectedProject = projectSelect.value;
+ let connectionUrl = `${url}/a2a/t-${token}`;
+ if (selectedProject) {
+ connectionUrl += `/p-${selectedProject}`;
+ }
+ editor.setValue(connectionUrl);
+ editor.clearSelection();
+ }
+
+ // Initialize editor
const editor = ace.edit("a2a-connection-example");
const dark = localStorage.getItem("darkMode");
editor.setTheme(dark !== "false" ? "ace/theme/github_dark" : "ace/theme/tomorrow");
editor.session.setMode("ace/mode/text");
- editor.setValue(connectionUrl);
- editor.clearSelection();
+ updateConnectionUrl();
editor.setReadOnly(true);
+
+ // Update URL when project selection changes
+ projectSelect.addEventListener('change', updateConnectionUrl);
}, 0);
</script>
</div>
diff --git a/webui/components/settings/external/api-examples.html b/webui/components/settings/external/api-examples.html
index 08569a1e9..615594682 100644
--- a/webui/components/settings/external/api-examples.html
+++ b/webui/components/settings/external/api-examples.html
@@ -34,7 +34,8 @@
• <code>context_id</code> (string, optional): Existing chat context ID<br>
• <code>message</code> (string, required): The message to send<br>
• <code>attachments</code> (array, optional): Array of {filename, base64} objects<br>
- • <code>lifetime_hours</code> (number, optional): Chat lifetime in hours (default: 24)
+ • <code>lifetime_hours</code> (number, optional): Chat lifetime in hours (default: 24)<br>
+ • <code>project</code> (string, optional): Project name to activate (only on first message)
</p>
<p style="margin: 0; color: var(--color-text-secondary); font-size: 14px;">
<strong>Headers:</strong> <code>X-API-KEY</code> (required), <code>Content-Type: application/json</code>
@@ -52,6 +53,9 @@
<h4>File Attachment Example</h4>
<div id="api-attachment-example"></div>
+
+ <h4>Project Usage Example</h4>
+ <div id="api-project-example"></div>
</div>
<!-- Section 2: api_log_get Endpoint -->
@@ -602,11 +606,66 @@ async function attachmentWorkflow() {
// Run the complete workflow
attachmentWorkflow();`;
+ // Project usage example
+ const projectExample = `// Working with projects
+async function sendMessageWithProject() {
+ try {
+ // First message - activate project
+ const response = await fetch('${url}/api_message', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-API-KEY': '${token}'
+ },
+ body: JSON.stringify({
+ message: "Analyze the project structure",
+ project: "my-web-app" // Activates this project
+ })
+ });
+
+ const data = await response.json();
+
+ if (response.ok) {
+ console.log('✅ Project activated!');
+ console.log('Context ID:', data.context_id);
+ console.log('Response:', data.response);
+
+ // Continue conversation - project already set
+ const followUp = await fetch('${url}/api_message', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-API-KEY': '${token}'
+ },
+ body: JSON.stringify({
+ context_id: data.context_id,
+ message: "What files are in the project?"
+ // Do NOT include project field here - already set on first message
+ })
+ });
+
+ const followUpData = await followUp.json();
+ console.log('Follow-up response:', followUpData.response);
+ return followUpData;
+ } else {
+ console.error('❌ Error:', data.error);
+ return null;
+ }
+ } catch (error) {
+ console.error('❌ Request failed:', error);
+ return null;
+ }
+}
+
+// Call the function
+sendMessageWithProject();`;
+
// Initialize ACE editors
const editors = [
{ id: "api-basic-example", content: basicExample },
{ id: "api-continuation-example", content: continuationExample },
{ id: "api-attachment-example", content: attachmentExample },
+ { id: "api-project-example", content: projectExample },
{ id: "api-log-get-example", content: logGetExample },
{ id: "api-log-post-example", content: logPostExample },
{ id: "api-terminate-example", content: terminateExample },
@@ -635,6 +694,7 @@ attachmentWorkflow();`;
#api-basic-example,
#api-continuation-example,
#api-attachment-example,
+ #api-project-example,
#api-log-get-example,
#api-log-post-example,
#api-terminate-example,
diff --git a/webui/components/settings/mcp/server/example.html b/webui/components/settings/mcp/server/example.html
index 4a1e033a6..db50343f4 100644
--- a/webui/components/settings/mcp/server/example.html
+++ b/webui/components/settings/mcp/server/example.html
@@ -20,37 +20,78 @@
</div>
<h3>Example MCP Server Configuration JSON</h3>
+
+ <!-- Project selector -->
+ <div style="margin: 16px 0;">
+ <label for="mcp-project-select" style="display: block; margin-bottom: 8px; color: var(--color-text-primary);">
+ Select Project (optional):
+ </label>
+ <select id="mcp-project-select" style="width: 100%; padding: 8px; background-color: var(--color-bg-secondary); color: var(--color-text-primary); border: 1px solid var(--color-border); border-radius: 4px;">
+ <option value="">No project</option>
+ </select>
+ </div>
+
<div id="mcp-server-example"></div>
<script>
- setTimeout(() => {
+ setTimeout(async () => {
const url = window.location.origin;
const token = settingsModalProxy.settings.sections.filter(x => x.id == "mcp_server")[0].fields.filter(x => x.id == "mcp_server_token")[0].value;
- const jsonExample = JSON.stringify({
- "mcpServers":
- {
- "agent-zero": {
- "type": "sse",
- "url": `${url}/mcp/t-${token}/sse`
- },
- "agent-zero-http": {
- "type": "streamable-http",
- "url": `${url}/mcp/t-${token}/http`
- }
+
+ // Fetch and populate projects
+ const projectSelect = document.getElementById('mcp-project-select');
+ try {
+ const response = await fetch('/projects', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ action: 'list' })
+ });
+ const data = await response.json();
+ if (data.ok && data.data) {
+ data.data.forEach(project => {
+ const option = document.createElement('option');
+ option.value = project.name;
+ option.textContent = project.title || project.name;
+ projectSelect.appendChild(option);
+ });
}
- }, null, 2);
+ } catch (e) {
+ console.error('Failed to load projects:', e);
+ }
+
+ // Function to update JSON based on selected project
+ function updateMcpConfig() {
+ const selectedProject = projectSelect.value;
+ const projectPath = selectedProject ? `/p-${selectedProject}` : '';
+ const jsonExample = JSON.stringify({
+ "mcpServers":
+ {
+ "agent-zero": {
+ "type": "sse",
+ "url": `${url}/mcp/t-${token}${projectPath}/sse`
+ },
+ "agent-zero-http": {
+ "type": "streamable-http",
+ "url": `${url}/mcp/t-${token}${projectPath}/http`
+ }
+ }
+ }, null, 2);
+
+ editor.setValue(jsonExample);
+ editor.clearSelection();
+ }
+
+ // Initialize editor
const editor = ace.edit("mcp-server-example");
const dark = localStorage.getItem("darkMode");
- if (dark != "false") {
- editor.setTheme("ace/theme/github_dark");
- } else {
- editor.setTheme("ace/theme/tomorrow");
- }
+ editor.setTheme(dark !== "false" ? "ace/theme/github_dark" : "ace/theme/tomorrow");
editor.session.setMode("ace/mode/json");
- editor.setValue(jsonExample);
- editor.clearSelection();
+ updateMcpConfig();
editor.setReadOnly(true);
+
+ // Update JSON when project selection changes
+ projectSelect.addEventListener('change', updateMcpConfig);
}, 0);
</script>
<!-- </template> -->