This document outlines the implementation plan for "Janus agents" in Srcbook - agentic entities that can both utilize external capabilities through an MCP client and serve functionality to other clients like an MCP server.
The implementation will focus specifically on exposing Srcbook's web app generation functionality as MCP tools, allowing other MCP clients to leverage Srcbook's generative AI capabilities.
The Janus agent will consist of:
- MCP Server Manager: A class that manages MCP server instances, handles connections, and registers tools.
- App Generation Tool: A tool that wraps Srcbook's existing app generation functionality.
- Server Entry Point: The main entry point for the MCP server.
- Configuration: Settings for the MCP server.
File: packages/api/mcp/server/server-manager.mts
This class will:
- Initialize the MCP server using the SDK
- Register tools with the server
- Handle connections using the appropriate transport (stdio)
- Manage server lifecycle (start, stop)
- Implement proper error handling and logging
File: packages/api/mcp/server/tools/generate-app.mts
This tool will:
- Define a clear input schema using Zod
- Wrap the existing
generateAppfunction - Format responses according to MCP specifications
- Handle errors properly
- Include appropriate annotations (e.g., destructiveHint: false)
File: packages/api/mcp/server/index.mts
This module will:
- Export functions to start/stop the server
- Handle transport setup and connection management
- Initialize the server manager
File: packages/api/mcp/config.mts
This module will:
- Define configuration options for the MCP server
- Load and validate configuration
File: packages/api/server.mts
Update to:
- Initialize both MCP client and server components
- Ensure proper resource management and error handling
File: packages/api/srcbook_mcp_config.json
Add configuration section for the MCP server.
- Validate all inputs using Zod schemas
- Implement proper error handling
- Sanitize file paths and system commands
- Use appropriate authentication for remote connections
- Follow the principle of least privilege
- Test the MCP server in isolation using the MCP Inspector tool
- Test integration with the existing MCP client
- Test the app generation tool with various inputs
- Test error handling and edge cases
- Add more tools for other Srcbook capabilities
- Implement resource templates for accessing project files
- Add support for prompts
- Implement streaming responses for long-running operations