This project demonstrates the use of the Model Context Protocol (MCP) with LangGraph to create workflows that generate prompts and AI-generated images based on a given topic. The project consists of three main files: app.py, graph.py, and ai-image-gen-pipeline.py. Each file showcases different aspects of using MCP with LangGraph, including the LangGraph Functional API, Graph API, and integration within Open WebUI Pipelines. These scripts utilize the Comfy MCP Server to generate AI image prompts and AI images.
This script demonstrates the use of the LangGraph Functional API along with Human-in-the-Loop (HIL) interaction to generate prompts and AI-generated images based on a given topic. The workflow includes user feedback to approve generated prompts before generating the corresponding image.
- Dependencies:
aiosqlite,langgraph,langgraph-checkpoint-sqlite,mcp[cli]. - Functions:
run_tool(tool: str, args: dict) -> str: Runs a tool using the MCP server.generate_prompt(topic: str) -> str: Generates a prompt for a given topic.generate_image(prompt: str) -> str: Generates an image based on a given prompt.get_feedback(topic: str, prompt: str) -> str: Collects user feedback on the generated prompt.workflow_func(saver): Defines the workflow function with checkpointing.
- Main Function:
- Parses command-line arguments to get thread id and optionally the topic and feedback.
- Initializes the workflow and runs it, based on the provided input.
This script demonstrates the use of the LangGraph Graph API along with Human-in-the-Loop (HIL) interaction to generate prompts and AI-generated images based on a given topic. The workflow includes user feedback to approve generated prompts before generating the corresponding image.