Skip to main content
Glama
README.md
# ๐Ÿš€ Dev.to AI Agent using MCP & OpenAI Agents SDK

An intelligent Dev.to assistant powered by the OpenAI Agents SDK, Model Context Protocol (MCP), Chainlit, and OpenRouter LLMs.

This project demonstrates how AI Agents can dynamically discover and execute tools exposed through a custom MCP Server, enabling natural language interactions with Dev.to. Users can search articles, explore trending content, retrieve author-specific posts, and even generate and publish new blog articlesโ€”all through a conversational interface.

---

## ๐Ÿ“– Overview

The Dev.to AI Agent acts as an intelligent bridge between users and the Dev.to platform.

Instead of hardcoding API calls directly into the application, all Dev.to operations are exposed as MCP tools through a custom MCP Server. The AI Agent analyzes user intent, discovers available tools, selects the appropriate tool, executes it, and returns a summarized response.

### Example Use Cases

* Browse latest Dev.to articles
* Discover trending content
* Search articles by keyword
* Find articles by tag
* Explore articles by author
* Retrieve article details
* Generate and publish new blog posts

---

## โœจ Features

* ๐Ÿค– AI-powered Dev.to assistant
* ๐Ÿ”Œ MCP-based tool architecture
* ๐Ÿ“ฐ Browse latest Dev.to articles
* ๐Ÿ”ฅ Discover trending articles
* ๐Ÿท๏ธ Search articles by tags
* ๐Ÿ” Keyword-based article search
* ๐Ÿ‘ค Find articles by author
* โœ๏ธ AI-generated article creation
* โšก Fully asynchronous architecture
* ๐Ÿ’ฌ Modern conversational UI with Chainlit
* ๐Ÿง  Intelligent tool selection using OpenAI Agents SDK
* ๐Ÿš€ Easily extensible MCP tool ecosystem

---

## ๐Ÿ—๏ธ Architecture

```text
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      Chainlit UI         โ”‚
โ”‚       (app.py)           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   OpenAI Agents SDK      โ”‚
โ”‚     (mcp_agent.py)       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚    Dev.to AI Agent       โ”‚
โ”‚  Instruction Driven      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   MCP Server (STDIO)     โ”‚
โ”‚      (server.py)         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      MCP Tools           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚      Dev.to APIs         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
```

---

## ๐Ÿ”„ End-to-End Flow

```text
User
 โ”‚
 โ–ผ
Chainlit Chat Interface
 โ”‚
 โ–ผ
OpenAI Agent SDK
 โ”‚
 โ–ผ
Dev.to AI Agent
 โ”‚
 โ–ผ
MCP Tool Discovery
 โ”‚
 โ–ผ
Tool Selection
 โ”‚
 โ–ผ
MCP Tool Execution
 โ”‚
 โ–ผ
Dev.to API
 โ”‚
 โ–ผ
Agent Summarization
 โ”‚
 โ–ผ
Response Displayed in UI
```

---

## ๐Ÿ’ฌ User Experience

The application uses Chainlit to provide a modern conversational interface.

### Starter Prompts

Users can quickly explore the agent using built-in starter suggestions:

* ๐Ÿ“ฐ Latest Articles
* ๐Ÿ”ฅ Top Trending Articles
* ๐Ÿ Python Articles
* ๐Ÿค– AI Articles
* ๐Ÿ” Search Articles
* โœ๏ธ Generate New Article

These prompts help users immediately understand the capabilities of the agent.

---

## โš™๏ธ Agent Execution Lifecycle

Every request follows the same execution workflow:

```text
1. User sends a message

2. Chainlit receives the request

3. Thinking indicator is displayed

4. AI Agent is invoked

5. MCP Server starts

6. Agent discovers available tools

7. Agent selects the appropriate tool

8. MCP Tool executes

9. Dev.to API returns data

10. Agent summarizes results

11. Response is displayed to the user
```

---

## ๐Ÿ› ๏ธ Technology Stack

| Technology                   | Purpose                              |
| ---------------------------- | ------------------------------------ |
| Python                       | Core programming language            |
| Chainlit                     | Conversational AI interface          |
| OpenAI Agents SDK            | Agent orchestration and tool calling |
| MCP (Model Context Protocol) | Tool discovery and execution         |
| OpenRouter                   | LLM provider                         |
| Qwen 3 235B                  | Foundation language model            |
| AsyncIO                      | Asynchronous execution               |
| MCPServerStdio               | MCP communication layer              |
| dotenv                       | Environment variable management      |

---

## ๐Ÿ“‚ Project Structure

```text
project/
โ”‚
โ”œโ”€โ”€ app.py
โ”œโ”€โ”€ mcp_agent.py
โ”œโ”€โ”€ server.py
โ”œโ”€โ”€ .env
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md
```

---

# ๐Ÿ“„ File Breakdown

## app.py

This file contains the Chainlit user interface and handles all user interactions.

### Responsibilities

* Displays the chat interface
* Registers starter prompts
* Receives user messages
* Displays agent progress
* Shows final responses

---

### set_starters()

Registers predefined starter prompts displayed on an empty chat screen.

#### Purpose

* Improve user onboarding
* Demonstrate available capabilities
* Provide quick actions

---

### on_chat_start()

Triggered whenever a new conversation begins.

#### Responsibilities

* Displays welcome message
* Introduces the assistant
* Explains supported actions

---

### on_message()

Main message processing function.

#### Responsibilities

* Receives user input
* Displays thinking indicator
* Invokes AI agent
* Displays final response

#### Flow

```text
User Message
      โ”‚
      โ–ผ
on_message()
      โ”‚
      โ–ผ
agent_main()
      โ”‚
      โ–ผ
Agent Execution
      โ”‚
      โ–ผ
Tool Execution
      โ”‚
      โ–ผ
Response Returned
      โ”‚
      โ–ผ
UI Updated
```

---

## mcp_agent.py

This file contains the AI Agent orchestration logic.

It acts as the bridge between:

* User Queries
* Language Model
* MCP Server
* MCP Tools

---

### setup_dev_agent()

Creates and configures the Dev.to Agent.

#### Responsibilities

* Defines agent instructions
* Connects MCP Server
* Attaches language model
* Configures tool usage behavior

The agent receives detailed instructions describing:

* Which tool should be used
* When it should be used
* How results should be formatted

This improves tool-calling reliability and response quality.

---

### main()

Primary execution entry point for all requests.

#### Responsibilities

* Starts MCP Server
* Creates agent instance
* Executes agent workflow
* Returns final output

#### Flow

```text
User Query
    โ”‚
    โ–ผ
Start MCP Server
    โ”‚
    โ–ผ
Create Agent
    โ”‚
    โ–ผ
Run Agent
    โ”‚
    โ–ผ
Tool Execution
    โ”‚
    โ–ผ
Final Response
```

---

## server.py

This file contains the MCP Server implementation.

The server exposes Dev.to functionality as MCP-compatible tools that can be dynamically discovered and used by the AI Agent.

---

## ๐Ÿ”Œ MCP Tools

The MCP Server exposes multiple tools to the agent.

### get_latest_articles()

Returns the latest articles from Dev.to.

---

### get_top_articles()

Returns trending or top-performing articles.

---

### get_articles_by_tag(tag)

Retrieves articles belonging to a specific tag.

#### Example

```text
Python
JavaScript
AI
MachineLearning
Agents
```

---

### search_articles(query)

Performs keyword-based article search.

#### Example

```text
LangChain
Agentic AI
OpenAI
MCP
```

---

### get_articles_by_username(username)

Returns articles published by a specific author.

---

### get_article_details(article_id)

Retrieves detailed information for a specific article.

---

### create_article()

Creates and publishes a new Dev.to article.

#### Parameters

```python
title
body_markdown
tags
published
```

---

## ๐Ÿค– Intelligent Tool Selection

The AI Agent uses instruction-based reasoning to select the correct MCP tool.

### Example 1

User:

```text
Show me the latest articles
```

Agent:

```text
Calls get_latest_articles()
```

---

### Example 2

User:

```text
Search for Agentic AI
```

Agent:

```text
Calls search_articles("Agentic AI")
```

---

### Example 3

User:

```text
Show articles by ThePracticalDev
```

Agent:

```text
Calls get_articles_by_username()
```

---

### Example 4

User:

```text
Create an article about MCP Servers
```

Agent:

```text
Generates content
      โ†“
Calls create_article()
```

---

## ๐Ÿ”Œ Why MCP?

This project intentionally uses Model Context Protocol (MCP) rather than directly integrating APIs into the agent.

### Benefits

* Standardized tool interface
* Dynamic tool discovery
* Decoupled architecture
* Easier maintenance
* Reusable integrations
* Future multi-agent compatibility
* Scalable tool ecosystem

New tools can be added to the MCP Server without changing the core agent implementation.

---

## ๐Ÿ“ธ Screenshots

### Home Screen

```md
Add screenshot here
```

### Agent Execution

```md
Add screenshot here
```

### Article Generation

```md
Add screenshot here
```

---

## ๐Ÿš€ Example Queries

```text
Show me the latest Dev.to articles
```

```text
Show me the top trending articles
```

```text
Find articles about Python
```

```text
Find articles about AI agents
```

```text
Search for machine learning articles
```

```text
Show articles by ThePracticalDev
```

```text
Create a blog about the latest advancements in Agentic AI
```

---

## ๐Ÿ”ฎ Future Enhancements

* Multi-agent workflows
* Medium integration
* Hashnode integration
* Memory-enabled agents
* Blog review agent
* SEO optimization agent
* Research assistant agent
* Content planning agent
* Analytics dashboard
* Streaming responses
* Human approval workflows

---

## ๐ŸŽฏ Learning Outcomes

This project demonstrates practical implementation of:

* OpenAI Agents SDK
* MCP (Model Context Protocol)
* Tool Calling Agents
* Agent Instructions Engineering
* Async Python Development
* OpenRouter Integration
* Chainlit Applications
* AI-Powered Content Automation
* Agentic AI Workflows

---

## ๐Ÿš€ Getting Started

### Clone the Repository

```bash
git clone https://github.com/Dharshini195/Blog-MCP.git
cd Blog-MCP
```

### Install Dependencies

```bash
pip install -r requirements.txt
```

### Configure Environment Variables

Create a `.env` file:

```env
OPENROUTER_API_KEY=your_openrouter_api_key
```

### Run the Application

```bash
chainlit run app.py
```

Open the provided local URL and start chatting with the Dev.to Assistant.

---

## ๐Ÿ“œ License

This project is intended for educational, experimentation, and learning purposes. Feel free to fork, modify, and extend it for your own MCP and Agent Engineering projects.